This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't toggle sync on/off on account rename.
More detais in: crbug.com/524675. What I have discovered is that AccountManager keeps the whole syncable and sync-enabled setting across rename events. We can leverage this by making this the source of truth for sync setting. That way, no matter when then actual sign-in occurs, it can simply check the master setting and decide if sync should be on or off without racing against sync service or the setting's cache. I tested this and it works 5/5 times. I don't know how good this solution is but at least the success rate is higher the current implementation of check right before signout. BUG=524675 Review URL: https://codereview.chromium.org/1454563002 Cr-Commit-Position: refs/heads/master@{#366225} (cherry picked from commit ab28048) Review URL: https://codereview.chromium.org/1537113003 . Cr-Commit-Position: refs/branch-heads/2564@{#401} Cr-Branched-From: 1283eca-refs/heads/master@{#359700}
- Loading branch information
Alan Leung
committed
Dec 19, 2015
1 parent
6307ed6
commit 3b46839
Showing
7 changed files
with
123 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,14 +11,21 @@ | |
|
||
import org.chromium.base.ActivityState; | ||
import org.chromium.base.ApplicationStatus; | ||
import org.chromium.base.ThreadUtils; | ||
import org.chromium.base.test.util.Feature; | ||
import org.chromium.chrome.browser.ChromeActivity; | ||
import org.chromium.chrome.browser.signin.AccountIdProvider; | ||
import org.chromium.chrome.browser.signin.AccountTrackerService; | ||
import org.chromium.chrome.browser.signin.SigninHelper; | ||
import org.chromium.chrome.test.util.browser.signin.MockChangeEventChecker; | ||
import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; | ||
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; | ||
import org.chromium.content.browser.ContentViewCore; | ||
import org.chromium.content.browser.test.util.Criteria; | ||
import org.chromium.content.browser.test.util.CriteriaHelper; | ||
import org.chromium.content.browser.test.util.JavaScriptUtils; | ||
import org.chromium.sync.AndroidSyncSettings; | ||
import org.chromium.sync.signin.ChromeSigninController; | ||
|
||
import java.util.concurrent.TimeoutException; | ||
|
||
|
@@ -122,6 +129,51 @@ public void testSignInAndOut() throws InterruptedException { | |
SyncTestUtil.verifySyncIsActiveForAccount(mContext, account); | ||
} | ||
|
||
@LargeTest | ||
@Feature({"Sync"}) | ||
public void testRename() throws InterruptedException { | ||
// The two accounts object that would represent the account rename. | ||
final Account oldAccount = setUpTestAccountAndSignInToSync(); | ||
final Account newAccount = SigninTestUtil.get().addTestAccount("[email protected]"); | ||
|
||
ThreadUtils.runOnUiThreadBlocking(new Runnable() { | ||
@Override | ||
public void run() { | ||
// First, we force a call to updateAccountRenameData. In the real world, | ||
// this should be called by one of our broadcast listener that listens to | ||
// real account rename events instead of the mocks. | ||
MockChangeEventChecker eventChecker = new MockChangeEventChecker(); | ||
eventChecker.insertRenameEvent(oldAccount.name, newAccount.name); | ||
SigninHelper.updateAccountRenameData(mContext, eventChecker); | ||
|
||
// Tell the fake content resolver that a rename had happen and copy over the sync | ||
// settings. This would normally be done by the SystemSyncContentResolver. | ||
mSyncContentResolver.renameAccounts( | ||
oldAccount, newAccount, AndroidSyncSettings.getContractAuthority(mContext)); | ||
|
||
// Inform the AccountTracker, these would normally be done by account validation | ||
// or signin. We will only be calling the testing versions of it. | ||
AccountIdProvider provider = AccountIdProvider.getInstance(); | ||
String[] accountNames = {newAccount.name}; | ||
String[] accountIds = {provider.getAccountId(mContext, accountNames[0])}; | ||
AccountTrackerService.get(mContext).syncForceRefreshForTest( | ||
accountIds, accountNames); | ||
|
||
// Starts the rename process. Normally, this is triggered by the broadcast | ||
// listener as well. | ||
SigninHelper.get(mContext).validateAccountSettings(true); | ||
} | ||
}); | ||
|
||
CriteriaHelper.pollForCriteria(new Criteria() { | ||
@Override | ||
public boolean isSatisfied() { | ||
return newAccount.equals(ChromeSigninController.get(mContext).getSignedInUser()); | ||
} | ||
}); | ||
SyncTestUtil.verifySyncIsActiveForAccount(mContext, newAccount); | ||
} | ||
|
||
@LargeTest | ||
@Feature({"Sync"}) | ||
public void testStopAndStartSync() throws InterruptedException { | ||
|
44 changes: 44 additions & 0 deletions
44
...id/javatests/src/org/chromium/chrome/test/util/browser/signin/MockChangeEventChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.chrome.test.util.browser.signin; | ||
|
||
import android.content.Context; | ||
|
||
import org.chromium.chrome.browser.signin.SigninHelper; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Fake AccountChangeEventChecker for testing. | ||
*/ | ||
public final class MockChangeEventChecker | ||
implements SigninHelper.AccountChangeEventChecker { | ||
private Map<String, List<String>> mEvents = | ||
new HashMap<String, List<String>>(); | ||
|
||
@Override | ||
public List<String> getAccountChangeEvents( | ||
Context context, int index, String accountName) { | ||
List<String> eventsList = getEventList(accountName); | ||
return eventsList.subList(index, eventsList.size()); | ||
} | ||
|
||
public void insertRenameEvent(String from, String to) { | ||
List<String> eventsList = getEventList(from); | ||
eventsList.add(to); | ||
} | ||
|
||
private List<String> getEventList(String account) { | ||
List<String> eventsList = mEvents.get(account); | ||
if (eventsList == null) { | ||
eventsList = new ArrayList<String>(); | ||
mEvents.put(account, eventsList); | ||
} | ||
return eventsList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters