Index: chrome/android/javatests/src/org/chromium/chrome/browser/sync/ChromeBrowserSyncAdapterTest.java |
diff --git a/chrome/android/javatests_shell/src/org/chromium/chrome/browser/sync/ChromiumSyncAdapterTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/sync/ChromeBrowserSyncAdapterTest.java |
similarity index 53% |
copy from chrome/android/javatests_shell/src/org/chromium/chrome/browser/sync/ChromiumSyncAdapterTest.java |
copy to chrome/android/javatests/src/org/chromium/chrome/browser/sync/ChromeBrowserSyncAdapterTest.java |
index a79a14e56ecf880c1a319f5441a4a812a683752c..c56a6bca5ed0bf2b31442e533f5e8f991bee402d 100644 |
--- a/chrome/android/javatests_shell/src/org/chromium/chrome/browser/sync/ChromiumSyncAdapterTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/sync/ChromeBrowserSyncAdapterTest.java |
@@ -1,4 +1,4 @@ |
-// Copyright 2013 The Chromium Authors. All rights reserved. |
+// 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. |
@@ -6,31 +6,56 @@ package org.chromium.chrome.browser.sync; |
import android.accounts.Account; |
import android.app.Application; |
-import android.content.ContentResolver; |
import android.content.Context; |
+import android.content.Intent; |
import android.content.SyncResult; |
import android.os.Bundle; |
import android.test.suitebuilder.annotation.MediumTest; |
-import com.google.protos.ipc.invalidation.Types; |
- |
+import org.chromium.base.ApplicationStatus; |
import org.chromium.base.CommandLine; |
import org.chromium.base.test.util.Feature; |
-import org.chromium.chrome.shell.ChromeShellTestBase; |
+import org.chromium.chrome.browser.ChromeActivity; |
+import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
+import org.chromium.content.browser.test.util.Criteria; |
+import org.chromium.content.browser.test.util.CriteriaHelper; |
import org.chromium.sync.AndroidSyncSettings; |
import org.chromium.sync.signin.AccountManagerHelper; |
/** |
- * Tests for ChromiumSyncAdapter. |
+ * Tests for ChromeBrowserSyncAdapter. |
+ * |
+ * TODO(nyquist) Remove this class when Chrome sync starts up the same way as the testshell. |
*/ |
-public class ChromiumSyncAdapterTest extends ChromeShellTestBase { |
+public class ChromeBrowserSyncAdapterTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
private static final Account TEST_ACCOUNT = |
AccountManagerHelper.createAccountFromName("test@gmail.com"); |
+ private static final long WAIT_FOR_LAUNCHER_MS = 10 * 1000; |
+ private static final long POLL_INTERVAL_MS = 100; |
+ |
+ private TestChromeSyncAdapter mSyncAdapter; |
+ |
+ public ChromeBrowserSyncAdapterTest() { |
+ super(ChromeActivity.class); |
+ } |
+ |
+ private static void sendChromeToBackground(Context context) throws InterruptedException { |
+ Intent intent = new Intent(Intent.ACTION_MAIN); |
+ intent.addCategory(Intent.CATEGORY_HOME); |
+ context.startActivity(intent); |
+ |
+ assertTrue("Activity should have been sent to background", |
+ CriteriaHelper.pollForCriteria(new Criteria() { |
+ @Override |
+ public boolean isSatisfied() { |
+ return !ApplicationStatus.hasVisibleActivities(); |
+ } |
+ }, WAIT_FOR_LAUNCHER_MS, POLL_INTERVAL_MS)); |
+ } |
- private TestChromiumSyncAdapter mSyncAdapter; |
- private static class TestChromiumSyncAdapter extends ChromiumSyncAdapter { |
+ private static class TestChromeSyncAdapter extends ChromiumSyncAdapter { |
private boolean mSyncRequested; |
private boolean mSyncRequestedForAllTypes; |
private int mObjectSource; |
@@ -38,13 +63,13 @@ public class ChromiumSyncAdapterTest extends ChromeShellTestBase { |
private long mVersion; |
private String mPayload; |
- public TestChromiumSyncAdapter(Context context, Application application) { |
+ public TestChromeSyncAdapter(Context context, Application application) { |
super(context, application); |
} |
@Override |
protected boolean useAsyncStartup() { |
- return true; |
+ return false; |
} |
@Override |
@@ -65,44 +90,40 @@ public class ChromiumSyncAdapterTest extends ChromeShellTestBase { |
@Override |
protected void setUp() throws Exception { |
super.setUp(); |
- launchChromeShellWithBlankPage(); |
- mSyncAdapter = new TestChromiumSyncAdapter(getInstrumentation().getTargetContext(), |
+ mSyncAdapter = new TestChromeSyncAdapter(getInstrumentation().getTargetContext(), |
getActivity().getApplication()); |
} |
- public void performSyncWithBundle(Bundle bundle) { |
- mSyncAdapter.onPerformSync(TEST_ACCOUNT, bundle, |
- AndroidSyncSettings.getContractAuthority(getActivity()), |
- null, new SyncResult()); |
+ @Override |
+ public void startMainActivity() throws InterruptedException { |
+ startMainActivityOnBlankPage(); |
} |
@MediumTest |
@Feature({"Sync"}) |
public void testRequestSyncNoInvalidationData() { |
- performSyncWithBundle(new Bundle()); |
+ SyncResult syncResult = new SyncResult(); |
+ mSyncAdapter.onPerformSync(TEST_ACCOUNT, new Bundle(), |
+ AndroidSyncSettings.getContractAuthority(getActivity()), null, syncResult); |
assertTrue(mSyncAdapter.mSyncRequestedForAllTypes); |
assertFalse(mSyncAdapter.mSyncRequested); |
assertTrue(CommandLine.isInitialized()); |
} |
- private void testRequestSyncSpecificDataType(boolean withObjectSource) { |
+ @MediumTest |
+ @Feature({"Sync"}) |
+ public void testRequestSyncSpecificDataType() { |
+ SyncResult syncResult = new SyncResult(); |
Bundle extras = new Bundle(); |
- if (withObjectSource) { |
- extras.putInt(ChromiumSyncAdapter.INVALIDATION_OBJECT_SOURCE_KEY, 61); |
- } |
+ extras.putInt(ChromiumSyncAdapter.INVALIDATION_OBJECT_SOURCE_KEY, 65); |
extras.putString(ChromiumSyncAdapter.INVALIDATION_OBJECT_ID_KEY, "objectid_value"); |
extras.putLong(ChromiumSyncAdapter.INVALIDATION_VERSION_KEY, 42); |
extras.putString(ChromiumSyncAdapter.INVALIDATION_PAYLOAD_KEY, "payload_value"); |
- |
- performSyncWithBundle(extras); |
- |
+ mSyncAdapter.onPerformSync(TEST_ACCOUNT, extras, |
+ AndroidSyncSettings.getContractAuthority(getActivity()), null, syncResult); |
assertFalse(mSyncAdapter.mSyncRequestedForAllTypes); |
assertTrue(mSyncAdapter.mSyncRequested); |
- if (withObjectSource) { |
- assertEquals(61, mSyncAdapter.mObjectSource); |
- } else { |
- assertEquals(Types.ObjectSource.CHROME_SYNC, mSyncAdapter.mObjectSource); |
- } |
+ assertEquals(65, mSyncAdapter.mObjectSource); |
assertEquals("objectid_value", mSyncAdapter.mObjectId); |
assertEquals(42, mSyncAdapter.mVersion); |
assertEquals("payload_value", mSyncAdapter.mPayload); |
@@ -111,32 +132,11 @@ public class ChromiumSyncAdapterTest extends ChromeShellTestBase { |
@MediumTest |
@Feature({"Sync"}) |
- public void testRequestSyncSpecificDataType() { |
- testRequestSyncSpecificDataType(true /* withObjectSource */); |
- } |
- |
- @MediumTest |
- @Feature({"Sync"}) |
- public void testRequestSyncSpecificDataType_withoutObjectSource() { |
- testRequestSyncSpecificDataType(false /* withObjectSource */); |
- } |
- |
- @MediumTest |
- @Feature({"Sync"}) |
public void testRequestSyncWhenChromeInBackground() throws InterruptedException { |
- DelayedSyncControllerTest.sendChromeToBackground(getActivity()); |
- performSyncWithBundle(new Bundle()); |
- assertFalse(mSyncAdapter.mSyncRequestedForAllTypes); |
- assertFalse(mSyncAdapter.mSyncRequested); |
- assertTrue(CommandLine.isInitialized()); |
- } |
- |
- @MediumTest |
- @Feature({"Sync"}) |
- public void testRequestInitializeSync() throws InterruptedException { |
- Bundle extras = new Bundle(); |
- extras.putBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, true); |
- performSyncWithBundle(extras); |
+ sendChromeToBackground(getActivity()); |
+ SyncResult syncResult = new SyncResult(); |
+ mSyncAdapter.onPerformSync(TEST_ACCOUNT, new Bundle(), |
+ AndroidSyncSettings.getContractAuthority(getActivity()), null, syncResult); |
assertFalse(mSyncAdapter.mSyncRequestedForAllTypes); |
assertFalse(mSyncAdapter.mSyncRequested); |
} |