OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.preferences; | 5 package org.chromium.chrome.browser.preferences; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.app.Instrumentation; | 9 import android.app.Instrumentation; |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.support.test.InstrumentationRegistry; | 12 import android.support.test.InstrumentationRegistry; |
13 import android.support.test.filters.SmallTest; | 13 import android.support.test.filters.SmallTest; |
14 | 14 |
15 import org.junit.After; | |
16 import org.junit.Assert; | 15 import org.junit.Assert; |
17 import org.junit.Before; | 16 import org.junit.Before; |
18 import org.junit.Rule; | 17 import org.junit.Rule; |
19 import org.junit.Test; | 18 import org.junit.Test; |
20 import org.junit.runner.RunWith; | 19 import org.junit.runner.RunWith; |
21 | 20 |
22 import org.chromium.base.ThreadUtils; | 21 import org.chromium.base.ThreadUtils; |
23 import org.chromium.base.test.BaseJUnit4ClassRunner; | 22 import org.chromium.base.test.BaseJUnit4ClassRunner; |
24 import org.chromium.base.test.util.CommandLineFlags; | 23 import org.chromium.base.test.util.CommandLineFlags; |
25 import org.chromium.base.test.util.Feature; | 24 import org.chromium.base.test.util.Feature; |
(...skipping 23 matching lines...) Expand all Loading... |
49 private Context mContext; | 48 private Context mContext; |
50 private MockSyncContentResolverDelegate mSyncContentResolverDelegate; | 49 private MockSyncContentResolverDelegate mSyncContentResolverDelegate; |
51 private String mAuthority; | 50 private String mAuthority; |
52 private Account mAccount; | 51 private Account mAccount; |
53 private FakeAccountManagerDelegate mAccountManager; | 52 private FakeAccountManagerDelegate mAccountManager; |
54 | 53 |
55 @Before | 54 @Before |
56 public void setUp() throws Exception { | 55 public void setUp() throws Exception { |
57 mSyncContentResolverDelegate = new MockSyncContentResolverDelegate(); | 56 mSyncContentResolverDelegate = new MockSyncContentResolverDelegate(); |
58 mContext = InstrumentationRegistry.getInstrumentation().getTargetContext
(); | 57 mContext = InstrumentationRegistry.getInstrumentation().getTargetContext
(); |
| 58 setupTestAccount(mContext); |
59 mMainPreferences = (MainPreferences) startMainPreferences( | 59 mMainPreferences = (MainPreferences) startMainPreferences( |
60 InstrumentationRegistry.getInstrumentation(), mContext) | 60 InstrumentationRegistry.getInstrumentation(), mContext) |
61 .getFragmentForTest(); | 61 .getFragmentForTest(); |
62 mPasswordsPref = (ChromeBasePreference) mMainPreferences.findPreference( | 62 mPasswordsPref = (ChromeBasePreference) mMainPreferences.findPreference( |
63 MainPreferences.PREF_SAVED_PASSWORDS); | 63 MainPreferences.PREF_SAVED_PASSWORDS); |
64 setupTestAccount(mContext); | |
65 AndroidSyncSettings.overrideForTests(mContext, mSyncContentResolverDeleg
ate); | 64 AndroidSyncSettings.overrideForTests(mContext, mSyncContentResolverDeleg
ate); |
66 mAuthority = AndroidSyncSettings.getContractAuthority(mContext); | 65 mAuthority = AndroidSyncSettings.getContractAuthority(mContext); |
67 AndroidSyncSettings.updateAccount(mContext, mAccount); | 66 AndroidSyncSettings.updateAccount(mContext, mAccount); |
68 mActivityTestRule.loadNativeLibraryAndInitBrowserProcess(); | 67 mActivityTestRule.loadNativeLibraryAndInitBrowserProcess(); |
69 } | 68 } |
70 | 69 |
71 private void setupTestAccount(Context context) { | 70 private void setupTestAccount(Context context) { |
72 mAccountManager = new FakeAccountManagerDelegate(context); | 71 mAccountManager = new FakeAccountManagerDelegate(); |
73 AccountManagerHelper.overrideAccountManagerHelperForTests(context, mAcco
untManager); | 72 AccountManagerHelper.overrideAccountManagerHelperForTests(mAccountManage
r); |
74 mAccount = AccountManagerHelper.createAccountFromName("account@example.c
om"); | 73 mAccount = AccountManagerHelper.createAccountFromName("account@example.c
om"); |
75 AccountHolder.Builder accountHolder = | 74 AccountHolder.Builder accountHolder = |
76 AccountHolder.builder(mAccount).password("password").alwaysAccep
t(true); | 75 AccountHolder.builder(mAccount).password("password").alwaysAccep
t(true); |
77 mAccountManager.addAccountHolderExplicitly(accountHolder.build()); | 76 mAccountManager.addAccountHolderExplicitly(accountHolder.build()); |
78 } | 77 } |
79 | 78 |
80 @After | |
81 public void tearDown() { | |
82 AccountManagerHelper.resetAccountManagerHelperForTests(); | |
83 } | |
84 | |
85 /** | 79 /** |
86 * Launches the main preferences. | 80 * Launches the main preferences. |
87 */ | 81 */ |
88 private static Preferences startMainPreferences(Instrumentation instrumentat
ion, | 82 private static Preferences startMainPreferences(Instrumentation instrumentat
ion, |
89 final Context mContext) { | 83 final Context mContext) { |
90 Intent intent = PreferencesLauncher.createIntentForSettingsPage(mContext
, | 84 Intent intent = PreferencesLauncher.createIntentForSettingsPage(mContext
, |
91 MainPreferences.class.getName()); | 85 MainPreferences.class.getName()); |
92 Activity activity = (Preferences) instrumentation.startActivitySync(inte
nt); | 86 Activity activity = (Preferences) instrumentation.startActivitySync(inte
nt); |
93 return (Preferences) activity; | 87 return (Preferences) activity; |
94 } | 88 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 */ | 169 */ |
176 @Test | 170 @Test |
177 @SmallTest | 171 @SmallTest |
178 public void testNonSyncingNativePasswordView() throws InterruptedException { | 172 public void testNonSyncingNativePasswordView() throws InterruptedException { |
179 setSyncability(false); | 173 setSyncability(false); |
180 Assert.assertEquals( | 174 Assert.assertEquals( |
181 SavePasswordsPreferences.class.getCanonicalName(), mPasswordsPre
f.getFragment()); | 175 SavePasswordsPreferences.class.getCanonicalName(), mPasswordsPre
f.getFragment()); |
182 } | 176 } |
183 | 177 |
184 } | 178 } |
OLD | NEW |