| Index: chrome/android/sync_shell/javatests/src/org/chromium/chrome/browser/sync/SyncCustomizationFragmentTest.java
|
| diff --git a/chrome/android/sync_shell/javatests/src/org/chromium/chrome/browser/sync/SyncCustomizationFragmentTest.java b/chrome/android/sync_shell/javatests/src/org/chromium/chrome/browser/sync/SyncCustomizationFragmentTest.java
|
| index 5f90874dab7d3d3c72d1b2cbd0526f9b83c63c3c..a10a51d85754c66180aae940477705dddc589458 100644
|
| --- a/chrome/android/sync_shell/javatests/src/org/chromium/chrome/browser/sync/SyncCustomizationFragmentTest.java
|
| +++ b/chrome/android/sync_shell/javatests/src/org/chromium/chrome/browser/sync/SyncCustomizationFragmentTest.java
|
| @@ -6,7 +6,10 @@ package org.chromium.chrome.browser.sync;
|
|
|
| import android.app.Activity;
|
| import android.app.FragmentTransaction;
|
| +import android.preference.CheckBoxPreference;
|
| +import android.preference.Preference;
|
| import android.preference.SwitchPreference;
|
| +import android.preference.TwoStatePreference;
|
| import android.test.suitebuilder.annotation.SmallTest;
|
|
|
| import org.chromium.base.ThreadUtils;
|
| @@ -36,23 +39,81 @@ public class SyncCustomizationFragmentTest extends SyncTestBase {
|
| @Feature({"Sync"})
|
| public void testSyncSwitch() throws Exception {
|
| setupTestAccountAndSignInToSync(CLIENT_ID);
|
| -
|
| - // Make sure sync is actually enabled.
|
| - mAndroidSyncSettings.enableChromeSync();
|
| - getInstrumentation().waitForIdleSync();
|
| + startSync();
|
| SyncCustomizationFragment fragment = startSyncCustomizationFragment();
|
| final SwitchPreference syncSwitch = getSyncSwitch(fragment);
|
|
|
| assertTrue(syncSwitch.isChecked());
|
| assertTrue(mAndroidSyncSettings.isChromeSyncEnabled());
|
| - toggleSwitch(syncSwitch);
|
| + togglePreference(syncSwitch);
|
| assertFalse(syncSwitch.isChecked());
|
| assertFalse(mAndroidSyncSettings.isChromeSyncEnabled());
|
| - toggleSwitch(syncSwitch);
|
| + togglePreference(syncSwitch);
|
| assertTrue(syncSwitch.isChecked());
|
| assertTrue(mAndroidSyncSettings.isChromeSyncEnabled());
|
| }
|
|
|
| + /**
|
| + * This is a regression test for http://crbug.com/454939.
|
| + */
|
| + @SmallTest
|
| + @Feature({"Sync"})
|
| + public void testOpeningSettingsDoesntEnableSync() throws Exception {
|
| + setupTestAccountAndSignInToSync(CLIENT_ID);
|
| + stopSync();
|
| + SyncCustomizationFragment fragment = startSyncCustomizationFragment();
|
| + closeFragment(fragment);
|
| + assertFalse(mAndroidSyncSettings.isChromeSyncEnabled());
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"Sync"})
|
| + public void testDefaultControlStatesWithSyncOffThenOn() throws Exception {
|
| + setupTestAccountAndSignInToSync(CLIENT_ID);
|
| + stopSync();
|
| + SyncCustomizationFragment fragment = startSyncCustomizationFragment();
|
| + assertDefaultSyncOffState(fragment);
|
| + togglePreference(getSyncSwitch(fragment));
|
| + waitForSyncInitialized();
|
| + assertDefaultSyncOnState(fragment);
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"Sync"})
|
| + public void testDefaultControlStatesWithSyncOnThenOff() throws Exception {
|
| + setupTestAccountAndSignInToSync(CLIENT_ID);
|
| + startSync();
|
| + SyncCustomizationFragment fragment = startSyncCustomizationFragment();
|
| + assertDefaultSyncOnState(fragment);
|
| + togglePreference(getSyncSwitch(fragment));
|
| + assertDefaultSyncOffState(fragment);
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"Sync"})
|
| + public void testSyncEverythingAndDataTypes() throws Exception {
|
| + setupTestAccountAndSignInToSync(CLIENT_ID);
|
| + startSync();
|
| + SyncCustomizationFragment fragment = startSyncCustomizationFragment();
|
| + SwitchPreference syncEverything = getSyncEverything(fragment);
|
| + CheckBoxPreference[] dataTypes = getDataTypes(fragment);
|
| +
|
| + assertDefaultSyncOnState(fragment);
|
| + togglePreference(syncEverything);
|
| + for (CheckBoxPreference dataType : dataTypes) {
|
| + assertTrue(dataType.isChecked());
|
| + assertTrue(dataType.isEnabled());
|
| + }
|
| +
|
| + // If all data types are unchecked, sync should turn off.
|
| + for (CheckBoxPreference dataType : dataTypes) {
|
| + togglePreference(dataType);
|
| + }
|
| + getInstrumentation().waitForIdleSync();
|
| + assertDefaultSyncOffState(fragment);
|
| + assertFalse(mAndroidSyncSettings.isChromeSyncEnabled());
|
| + }
|
| +
|
| private SyncCustomizationFragment startSyncCustomizationFragment() {
|
| FragmentTransaction transaction = mActivity.getFragmentManager().beginTransaction();
|
| transaction.add(R.id.content_container, new SyncCustomizationFragment(), TAG);
|
| @@ -61,6 +122,13 @@ public class SyncCustomizationFragmentTest extends SyncTestBase {
|
| return (SyncCustomizationFragment) mActivity.getFragmentManager().findFragmentByTag(TAG);
|
| }
|
|
|
| + private void closeFragment(SyncCustomizationFragment fragment) {
|
| + FragmentTransaction transaction = mActivity.getFragmentManager().beginTransaction();
|
| + transaction.remove(fragment);
|
| + transaction.commit();
|
| + getInstrumentation().waitForIdleSync();
|
| + }
|
| +
|
| private SwitchPreference getSyncSwitch(SyncCustomizationFragment fragment) {
|
| return (SwitchPreference) fragment.findPreference(
|
| SyncCustomizationFragment.PREF_SYNC_SWITCH);
|
| @@ -71,7 +139,66 @@ public class SyncCustomizationFragmentTest extends SyncTestBase {
|
| SyncCustomizationFragment.PREFERENCE_SYNC_EVERYTHING);
|
| }
|
|
|
| - private void toggleSwitch(final SwitchPreference pref) {
|
| + private CheckBoxPreference[] getDataTypes(SyncCustomizationFragment fragment) {
|
| + return new CheckBoxPreference[] {
|
| + (CheckBoxPreference) fragment.findPreference(
|
| + SyncCustomizationFragment.PREFERENCE_SYNC_AUTOFILL),
|
| + (CheckBoxPreference) fragment.findPreference(
|
| + SyncCustomizationFragment.PREFERENCE_SYNC_BOOKMARKS),
|
| + (CheckBoxPreference) fragment.findPreference(
|
| + SyncCustomizationFragment.PREFERENCE_SYNC_OMNIBOX),
|
| + (CheckBoxPreference) fragment.findPreference(
|
| + SyncCustomizationFragment.PREFERENCE_SYNC_PASSWORDS),
|
| + (CheckBoxPreference) fragment.findPreference(
|
| + SyncCustomizationFragment.PREFERENCE_SYNC_RECENT_TABS)
|
| + };
|
| + }
|
| +
|
| + private Preference getEncryption(SyncCustomizationFragment fragment) {
|
| + return (Preference) fragment.findPreference(
|
| + SyncCustomizationFragment.PREFERENCE_ENCRYPTION);
|
| + }
|
| +
|
| + private Preference getManageData(SyncCustomizationFragment fragment) {
|
| + return (Preference) fragment.findPreference(
|
| + SyncCustomizationFragment.PREFERENCE_SYNC_MANAGE_DATA);
|
| + }
|
| +
|
| + private void assertDefaultSyncOnState(SyncCustomizationFragment fragment) {
|
| + assertTrue("The sync switch should be on.", getSyncSwitch(fragment).isChecked());
|
| + assertTrue("The sync switch should be enabled.", getSyncSwitch(fragment).isEnabled());
|
| + SwitchPreference syncEverything = getSyncEverything(fragment);
|
| + assertTrue("The sync everything switch should be on.", syncEverything.isChecked());
|
| + assertTrue("The sync everything switch should be enabled.", syncEverything.isEnabled());
|
| + for (CheckBoxPreference dataType : getDataTypes(fragment)) {
|
| + String key = dataType.getKey();
|
| + assertTrue("Data type " + key + " should be checked.", dataType.isChecked());
|
| + assertFalse("Data type " + key + " should be disabled.", dataType.isEnabled());
|
| + }
|
| + assertTrue("The encryption button should be enabled.",
|
| + getEncryption(fragment).isEnabled());
|
| + assertTrue("The manage sync data button should be always enabled.",
|
| + getManageData(fragment).isEnabled());
|
| + }
|
| +
|
| + private void assertDefaultSyncOffState(SyncCustomizationFragment fragment) {
|
| + assertFalse("The sync switch should be off.", getSyncSwitch(fragment).isChecked());
|
| + assertTrue("The sync switch should be enabled.", getSyncSwitch(fragment).isEnabled());
|
| + SwitchPreference syncEverything = getSyncEverything(fragment);
|
| + assertTrue("The sync everything switch should be on.", syncEverything.isChecked());
|
| + assertFalse("The sync everything switch should be disabled.", syncEverything.isEnabled());
|
| + for (CheckBoxPreference dataType : getDataTypes(fragment)) {
|
| + String key = dataType.getKey();
|
| + assertTrue("Data type " + key + " should be checked.", dataType.isChecked());
|
| + assertFalse("Data type " + key + " should be disabled.", dataType.isEnabled());
|
| + }
|
| + assertFalse("The encryption button should be disabled.",
|
| + getEncryption(fragment).isEnabled());
|
| + assertTrue("The manage sync data button should be always enabled.",
|
| + getManageData(fragment).isEnabled());
|
| + }
|
| +
|
| + private void togglePreference(final TwoStatePreference pref) {
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
|
|