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

Unified Diff: chrome/android/sync_shell/javatests/src/org/chromium/chrome/browser/sync/SyncCustomizationFragmentTest.java

Issue 1133453010: [Sync] Test Android passphrase creation UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove TAG. Created 5 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 496f87d24e6ddb7a706741b54e47be09f02f303d..e26e383a129711e8044921c0e2610c6a00f6820b 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
@@ -5,6 +5,8 @@
package org.chromium.chrome.browser.sync;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
@@ -13,10 +15,14 @@ import android.preference.SwitchPreference;
import android.preference.TwoStatePreference;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
import android.widget.ListView;
+import android.widget.TextView;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.Feature;
+import org.chromium.chrome.browser.sync.ui.PassphraseCreationDialogFragment;
import org.chromium.chrome.browser.sync.ui.PassphraseTypeDialogFragment;
import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment;
import org.chromium.chrome.shell.R;
@@ -204,6 +210,64 @@ public class SyncCustomizationFragmentTest extends SyncTestBase {
assertEquals(keystoreView, listView.getSelectedView());
}
+ @SmallTest
+ @Feature({"Sync"})
+ public void testPassphraseCreation() throws Exception {
+ setupTestAccountAndSignInToSync(CLIENT_ID);
+ startSync();
+ final SyncCustomizationFragment fragment = startSyncCustomizationFragment();
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ fragment.onPassphraseTypeSelected(PassphraseType.CUSTOM_PASSPHRASE);
+ }
+ });
+ getInstrumentation().waitForIdleSync();
+ PassphraseCreationDialogFragment pcdf = getPassphraseCreationDialogFragment();
+ AlertDialog dialog = (AlertDialog) pcdf.getDialog();
+ Button okButton = dialog.getButton(Dialog.BUTTON_POSITIVE);
+ EditText enterPassphrase = (EditText) dialog.findViewById(R.id.passphrase);
+ EditText confirmPassphrase = (EditText) dialog.findViewById(R.id.confirm_passphrase);
+
+ // Error if you try to submit empty passphrase.
+ assertNull(confirmPassphrase.getError());
+ clickButton(okButton);
+ assertTrue(pcdf.isResumed());
+ assertNotNull(confirmPassphrase.getError());
+
+ // Error if you try to submit with only the first box filled.
+ clearError(confirmPassphrase);
+ setText(enterPassphrase, "foo");
+ clickButton(okButton);
+ assertTrue(pcdf.isResumed());
+ assertNotNull(confirmPassphrase.getError());
+
+ // Error if you try to submit with only the second box filled.
+ setText(enterPassphrase, "");
+ clearError(confirmPassphrase);
+ setText(confirmPassphrase, "foo");
+ clickButton(okButton);
+ assertTrue(pcdf.isResumed());
+ assertNotNull(confirmPassphrase.getError());
+
+ // Error if text doesn't match without button press.
+ setText(enterPassphrase, "foo");
+ clearError(confirmPassphrase);
+ setText(confirmPassphrase, "bar");
+ assertNotNull(confirmPassphrase.getError());
+
+ // Error if you try to submit unmatching text.
+ clearError(confirmPassphrase);
+ clickButton(okButton);
+ assertTrue(pcdf.isResumed());
+ assertNotNull(confirmPassphrase.getError());
+
+ // Success if text matches.
+ setText(confirmPassphrase, "foo");
+ clickButton(okButton);
+ assertFalse(pcdf.isResumed());
+ }
+
private SyncCustomizationFragment startSyncCustomizationFragment() {
SyncCustomizationFragment fragment = new SyncCustomizationFragment();
Bundle args = new Bundle();
@@ -259,6 +323,11 @@ public class SyncCustomizationFragmentTest extends SyncTestBase {
.findFragmentByTag(SyncCustomizationFragment.FRAGMENT_PASSWORD_TYPE);
}
+ private PassphraseCreationDialogFragment getPassphraseCreationDialogFragment() {
+ return (PassphraseCreationDialogFragment) mActivity.getFragmentManager()
+ .findFragmentByTag(SyncCustomizationFragment.FRAGMENT_CUSTOM_PASSWORD);
+ }
+
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());
@@ -309,6 +378,8 @@ public class SyncCustomizationFragmentTest extends SyncTestBase {
});
}
+ // UI interaction convenience methods.
+
private void togglePreference(final TwoStatePreference pref) {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
@@ -331,4 +402,34 @@ public class SyncCustomizationFragmentTest extends SyncTestBase {
});
getInstrumentation().waitForIdleSync();
}
+
+ private void clickButton(final Button button) {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ button.performClick();
+ }
+ });
+ getInstrumentation().waitForIdleSync();
+ }
+
+ private void setText(final TextView textView, final String text) {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ textView.setText(text);
+ }
+ });
+ getInstrumentation().waitForIdleSync();
+ }
+
+ private void clearError(final TextView textView) {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ textView.setError(null);
+ }
+ });
+ getInstrumentation().waitForIdleSync();
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698