| 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; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import android.accounts.Account; | 7 import android.accounts.Account; |
| 8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.SharedPreferences; | 10 import android.content.SharedPreferences; |
| 11 import android.os.Build; | 11 import android.os.Build; |
| 12 import android.test.suitebuilder.annotation.SmallTest; | 12 import android.test.suitebuilder.annotation.SmallTest; |
| 13 | 13 |
| 14 import org.chromium.base.ContextUtils; | 14 import org.chromium.base.ContextUtils; |
| 15 import org.chromium.base.StreamUtil; | 15 import org.chromium.base.StreamUtil; |
| 16 import org.chromium.base.ThreadUtils; |
| 16 import org.chromium.base.test.util.CommandLineFlags; | 17 import org.chromium.base.test.util.CommandLineFlags; |
| 17 import org.chromium.base.test.util.MinAndroidSdkLevel; | 18 import org.chromium.base.test.util.MinAndroidSdkLevel; |
| 18 import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor; | 19 import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor; |
| 19 import org.chromium.chrome.browser.firstrun.FirstRunStatus; | 20 import org.chromium.chrome.browser.firstrun.FirstRunStatus; |
| 20 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; | 21 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
| 21 import org.chromium.chrome.browser.signin.AccountIdProvider; | 22 import org.chromium.chrome.browser.signin.AccountIdProvider; |
| 22 import org.chromium.chrome.test.ChromeTabbedActivityTestBase; | 23 import org.chromium.chrome.test.ChromeTabbedActivityTestBase; |
| 23 import org.chromium.sync.signin.AccountManagerHelper; | 24 import org.chromium.sync.signin.AccountManagerHelper; |
| 24 import org.chromium.sync.signin.ChromeSigninController; | 25 import org.chromium.sync.signin.ChromeSigninController; |
| 25 import org.chromium.sync.test.util.MockAccountManager; | 26 import org.chromium.sync.test.util.MockAccountManager; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 85 |
| 85 mTargetContext = getInstrumentation().getTargetContext(); | 86 mTargetContext = getInstrumentation().getTargetContext(); |
| 86 | 87 |
| 87 // Create a mock account manager. Although this isn't used by ChromeBack
upAgent it is used | 88 // Create a mock account manager. Although this isn't used by ChromeBack
upAgent it is used |
| 88 // when we test the result by starting Chrome. | 89 // when we test the result by starting Chrome. |
| 89 ChromeBackupAgent.allowChromeApplicationForTesting(); | 90 ChromeBackupAgent.allowChromeApplicationForTesting(); |
| 90 Account account = new Account(TEST_ACCOUNT_1, GOOGLE_ACCOUNT_TYPE); | 91 Account account = new Account(TEST_ACCOUNT_1, GOOGLE_ACCOUNT_TYPE); |
| 91 MockAccountManager accountManager = | 92 MockAccountManager accountManager = |
| 92 new MockAccountManager(mTargetContext, getInstrumentation().getC
ontext(), account); | 93 new MockAccountManager(mTargetContext, getInstrumentation().getC
ontext(), account); |
| 93 AccountManagerHelper.overrideAccountManagerHelperForTests(mTargetContext
, accountManager); | 94 AccountManagerHelper.overrideAccountManagerHelperForTests(mTargetContext
, accountManager); |
| 94 AccountIdProvider.setInstanceForTest(new MockAccountIdProvider()); | 95 |
| 96 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 97 @Override |
| 98 public void run() { |
| 99 AccountIdProvider.setInstanceForTest(new MockAccountIdProvider()
); |
| 100 } |
| 101 }); |
| 95 } | 102 } |
| 96 | 103 |
| 97 @SmallTest | 104 @SmallTest |
| 98 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP) | 105 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP) |
| 99 public void testSimpleRestore() throws InterruptedException, IOException { | 106 public void testSimpleRestore() throws InterruptedException, IOException { |
| 100 | 107 |
| 101 // Fake having previously gone through FRE and signed in. | 108 // Fake having previously gone through FRE and signed in. |
| 102 SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); | 109 SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); |
| 103 SharedPreferences.Editor preferenceEditor = prefs.edit(); | 110 SharedPreferences.Editor preferenceEditor = prefs.edit(); |
| 104 preferenceEditor.putBoolean(FirstRunStatus.FIRST_RUN_FLOW_COMPLETE, true
); | 111 preferenceEditor.putBoolean(FirstRunStatus.FIRST_RUN_FLOW_COMPLETE, true
); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 int fileLength = (int) prefsFile.length(); | 200 int fileLength = (int) prefsFile.length(); |
| 194 byte[] inputBuffer = new byte[fileLength]; | 201 byte[] inputBuffer = new byte[fileLength]; |
| 195 assertEquals(fileLength, prefsFileReader.read(inputBuffer)); | 202 assertEquals(fileLength, prefsFileReader.read(inputBuffer)); |
| 196 return new String(inputBuffer, "UTF-8"); | 203 return new String(inputBuffer, "UTF-8"); |
| 197 } finally { | 204 } finally { |
| 198 StreamUtil.closeQuietly(prefsFileReader); | 205 StreamUtil.closeQuietly(prefsFileReader); |
| 199 } | 206 } |
| 200 } | 207 } |
| 201 | 208 |
| 202 } | 209 } |
| OLD | NEW |