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

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

Issue 2784353002: Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Fix tests Created 3 years, 8 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.superviseduser; 5 package org.chromium.chrome.browser.superviseduser;
6 6
7 import static org.hamcrest.CoreMatchers.is; 7 import static org.hamcrest.CoreMatchers.is;
8 import static org.junit.Assert.assertThat; 8 import static org.junit.Assert.assertThat;
9 import static org.mockito.ArgumentMatchers.any; 9 import static org.mockito.ArgumentMatchers.any;
10 import static org.mockito.ArgumentMatchers.anyLong; 10 import static org.mockito.ArgumentMatchers.anyLong;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 public DisableHistogramsRule mDisableHistogramsRule = new DisableHistogramsR ule(); 54 public DisableHistogramsRule mDisableHistogramsRule = new DisableHistogramsR ule();
55 55
56 private SupervisedUserContentProvider mSupervisedUserContentProvider; 56 private SupervisedUserContentProvider mSupervisedUserContentProvider;
57 57
58 private static final String DEFAULT_CALLING_PACKAGE = "com.example.some.app" ; 58 private static final String DEFAULT_CALLING_PACKAGE = "com.example.some.app" ;
59 59
60 // Override methods that wrap things that can't be mocked (including native calls). 60 // Override methods that wrap things that can't be mocked (including native calls).
61 private static class MySupervisedUserContentProvider extends SupervisedUserC ontentProvider { 61 private static class MySupervisedUserContentProvider extends SupervisedUserC ontentProvider {
62 @Override 62 @Override
63 void startForcedSigninProcessor(Context context, Runnable onComplete) { 63 void startForcedSigninProcessor(Context context, Runnable onComplete) {
64 ChromeSigninController.get(RuntimeEnvironment.application) 64 ChromeSigninController.get().setSignedInAccountName("Dummy");
65 .setSignedInAccountName("Dummy");
66 onComplete.run(); 65 onComplete.run();
67 } 66 }
68 67
69 @Override 68 @Override
70 void listenForChildAccountStatusChange(Callback<Boolean> callback) { 69 void listenForChildAccountStatusChange(Callback<Boolean> callback) {
71 callback.onResult(true); 70 callback.onResult(true);
72 } 71 }
73 72
74 @Override 73 @Override
75 void nativeShouldProceed(long l, SupervisedUserQueryReply reply, String url) { 74 void nativeShouldProceed(long l, SupervisedUserQueryReply reply, String url) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 assertThat(mSupervisedUserContentProvider.requestInsert("url"), is(false )); 189 assertThat(mSupervisedUserContentProvider.requestInsert("url"), is(false ));
191 verify(mSupervisedUserContentProvider) 190 verify(mSupervisedUserContentProvider)
192 .nativeRequestInsert(eq(1234L), 191 .nativeRequestInsert(eq(1234L),
193 any(SupervisedUserContentProvider.SupervisedUserInsertRe ply.class), 192 any(SupervisedUserContentProvider.SupervisedUserInsertRe ply.class),
194 eq("url")); 193 eq("url"));
195 } 194 }
196 195
197 @Test 196 @Test
198 public void testShouldProceed_withStartupSignedIn() throws ProcessInitExcept ion { 197 public void testShouldProceed_withStartupSignedIn() throws ProcessInitExcept ion {
199 // Set up a signed in user 198 // Set up a signed in user
200 ChromeSigninController.get(RuntimeEnvironment.application).setSignedInAc countName("Dummy"); 199 ChromeSigninController.get().setSignedInAccountName("Dummy");
201 // Mock things called during startup 200 // Mock things called during startup
202 ChromeBrowserInitializer mockBrowserInitializer = mock(ChromeBrowserInit ializer.class); 201 ChromeBrowserInitializer mockBrowserInitializer = mock(ChromeBrowserInit ializer.class);
203 ChromeBrowserInitializer.setForTesting(mockBrowserInitializer); 202 ChromeBrowserInitializer.setForTesting(mockBrowserInitializer);
204 203
205 WebRestrictionsResult result = 204 WebRestrictionsResult result =
206 mSupervisedUserContentProvider.shouldProceed(DEFAULT_CALLING_PAC KAGE, "url"); 205 mSupervisedUserContentProvider.shouldProceed(DEFAULT_CALLING_PAC KAGE, "url");
207 206
208 assertThat(result.shouldProceed(), is(true)); 207 assertThat(result.shouldProceed(), is(true));
209 verify(mockBrowserInitializer).handleSynchronousStartup(); 208 verify(mockBrowserInitializer).handleSynchronousStartup();
210 verify(mSupervisedUserContentProvider) 209 verify(mSupervisedUserContentProvider)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 297
299 WebRestrictionsResult wrongCallingPackage = mSupervisedUserContentProvid er.shouldProceed( 298 WebRestrictionsResult wrongCallingPackage = mSupervisedUserContentProvid er.shouldProceed(
300 DEFAULT_CALLING_PACKAGE, "https://accounts.google.com/reauth"); 299 DEFAULT_CALLING_PACKAGE, "https://accounts.google.com/reauth");
301 assertThat(wrongCallingPackage.shouldProceed(), is(false)); 300 assertThat(wrongCallingPackage.shouldProceed(), is(false));
302 301
303 WebRestrictionsResult nullCallingPackage = mSupervisedUserContentProvide r.shouldProceed( 302 WebRestrictionsResult nullCallingPackage = mSupervisedUserContentProvide r.shouldProceed(
304 null, "https://accounts.google.com/reauth"); 303 null, "https://accounts.google.com/reauth");
305 assertThat(nullCallingPackage.shouldProceed(), is(false)); 304 assertThat(nullCallingPackage.shouldProceed(), is(false));
306 } 305 }
307 } 306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698