OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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.components.signin.test; | 5 package org.chromium.components.signin.test; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.content.Context; | |
9 import android.support.test.filters.SmallTest; | 8 import android.support.test.filters.SmallTest; |
10 import android.test.InstrumentationTestCase; | 9 import android.test.InstrumentationTestCase; |
11 | 10 |
12 import org.chromium.components.signin.AccountManagerHelper; | 11 import org.chromium.components.signin.AccountManagerHelper; |
13 import org.chromium.components.signin.test.util.AccountHolder; | 12 import org.chromium.components.signin.test.util.AccountHolder; |
14 import org.chromium.components.signin.test.util.FakeAccountManagerDelegate; | 13 import org.chromium.components.signin.test.util.FakeAccountManagerDelegate; |
15 import org.chromium.components.signin.test.util.SimpleFuture; | 14 import org.chromium.components.signin.test.util.SimpleFuture; |
16 | 15 |
17 /** | 16 /** |
18 * Test class for {@link AccountManagerHelper}. | 17 * Test class for {@link AccountManagerHelper}. |
19 */ | 18 */ |
20 public class AccountManagerHelperTest extends InstrumentationTestCase { | 19 public class AccountManagerHelperTest extends InstrumentationTestCase { |
21 private FakeAccountManagerDelegate mDelegate; | 20 private FakeAccountManagerDelegate mDelegate; |
22 private AccountManagerHelper mHelper; | 21 private AccountManagerHelper mHelper; |
23 | 22 |
24 @Override | 23 @Override |
25 protected void setUp() throws Exception { | 24 protected void setUp() throws Exception { |
26 super.setUp(); | 25 super.setUp(); |
27 | 26 |
28 Context context = getInstrumentation().getTargetContext(); | 27 mDelegate = new FakeAccountManagerDelegate(); |
29 mDelegate = new FakeAccountManagerDelegate(context); | 28 AccountManagerHelper.overrideAccountManagerHelperForTests(mDelegate); |
30 AccountManagerHelper.overrideAccountManagerHelperForTests(context, mDele
gate); | |
31 mHelper = AccountManagerHelper.get(); | 29 mHelper = AccountManagerHelper.get(); |
32 } | 30 } |
33 | 31 |
34 @Override | |
35 protected void tearDown() throws Exception { | |
36 AccountManagerHelper.resetAccountManagerHelperForTests(); | |
37 super.tearDown(); | |
38 } | |
39 | |
40 @SmallTest | 32 @SmallTest |
41 public void testCanonicalAccount() throws InterruptedException { | 33 public void testCanonicalAccount() throws InterruptedException { |
42 addTestAccount("test@gmail.com", "password"); | 34 addTestAccount("test@gmail.com", "password"); |
43 | 35 |
44 assertTrue(hasAccountForName("test@gmail.com")); | 36 assertTrue(hasAccountForName("test@gmail.com")); |
45 assertTrue(hasAccountForName("Test@gmail.com")); | 37 assertTrue(hasAccountForName("Test@gmail.com")); |
46 assertTrue(hasAccountForName("te.st@gmail.com")); | 38 assertTrue(hasAccountForName("te.st@gmail.com")); |
47 } | 39 } |
48 | 40 |
49 // If this test starts flaking, please re-open crbug.com/568636 and make sur
e there is some sort | 41 // If this test starts flaking, please re-open crbug.com/568636 and make sur
e there is some sort |
(...skipping 15 matching lines...) Expand all Loading... |
65 mDelegate.addAccountHolderExplicitly(accountHolder.build()); | 57 mDelegate.addAccountHolderExplicitly(accountHolder.build()); |
66 return account; | 58 return account; |
67 } | 59 } |
68 | 60 |
69 private boolean hasAccountForName(String accountName) throws InterruptedExce
ption { | 61 private boolean hasAccountForName(String accountName) throws InterruptedExce
ption { |
70 SimpleFuture<Boolean> result = new SimpleFuture<Boolean>(); | 62 SimpleFuture<Boolean> result = new SimpleFuture<Boolean>(); |
71 mHelper.hasAccountForName(accountName, result.createCallback()); | 63 mHelper.hasAccountForName(accountName, result.createCallback()); |
72 return result.get(); | 64 return result.get(); |
73 } | 65 } |
74 } | 66 } |
OLD | NEW |