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