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

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: Modify redirect test to verify sync settings 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..961dada96027c74c509fb081f0e875009858b509
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PasswordViewingTypeTest.java
@@ -0,0 +1,251 @@
+// 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.os.Bundle;
+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.AndroidSyncSettings.AndroidSyncSettingsObserver;
+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 static class CountingMockSyncContentResolverDelegate
+ extends MockSyncContentResolverDelegate {
+ private int mGetMasterSyncAutomaticallyCalls;
vabr (Chromium) 2016/07/20 11:15:07 The *Calls variables seem to be never read. Could
dozsa 2016/07/20 13:12:44 Sorry, that was something I used while playing wit
+ private int mGetSyncAutomaticallyCalls;
+ private int mGetIsSyncableCalls;
+ private int mSetIsSyncableCalls;
+ private int mSetSyncAutomaticallyCalls;
+ private int mRemovePeriodicSyncCalls;
+
+ @Override
+ public boolean getMasterSyncAutomatically() {
+ mGetMasterSyncAutomaticallyCalls++;
+ return super.getMasterSyncAutomatically();
+ }
+
+ @Override
+ public boolean getSyncAutomatically(Account account, String authority) {
+ mGetSyncAutomaticallyCalls++;
+ return super.getSyncAutomatically(account, authority);
+ }
+
+ @Override
+ public int getIsSyncable(Account account, String authority) {
+ mGetIsSyncableCalls++;
+ return super.getIsSyncable(account, authority);
+ }
+
+ @Override
+ public void setIsSyncable(Account account, String authority, int syncable) {
+ mSetIsSyncableCalls++;
+ super.setIsSyncable(account, authority, syncable);
+ }
+
+ @Override
+ public void setSyncAutomatically(Account account, String authority, boolean sync) {
+ mSetSyncAutomaticallyCalls++;
+ super.setSyncAutomatically(account, authority, sync);
+ }
+
+ @Override
+ public void removePeriodicSync(Account account, String authority, Bundle extras) {
+ mRemovePeriodicSyncCalls++;
+ super.removePeriodicSync(account, authority, extras);
+ }
+ }
+
+ private Context mContext;
+ private CountingMockSyncContentResolverDelegate mSyncContentResolverDelegate;
+ private String mAuthority;
+ private Account mAccount;
+ private Account mAlternateAccount;
+ private MockSyncSettingsObserver mSyncSettingsObserver;
+ private MockAccountManager mAccountManager;
+
+ @Override
+ protected void setUp() throws Exception {
+
+ mSyncContentResolverDelegate = new CountingMockSyncContentResolverDelegate();
+ 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);
+ mSyncSettingsObserver = new MockSyncSettingsObserver();
+ AndroidSyncSettings.registerObserver(mContext, mSyncSettingsObserver);
+ 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;
+ }
+
+ private static class MockSyncSettingsObserver implements AndroidSyncSettingsObserver {
+ private boolean mReceivedNotification;
+
+ public void clearNotification() {
+ mReceivedNotification = false;
+ }
+
+ public boolean receivedNotification() {
vabr (Chromium) 2016/07/20 11:15:07 Is this getter ever called? If not, could you drop
dozsa 2016/07/20 13:12:44 Same as above. Removed.
+ return mReceivedNotification;
+ }
+
+ @Override
+ public void androidSyncSettingsChanged() {
+ mReceivedNotification = true;
+ }
+ }
+
+ /*
+ * 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 {
+
+ private boolean mUsingPassphrase;
+
+ 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 {
+
+ // Turn on syncability
+ mSyncContentResolverDelegate.setMasterSyncAutomatically(true);
+ mSyncContentResolverDelegate.waitForLastNotificationCompleted();
+
+ //First sync
+ mSyncContentResolverDelegate.setIsSyncable(mAccount, mAuthority, 1);
+ mSyncContentResolverDelegate.waitForLastNotificationCompleted();
+ mSyncContentResolverDelegate.setSyncAutomatically(mAccount, mAuthority, true);
+ mSyncContentResolverDelegate.waitForLastNotificationCompleted();
+
+ 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() {
+ mSyncContentResolverDelegate.setMasterSyncAutomatically(true);
+ mSyncContentResolverDelegate.setIsSyncable(mAccount, mAuthority, 1);
+ AndroidSyncSettings.overrideForTests(mContext, mSyncContentResolverDelegate);
+ enableChromeSyncOnUiThread();
+ 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() {
+ mSyncContentResolverDelegate.setIsSyncable(mAccount, mAuthority, 0);
+ AndroidSyncSettings.overrideForTests(mContext, mSyncContentResolverDelegate);
+ assertEquals(SavePasswordsPreferences.class.getCanonicalName(),
+ mPasswordsPref.getFragment());
+ }
+
+}

Powered by Google App Engine
This is Rietveld 408576698