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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PasswordViewingTypeTest.java

Issue 2092723002: Redirect users without sync passphrase to passwords.google.com (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make sync set-up similar across tests Created 4 years, 5 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
Index: chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PasswordViewingTypeTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PasswordViewingTypeTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PasswordViewingTypeTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..396a0803860284254cc071c873d5706124c8efdb
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PasswordViewingTypeTest.java
@@ -0,0 +1,195 @@
+// Copyright 2016 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.
+
+package org.chromium.chrome.browser.preferences;
+
+import android.accounts.Account;
+import android.app.Activity;
+import android.app.Instrumentation;
+import android.content.Context;
+import android.content.Intent;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.test.util.CommandLineFlags;
+import org.chromium.base.test.util.Feature;
+import org.chromium.chrome.browser.preferences.password.SavePasswordsPreferences;
+import org.chromium.chrome.browser.sync.ProfileSyncService;
+import org.chromium.content.browser.test.NativeLibraryTestBase;
+import org.chromium.sync.AndroidSyncSettings;
+import org.chromium.sync.signin.AccountManagerHelper;
+import org.chromium.sync.test.util.AccountHolder;
+import org.chromium.sync.test.util.MockAccountManager;
+import org.chromium.sync.test.util.MockSyncContentResolverDelegate;
+
+/**
+ * Tests for verifying whether users are presented with the correct option of viewing
+ * passwords according to the user group they belong to (syncing with sync passphrase,
+ * syncing without sync passsphrase, non-syncing).
+ */
+
+public class PasswordViewingTypeTest extends NativeLibraryTestBase {
+
+ private MainPreferences mMainPreferences;
+ private ChromeBasePreference mPasswordsPref;
+ private static final String DEFAULT_ACCOUNT = "test@gmail.com";
+ private Context mContext;
+ private MockSyncContentResolverDelegate mSyncContentResolverDelegate;
+ private String mAuthority;
+ private Account mAccount;
+ private Account mAlternateAccount;
+ private MockAccountManager mAccountManager;
+
+ @Override
+ protected void setUp() throws Exception {
+
+ mSyncContentResolverDelegate = new MockSyncContentResolverDelegate();
+ mContext = getInstrumentation().getTargetContext();
+ mMainPreferences = (MainPreferences) startMainPreferences(getInstrumentation(),
+ mContext).getFragmentForTest();
+ mPasswordsPref = (ChromeBasePreference) mMainPreferences.findPreference(
+ MainPreferences.PREF_SAVED_PASSWORDS);
+ setupTestAccounts(mContext);
+ AndroidSyncSettings.overrideForTests(mContext, mSyncContentResolverDelegate);
+ mAuthority = AndroidSyncSettings.getContractAuthority(mContext);
+ AndroidSyncSettings.updateAccount(mContext, mAccount);
+ super.setUp();
+ loadNativeLibraryAndInitBrowserProcess();
+ }
+
+ private void setupTestAccounts(Context context) {
+ mAccountManager = new MockAccountManager(context, context);
+ AccountManagerHelper.overrideAccountManagerHelperForTests(context, mAccountManager);
+ mAccount = setupTestAccount("account@example.com");
+ mAlternateAccount = setupTestAccount("alternate@example.com");
+ }
+
+ private Account setupTestAccount(String accountName) {
+ Account account = AccountManagerHelper.createAccountFromName(accountName);
+ AccountHolder.Builder accountHolder =
+ AccountHolder.create().account(account).password("password").alwaysAccept(true);
+ mAccountManager.addAccountHolderExplicitly(accountHolder.build());
+ return account;
+ }
+
+ /*
Bernhard Bauer 2016/07/20 14:56:19 Javadoc-style comment.
dozsa 2016/07/21 08:51:33 Done.
+ * Launches the main preferences.
+ */
+ private static Preferences startMainPreferences(Instrumentation instrumentation,
+ final Context mContext) {
+ Intent intent = PreferencesLauncher.createIntentForSettingsPage(mContext,
+ MainPreferences.class.getName());
+ Activity activity = (Preferences) instrumentation.startActivitySync(intent);
+ assertTrue(activity instanceof Preferences);
+ return (Preferences) activity;
+ }
+
+ /**
+ * Fake ProfileSyncService to test redirecting the user to passwords.google.com
+ * and natively displaying passwords.
+ */
+ private static class FakeProfileSyncService extends ProfileSyncService {
Bernhard Bauer 2016/07/20 14:56:19 You could make this an anonymous class in override
dozsa 2016/07/21 08:51:33 Thank you for the suggestion. Done.
+
+ private boolean mUsingPassphrase;
Bernhard Bauer 2016/07/20 14:56:19 Make this final?
dozsa 2016/07/21 08:51:33 Removed so no longer necessary.
+
+ public FakeProfileSyncService(boolean usingPassphrase) {
+ super();
+ mUsingPassphrase = usingPassphrase;
+ }
+
+ @Override
+ public boolean isUsingSecondaryPassphrase() {
+ return mUsingPassphrase;
+ }
+
+ @Override
+ public boolean isBackendInitialized() {
+ return true;
+ }
+ }
+
+ private void overrideProfileSyncService(final boolean usingPassphrase) {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ ProfileSyncService.overrideForTests(new FakeProfileSyncService(usingPassphrase));
+ }
+ });
+ }
+
+ private void enableChromeSyncOnUiThread() {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ AndroidSyncSettings.enableChromeSync(mContext);
+ }
+ });
+ }
+
+ /**
+ * Verifies that sync settings are being set up correctly in the case of redirecting users.
+ */
+ @SmallTest
+ @CommandLineFlags.Add("enable-features=" + MainPreferences.VIEW_PASSWORDS)
+ @Feature({"Sync"})
+ public void testUserRedirectSyncSettings() throws InterruptedException {
vabr (Chromium) 2016/07/20 14:16:44 Since tests now pass, and you know that the sync s
dozsa 2016/07/21 08:51:33 I've kept the test but made a helper method for tu
+
+ // Turn on syncability
+ mSyncContentResolverDelegate.setMasterSyncAutomatically(true);
+ mSyncContentResolverDelegate.waitForLastNotificationCompleted();
+
+ //First sync
Bernhard Bauer 2016/07/20 14:56:19 Add a space at the beginning of the comment (also
dozsa 2016/07/21 08:51:33 Done.
+ mSyncContentResolverDelegate.setIsSyncable(mAccount, mAuthority, 1);
+ mSyncContentResolverDelegate.waitForLastNotificationCompleted();
+ mSyncContentResolverDelegate.setSyncAutomatically(mAccount, mAuthority, true);
+ mSyncContentResolverDelegate.waitForLastNotificationCompleted();
+
+ //Set ProfileSyncService to not use passphrase
+ overrideProfileSyncService(false);
+
+ assertTrue(AndroidSyncSettings.isSyncEnabled(mContext));
+ assertTrue(ProfileSyncService.get().isBackendInitialized());
+ assertFalse(ProfileSyncService.get().isUsingSecondaryPassphrase());
+ }
+
+ /**
+ * Verifies that syncing users with a custom passphrase are allowed to
+ * natively view passwords.
+ */
+ @SmallTest
+ public void testSyncingNativePasswordView() throws InterruptedException {
+ // Turn off syncability
+ mSyncContentResolverDelegate.setMasterSyncAutomatically(true);
+ mSyncContentResolverDelegate.waitForLastNotificationCompleted();
+
+ //First sync
+ mSyncContentResolverDelegate.setIsSyncable(mAccount, mAuthority, 1);
+ mSyncContentResolverDelegate.waitForLastNotificationCompleted();
+ mSyncContentResolverDelegate.setSyncAutomatically(mAccount, mAuthority, true);
+ mSyncContentResolverDelegate.waitForLastNotificationCompleted();
+
+ //Set ProfileSyncService to use passphrase
+ overrideProfileSyncService(true);
+
+ assertEquals(SavePasswordsPreferences.class.getCanonicalName(),
+ mPasswordsPref.getFragment());
+ assertNotNull(mMainPreferences.getActivity().getIntent());
+ }
+
+ /**
+ * Verifies that non-syncing users are allowed to natively view passwords.
+ */
+ @SmallTest
+ public void testNonSyncingNativePasswordView() throws InterruptedException {
+ // Turn off syncability
+ mSyncContentResolverDelegate.setMasterSyncAutomatically(false);
+ mSyncContentResolverDelegate.waitForLastNotificationCompleted();
+ mSyncContentResolverDelegate.setIsSyncable(mAccount, mAuthority, 0);
+ mSyncContentResolverDelegate.waitForLastNotificationCompleted();
+ AndroidSyncSettings.overrideForTests(mContext, mSyncContentResolverDelegate);
+ assertEquals(SavePasswordsPreferences.class.getCanonicalName(),
+ mPasswordsPref.getFragment());
+ }
+
+}

Powered by Google App Engine
This is Rietveld 408576698