Commit 532127e5 authored by maxbogue's avatar maxbogue Committed by Commit bot

[Sync] Test encryption UI options.

Add tests to make sure the encryption UI shows the correct options
by default, and that those options are enabled.

BUG=480604

Review URL: https://codereview.chromium.org/1124073004

Cr-Commit-Position: refs/heads/master@{#330122}
parent 716c586d
......@@ -11,7 +11,7 @@
<item type="id" name="button_secondary" />
<item type="id" name="button_tertiary" />
<item type="id" name="infobar_extra_check" />
<!-- Menu Animation Constants -->
<item type="fraction" format="fraction" name="menu_animation_pivot_x">95%</item>
......@@ -41,5 +41,8 @@
<!-- Cast notification -->
<item type="id" name="remote_notification" />
<!-- Sync UI constants -->
<item type="id" name="passphrase_type_list" />
</resources>
......@@ -31,6 +31,7 @@ import java.util.Set;
*/
public class PassphraseTypeDialogFragment extends DialogFragment implements
DialogInterface.OnClickListener, OnItemClickListener {
private static final String TAG = "PassphraseTypeDialogFragment";
interface Listener {
void onPassphraseTypeSelected(PassphraseType type);
......@@ -96,7 +97,11 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements
return new Adapter(container, container.getDisplayNames());
}
private class Adapter extends ArrayAdapter<String> {
/**
* The adapter for our ListView; only visible for testing purposes.
*/
@VisibleForTesting
public class Adapter extends ArrayAdapter<String> {
private final PassphraseTypeUiElementContainer mElementsContainer;
......@@ -176,6 +181,7 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements
ListView list = new ListView(getActivity());
Adapter adapter = createAdapter(getCurrentTypeFromArguments());
list.setAdapter(adapter);
list.setId(R.id.passphrase_type_list);
list.setOnItemClickListener(this);
list.setDividerHeight(0);
PassphraseType currentType = getCurrentTypeFromArguments();
......
......@@ -12,13 +12,17 @@ import android.preference.Preference;
import android.preference.SwitchPreference;
import android.preference.TwoStatePreference;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.View;
import android.widget.ListView;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.sync.ui.PassphraseTypeDialogFragment;
import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment;
import org.chromium.chrome.shell.R;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.sync.AndroidSyncSettings;
import org.chromium.sync.internal_api.pub.PassphraseType;
import org.chromium.sync.internal_api.pub.base.ModelType;
import java.util.Collection;
......@@ -138,6 +142,12 @@ public class SyncCustomizationFragmentTest extends SyncTestBase {
assertFalse(mAndroidSyncSettings.isChromeSyncEnabled());
}
/**
* Make sure that the encryption UI presents the correct options.
*
* By default it should show the CUSTOM and KEYSTORE options, in that order.
* KEYSTORE should be selected but both should be enabled.
*/
@SmallTest
@Feature({"Sync"})
public void testSettingDataTypes() throws Exception {
......@@ -167,6 +177,33 @@ public class SyncCustomizationFragmentTest extends SyncTestBase {
assertDataTypesAre(expectedTypes);
}
@SmallTest
@Feature({"Sync"})
public void testDefaultEncryptionOptions() throws Exception {
setupTestAccountAndSignInToSync(CLIENT_ID);
startSync();
SyncCustomizationFragment fragment = startSyncCustomizationFragment();
Preference encryption = getEncryption(fragment);
clickPreference(encryption);
PassphraseTypeDialogFragment typeFragment = getPassphraseTypeDialogFragment();
ListView listView = (ListView) typeFragment.getDialog()
.findViewById(R.id.passphrase_type_list);
PassphraseTypeDialogFragment.Adapter adapter =
(PassphraseTypeDialogFragment.Adapter) listView.getAdapter();
// Confirm that correct types show up in the correct order.
assertEquals(PassphraseType.CUSTOM_PASSPHRASE, adapter.getType(0));
assertEquals(PassphraseType.KEYSTORE_PASSPHRASE, adapter.getType(1));
assertEquals(2, listView.getCount());
// Make sure they are both enabled and the correct on is selected.
View customView = listView.getChildAt(0);
View keystoreView = listView.getChildAt(1);
assertTrue(customView.isEnabled());
assertTrue(keystoreView.isEnabled());
assertEquals(keystoreView, listView.getSelectedView());
}
private SyncCustomizationFragment startSyncCustomizationFragment() {
SyncCustomizationFragment fragment = new SyncCustomizationFragment();
Bundle args = new Bundle();
......@@ -217,6 +254,11 @@ public class SyncCustomizationFragmentTest extends SyncTestBase {
SyncCustomizationFragment.PREFERENCE_SYNC_MANAGE_DATA);
}
private PassphraseTypeDialogFragment getPassphraseTypeDialogFragment() {
return (PassphraseTypeDialogFragment) mActivity.getFragmentManager()
.findFragmentByTag(SyncCustomizationFragment.FRAGMENT_PASSWORD_TYPE);
}
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());
......@@ -279,4 +321,14 @@ public class SyncCustomizationFragmentTest extends SyncTestBase {
});
getInstrumentation().waitForIdleSync();
}
private void clickPreference(final Preference pref) {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
pref.getOnPreferenceClickListener().onPreferenceClick(pref);
}
});
getInstrumentation().waitForIdleSync();
}
}
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