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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/ChromeBackupIntegrationTest.java

Issue 2175603004: Fix tests calling methods on the wrong thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698