OLD | NEW |
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 Loading... |
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().setSignedInAccountName("Dummy"); | 64 ChromeSigninController.get(RuntimeEnvironment.application) |
| 65 .setSignedInAccountName("Dummy"); |
65 onComplete.run(); | 66 onComplete.run(); |
66 } | 67 } |
67 | 68 |
68 @Override | 69 @Override |
69 void listenForChildAccountStatusChange(Callback<Boolean> callback) { | 70 void listenForChildAccountStatusChange(Callback<Boolean> callback) { |
70 callback.onResult(true); | 71 callback.onResult(true); |
71 } | 72 } |
72 | 73 |
73 @Override | 74 @Override |
74 void nativeShouldProceed(long l, SupervisedUserQueryReply reply, String
url) { | 75 void nativeShouldProceed(long l, SupervisedUserQueryReply reply, String
url) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 assertThat(mSupervisedUserContentProvider.requestInsert("url"), is(false
)); | 190 assertThat(mSupervisedUserContentProvider.requestInsert("url"), is(false
)); |
190 verify(mSupervisedUserContentProvider) | 191 verify(mSupervisedUserContentProvider) |
191 .nativeRequestInsert(eq(1234L), | 192 .nativeRequestInsert(eq(1234L), |
192 any(SupervisedUserContentProvider.SupervisedUserInsertRe
ply.class), | 193 any(SupervisedUserContentProvider.SupervisedUserInsertRe
ply.class), |
193 eq("url")); | 194 eq("url")); |
194 } | 195 } |
195 | 196 |
196 @Test | 197 @Test |
197 public void testShouldProceed_withStartupSignedIn() throws ProcessInitExcept
ion { | 198 public void testShouldProceed_withStartupSignedIn() throws ProcessInitExcept
ion { |
198 // Set up a signed in user | 199 // Set up a signed in user |
199 ChromeSigninController.get().setSignedInAccountName("Dummy"); | 200 ChromeSigninController.get(RuntimeEnvironment.application).setSignedInAc
countName("Dummy"); |
200 // Mock things called during startup | 201 // Mock things called during startup |
201 ChromeBrowserInitializer mockBrowserInitializer = mock(ChromeBrowserInit
ializer.class); | 202 ChromeBrowserInitializer mockBrowserInitializer = mock(ChromeBrowserInit
ializer.class); |
202 ChromeBrowserInitializer.setForTesting(mockBrowserInitializer); | 203 ChromeBrowserInitializer.setForTesting(mockBrowserInitializer); |
203 | 204 |
204 WebRestrictionsResult result = | 205 WebRestrictionsResult result = |
205 mSupervisedUserContentProvider.shouldProceed(DEFAULT_CALLING_PAC
KAGE, "url"); | 206 mSupervisedUserContentProvider.shouldProceed(DEFAULT_CALLING_PAC
KAGE, "url"); |
206 | 207 |
207 assertThat(result.shouldProceed(), is(true)); | 208 assertThat(result.shouldProceed(), is(true)); |
208 verify(mockBrowserInitializer).handleSynchronousStartup(); | 209 verify(mockBrowserInitializer).handleSynchronousStartup(); |
209 verify(mSupervisedUserContentProvider) | 210 verify(mSupervisedUserContentProvider) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 298 |
298 WebRestrictionsResult wrongCallingPackage = mSupervisedUserContentProvid
er.shouldProceed( | 299 WebRestrictionsResult wrongCallingPackage = mSupervisedUserContentProvid
er.shouldProceed( |
299 DEFAULT_CALLING_PACKAGE, "https://accounts.google.com/reauth"); | 300 DEFAULT_CALLING_PACKAGE, "https://accounts.google.com/reauth"); |
300 assertThat(wrongCallingPackage.shouldProceed(), is(false)); | 301 assertThat(wrongCallingPackage.shouldProceed(), is(false)); |
301 | 302 |
302 WebRestrictionsResult nullCallingPackage = mSupervisedUserContentProvide
r.shouldProceed( | 303 WebRestrictionsResult nullCallingPackage = mSupervisedUserContentProvide
r.shouldProceed( |
303 null, "https://accounts.google.com/reauth"); | 304 null, "https://accounts.google.com/reauth"); |
304 assertThat(nullCallingPackage.shouldProceed(), is(false)); | 305 assertThat(nullCallingPackage.shouldProceed(), is(false)); |
305 } | 306 } |
306 } | 307 } |
OLD | NEW |