| Index: chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/sync/SyncTestUtil.java
|
| diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/sync/SyncTestUtil.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/sync/SyncTestUtil.java
|
| index 75fba1c62c5d10d0482a3a7211073af050d10b0a..54932da3f750614cfd0618f2360a28b71b893398 100644
|
| --- a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/sync/SyncTestUtil.java
|
| +++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/sync/SyncTestUtil.java
|
| @@ -6,6 +6,7 @@
|
|
|
| import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
|
|
|
| +import android.accounts.Account;
|
| import android.content.Context;
|
| import android.util.Pair;
|
|
|
| @@ -17,6 +18,7 @@
|
| import org.chromium.chrome.browser.sync.ProfileSyncService;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| import org.chromium.content.browser.test.util.CriteriaHelper;
|
| +import org.chromium.sync.signin.ChromeSigninController;
|
| import org.json.JSONArray;
|
| import org.json.JSONException;
|
| import org.json.JSONObject;
|
| @@ -40,18 +42,6 @@
|
| private SyncTestUtil() {}
|
|
|
| /**
|
| - * Returns whether sync is requested.
|
| - */
|
| - public static boolean isSyncRequested() {
|
| - return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean>() {
|
| - @Override
|
| - public Boolean call() {
|
| - return ProfileSyncService.get().isSyncRequested();
|
| - }
|
| - });
|
| - }
|
| -
|
| - /**
|
| * Returns whether sync is active.
|
| */
|
| public static boolean isSyncActive() {
|
| @@ -61,18 +51,6 @@
|
| return ProfileSyncService.get().isSyncActive();
|
| }
|
| });
|
| - }
|
| -
|
| - /**
|
| - * Waits for sync to become active.
|
| - */
|
| - public static void waitForSyncActive() throws InterruptedException {
|
| - CriteriaHelper.pollUiThread(new Criteria("Timed out waiting for sync to become active.") {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - return ProfileSyncService.get().isSyncActive();
|
| - }
|
| - }, TIMEOUT_MS, INTERVAL_MS);
|
| }
|
|
|
| /**
|
| @@ -90,6 +68,13 @@
|
| }
|
|
|
| /**
|
| + * Verifies that sync is signed out.
|
| + */
|
| + public static void verifySyncIsSignedOut() {
|
| + Assert.assertTrue(isSyncOff());
|
| + }
|
| +
|
| + /**
|
| * Triggers a sync cycle.
|
| */
|
| public static void triggerSync() {
|
| @@ -126,6 +111,54 @@
|
| @Override
|
| public Long call() {
|
| return ProfileSyncService.get().getLastSyncedTimeForTest();
|
| + }
|
| + });
|
| + }
|
| +
|
| + /**
|
| + * Waits for sync to become active.
|
| + */
|
| + public static void waitForSyncActive() throws InterruptedException {
|
| + CriteriaHelper.pollUiThread(new Criteria(
|
| + "Timed out waiting for sync to become active.") {
|
| + @Override
|
| + public boolean isSatisfied() {
|
| + return ProfileSyncService.get().isSyncActive();
|
| + }
|
| + }, TIMEOUT_MS, INTERVAL_MS);
|
| + }
|
| +
|
| + /**
|
| + * Verifies that the sync is active and signed in with the given account.
|
| + */
|
| + public static void verifySyncIsActiveForAccount(Context context, Account account)
|
| + throws InterruptedException {
|
| + waitForSyncActive();
|
| + triggerSyncAndWaitForCompletion();
|
| + verifySignedInWithAccount(context, account);
|
| + }
|
| +
|
| + /**
|
| + * Makes sure that sync is enabled with the correct account.
|
| + */
|
| + public static void verifySignedInWithAccount(Context context, Account account) {
|
| + Assert.assertEquals(account, ChromeSigninController.get(context).getSignedInUser());
|
| + }
|
| +
|
| + /**
|
| + * Verifies that the sync is off but signed in with the account.
|
| + */
|
| + public static void verifySyncIsDisabled(Context context, Account account) {
|
| + Assert.assertTrue("Expected sync to be disabled.", isSyncOff());
|
| + verifySignedInWithAccount(context, account);
|
| + }
|
| +
|
| + private static boolean isSyncOff() {
|
| + return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean>() {
|
| + @Override
|
| + public Boolean call() {
|
| + ProfileSyncService syncService = ProfileSyncService.get();
|
| + return !syncService.isBackendInitialized() && !syncService.isSyncRequested();
|
| }
|
| });
|
| }
|
|
|