OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.signin; | 5 package org.chromium.chrome.browser.signin; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.support.test.InstrumentationRegistry; | 8 import android.support.test.InstrumentationRegistry; |
9 import android.support.test.filters.SmallTest; | 9 import android.support.test.filters.SmallTest; |
10 | 10 |
11 import org.junit.After; | |
12 import org.junit.Assert; | 11 import org.junit.Assert; |
13 import org.junit.Before; | 12 import org.junit.Before; |
14 import org.junit.Test; | 13 import org.junit.Test; |
15 import org.junit.runner.RunWith; | 14 import org.junit.runner.RunWith; |
16 | 15 |
17 import org.chromium.base.test.util.AdvancedMockContext; | 16 import org.chromium.base.test.util.AdvancedMockContext; |
18 import org.chromium.base.test.util.DisabledTest; | 17 import org.chromium.base.test.util.DisabledTest; |
19 import org.chromium.base.test.util.Feature; | 18 import org.chromium.base.test.util.Feature; |
20 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | 19 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
21 import org.chromium.components.signin.AccountManagerHelper; | 20 import org.chromium.components.signin.AccountManagerHelper; |
22 import org.chromium.components.signin.test.util.AccountHolder; | 21 import org.chromium.components.signin.test.util.AccountHolder; |
23 import org.chromium.components.signin.test.util.FakeAccountManagerDelegate; | 22 import org.chromium.components.signin.test.util.FakeAccountManagerDelegate; |
24 | 23 |
25 import java.util.Arrays; | 24 import java.util.Arrays; |
26 import java.util.concurrent.TimeUnit; | 25 import java.util.concurrent.TimeUnit; |
27 | 26 |
28 /** Tests for OAuth2TokenService. */ | 27 /** Tests for OAuth2TokenService. */ |
29 @RunWith(ChromeJUnit4ClassRunner.class) | 28 @RunWith(ChromeJUnit4ClassRunner.class) |
30 public class OAuth2TokenServiceTest { | 29 public class OAuth2TokenServiceTest { |
31 private AdvancedMockContext mContext; | 30 private AdvancedMockContext mContext; |
32 private FakeAccountManagerDelegate mAccountManager; | 31 private FakeAccountManagerDelegate mAccountManager; |
33 | 32 |
34 @Before | 33 @Before |
35 public void setUp() throws Exception { | 34 public void setUp() throws Exception { |
36 mContext = new AdvancedMockContext( | 35 mContext = new AdvancedMockContext( |
37 InstrumentationRegistry.getInstrumentation().getTargetContext())
; | 36 InstrumentationRegistry.getInstrumentation().getTargetContext())
; |
38 mAccountManager = new FakeAccountManagerDelegate(mContext); | 37 mAccountManager = new FakeAccountManagerDelegate(); |
39 AccountManagerHelper.overrideAccountManagerHelperForTests(mContext, mAcc
ountManager); | 38 AccountManagerHelper.overrideAccountManagerHelperForTests(mAccountManage
r); |
40 } | |
41 | |
42 @After | |
43 public void tearDown() { | |
44 AccountManagerHelper.resetAccountManagerHelperForTests(); | |
45 } | 39 } |
46 | 40 |
47 /* | 41 /* |
48 * @SmallTest | 42 * @SmallTest |
49 * @Feature({"Sync"}) | 43 * @Feature({"Sync"}) |
50 */ | 44 */ |
51 @Test | 45 @Test |
52 @DisabledTest(message = "crbug.com/533417") | 46 @DisabledTest(message = "crbug.com/533417") |
53 public void testGetAccountsNoAccountsRegistered() { | 47 public void testGetAccountsNoAccountsRegistered() { |
54 String[] accounts = OAuth2TokenService.getAccounts(); | 48 String[] accounts = OAuth2TokenService.getAccounts(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 .hasBeenAccepted(oauth2Scope, true
) | 119 .hasBeenAccepted(oauth2Scope, true
) |
126 .authToken(oauth2Scope, expectedTo
ken) | 120 .authToken(oauth2Scope, expectedTo
ken) |
127 .build(); | 121 .build(); |
128 mAccountManager.addAccountHolderExplicitly(accountHolder); | 122 mAccountManager.addAccountHolderExplicitly(accountHolder); |
129 | 123 |
130 String accessToken = OAuth2TokenService.getOAuth2AccessTokenWithTimeout( | 124 String accessToken = OAuth2TokenService.getOAuth2AccessTokenWithTimeout( |
131 mContext, account, scope, 5, TimeUnit.SECONDS); | 125 mContext, account, scope, 5, TimeUnit.SECONDS); |
132 Assert.assertEquals(expectedToken, accessToken); | 126 Assert.assertEquals(expectedToken, accessToken); |
133 } | 127 } |
134 } | 128 } |
OLD | NEW |