Commit 6258401b authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Signin][Android] Cleanup SigninTestUtil

This CL removes unused Context field from SigninTestUtil, fixes usages
and also replaces a couple of anonymous classes with lambdas.

Bug: 738533
Change-Id: Ia47262016a7aa7d5bc7a682a949518613760cf8a
Reviewed-on: https://chromium-review.googlesource.com/c/1352319Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612259}
parent 67e41cf3
......@@ -20,7 +20,6 @@ import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.provider.Browser;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.filters.SmallTest;
import android.support.v7.widget.RecyclerView;
......@@ -675,7 +674,7 @@ public class HistoryActivityTest {
// Sign in to account. Note that if supervised user is set before sign in, the supervised
// user setting will be reset.
SigninTestUtil.setUpAuthForTest(InstrumentationRegistry.getInstrumentation());
SigninTestUtil.setUpAuthForTest();
final Account account = SigninTestUtil.addTestAccount();
ThreadUtils.runOnUiThreadBlocking(() -> {
SigninManager.get().onFirstRunCheckDone();
......
......@@ -54,7 +54,7 @@ public class ClearBrowsingDataPreferencesBasicTest {
@Before
public void setUp() throws InterruptedException {
SigninTestUtil.setUpAuthForTest(InstrumentationRegistry.getInstrumentation());
SigninTestUtil.setUpAuthForTest();
mActivityTestRule.startMainActivityOnBlankPage();
}
......
......@@ -83,7 +83,7 @@ public class ClearBrowsingDataPreferencesTest {
@Before
public void setUp() throws Exception {
SigninTestUtil.setUpAuthForTest(InstrumentationRegistry.getInstrumentation());
SigninTestUtil.setUpAuthForTest();
mActivityTestRule.startMainActivityOnBlankPage();
mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
......
......@@ -215,7 +215,7 @@ public class SigninTest {
@Before
public void setUp() throws Exception {
// Mock out the account manager on the device.
SigninTestUtil.setUpAuthForTest(InstrumentationRegistry.getInstrumentation());
SigninTestUtil.setUpAuthForTest();
mActivityTestRule.startMainActivityOnBlankPage();
mContext = InstrumentationRegistry.getTargetContext();
......
......@@ -271,7 +271,7 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> {
ApplicationTestUtils.clearAppData(InstrumentationRegistry.getTargetContext());
// This must be called before super.setUp() in order for test authentication to work.
SigninTestUtil.setUpAuthForTest(InstrumentationRegistry.getInstrumentation());
SigninTestUtil.setUpAuthForTest();
}
private void ruleTearDown() throws Exception {
......
......@@ -458,7 +458,7 @@ public class DocumentModeAssassinTest {
throws Exception {
// Load up the metadata file via a TabPersistentStore to make sure that it contains all of
// the migrated tab information.
SigninTestUtil.setUpAuthForTest(InstrumentationRegistry.getInstrumentation());
SigninTestUtil.setUpAuthForTest();
mTestRule.loadNativeLibraryAndInitBrowserProcess();
TabPersistentStore.setBaseStateDirectoryForTests(mTabbedModeDirectory.getBaseDirectory());
......
......@@ -4,7 +4,6 @@
package org.chromium.chrome.browser.test;
import android.app.Instrumentation;
import android.support.test.InstrumentationRegistry;
import org.junit.runner.Description;
......@@ -19,9 +18,9 @@ import org.chromium.content_public.browser.test.NativeLibraryTestRule;
* initializing the AccountManagerFacade.
*/
public class ChromeBrowserTestRule extends NativeLibraryTestRule {
private void setUp(Instrumentation instrumentation) {
private void setUp() {
ApplicationData.clearAppData(InstrumentationRegistry.getTargetContext());
SigninTestUtil.setUpAuthForTest(instrumentation);
SigninTestUtil.setUpAuthForTest();
loadNativeLibraryAndInitBrowserProcess();
}
......@@ -35,7 +34,7 @@ public class ChromeBrowserTestRule extends NativeLibraryTestRule {
* UI thread). After loading the library, this will initialize the browser process
* if necessary.
*/
setUp(InstrumentationRegistry.getInstrumentation());
setUp();
try {
base.evaluate();
} finally {
......
......@@ -6,8 +6,6 @@ package org.chromium.chrome.test.util.browser.signin;
import android.accounts.Account;
import android.annotation.SuppressLint;
import android.app.Instrumentation;
import android.content.Context;
import android.support.annotation.WorkerThread;
import org.chromium.base.ContextUtils;
......@@ -33,8 +31,6 @@ public final class SigninTestUtil {
private static final String DEFAULT_ACCOUNT = "test@gmail.com";
@SuppressLint("StaticFieldLeak")
private static Context sContext;
@SuppressLint("StaticFieldLeak")
private static FakeAccountManagerDelegate sAccountManager;
@SuppressLint("StaticFieldLeak")
......@@ -46,15 +42,9 @@ public final class SigninTestUtil {
* This must be called before native is loaded.
*/
@WorkerThread
public static void setUpAuthForTest(Instrumentation instrumentation) {
assert sContext == null;
sContext = instrumentation.getTargetContext();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
ProcessInitializationHandler.getInstance().initializePreNative();
}
});
public static void setUpAuthForTest() {
ThreadUtils.runOnUiThreadBlocking(
() -> ProcessInitializationHandler.getInstance().initializePreNative());
sAccountManager = new FakeAccountManagerDelegate(
FakeAccountManagerDelegate.DISABLE_PROFILE_DATA_SOURCE);
AccountManagerFacade.overrideAccountManagerFacadeForTests(sAccountManager);
......@@ -71,14 +61,12 @@ public final class SigninTestUtil {
sAccountManager.removeAccountHolderBlocking(accountHolder);
}
sAddedAccounts.clear();
sContext = null;
}
/**
* Returns the currently signed in account.
*/
public static Account getCurrentAccount() {
assert sContext != null;
return ChromeSigninController.get().getSignedInUser();
}
......@@ -115,21 +103,18 @@ public final class SigninTestUtil {
}
private static void overrideAccountIdProvider() {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
AccountIdProvider.setInstanceForTest(new AccountIdProvider() {
@Override
public String getAccountId(String accountName) {
return "gaia-id-" + accountName;
}
@Override
public boolean canBeUsed() {
return true;
}
});
}
ThreadUtils.runOnUiThreadBlocking(() -> {
AccountIdProvider.setInstanceForTest(new AccountIdProvider() {
@Override
public String getAccountId(String accountName) {
return "gaia-id-" + accountName;
}
@Override
public boolean canBeUsed() {
return true;
}
});
});
}
......@@ -142,7 +127,7 @@ public final class SigninTestUtil {
ChromeSigninController.get().setSignedInAccountName(null);
ContextUtils.getAppSharedPreferences()
.edit()
.putStringSet(OAuth2TokenService.STORED_ACCOUNTS_KEY, new HashSet<String>())
.putStringSet(OAuth2TokenService.STORED_ACCOUNTS_KEY, new HashSet<>())
.apply();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment