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

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderUnitTest.java

Issue 2872743003: Change AccountManagerHelper initialization
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/junit/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderUnitTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderUnitTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderUnitTest.java
index 3698d0066530c6c5369e4e000f192217af6cb65c..0fd8bddba7d30391c0cee3b682bd2244d893f83a 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderUnitTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderUnitTest.java
@@ -21,6 +21,7 @@ import android.content.pm.ProviderInfo;
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -57,6 +58,14 @@ public class SupervisedUserContentProviderUnitTest {
private static final String DEFAULT_CALLING_PACKAGE = "com.example.some.app";
+ private static AccountManagerDelegate sMockDelegate;
+
+ @BeforeClass
+ public static void overrideAccountManagerHelper() {
+ sMockDelegate = mock(AccountManagerDelegate.class);
+ AccountManagerHelper.overrideAccountManagerHelperForTests(sMockDelegate);
+ }
+
// Override methods that wrap things that can't be mocked (including native calls).
private static class MySupervisedUserContentProvider extends SupervisedUserContentProvider {
@Override
@@ -218,11 +227,8 @@ public class SupervisedUserContentProviderUnitTest {
// Mock things called during startup
ChromeBrowserInitializer mockBrowserInitializer = mock(ChromeBrowserInitializer.class);
ChromeBrowserInitializer.setForTesting(mockBrowserInitializer);
- AccountManagerDelegate mockDelegate = mock(AccountManagerDelegate.class);
- AccountManagerHelper.overrideAccountManagerHelperForTests(
- RuntimeEnvironment.application, mockDelegate);
Account account = new Account("Google", "Dummy");
- when(mockDelegate.getAccountsByType("Google")).thenReturn(new Account[] {account});
+ when(sMockDelegate.getAccountsByType("Google")).thenReturn(new Account[] {account});
WebRestrictionsResult result =
mSupervisedUserContentProvider.shouldProceed(DEFAULT_CALLING_PACKAGE, "url");
@@ -237,8 +243,6 @@ public class SupervisedUserContentProviderUnitTest {
.nativeShouldProceed(eq(5678L),
any(SupervisedUserContentProvider.SupervisedUserQueryReply.class),
eq("url"));
-
- AccountManagerHelper.resetAccountManagerHelperForTests();
}
@Test
@@ -246,11 +250,8 @@ public class SupervisedUserContentProviderUnitTest {
// Mock things called during startup
ChromeBrowserInitializer mockBrowserInitializer = mock(ChromeBrowserInitializer.class);
ChromeBrowserInitializer.setForTesting(mockBrowserInitializer);
- AccountManagerDelegate mockDelegate = mock(AccountManagerDelegate.class);
- AccountManagerHelper.overrideAccountManagerHelperForTests(
- RuntimeEnvironment.application, mockDelegate);
Account account = new Account("Google", "Dummy");
- when(mockDelegate.getAccountsByType("Google")).thenReturn(new Account[] {account});
+ when(sMockDelegate.getAccountsByType("Google")).thenReturn(new Account[] {account});
// Change the behavior of the forced sign-in processor to not sign in.
doAnswer(new Answer<Void>() {
@@ -268,8 +269,6 @@ public class SupervisedUserContentProviderUnitTest {
assertThat(result.shouldProceed(), is(false));
assertThat(result.getErrorInt(0), is(5));
-
- AccountManagerHelper.resetAccountManagerHelperForTests();
}
@Test

Powered by Google App Engine
This is Rietveld 408576698