OLD | NEW |
| (Empty) |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.sync.notifier.signin; | |
6 | |
7 import android.accounts.Account; | |
8 import android.content.Context; | |
9 import android.test.InstrumentationTestCase; | |
10 import android.test.suitebuilder.annotation.SmallTest; | |
11 | |
12 import org.chromium.sync.signin.AccountManagerHelper; | |
13 import org.chromium.sync.test.util.AccountHolder; | |
14 import org.chromium.sync.test.util.MockAccountManager; | |
15 import org.chromium.sync.test.util.SimpleFuture; | |
16 | |
17 /** | |
18 * Test class for {@link AccountManagerHelper}. | |
19 */ | |
20 public class AccountManagerHelperTest extends InstrumentationTestCase { | |
21 | |
22 private MockAccountManager mAccountManager; | |
23 private AccountManagerHelper mHelper; | |
24 | |
25 @Override | |
26 protected void setUp() throws Exception { | |
27 super.setUp(); | |
28 | |
29 Context context = getInstrumentation().getTargetContext(); | |
30 mAccountManager = new MockAccountManager(context, context); | |
31 AccountManagerHelper.overrideAccountManagerHelperForTests(context, mAcco
untManager); | |
32 mHelper = AccountManagerHelper.get(context); | |
33 } | |
34 | |
35 @SmallTest | |
36 public void testCanonicalAccount() throws InterruptedException { | |
37 addTestAccount("test@gmail.com", "password"); | |
38 | |
39 assertTrue(hasAccountForName("test@gmail.com")); | |
40 assertTrue(hasAccountForName("Test@gmail.com")); | |
41 assertTrue(hasAccountForName("te.st@gmail.com")); | |
42 } | |
43 | |
44 // If this test starts flaking, please re-open crbug.com/568636 and make sur
e there is some sort | |
45 // of stack trace or error message in that bug BEFORE disabling the test. | |
46 @SmallTest | |
47 public void testNonCanonicalAccount() throws InterruptedException { | |
48 addTestAccount("test.me@gmail.com", "password"); | |
49 | |
50 assertTrue(hasAccountForName("test.me@gmail.com")); | |
51 assertTrue(hasAccountForName("testme@gmail.com")); | |
52 assertTrue(hasAccountForName("Testme@gmail.com")); | |
53 assertTrue(hasAccountForName("te.st.me@gmail.com")); | |
54 } | |
55 | |
56 private Account addTestAccount(String accountName, String password) { | |
57 Account account = AccountManagerHelper.createAccountFromName(accountName
); | |
58 AccountHolder.Builder accountHolder = | |
59 AccountHolder.create().account(account).password(password).alway
sAccept(true); | |
60 mAccountManager.addAccountHolderExplicitly(accountHolder.build()); | |
61 return account; | |
62 } | |
63 | |
64 private boolean hasAccountForName(String accountName) throws InterruptedExce
ption { | |
65 SimpleFuture<Boolean> result = new SimpleFuture<Boolean>(); | |
66 mHelper.hasAccountForName(accountName, result.createCallback()); | |
67 return result.get(); | |
68 } | |
69 } | |
OLD | NEW |