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.net; | 5 package org.chromium.net; |
6 | 6 |
7 import static org.hamcrest.CoreMatchers.equalTo; | 7 import static org.hamcrest.CoreMatchers.equalTo; |
8 import static org.hamcrest.CoreMatchers.notNullValue; | 8 import static org.hamcrest.CoreMatchers.notNullValue; |
9 import static org.hamcrest.CoreMatchers.nullValue; | 9 import static org.hamcrest.CoreMatchers.nullValue; |
10 import static org.junit.Assert.assertThat; | 10 import static org.junit.Assert.assertThat; |
(...skipping 26 matching lines...) Expand all Loading... |
37 import android.content.Context; | 37 import android.content.Context; |
38 import android.content.Intent; | 38 import android.content.Intent; |
39 import android.os.Bundle; | 39 import android.os.Bundle; |
40 import android.os.Handler; | 40 import android.os.Handler; |
41 | 41 |
42 import junit.framework.Assert; | 42 import junit.framework.Assert; |
43 | 43 |
44 import org.chromium.base.ApplicationStatus; | 44 import org.chromium.base.ApplicationStatus; |
45 import org.chromium.base.BaseChromiumApplication; | 45 import org.chromium.base.BaseChromiumApplication; |
46 import org.chromium.base.ContextUtils; | 46 import org.chromium.base.ContextUtils; |
| 47 import org.chromium.base.test.shadows.ShadowMultiDex; |
47 import org.chromium.net.HttpNegotiateAuthenticator.GetAccountsCallback; | 48 import org.chromium.net.HttpNegotiateAuthenticator.GetAccountsCallback; |
48 import org.chromium.net.HttpNegotiateAuthenticator.RequestData; | 49 import org.chromium.net.HttpNegotiateAuthenticator.RequestData; |
49 import org.chromium.testing.local.LocalRobolectricTestRunner; | 50 import org.chromium.testing.local.LocalRobolectricTestRunner; |
50 import org.junit.After; | 51 import org.junit.After; |
51 import org.junit.Before; | 52 import org.junit.Before; |
52 import org.junit.Test; | 53 import org.junit.Test; |
53 import org.junit.runner.RunWith; | 54 import org.junit.runner.RunWith; |
54 import org.mockito.ArgumentCaptor; | 55 import org.mockito.ArgumentCaptor; |
55 import org.mockito.Captor; | 56 import org.mockito.Captor; |
56 import org.mockito.Mock; | 57 import org.mockito.Mock; |
57 import org.mockito.MockitoAnnotations; | 58 import org.mockito.MockitoAnnotations; |
58 import org.robolectric.Robolectric; | 59 import org.robolectric.Robolectric; |
59 import org.robolectric.RuntimeEnvironment; | |
60 import org.robolectric.annotation.Config; | 60 import org.robolectric.annotation.Config; |
61 import org.robolectric.annotation.Implementation; | 61 import org.robolectric.annotation.Implementation; |
62 import org.robolectric.annotation.Implements; | 62 import org.robolectric.annotation.Implements; |
63 import org.robolectric.shadows.ShadowAccountManager; | 63 import org.robolectric.shadows.ShadowAccountManager; |
64 import org.robolectric.shadows.ShadowApplication; | 64 import org.robolectric.shadows.ShadowApplication; |
65 import org.robolectric.shadows.multidex.ShadowMultiDex; | |
66 | 65 |
67 import java.io.IOException; | 66 import java.io.IOException; |
68 import java.util.List; | 67 import java.util.List; |
69 | 68 |
70 /** | 69 /** |
71 * Robolectric tests for HttpNegotiateAuthenticator | 70 * Robolectric tests for HttpNegotiateAuthenticator |
72 */ | 71 */ |
73 @RunWith(LocalRobolectricTestRunner.class) | 72 @RunWith(LocalRobolectricTestRunner.class) |
74 @Config(manifest = Config.NONE, application = BaseChromiumApplication.class, | 73 @Config(manifest = Config.NONE, application = BaseChromiumApplication.class, |
75 shadows = {HttpNegotiateAuthenticatorTest.ExtendedShadowAccountManager.c
lass, | 74 shadows = {HttpNegotiateAuthenticatorTest.ExtendedShadowAccountManager.c
lass, |
(...skipping 16 matching lines...) Expand all Loading... |
92 @Captor | 91 @Captor |
93 private ArgumentCaptor<AccountManagerCallback<Bundle>> mBundleCallbackCaptor
; | 92 private ArgumentCaptor<AccountManagerCallback<Bundle>> mBundleCallbackCaptor
; |
94 @Captor | 93 @Captor |
95 private ArgumentCaptor<AccountManagerCallback<Account[]>> mAccountCallbackCa
ptor; | 94 private ArgumentCaptor<AccountManagerCallback<Account[]>> mAccountCallbackCa
ptor; |
96 @Captor | 95 @Captor |
97 private ArgumentCaptor<Bundle> mBundleCaptor; | 96 private ArgumentCaptor<Bundle> mBundleCaptor; |
98 | 97 |
99 @Before | 98 @Before |
100 public void setUp() { | 99 public void setUp() { |
101 MockitoAnnotations.initMocks(this); | 100 MockitoAnnotations.initMocks(this); |
102 ContextUtils.initApplicationContextForTests(RuntimeEnvironment.applicati
on); | 101 ContextUtils.initApplicationContextForTests(Robolectric.application); |
103 } | 102 } |
104 | 103 |
105 @After | 104 @After |
106 public void tearDown() { | 105 public void tearDown() { |
107 ApplicationStatus.destroyForJUnitTests(); | 106 ApplicationStatus.destroyForJUnitTests(); |
108 } | 107 } |
109 | 108 |
110 /** | 109 /** |
111 * Test of {@link HttpNegotiateAuthenticator#getNextAuthToken} | 110 * Test of {@link HttpNegotiateAuthenticator#getNextAuthToken} |
112 */ | 111 */ |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 requestData.account = new Account("a", type); | 232 requestData.account = new Account("a", type); |
234 requestData.accountManager = sMockAccountManager; | 233 requestData.accountManager = sMockAccountManager; |
235 Bundle b = new Bundle(); | 234 Bundle b = new Bundle(); |
236 b.putParcelable(AccountManager.KEY_INTENT, new Intent()); | 235 b.putParcelable(AccountManager.KEY_INTENT, new Intent()); |
237 | 236 |
238 authenticator.new GetTokenCallback(requestData).run(makeFuture(b)); | 237 authenticator.new GetTokenCallback(requestData).run(makeFuture(b)); |
239 verifyZeroInteractions(sMockAccountManager); | 238 verifyZeroInteractions(sMockAccountManager); |
240 | 239 |
241 // Verify that the broadcast receiver is registered | 240 // Verify that the broadcast receiver is registered |
242 Intent intent = new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION)
; | 241 Intent intent = new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION)
; |
243 ShadowApplication shadowApplication = ShadowApplication.getInstance(); | 242 ShadowApplication shadowApplication = Robolectric.getShadowApplication()
; |
244 List<BroadcastReceiver> receivers = shadowApplication.getReceiversForInt
ent(intent); | 243 List<BroadcastReceiver> receivers = shadowApplication.getReceiversForInt
ent(intent); |
245 assertThat("There is one registered broadcast receiver", receivers.size(
), equalTo(1)); | 244 assertThat("There is one registered broadcast receiver", receivers.size(
), equalTo(1)); |
246 | 245 |
247 // Send the intent to the receiver. | 246 // Send the intent to the receiver. |
248 BroadcastReceiver receiver = receivers.get(0); | 247 BroadcastReceiver receiver = receivers.get(0); |
249 receiver.onReceive(ShadowApplication.getInstance().getApplicationContext
(), intent); | 248 receiver.onReceive(Robolectric.getShadowApplication().getApplicationCont
ext(), intent); |
250 | 249 |
251 // Verify that the auth token is properly requested from the account man
ager. | 250 // Verify that the auth token is properly requested from the account man
ager. |
252 verify(sMockAccountManager).getAuthToken( | 251 verify(sMockAccountManager).getAuthToken( |
253 eq(new Account("a", type)), | 252 eq(new Account("a", type)), |
254 eq("foo"), | 253 eq("foo"), |
255 isNull(Bundle.class), | 254 isNull(Bundle.class), |
256 eq(true), | 255 eq(true), |
257 any(HttpNegotiateAuthenticator.GetTokenCallback.class), | 256 any(HttpNegotiateAuthenticator.GetTokenCallback.class), |
258 any(Handler.class)); | 257 any(Handler.class)); |
259 } | 258 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 private HttpNegotiateAuthenticator createWithoutNative(String accountType) { | 453 private HttpNegotiateAuthenticator createWithoutNative(String accountType) { |
455 HttpNegotiateAuthenticator authenticator = | 454 HttpNegotiateAuthenticator authenticator = |
456 spy(HttpNegotiateAuthenticator.create(accountType)); | 455 spy(HttpNegotiateAuthenticator.create(accountType)); |
457 doNothing().when(authenticator).nativeSetResult(anyLong(), anyInt(), any
String()); | 456 doNothing().when(authenticator).nativeSetResult(anyLong(), anyInt(), any
String()); |
458 doReturn(false) | 457 doReturn(false) |
459 .when(authenticator) | 458 .when(authenticator) |
460 .lacksPermission(any(Context.class), anyString(), anyBoolean()); | 459 .lacksPermission(any(Context.class), anyString(), anyBoolean()); |
461 return authenticator; | 460 return authenticator; |
462 } | 461 } |
463 } | 462 } |
OLD | NEW |