Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PreferencesTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PreferencesTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PreferencesTest.java |
| index 12d69bb81a3ad844e0fa5d8a2b84c5e1125ef696..f11a963d260c369bf4cfd7efa0de154f3d9455ca 100644 |
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PreferencesTest.java |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PreferencesTest.java |
| @@ -4,6 +4,7 @@ |
| package org.chromium.chrome.browser.preferences; |
| +import android.accounts.Account; |
| import android.app.Activity; |
| import android.app.Instrumentation; |
| import android.content.Context; |
| @@ -14,6 +15,7 @@ import android.preference.PreferenceScreen; |
| import android.test.suitebuilder.annotation.SmallTest; |
| import org.chromium.base.ThreadUtils; |
| +import org.chromium.base.test.util.CommandLineFlags; |
| import org.chromium.base.test.util.DisableIf; |
| import org.chromium.base.test.util.Feature; |
| import org.chromium.chrome.browser.accessibility.FontSizePrefs; |
| @@ -23,9 +25,13 @@ import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge; |
| import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
| import org.chromium.chrome.browser.search_engines.TemplateUrlService.LoadListener; |
| import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl; |
| +import org.chromium.chrome.browser.sync.ProfileSyncService; |
| import org.chromium.content.browser.test.NativeLibraryTestBase; |
| import org.chromium.content.browser.test.util.CallbackHelper; |
| import org.chromium.content.browser.test.util.UiUtils; |
| +import org.chromium.sync.AndroidSyncSettings; |
| +import org.chromium.sync.signin.AccountManagerHelper; |
| +import org.chromium.sync.test.util.MockSyncContentResolverDelegate; |
| import java.lang.reflect.InvocationTargetException; |
| import java.lang.reflect.Method; |
| @@ -56,6 +62,110 @@ public class PreferencesTest extends NativeLibraryTestBase { |
| return (Preferences) activity; |
| } |
| + /** |
| + * Fake ProfileSyncService to test displaying passwords natively. |
| + */ |
| + private static class FakeProfileSyncServiceWithPassphrase extends ProfileSyncService { |
| + public boolean isUsingSecondaryPassphrase() { |
| + return true; |
| + } |
| + } |
| + |
| + /** |
| + * Fake ProfileSyncService to test redirecting the user to passwords.google.com. |
| + */ |
| + private static class FakeProfileSyncServiceWithoutPassphrase extends ProfileSyncService { |
|
Bernhard Bauer
2016/07/01 16:55:28
I think you could merge this with FakeProfileSyncS
dozsa
2016/07/05 10:19:54
Done.
|
| + public boolean isUsingSecondaryPassphrase() { |
| + return false; |
| + } |
| + } |
| + |
| + private void overrideProfileSyncService(final boolean usingPassphrase) { |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + if (usingPassphrase) { |
| + // PSS has to be constructed on the UI thread. |
| + ProfileSyncService.overrideForTests( |
| + new FakeProfileSyncServiceWithPassphrase()); |
| + } else { |
| + // PSS has to be constructed on the UI thread. |
| + ProfileSyncService.overrideForTests( |
| + new FakeProfileSyncServiceWithoutPassphrase()); |
| + } |
| + } |
| + }); |
| + } |
| + |
| + /** |
| + * Verifies that syncing users without a custom passphrase are redirected to |
| + * passwords.google.com. |
| + */ |
| + @SmallTest |
| + @CommandLineFlags.Add("enable-features=" + MainPreferences.VIEW_PASSWORDS) |
| + public void testUserRedirect() { |
| + Account account = AccountManagerHelper.createAccountFromName("account@example.com"); |
| + String authority = AndroidSyncSettings.getContractAuthority( |
| + getInstrumentation().getTargetContext()); |
| + MainPreferences mainPreferences = (MainPreferences) startPreferences(getInstrumentation(), |
| + MainPreferences.class.getName()).getFragmentForTest(); |
| + ChromeBasePreference passwordsPref = |
| + (ChromeBasePreference) mainPreferences.findPreference( |
| + MainPreferences.PREF_SAVED_PASSWORDS); |
|
Bernhard Bauer
2016/07/01 16:55:28
Could you move these tests to a new class? Then yo
dozsa
2016/07/05 10:19:54
Done.
|
| + overrideProfileSyncService(false); |
| + MockSyncContentResolverDelegate delegate = new MockSyncContentResolverDelegate(); |
| + delegate.setIsSyncable(account, authority, 1); |
| + AndroidSyncSettings.overrideForTests(getInstrumentation().getTargetContext(), |
| + delegate); |
| + assertTrue(mainPreferences.onPreferenceClick(passwordsPref)); |
| + } |
| + |
| + /** |
| + * Verifies that syncing users with a custom passphrase are allowed to |
| + * natively view passwords. |
| + */ |
| + @SmallTest |
| + @CommandLineFlags.Add("enable-features=" + MainPreferences.VIEW_PASSWORDS) |
| + public void testNativePasswordViewSyncing() { |
| + Account account = AccountManagerHelper.createAccountFromName("account@example.com"); |
| + String authority = AndroidSyncSettings.getContractAuthority( |
| + getInstrumentation().getTargetContext()); |
| + MainPreferences mainPreferences = (MainPreferences) startPreferences(getInstrumentation(), |
| + MainPreferences.class.getName()).getFragmentForTest(); |
| + ChromeBasePreference passwordsPref = |
| + (ChromeBasePreference) mainPreferences.findPreference( |
| + MainPreferences.PREF_SAVED_PASSWORDS); |
| + overrideProfileSyncService(true); |
| + MockSyncContentResolverDelegate delegate = new MockSyncContentResolverDelegate(); |
| + delegate.setIsSyncable(account, authority, 1); |
| + AndroidSyncSettings.overrideForTests(getInstrumentation().getTargetContext(), |
| + delegate); |
| + assertEquals(passwordsPref.getFragment(), "org.chromium.chrome.browser.preferences" |
|
Bernhard Bauer
2016/07/01 16:55:28
Expected value goes first.
dozsa
2016/07/05 10:19:54
Done.
|
| + + ".password.SavePasswordsPreferences"); |
| + } |
| + |
| + /** |
| + * Verifies that non-syncing users are allowed to natively view passwords. |
| + */ |
| + @SmallTest |
| + @CommandLineFlags.Add("enable-features=" + MainPreferences.VIEW_PASSWORDS) |
| + public void testNativePasswordViewNonSyncing() { |
| + Account account = AccountManagerHelper.createAccountFromName("account@example.com"); |
| + String authority = AndroidSyncSettings.getContractAuthority( |
| + getInstrumentation().getTargetContext()); |
| + MainPreferences mainPreferences = (MainPreferences) startPreferences(getInstrumentation(), |
| + MainPreferences.class.getName()).getFragmentForTest(); |
| + ChromeBasePreference passwordsPref = |
| + (ChromeBasePreference) mainPreferences.findPreference( |
| + MainPreferences.PREF_SAVED_PASSWORDS); |
| + MockSyncContentResolverDelegate delegate = new MockSyncContentResolverDelegate(); |
| + delegate.setIsSyncable(account, authority, 0); |
| + AndroidSyncSettings.overrideForTests(getInstrumentation().getTargetContext(), |
| + delegate); |
| + assertEquals(passwordsPref.getFragment(), "org.chromium.chrome.browser.preferences" |
| + + ".password.SavePasswordsPreferences"); |
| + } |
| + |
| public static void clickPreference(PreferenceFragment fragment, Preference preference) { |
| try { |
| Method performClick = Preference.class.getDeclaredMethod("performClick", |