Commit b7b11b3d authored by Yoland Yan's avatar Yoland Yan Committed by Commit Bot

Convert sync shell tests

For more on JUnit4 migration, please check src/testing/android/docs/junit4.md

Bug: 640116
Change-Id: I119a6edf80a0de750d0b7ee61e3b748321dd20dc
Reviewed-on: https://chromium-review.googlesource.com/618301
Commit-Queue: Yoland Yan <yolandyan@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarNicolas Zea <zea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501480}
parent ba61b3d8
...@@ -1133,7 +1133,7 @@ instrumentation_test_apk("chrome_sync_shell_test_apk") { ...@@ -1133,7 +1133,7 @@ instrumentation_test_apk("chrome_sync_shell_test_apk") {
"sync_shell/javatests/src/org/chromium/chrome/browser/sync/OpenTabsTest.java", "sync_shell/javatests/src/org/chromium/chrome/browser/sync/OpenTabsTest.java",
"sync_shell/javatests/src/org/chromium/chrome/browser/sync/SyncCustomizationFragmentTest.java", "sync_shell/javatests/src/org/chromium/chrome/browser/sync/SyncCustomizationFragmentTest.java",
"sync_shell/javatests/src/org/chromium/chrome/browser/sync/SyncTest.java", "sync_shell/javatests/src/org/chromium/chrome/browser/sync/SyncTest.java",
"sync_shell/javatests/src/org/chromium/chrome/browser/sync/SyncTestBase.java", "sync_shell/javatests/src/org/chromium/chrome/browser/sync/SyncTestRule.java",
"sync_shell/javatests/src/org/chromium/chrome/browser/sync/TypedUrlsTest.java", "sync_shell/javatests/src/org/chromium/chrome/browser/sync/TypedUrlsTest.java",
"sync_shell/javatests/src/org/chromium/chrome/browser/sync/ui/PassphraseTypeDialogFragmentTest.java", "sync_shell/javatests/src/org/chromium/chrome/browser/sync/ui/PassphraseTypeDialogFragmentTest.java",
] ]
...@@ -1152,8 +1152,10 @@ instrumentation_test_apk("chrome_sync_shell_test_apk") { ...@@ -1152,8 +1152,10 @@ instrumentation_test_apk("chrome_sync_shell_test_apk") {
"//components/sync/android:sync_java", "//components/sync/android:sync_java",
"//content/public/android:content_java", "//content/public/android:content_java",
"//content/public/test/android:content_java_test_support", "//content/public/test/android:content_java_test_support",
"//third_party/android_support_test_runner:rules_java",
"//third_party/android_support_test_runner:runner_java", "//third_party/android_support_test_runner:runner_java",
"//third_party/android_tools:android_support_v7_appcompat_java", "//third_party/android_tools:android_support_v7_appcompat_java",
"//third_party/junit",
"//ui/android:ui_java", "//ui/android:ui_java",
] ]
proguard_enabled = !is_java_debug proguard_enabled = !is_java_debug
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
android:label="ChromeSyncShellTest"> android:label="ChromeSyncShellTest">
<uses-library android:name="android.test.runner" /> <uses-library android:name="android.test.runner" />
</application> </application>
<instrumentation android:name="org.chromium.base.test.BaseChromiumAndroidJUnitRunner"
android:targetPackage="{{manifest_package}}"
android:label="Tests for {{manifest_package}}"
chromium-junit4="true"/>
<instrumentation android:name="org.chromium.chrome.test.ChromeInstrumentationTestRunner" <instrumentation android:name="org.chromium.chrome.test.ChromeInstrumentationTestRunner"
android:targetPackage="{{manifest_package}}" android:targetPackage="{{manifest_package}}"
android:label="Tests for {{manifest_package}}"/> android:label="Tests for {{manifest_package}}"/>
......
...@@ -9,9 +9,19 @@ import android.util.Pair; ...@@ -9,9 +9,19 @@ import android.util.Pair;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.sync.SyncTestRule.DataCriteria;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.components.sync.ModelType; import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.protocol.AutofillProfileSpecifics; import org.chromium.components.sync.protocol.AutofillProfileSpecifics;
...@@ -26,8 +36,16 @@ import java.util.concurrent.Callable; ...@@ -26,8 +36,16 @@ import java.util.concurrent.Callable;
/** /**
* Test suite for the autofill profile sync data type. * Test suite for the autofill profile sync data type.
*/ */
@RetryOnFailure // crbug.com/637448 @RunWith(ChromeJUnit4ClassRunner.class)
public class AutofillTest extends SyncTestBase { @CommandLineFlags.Add({
ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
})
@RetryOnFailure // crbug.com/637448
public class AutofillTest {
@Rule
public SyncTestRule mSyncTestRule = new SyncTestRule();
private static final String TAG = "AutofillTest"; private static final String TAG = "AutofillTest";
private static final String AUTOFILL_TYPE = "Autofill Profiles"; private static final String AUTOFILL_TYPE = "Autofill Profiles";
...@@ -65,16 +83,16 @@ public class AutofillTest extends SyncTestBase { ...@@ -65,16 +83,16 @@ public class AutofillTest extends SyncTestBase {
} }
} }
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); mSyncTestRule.setUpTestAccountAndSignIn();
setUpTestAccountAndSignIn();
// Make sure the initial state is clean. // Make sure the initial state is clean.
assertClientAutofillProfileCount(0); assertClientAutofillProfileCount(0);
assertServerAutofillProfileCountWithName(0, STREET); assertServerAutofillProfileCountWithName(0, STREET);
} }
// Test syncing an autofill profile from server to client. // Test syncing an autofill profile from server to client.
@Test
@LargeTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testDownloadAutofill() throws Exception { public void testDownloadAutofill() throws Exception {
...@@ -84,16 +102,17 @@ public class AutofillTest extends SyncTestBase { ...@@ -84,16 +102,17 @@ public class AutofillTest extends SyncTestBase {
// Verify data synced to client. // Verify data synced to client.
List<Autofill> autofills = getClientAutofillProfiles(); List<Autofill> autofills = getClientAutofillProfiles();
assertEquals("Only the injected autofill should exist on the client.", Assert.assertEquals(
1, autofills.size()); "Only the injected autofill should exist on the client.", 1, autofills.size());
Autofill autofill = autofills.get(0); Autofill autofill = autofills.get(0);
assertEquals("The wrong street was found for the address.", STREET, autofill.street); Assert.assertEquals("The wrong street was found for the address.", STREET, autofill.street);
assertEquals("The wrong city was found for the autofill.", CITY, autofill.city); Assert.assertEquals("The wrong city was found for the autofill.", CITY, autofill.city);
assertEquals("The wrong state was found for the autofill.", STATE, autofill.state); Assert.assertEquals("The wrong state was found for the autofill.", STATE, autofill.state);
assertEquals("The wrong zip was found for the autofill.", ZIP, autofill.zip); Assert.assertEquals("The wrong zip was found for the autofill.", ZIP, autofill.zip);
} }
// Test syncing an autofill profile modification from server to client. // Test syncing an autofill profile modification from server to client.
@Test
@LargeTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testDownloadAutofillModification() throws Exception { public void testDownloadAutofillModification() throws Exception {
...@@ -105,9 +124,9 @@ public class AutofillTest extends SyncTestBase { ...@@ -105,9 +124,9 @@ public class AutofillTest extends SyncTestBase {
// Modify on server, sync, and verify modification locally. // Modify on server, sync, and verify modification locally.
Autofill autofill = getClientAutofillProfiles().get(0); Autofill autofill = getClientAutofillProfiles().get(0);
specifics.autofillProfile.addressHomeCity = MODIFIED_CITY; specifics.autofillProfile.addressHomeCity = MODIFIED_CITY;
mFakeServerHelper.modifyEntitySpecifics(autofill.id, specifics); mSyncTestRule.getFakeServerHelper().modifyEntitySpecifics(autofill.id, specifics);
SyncTestUtil.triggerSync(); SyncTestUtil.triggerSync();
pollInstrumentationThread(new ClientAutofillCriteria() { mSyncTestRule.pollInstrumentationThread(new ClientAutofillCriteria() {
@Override @Override
public boolean isSatisfied(List<Autofill> autofills) { public boolean isSatisfied(List<Autofill> autofills) {
Autofill modifiedAutofill = autofills.get(0); Autofill modifiedAutofill = autofills.get(0);
...@@ -117,6 +136,7 @@ public class AutofillTest extends SyncTestBase { ...@@ -117,6 +136,7 @@ public class AutofillTest extends SyncTestBase {
} }
// Test syncing an autofill profile deletion from server to client. // Test syncing an autofill profile deletion from server to client.
@Test
@LargeTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testDownloadDeletedAutofill() throws Exception { public void testDownloadDeletedAutofill() throws Exception {
...@@ -127,17 +147,18 @@ public class AutofillTest extends SyncTestBase { ...@@ -127,17 +147,18 @@ public class AutofillTest extends SyncTestBase {
// Delete on server, sync, and verify deleted locally. // Delete on server, sync, and verify deleted locally.
Autofill autofill = getClientAutofillProfiles().get(0); Autofill autofill = getClientAutofillProfiles().get(0);
mFakeServerHelper.deleteEntity(autofill.id); mSyncTestRule.getFakeServerHelper().deleteEntity(autofill.id);
SyncTestUtil.triggerSync(); SyncTestUtil.triggerSync();
waitForClientAutofillProfileCount(0); waitForClientAutofillProfileCount(0);
} }
// Test that autofill profiles don't get synced if the data type is disabled. // Test that autofill profiles don't get synced if the data type is disabled.
@Test
@LargeTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testDisabledNoDownloadAutofill() throws Exception { public void testDisabledNoDownloadAutofill() throws Exception {
// The AUTOFILL type here controls both AUTOFILL and AUTOFILL_PROFILE. // The AUTOFILL type here controls both AUTOFILL and AUTOFILL_PROFILE.
disableDataType(ModelType.AUTOFILL); mSyncTestRule.disableDataType(ModelType.AUTOFILL);
addServerAutofillProfile(STREET, CITY, STATE, ZIP); addServerAutofillProfile(STREET, CITY, STATE, ZIP);
SyncTestUtil.triggerSyncAndWaitForCompletion(); SyncTestUtil.triggerSyncAndWaitForCompletion();
assertClientAutofillProfileCount(0); assertClientAutofillProfileCount(0);
...@@ -154,13 +175,13 @@ public class AutofillTest extends SyncTestBase { ...@@ -154,13 +175,13 @@ public class AutofillTest extends SyncTestBase {
profile.addressHomeState = state; profile.addressHomeState = state;
profile.addressHomeZip = zip; profile.addressHomeZip = zip;
specifics.autofillProfile = profile; specifics.autofillProfile = profile;
mFakeServerHelper.injectUniqueClientEntity(street /* name */, specifics); mSyncTestRule.getFakeServerHelper().injectUniqueClientEntity(street /* name */, specifics);
return specifics; return specifics;
} }
private List<Autofill> getClientAutofillProfiles() throws JSONException { private List<Autofill> getClientAutofillProfiles() throws JSONException {
List<Pair<String, JSONObject>> entities = SyncTestUtil.getLocalData( List<Pair<String, JSONObject>> entities =
mContext, AUTOFILL_TYPE); SyncTestUtil.getLocalData(mSyncTestRule.getTargetContext(), AUTOFILL_TYPE);
List<Autofill> autofills = new ArrayList<Autofill>(entities.size()); List<Autofill> autofills = new ArrayList<Autofill>(entities.size());
for (Pair<String, JSONObject> entity : entities) { for (Pair<String, JSONObject> entity : entities) {
String id = entity.first; String id = entity.first;
...@@ -175,13 +196,13 @@ public class AutofillTest extends SyncTestBase { ...@@ -175,13 +196,13 @@ public class AutofillTest extends SyncTestBase {
} }
private void assertClientAutofillProfileCount(int count) throws JSONException { private void assertClientAutofillProfileCount(int count) throws JSONException {
assertEquals("There should be " + count + " local autofill profiles.", Assert.assertEquals("There should be " + count + " local autofill profiles.", count,
count, SyncTestUtil.getLocalData(mContext, AUTOFILL_TYPE).size()); SyncTestUtil.getLocalData(mSyncTestRule.getTargetContext(), AUTOFILL_TYPE).size());
} }
private void assertServerAutofillProfileCountWithName(int count, String name) { private void assertServerAutofillProfileCountWithName(int count, String name) {
assertTrue("Expected " + count + " server autofill profiles with name " + name + ".", Assert.assertTrue("Expected " + count + " server autofill profiles with name " + name + ".",
mFakeServerHelper.verifyEntityCountByTypeAndName( mSyncTestRule.getFakeServerHelper().verifyEntityCountByTypeAndName(
count, ModelType.AUTOFILL_PROFILE, name)); count, ModelType.AUTOFILL_PROFILE, name));
} }
...@@ -189,7 +210,8 @@ public class AutofillTest extends SyncTestBase { ...@@ -189,7 +210,8 @@ public class AutofillTest extends SyncTestBase {
CriteriaHelper.pollInstrumentationThread(Criteria.equals(count, new Callable<Integer>() { CriteriaHelper.pollInstrumentationThread(Criteria.equals(count, new Callable<Integer>() {
@Override @Override
public Integer call() throws Exception { public Integer call() throws Exception {
return SyncTestUtil.getLocalData(mContext, AUTOFILL_TYPE).size(); return SyncTestUtil.getLocalData(mSyncTestRule.getTargetContext(), AUTOFILL_TYPE)
.size();
} }
}), SyncTestUtil.TIMEOUT_MS, SyncTestUtil.INTERVAL_MS); }), SyncTestUtil.TIMEOUT_MS, SyncTestUtil.INTERVAL_MS);
} }
......
...@@ -11,9 +11,17 @@ import android.app.Instrumentation.ActivityMonitor; ...@@ -11,9 +11,17 @@ import android.app.Instrumentation.ActivityMonitor;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.base.test.util.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
...@@ -26,6 +34,8 @@ import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer; ...@@ -26,6 +34,8 @@ import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer;
import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor; import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor;
import org.chromium.chrome.browser.preferences.Preferences; import org.chromium.chrome.browser.preferences.Preferences;
import org.chromium.chrome.browser.signin.AccountManagementFragment; import org.chromium.chrome.browser.signin.AccountManagementFragment;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ActivityUtils; import org.chromium.chrome.test.util.ActivityUtils;
import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; import org.chromium.chrome.test.util.browser.signin.SigninTestUtil;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
...@@ -37,9 +47,61 @@ import java.util.concurrent.TimeoutException; ...@@ -37,9 +47,61 @@ import java.util.concurrent.TimeoutException;
/** /**
* Tests for the first run experience. * Tests for the first run experience.
*/ */
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add(ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG)
@CommandLineFlags.Remove(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE) @CommandLineFlags.Remove(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)
@RetryOnFailure // crbug.com/637448 @RetryOnFailure // crbug.com/637448
public class FirstRunTest extends SyncTestBase { public class FirstRunTest {
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
@Rule
public SyncTestRule mSyncTestRule = new SyncTestRule() {
@Override
public void startMainActivityForSyncTest() throws Exception {
FirstRunActivity.setObserverForTest(mTestObserver);
// Starts up and waits for the FirstRunActivity to be ready.
// This isn't exactly what startMainActivity is supposed to be doing, but short of a
// refactoring of SyncTestBase to use something other than ChromeTabbedActivity,
// it's the only way to reuse the rest of the setup and initialization code inside of
// it.
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
final Context context = instrumentation.getTargetContext();
// Create an Intent that causes Chrome to run.
final Intent intent = new Intent(TEST_ACTION);
intent.setPackage(context.getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Start the FRE.
final ActivityMonitor freMonitor =
new ActivityMonitor(FirstRunActivity.class.getName(), null, false);
instrumentation.addMonitor(freMonitor);
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
FirstRunFlowSequencer.launch(context, intent, false /* requiresBroadcast */,
false /* preferLightweightFre */);
}
});
// Wait for the FRE to be ready to use.
Activity activity =
freMonitor.waitForActivityWithTimeout(CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
instrumentation.removeMonitor(freMonitor);
Assert.assertTrue(activity instanceof FirstRunActivity);
mActivity = (FirstRunActivity) activity;
try {
mTestObserver.flowIsKnownCallback.waitForCallback(0);
} catch (TimeoutException e) {
Assert.fail();
}
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
}
};
private static final String TEST_ACTION = "com.artificial.package.TEST_ACTION"; private static final String TEST_ACTION = "com.artificial.package.TEST_ACTION";
private static enum ShowSettings { private static enum ShowSettings {
...@@ -71,60 +133,10 @@ public class FirstRunTest extends SyncTestBase { ...@@ -71,60 +133,10 @@ public class FirstRunTest extends SyncTestBase {
private final TestObserver mTestObserver = new TestObserver(); private final TestObserver mTestObserver = new TestObserver();
private FirstRunActivity mActivity; private FirstRunActivity mActivity;
@Override
public void startMainActivity() throws InterruptedException {
FirstRunActivity.setObserverForTest(mTestObserver);
// Starts up and waits for the FirstRunActivity to be ready.
// This isn't exactly what startMainActivity is supposed to be doing, but short of a
// refactoring of SyncTestBase to use something other than ChromeTabbedActivity, it's the
// only way to reuse the rest of the setup and initialization code inside of it.
final Instrumentation instrumentation = getInstrumentation();
final Context context = instrumentation.getTargetContext();
// Create an Intent that causes Chrome to run.
final Intent intent = new Intent(TEST_ACTION);
intent.setPackage(context.getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Start the FRE.
final ActivityMonitor freMonitor =
new ActivityMonitor(FirstRunActivity.class.getName(), null, false);
instrumentation.addMonitor(freMonitor);
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
FirstRunFlowSequencer.launch(context, intent, false /* requiresBroadcast */,
false /* preferLightweightFre */);
}
});
// Wait for the FRE to be ready to use.
Activity activity =
freMonitor.waitForActivityWithTimeout(CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
instrumentation.removeMonitor(freMonitor);
assertTrue(activity instanceof FirstRunActivity);
mActivity = (FirstRunActivity) activity;
try {
mTestObserver.flowIsKnownCallback.waitForCallback(0);
} catch (TimeoutException e) {
fail();
}
getInstrumentation().waitForIdleSync();
}
@Override
public void setUp() throws Exception {
super.setUp();
}
@Override @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
if (mActivity != null) mActivity.finish(); if (mActivity != null) mActivity.finish();
super.tearDown();
} }
// Test that signing in through FirstRun signs in and starts sync. // Test that signing in through FirstRun signs in and starts sync.
...@@ -132,14 +144,15 @@ public class FirstRunTest extends SyncTestBase { ...@@ -132,14 +144,15 @@ public class FirstRunTest extends SyncTestBase {
* @SmallTest * @SmallTest
* @Feature({"Sync"}) * @Feature({"Sync"})
*/ */
@Test
@FlakyTest(message = "https://crbug.com/616456") @FlakyTest(message = "https://crbug.com/616456")
public void testSignIn() throws Exception { public void testSignIn() throws Exception {
Account testAccount = SigninTestUtil.addTestAccount(); Account testAccount = SigninTestUtil.addTestAccount();
assertNull(SigninTestUtil.getCurrentAccount()); Assert.assertNull(SigninTestUtil.getCurrentAccount());
assertFalse(SyncTestUtil.isSyncRequested()); Assert.assertFalse(SyncTestUtil.isSyncRequested());
processFirstRun(testAccount.name, ShowSettings.NO); processFirstRun(testAccount.name, ShowSettings.NO);
assertEquals(testAccount, SigninTestUtil.getCurrentAccount()); Assert.assertEquals(testAccount, SigninTestUtil.getCurrentAccount());
SyncTestUtil.waitForSyncActive(); SyncTestUtil.waitForSyncActive();
} }
...@@ -149,6 +162,7 @@ public class FirstRunTest extends SyncTestBase { ...@@ -149,6 +162,7 @@ public class FirstRunTest extends SyncTestBase {
* @SmallTest * @SmallTest
* @Feature({"Sync"}) * @Feature({"Sync"})
*/ */
@Test
@FlakyTest(message = "https://crbug.com/616456") @FlakyTest(message = "https://crbug.com/616456")
public void testSignInWithOpenSettings() throws Exception { public void testSignInWithOpenSettings() throws Exception {
final Account testAccount = SigninTestUtil.addTestAccount(); final Account testAccount = SigninTestUtil.addTestAccount();
...@@ -156,29 +170,30 @@ public class FirstRunTest extends SyncTestBase { ...@@ -156,29 +170,30 @@ public class FirstRunTest extends SyncTestBase {
// User should be signed in and the sync backend should initialize, but sync should not // User should be signed in and the sync backend should initialize, but sync should not
// become fully active until the settings page is closed. // become fully active until the settings page is closed.
assertEquals(testAccount, SigninTestUtil.getCurrentAccount()); Assert.assertEquals(testAccount, SigninTestUtil.getCurrentAccount());
SyncTestUtil.waitForEngineInitialized(); SyncTestUtil.waitForEngineInitialized();
assertFalse(SyncTestUtil.isSyncActive()); Assert.assertFalse(SyncTestUtil.isSyncActive());
// Close the settings fragment. // Close the settings fragment.
AccountManagementFragment fragment = AccountManagementFragment fragment =
(AccountManagementFragment) prefActivity.getFragmentForTest(); (AccountManagementFragment) prefActivity.getFragmentForTest();
assertNotNull(fragment); Assert.assertNotNull(fragment);
prefActivity.getFragmentManager().beginTransaction().remove(fragment).commit(); prefActivity.getFragmentManager().beginTransaction().remove(fragment).commit();
// Sync should immediately become active. // Sync should immediately become active.
assertTrue(SyncTestUtil.isSyncActive()); Assert.assertTrue(SyncTestUtil.isSyncActive());
} }
// Test that not signing in through FirstRun does not sign in sync. // Test that not signing in through FirstRun does not sign in sync.
@Test
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testNoSignIn() throws Exception { public void testNoSignIn() throws Exception {
SigninTestUtil.addTestAccount(); SigninTestUtil.addTestAccount();
assertFalse(SyncTestUtil.isSyncRequested()); Assert.assertFalse(SyncTestUtil.isSyncRequested());
processFirstRun(null, ShowSettings.NO); processFirstRun(null, ShowSettings.NO);
assertNull(SigninTestUtil.getCurrentAccount()); Assert.assertNull(SigninTestUtil.getCurrentAccount());
assertFalse(SyncTestUtil.isSyncRequested()); Assert.assertFalse(SyncTestUtil.isSyncRequested());
} }
/** /**
...@@ -199,13 +214,14 @@ public class FirstRunTest extends SyncTestBase { ...@@ -199,13 +214,14 @@ public class FirstRunTest extends SyncTestBase {
Preferences prefActivity = null; Preferences prefActivity = null;
if (showSettings == ShowSettings.YES) { if (showSettings == ShowSettings.YES) {
prefActivity = ActivityUtils.waitForActivity( prefActivity = ActivityUtils.waitForActivity(
getInstrumentation(), Preferences.class, new Runnable() { InstrumentationRegistry.getInstrumentation(), Preferences.class,
new Runnable() {
@Override @Override
public void run() { public void run() {
processFirstRunOnUiThread(); processFirstRunOnUiThread();
} }
}); });
assertNotNull("Could not find the preferences activity", prefActivity); Assert.assertNotNull("Could not find the preferences activity", prefActivity);
} else { } else {
processFirstRunOnUiThread(); processFirstRunOnUiThread();
} }
......
...@@ -7,9 +7,20 @@ package org.chromium.chrome.browser.sync; ...@@ -7,9 +7,20 @@ package org.chromium.chrome.browser.sync;
import android.accounts.Account; import android.accounts.Account;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
...@@ -19,8 +30,16 @@ import java.util.concurrent.Callable; ...@@ -19,8 +30,16 @@ import java.util.concurrent.Callable;
/** /**
* Test suite for the GmsCoreSyncListener. * Test suite for the GmsCoreSyncListener.
*/ */
@RetryOnFailure // crbug.com/637448 @RunWith(ChromeJUnit4ClassRunner.class)
public class GmsCoreSyncListenerTest extends SyncTestBase { @CommandLineFlags.Add({
ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
})
@RetryOnFailure // crbug.com/637448
public class GmsCoreSyncListenerTest {
@Rule
public SyncTestRule mSyncTestRule = new SyncTestRule();
private static final String PASSPHRASE = "passphrase"; private static final String PASSPHRASE = "passphrase";
static class CountingGmsCoreSyncListener extends GmsCoreSyncListener { static class CountingGmsCoreSyncListener extends GmsCoreSyncListener {
...@@ -38,9 +57,8 @@ public class GmsCoreSyncListenerTest extends SyncTestBase { ...@@ -38,9 +57,8 @@ public class GmsCoreSyncListenerTest extends SyncTestBase {
private CountingGmsCoreSyncListener mListener; private CountingGmsCoreSyncListener mListener;
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
mListener = new CountingGmsCoreSyncListener(); mListener = new CountingGmsCoreSyncListener();
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
...@@ -50,40 +68,41 @@ public class GmsCoreSyncListenerTest extends SyncTestBase { ...@@ -50,40 +68,41 @@ public class GmsCoreSyncListenerTest extends SyncTestBase {
}); });
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
ProfileSyncService.get().removeSyncStateChangedListener(mListener); ProfileSyncService.get().removeSyncStateChangedListener(mListener);
} }
}); });
super.tearDown();
} }
@Test
@MediumTest @MediumTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testGetsKey() throws Throwable { public void testGetsKey() throws Throwable {
Account account = setUpTestAccountAndSignIn(); Account account = mSyncTestRule.setUpTestAccountAndSignIn();
assertEquals(0, mListener.callCount()); Assert.assertEquals(0, mListener.callCount());
encryptWithPassphrase(PASSPHRASE); encryptWithPassphrase(PASSPHRASE);
waitForCallCount(1); waitForCallCount(1);
signOut(); mSyncTestRule.signOut();
signIn(account); mSyncTestRule.signIn(account);
assertEquals(1, mListener.callCount()); Assert.assertEquals(1, mListener.callCount());
decryptWithPassphrase(PASSPHRASE); decryptWithPassphrase(PASSPHRASE);
waitForCallCount(2); waitForCallCount(2);
} }
@Test
@MediumTest @MediumTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testClearData() throws Throwable { public void testClearData() throws Throwable {
Account account = setUpTestAccountAndSignIn(); Account account = mSyncTestRule.setUpTestAccountAndSignIn();
assertEquals(0, mListener.callCount()); Assert.assertEquals(0, mListener.callCount());
encryptWithPassphrase(PASSPHRASE); encryptWithPassphrase(PASSPHRASE);
waitForCallCount(1); waitForCallCount(1);
clearServerData(); mSyncTestRule.clearServerData();
signIn(account); mSyncTestRule.signIn(account);
encryptWithPassphrase(PASSPHRASE); encryptWithPassphrase(PASSPHRASE);
waitForCallCount(2); waitForCallCount(2);
} }
......
...@@ -9,11 +9,20 @@ import android.util.Pair; ...@@ -9,11 +9,20 @@ import android.util.Pair;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.FlakyTest; import org.chromium.base.test.util.FlakyTest;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.components.sync.ModelType; import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.protocol.EntitySpecifics; import org.chromium.components.sync.protocol.EntitySpecifics;
...@@ -31,8 +40,16 @@ import java.util.concurrent.Callable; ...@@ -31,8 +40,16 @@ import java.util.concurrent.Callable;
/** /**
* Test suite for the typed URLs sync data type. * Test suite for the typed URLs sync data type.
*/ */
@RetryOnFailure // crbug.com/637448 @RunWith(ChromeJUnit4ClassRunner.class)
public class TypedUrlsTest extends SyncTestBase { @CommandLineFlags.Add({
ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
})
@RetryOnFailure // crbug.com/637448
public class TypedUrlsTest {
@Rule
public SyncTestRule mSyncTestRule = new SyncTestRule();
private static final String TAG = "TypedUrlsTest"; private static final String TAG = "TypedUrlsTest";
private static final String TYPED_URLS_TYPE = "Typed URLs"; private static final String TYPED_URLS_TYPE = "Typed URLs";
...@@ -53,10 +70,9 @@ public class TypedUrlsTest extends SyncTestBase { ...@@ -53,10 +70,9 @@ public class TypedUrlsTest extends SyncTestBase {
} }
} }
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); mSyncTestRule.setUpTestAccountAndSignIn();
setUpTestAccountAndSignIn();
// Make sure the initial state is clean. // Make sure the initial state is clean.
assertClientTypedUrlCount(0); assertClientTypedUrlCount(0);
assertServerTypedUrlCountWithName(0, URL); assertServerTypedUrlCountWithName(0, URL);
...@@ -67,6 +83,7 @@ public class TypedUrlsTest extends SyncTestBase { ...@@ -67,6 +83,7 @@ public class TypedUrlsTest extends SyncTestBase {
@LargeTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
*/ */
@Test
@FlakyTest(message = "https://crbug.com/592437") @FlakyTest(message = "https://crbug.com/592437")
public void testUploadTypedUrl() { public void testUploadTypedUrl() {
loadUrlByTyping(URL); loadUrlByTyping(URL);
...@@ -75,6 +92,7 @@ public class TypedUrlsTest extends SyncTestBase { ...@@ -75,6 +92,7 @@ public class TypedUrlsTest extends SyncTestBase {
} }
// Test syncing a typed URL from server to client. // Test syncing a typed URL from server to client.
@Test
@LargeTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testDownloadTypedUrl() throws Exception { public void testDownloadTypedUrl() throws Exception {
...@@ -84,13 +102,14 @@ public class TypedUrlsTest extends SyncTestBase { ...@@ -84,13 +102,14 @@ public class TypedUrlsTest extends SyncTestBase {
// Verify data synced to client. // Verify data synced to client.
List<TypedUrl> typedUrls = getClientTypedUrls(); List<TypedUrl> typedUrls = getClientTypedUrls();
assertEquals("Only the injected typed URL should exist on the client.", Assert.assertEquals(
1, typedUrls.size()); "Only the injected typed URL should exist on the client.", 1, typedUrls.size());
TypedUrl typedUrl = typedUrls.get(0); TypedUrl typedUrl = typedUrls.get(0);
assertEquals("The wrong URL was found for the typed URL.", URL, typedUrl.url); Assert.assertEquals("The wrong URL was found for the typed URL.", URL, typedUrl.url);
} }
// Test syncing a typed URL deletion from server to client. // Test syncing a typed URL deletion from server to client.
@Test
@LargeTest @LargeTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testDownloadDeletedTypedUrl() throws Exception { public void testDownloadDeletedTypedUrl() throws Exception {
...@@ -101,7 +120,7 @@ public class TypedUrlsTest extends SyncTestBase { ...@@ -101,7 +120,7 @@ public class TypedUrlsTest extends SyncTestBase {
// Delete on server, sync, and verify deleted locally. // Delete on server, sync, and verify deleted locally.
TypedUrl typedUrl = getClientTypedUrls().get(0); TypedUrl typedUrl = getClientTypedUrls().get(0);
mFakeServerHelper.deleteEntity(typedUrl.id); mSyncTestRule.getFakeServerHelper().deleteEntity(typedUrl.id);
SyncTestUtil.triggerSync(); SyncTestUtil.triggerSync();
waitForClientTypedUrlCount(0); waitForClientTypedUrlCount(0);
} }
...@@ -111,7 +130,7 @@ public class TypedUrlsTest extends SyncTestBase { ...@@ -111,7 +130,7 @@ public class TypedUrlsTest extends SyncTestBase {
@Override @Override
public void run() { public void run() {
LoadUrlParams params = new LoadUrlParams(url, PageTransition.TYPED); LoadUrlParams params = new LoadUrlParams(url, PageTransition.TYPED);
getActivity().getActivityTab().loadUrl(params); mSyncTestRule.getActivity().getActivityTab().loadUrl(params);
} }
}); });
} }
...@@ -123,12 +142,12 @@ public class TypedUrlsTest extends SyncTestBase { ...@@ -123,12 +142,12 @@ public class TypedUrlsTest extends SyncTestBase {
specifics.typedUrl.title = url; specifics.typedUrl.title = url;
specifics.typedUrl.visits = new long[]{1L}; specifics.typedUrl.visits = new long[]{1L};
specifics.typedUrl.visitTransitions = new int[]{SyncEnums.TYPED}; specifics.typedUrl.visitTransitions = new int[]{SyncEnums.TYPED};
mFakeServerHelper.injectUniqueClientEntity(url /* name */, specifics); mSyncTestRule.getFakeServerHelper().injectUniqueClientEntity(url /* name */, specifics);
} }
private List<TypedUrl> getClientTypedUrls() throws JSONException { private List<TypedUrl> getClientTypedUrls() throws JSONException {
List<Pair<String, JSONObject>> rawTypedUrls = SyncTestUtil.getLocalData( List<Pair<String, JSONObject>> rawTypedUrls =
mContext, TYPED_URLS_TYPE); SyncTestUtil.getLocalData(mSyncTestRule.getTargetContext(), TYPED_URLS_TYPE);
List<TypedUrl> typedUrls = new ArrayList<TypedUrl>(rawTypedUrls.size()); List<TypedUrl> typedUrls = new ArrayList<TypedUrl>(rawTypedUrls.size());
for (Pair<String, JSONObject> rawTypedUrl : rawTypedUrls) { for (Pair<String, JSONObject> rawTypedUrl : rawTypedUrls) {
String id = rawTypedUrl.first; String id = rawTypedUrl.first;
...@@ -138,13 +157,14 @@ public class TypedUrlsTest extends SyncTestBase { ...@@ -138,13 +157,14 @@ public class TypedUrlsTest extends SyncTestBase {
} }
private void assertClientTypedUrlCount(int count) throws JSONException { private void assertClientTypedUrlCount(int count) throws JSONException {
assertEquals("There should be " + count + " local typed URL entities.", Assert.assertEquals("There should be " + count + " local typed URL entities.", count,
count, SyncTestUtil.getLocalData(mContext, TYPED_URLS_TYPE).size()); SyncTestUtil.getLocalData(mSyncTestRule.getTargetContext(), TYPED_URLS_TYPE)
.size());
} }
private void assertServerTypedUrlCountWithName(int count, String name) { private void assertServerTypedUrlCountWithName(int count, String name) {
assertTrue("Expected " + count + " server typed URLs with name " + name + ".", Assert.assertTrue("Expected " + count + " server typed URLs with name " + name + ".",
mFakeServerHelper.verifyEntityCountByTypeAndName( mSyncTestRule.getFakeServerHelper().verifyEntityCountByTypeAndName(
count, ModelType.TYPED_URLS, name)); count, ModelType.TYPED_URLS, name));
} }
...@@ -152,7 +172,8 @@ public class TypedUrlsTest extends SyncTestBase { ...@@ -152,7 +172,8 @@ public class TypedUrlsTest extends SyncTestBase {
CriteriaHelper.pollInstrumentationThread(Criteria.equals(count, new Callable<Integer>() { CriteriaHelper.pollInstrumentationThread(Criteria.equals(count, new Callable<Integer>() {
@Override @Override
public Integer call() throws Exception { public Integer call() throws Exception {
return SyncTestUtil.getLocalData(mContext, TYPED_URLS_TYPE).size(); return SyncTestUtil.getLocalData(mSyncTestRule.getTargetContext(), TYPED_URLS_TYPE)
.size();
} }
}), SyncTestUtil.TIMEOUT_MS, SyncTestUtil.INTERVAL_MS); }), SyncTestUtil.TIMEOUT_MS, SyncTestUtil.INTERVAL_MS);
} }
...@@ -163,7 +184,7 @@ public class TypedUrlsTest extends SyncTestBase { ...@@ -163,7 +184,7 @@ public class TypedUrlsTest extends SyncTestBase {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
try { try {
return mFakeServerHelper.verifyEntityCountByTypeAndName( return mSyncTestRule.getFakeServerHelper().verifyEntityCountByTypeAndName(
count, ModelType.TYPED_URLS, name); count, ModelType.TYPED_URLS, name);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
......
...@@ -4,22 +4,40 @@ ...@@ -4,22 +4,40 @@
package org.chromium.chrome.browser.sync.ui; package org.chromium.chrome.browser.sync.ui;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import android.widget.CheckedTextView; import android.widget.CheckedTextView;
import android.widget.ListView; import android.widget.ListView;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.FlakyTest; import org.chromium.base.test.util.FlakyTest;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.sync.SyncTestBase; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.sync.SyncTestRule;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.components.sync.PassphraseType; import org.chromium.components.sync.PassphraseType;
/** /**
* Tests to make sure that PassphraseTypeDialogFragment presents the correct options. * Tests to make sure that PassphraseTypeDialogFragment presents the correct options.
*/ */
@RetryOnFailure // crbug.com/637448 @RunWith(ChromeJUnit4ClassRunner.class)
public class PassphraseTypeDialogFragmentTest extends SyncTestBase { @CommandLineFlags.Add({
ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
})
@RetryOnFailure // crbug.com/637448
public class PassphraseTypeDialogFragmentTest {
@Rule
public SyncTestRule mSyncTestRule = new SyncTestRule();
private static final String TAG = "PassphraseTypeDialogFragmentTest"; private static final String TAG = "PassphraseTypeDialogFragmentTest";
private static final boolean ENABLED = true; private static final boolean ENABLED = true;
...@@ -40,6 +58,7 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase { ...@@ -40,6 +58,7 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase {
private PassphraseTypeDialogFragment mTypeFragment; private PassphraseTypeDialogFragment mTypeFragment;
@Test
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testKeystoreEncryptionOptions() throws Exception { public void testKeystoreEncryptionOptions() throws Exception {
...@@ -49,6 +68,7 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase { ...@@ -49,6 +68,7 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase {
new TypeOptions(PassphraseType.KEYSTORE_PASSPHRASE, ENABLED, CHECKED)); new TypeOptions(PassphraseType.KEYSTORE_PASSPHRASE, ENABLED, CHECKED));
} }
@Test
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testCustomEncryptionOptions() throws Exception { public void testCustomEncryptionOptions() throws Exception {
...@@ -62,6 +82,7 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase { ...@@ -62,6 +82,7 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase {
* @SmallTest * @SmallTest
* @Feature({"Sync"}) * @Feature({"Sync"})
*/ */
@Test
@FlakyTest(message = "crbug.com/588050") @FlakyTest(message = "crbug.com/588050")
public void testFrozenImplicitEncryptionOptions() throws Exception { public void testFrozenImplicitEncryptionOptions() throws Exception {
createFragment(PassphraseType.FROZEN_IMPLICIT_PASSPHRASE, true); createFragment(PassphraseType.FROZEN_IMPLICIT_PASSPHRASE, true);
...@@ -70,6 +91,7 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase { ...@@ -70,6 +91,7 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase {
new TypeOptions(PassphraseType.KEYSTORE_PASSPHRASE, DISABLED, UNCHECKED)); new TypeOptions(PassphraseType.KEYSTORE_PASSPHRASE, DISABLED, UNCHECKED));
} }
@Test
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testImplicitEncryptionOptions() throws Exception { public void testImplicitEncryptionOptions() throws Exception {
...@@ -79,6 +101,7 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase { ...@@ -79,6 +101,7 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase {
new TypeOptions(PassphraseType.IMPLICIT_PASSPHRASE, ENABLED, CHECKED)); new TypeOptions(PassphraseType.IMPLICIT_PASSPHRASE, ENABLED, CHECKED));
} }
@Test
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testKeystoreEncryptionOptionsEncryptEverythingDisallowed() throws Exception { public void testKeystoreEncryptionOptionsEncryptEverythingDisallowed() throws Exception {
...@@ -88,6 +111,7 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase { ...@@ -88,6 +111,7 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase {
new TypeOptions(PassphraseType.KEYSTORE_PASSPHRASE, ENABLED, CHECKED)); new TypeOptions(PassphraseType.KEYSTORE_PASSPHRASE, ENABLED, CHECKED));
} }
@Test
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testImplicitEncryptionOptionsEncryptEverythingDisallowed() throws Exception { public void testImplicitEncryptionOptionsEncryptEverythingDisallowed() throws Exception {
...@@ -99,25 +123,27 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase { ...@@ -99,25 +123,27 @@ public class PassphraseTypeDialogFragmentTest extends SyncTestBase {
public void createFragment(PassphraseType type, boolean isEncryptEverythingAllowed) { public void createFragment(PassphraseType type, boolean isEncryptEverythingAllowed) {
mTypeFragment = PassphraseTypeDialogFragment.create(type, 0, isEncryptEverythingAllowed); mTypeFragment = PassphraseTypeDialogFragment.create(type, 0, isEncryptEverythingAllowed);
mTypeFragment.show(getActivity().getFragmentManager(), TAG); mTypeFragment.show(mSyncTestRule.getActivity().getFragmentManager(), TAG);
getInstrumentation().waitForIdleSync(); InstrumentationRegistry.getInstrumentation().waitForIdleSync();
} }
public void assertPassphraseTypeOptions(TypeOptions... optionsList) { public void assertPassphraseTypeOptions(TypeOptions... optionsList) {
ListView listView = ListView listView =
(ListView) mTypeFragment.getDialog().findViewById(R.id.passphrase_type_list); (ListView) mTypeFragment.getDialog().findViewById(R.id.passphrase_type_list);
assertEquals("Number of options doesn't match.", optionsList.length, listView.getCount()); Assert.assertEquals(
"Number of options doesn't match.", optionsList.length, listView.getCount());
PassphraseTypeDialogFragment.Adapter adapter = PassphraseTypeDialogFragment.Adapter adapter =
(PassphraseTypeDialogFragment.Adapter) listView.getAdapter(); (PassphraseTypeDialogFragment.Adapter) listView.getAdapter();
for (int i = 0; i < optionsList.length; i++) { for (int i = 0; i < optionsList.length; i++) {
TypeOptions options = optionsList[i]; TypeOptions options = optionsList[i];
assertEquals("Option " + i + " type is wrong.", options.type, adapter.getType(i)); Assert.assertEquals(
"Option " + i + " type is wrong.", options.type, adapter.getType(i));
CheckedTextView checkedView = (CheckedTextView) listView.getChildAt(i); CheckedTextView checkedView = (CheckedTextView) listView.getChildAt(i);
assertEquals("Option " + i + " enabled state is wrong.", Assert.assertEquals("Option " + i + " enabled state is wrong.", options.isEnabled,
options.isEnabled, checkedView.isEnabled()); checkedView.isEnabled());
assertEquals("Option " + i + " checked state is wrong.", Assert.assertEquals("Option " + i + " checked state is wrong.", options.isChecked,
options.isChecked, checkedView.isChecked()); checkedView.isChecked());
} }
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment