Chromium Code Reviews| 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.test.InstrumentationTestCase; | 8 import android.test.InstrumentationTestCase; |
| 9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 assertEquals("There should be no accounts registered", 0, accounts.lengt h); | 39 assertEquals("There should be no accounts registered", 0, accounts.lengt h); |
| 40 } | 40 } |
| 41 | 41 |
| 42 @SmallTest | 42 @SmallTest |
| 43 @Feature({"Sync"}) | 43 @Feature({"Sync"}) |
| 44 public void testGetAccountsOneAccountRegistered() { | 44 public void testGetAccountsOneAccountRegistered() { |
| 45 Account account1 = AccountManagerHelper.createAccountFromName("foo@gmail .com"); | 45 Account account1 = AccountManagerHelper.createAccountFromName("foo@gmail .com"); |
| 46 AccountHolder accountHolder1 = AccountHolder.create().account(account1). build(); | 46 AccountHolder accountHolder1 = AccountHolder.create().account(account1). build(); |
| 47 mAccountManager.addAccountHolderExplicitly(accountHolder1); | 47 mAccountManager.addAccountHolderExplicitly(accountHolder1); |
| 48 | 48 |
| 49 String[] sysAccounts = OAuth2TokenService.getSystemAccounts(mContext); | |
| 50 assertEquals("There should be one registered account", 1, sysAccounts.le ngth); | |
| 51 assertEquals("The account should be " + account1, account1.name, sysAcco unts[0]); | |
| 52 | |
| 49 String[] accounts = OAuth2TokenService.getAccounts(mContext); | 53 String[] accounts = OAuth2TokenService.getAccounts(mContext); |
| 50 assertEquals("There should be one registered account", 1, accounts.lengt h); | 54 assertEquals("There should be zero registered account", 0, accounts.leng th); |
| 51 assertEquals("The account should be " + account1, account1.name, account s[0]); | |
| 52 } | 55 } |
| 53 | 56 |
| 54 @SmallTest | 57 @SmallTest |
| 55 @Feature({"Sync"}) | 58 @Feature({"Sync"}) |
| 56 public void testGetAccountsTwoAccountsRegistered() { | 59 public void testGetAccountsTwoAccountsRegistered() { |
| 57 Account account1 = AccountManagerHelper.createAccountFromName("foo@gmail .com"); | 60 Account account1 = AccountManagerHelper.createAccountFromName("foo@gmail .com"); |
| 58 AccountHolder accountHolder1 = AccountHolder.create().account(account1). build(); | 61 AccountHolder accountHolder1 = AccountHolder.create().account(account1). build(); |
| 59 mAccountManager.addAccountHolderExplicitly(accountHolder1); | 62 mAccountManager.addAccountHolderExplicitly(accountHolder1); |
| 60 Account account2 = AccountManagerHelper.createAccountFromName("bar@gmail .com"); | 63 Account account2 = AccountManagerHelper.createAccountFromName("bar@gmail .com"); |
| 61 AccountHolder accountHolder2 = AccountHolder.create().account(account2). build(); | 64 AccountHolder accountHolder2 = AccountHolder.create().account(account2). build(); |
| 62 mAccountManager.addAccountHolderExplicitly(accountHolder2); | 65 mAccountManager.addAccountHolderExplicitly(accountHolder2); |
| 63 | 66 |
| 67 String[] sysAccounts = OAuth2TokenService.getSystemAccounts(mContext); | |
| 68 assertEquals("There should be one registered account", 2, sysAccounts.le ngth); | |
|
nyquist
2014/04/24 22:27:05
s/one/two
| |
| 69 assertTrue("The list should contain " + account1, | |
| 70 Arrays.asList(sysAccounts).contains(account1.name)); | |
| 71 assertTrue("The list should contain " + account2, | |
| 72 Arrays.asList(sysAccounts).contains(account2.name)); | |
| 73 | |
| 64 String[] accounts = OAuth2TokenService.getAccounts(mContext); | 74 String[] accounts = OAuth2TokenService.getAccounts(mContext); |
| 65 assertEquals("There should be one registered account", 2, accounts.lengt h); | 75 assertEquals("There should be zero registered account", 0, accounts.leng th); |
| 66 assertTrue("The list should contain " + account1, | |
| 67 Arrays.asList(accounts).contains(account1.name)); | |
| 68 assertTrue("The list should contain " + account2, | |
| 69 Arrays.asList(accounts).contains(account2.name)); | |
| 70 } | 76 } |
| 71 | 77 |
| 72 @SmallTest | 78 @SmallTest |
| 73 @Feature({"Sync"}) | 79 @Feature({"Sync"}) |
| 74 public void testGetOAuth2AccessTokenWithTimeoutOnSuccess() { | 80 public void testGetOAuth2AccessTokenWithTimeoutOnSuccess() { |
| 75 String authToken = "someToken"; | 81 String authToken = "someToken"; |
| 76 // Auth token should be successfully received. | 82 // Auth token should be successfully received. |
| 77 runTestOfGetOAuth2AccessTokenWithTimeout(authToken); | 83 runTestOfGetOAuth2AccessTokenWithTimeout(authToken); |
| 78 } | 84 } |
| 79 | 85 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 97 .hasBeenAccepted(oauth2Scope, true) | 103 .hasBeenAccepted(oauth2Scope, true) |
| 98 .authToken(oauth2Scope, expectedToken).build(); | 104 .authToken(oauth2Scope, expectedToken).build(); |
| 99 mAccountManager.addAccountHolderExplicitly(accountHolder); | 105 mAccountManager.addAccountHolderExplicitly(accountHolder); |
| 100 | 106 |
| 101 String accessToken = | 107 String accessToken = |
| 102 OAuth2TokenService.getOAuth2AccessTokenWithTimeout( | 108 OAuth2TokenService.getOAuth2AccessTokenWithTimeout( |
| 103 mContext, null, account, scope, 5, TimeUnit.SECONDS); | 109 mContext, null, account, scope, 5, TimeUnit.SECONDS); |
| 104 assertEquals(expectedToken, accessToken); | 110 assertEquals(expectedToken, accessToken); |
| 105 } | 111 } |
| 106 } | 112 } |
| OLD | NEW |