| 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 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 AccountManagerHelper.overrideAccountManagerHelperForTests(mContext, mAcc
ountManager); | 40 AccountManagerHelper.overrideAccountManagerHelperForTests(mContext, mAcc
ountManager); |
| 41 } | 41 } |
| 42 | 42 |
| 43 /* | 43 /* |
| 44 * @SmallTest | 44 * @SmallTest |
| 45 * @Feature({"Sync"}) | 45 * @Feature({"Sync"}) |
| 46 */ | 46 */ |
| 47 @Test | 47 @Test |
| 48 @DisabledTest(message = "crbug.com/533417") | 48 @DisabledTest(message = "crbug.com/533417") |
| 49 public void testGetAccountsNoAccountsRegistered() { | 49 public void testGetAccountsNoAccountsRegistered() { |
| 50 String[] accounts = OAuth2TokenService.getAccounts(); | 50 String[] accounts = OAuth2TokenService.getAccounts(mContext); |
| 51 Assert.assertEquals("There should be no accounts registered", 0, account
s.length); | 51 Assert.assertEquals("There should be no accounts registered", 0, account
s.length); |
| 52 } | 52 } |
| 53 | 53 |
| 54 /*@SmallTest | 54 /*@SmallTest |
| 55 @Feature({"Sync"})*/ | 55 @Feature({"Sync"})*/ |
| 56 @Test | 56 @Test |
| 57 @DisabledTest(message = "crbug.com/527852") | 57 @DisabledTest(message = "crbug.com/527852") |
| 58 public void testGetAccountsOneAccountRegistered() { | 58 public void testGetAccountsOneAccountRegistered() { |
| 59 Account account1 = AccountManagerHelper.createAccountFromName("foo@gmail
.com"); | 59 Account account1 = AccountManagerHelper.createAccountFromName("foo@gmail
.com"); |
| 60 AccountHolder accountHolder1 = AccountHolder.builder(account1).build(); | 60 AccountHolder accountHolder1 = AccountHolder.builder(account1).build(); |
| 61 mAccountManager.addAccountHolderExplicitly(accountHolder1); | 61 mAccountManager.addAccountHolderExplicitly(accountHolder1); |
| 62 | 62 |
| 63 String[] sysAccounts = OAuth2TokenService.getSystemAccountNames(); | 63 String[] sysAccounts = OAuth2TokenService.getSystemAccountNames(mContext
); |
| 64 Assert.assertEquals("There should be one registered account", 1, sysAcco
unts.length); | 64 Assert.assertEquals("There should be one registered account", 1, sysAcco
unts.length); |
| 65 Assert.assertEquals("The account should be " + account1, account1.name,
sysAccounts[0]); | 65 Assert.assertEquals("The account should be " + account1, account1.name,
sysAccounts[0]); |
| 66 | 66 |
| 67 String[] accounts = OAuth2TokenService.getAccounts(); | 67 String[] accounts = OAuth2TokenService.getAccounts(mContext); |
| 68 Assert.assertEquals("There should be zero registered account", 0, accoun
ts.length); | 68 Assert.assertEquals("There should be zero registered account", 0, accoun
ts.length); |
| 69 } | 69 } |
| 70 | 70 |
| 71 /*@SmallTest | 71 /*@SmallTest |
| 72 @Feature({"Sync"})*/ | 72 @Feature({"Sync"})*/ |
| 73 @Test | 73 @Test |
| 74 @DisabledTest(message = "crbug.com/527852") | 74 @DisabledTest(message = "crbug.com/527852") |
| 75 public void testGetAccountsTwoAccountsRegistered() { | 75 public void testGetAccountsTwoAccountsRegistered() { |
| 76 Account account1 = AccountManagerHelper.createAccountFromName("foo@gmail
.com"); | 76 Account account1 = AccountManagerHelper.createAccountFromName("foo@gmail
.com"); |
| 77 AccountHolder accountHolder1 = AccountHolder.builder(account1).build(); | 77 AccountHolder accountHolder1 = AccountHolder.builder(account1).build(); |
| 78 mAccountManager.addAccountHolderExplicitly(accountHolder1); | 78 mAccountManager.addAccountHolderExplicitly(accountHolder1); |
| 79 Account account2 = AccountManagerHelper.createAccountFromName("bar@gmail
.com"); | 79 Account account2 = AccountManagerHelper.createAccountFromName("bar@gmail
.com"); |
| 80 AccountHolder accountHolder2 = AccountHolder.builder(account2).build(); | 80 AccountHolder accountHolder2 = AccountHolder.builder(account2).build(); |
| 81 mAccountManager.addAccountHolderExplicitly(accountHolder2); | 81 mAccountManager.addAccountHolderExplicitly(accountHolder2); |
| 82 | 82 |
| 83 String[] sysAccounts = OAuth2TokenService.getSystemAccountNames(); | 83 String[] sysAccounts = OAuth2TokenService.getSystemAccountNames(mContext
); |
| 84 Assert.assertEquals("There should be one registered account", 2, sysAcco
unts.length); | 84 Assert.assertEquals("There should be one registered account", 2, sysAcco
unts.length); |
| 85 Assert.assertTrue("The list should contain " + account1, | 85 Assert.assertTrue("The list should contain " + account1, |
| 86 Arrays.asList(sysAccounts).contains(account1.name)); | 86 Arrays.asList(sysAccounts).contains(account1.name)); |
| 87 Assert.assertTrue("The list should contain " + account2, | 87 Assert.assertTrue("The list should contain " + account2, |
| 88 Arrays.asList(sysAccounts).contains(account2.name)); | 88 Arrays.asList(sysAccounts).contains(account2.name)); |
| 89 | 89 |
| 90 String[] accounts = OAuth2TokenService.getAccounts(); | 90 String[] accounts = OAuth2TokenService.getAccounts(mContext); |
| 91 Assert.assertEquals("There should be zero registered account", 0, accoun
ts.length); | 91 Assert.assertEquals("There should be zero registered account", 0, accoun
ts.length); |
| 92 } | 92 } |
| 93 | 93 |
| 94 @Test | 94 @Test |
| 95 @DisabledTest(message = "crbug.com/568620") | 95 @DisabledTest(message = "crbug.com/568620") |
| 96 @SmallTest | 96 @SmallTest |
| 97 @Feature({"Sync"}) | 97 @Feature({"Sync"}) |
| 98 public void testGetOAuth2AccessTokenWithTimeoutOnSuccess() { | 98 public void testGetOAuth2AccessTokenWithTimeoutOnSuccess() { |
| 99 String authToken = "someToken"; | 99 String authToken = "someToken"; |
| 100 // Auth token should be successfully received. | 100 // Auth token should be successfully received. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 121 .hasBeenAccepted(oauth2Scope, true
) | 121 .hasBeenAccepted(oauth2Scope, true
) |
| 122 .authToken(oauth2Scope, expectedTo
ken) | 122 .authToken(oauth2Scope, expectedTo
ken) |
| 123 .build(); | 123 .build(); |
| 124 mAccountManager.addAccountHolderExplicitly(accountHolder); | 124 mAccountManager.addAccountHolderExplicitly(accountHolder); |
| 125 | 125 |
| 126 String accessToken = OAuth2TokenService.getOAuth2AccessTokenWithTimeout( | 126 String accessToken = OAuth2TokenService.getOAuth2AccessTokenWithTimeout( |
| 127 mContext, account, scope, 5, TimeUnit.SECONDS); | 127 mContext, account, scope, 5, TimeUnit.SECONDS); |
| 128 Assert.assertEquals(expectedToken, accessToken); | 128 Assert.assertEquals(expectedToken, accessToken); |
| 129 } | 129 } |
| 130 } | 130 } |
| OLD | NEW |