Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Unified Diff: chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/sync/SyncTestUtil.java

Issue 2019363002: Revert of [Sync] Clean up Android test code a bit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@signin-test
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/signin/SigninTestUtil.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
});
}
« no previous file with comments | « chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/signin/SigninTestUtil.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698