| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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.chrome.test.util; | |
| 6 | |
| 7 import android.test.InstrumentationTestCase; | |
| 8 import android.test.suitebuilder.annotation.MediumTest; | |
| 9 import android.test.suitebuilder.annotation.SmallTest; | |
| 10 | |
| 11 import org.chromium.base.test.util.Restriction; | |
| 12 import org.chromium.sync.signin.ChromeSigninController; | |
| 13 | |
| 14 /** | |
| 15 * Tests for {@link ChromeSigninUtils}. | |
| 16 */ | |
| 17 public class ChromeSigninUtilsTest extends InstrumentationTestCase { | |
| 18 private static final String FAKE_ACCOUNT_USERNAME = "test@google.com"; | |
| 19 private static final String FAKE_ACCOUNT_PASSWORD = "$3cr3t"; | |
| 20 private static final String GOOGLE_ACCOUNT_USERNAME = "chromiumforandroid01@
gmail.com"; | |
| 21 private static final String GOOGLE_ACCOUNT_PASSWORD = "chromeforandroid"; | |
| 22 private static final String GOOGLE_ACCOUNT_TYPE = "mail"; | |
| 23 | |
| 24 private ChromeSigninUtils mSigninUtil; | |
| 25 private ChromeSigninController mSigninController; | |
| 26 | |
| 27 @Override | |
| 28 public void setUp() throws Exception { | |
| 29 super.setUp(); | |
| 30 mSigninUtil = new ChromeSigninUtils(this); | |
| 31 mSigninController = ChromeSigninController.get(getInstrumentation().getT
argetContext()); | |
| 32 mSigninController.clearSignedInUser(); | |
| 33 mSigninUtil.removeAllFakeAccountsFromOs(); | |
| 34 mSigninUtil.removeAllGoogleAccountsFromOs(); | |
| 35 } | |
| 36 | |
| 37 @SmallTest | |
| 38 public void testActivityIsNotSignedInOnAppOrFakeOSorGoogleOS() { | |
| 39 assertFalse("Should not be signed into app.", | |
| 40 mSigninController.isSignedIn()); | |
| 41 assertFalse("Should not be signed into OS with fake account.", | |
| 42 mSigninUtil.isExistingFakeAccountOnOs(FAKE_ACCOUNT_USERNAME)); | |
| 43 assertFalse("Should not be signed in on OS with Google account.", | |
| 44 mSigninUtil.isExistingGoogleAccountOnOs(GOOGLE_ACCOUNT_USERNAME)
); | |
| 45 } | |
| 46 | |
| 47 @SmallTest | |
| 48 public void testIsSignedInOnApp() { | |
| 49 mSigninUtil.addAccountToApp(FAKE_ACCOUNT_USERNAME); | |
| 50 assertTrue("Should be signed on app.", | |
| 51 mSigninController.isSignedIn()); | |
| 52 assertFalse("Should not be signed on OS with fake account.", | |
| 53 mSigninUtil.isExistingFakeAccountOnOs(FAKE_ACCOUNT_USERNAME)); | |
| 54 assertFalse("Should not be signed in on OS with Google account.", | |
| 55 mSigninUtil.isExistingGoogleAccountOnOs(GOOGLE_ACCOUNT_USERNAME)
); | |
| 56 } | |
| 57 | |
| 58 @SmallTest | |
| 59 public void testIsSignedInOnFakeOS() { | |
| 60 mSigninUtil.addFakeAccountToOs(FAKE_ACCOUNT_USERNAME, FAKE_ACCOUNT_PASSW
ORD); | |
| 61 assertFalse("Should not be signed in on app.", | |
| 62 mSigninController.isSignedIn()); | |
| 63 assertTrue("Should be signed in on OS with fake account.", | |
| 64 mSigninUtil.isExistingFakeAccountOnOs(FAKE_ACCOUNT_USERNAME)); | |
| 65 assertFalse("Should not be signed in on OS with Google account.", | |
| 66 mSigninUtil.isExistingGoogleAccountOnOs(GOOGLE_ACCOUNT_USERNAME)
); | |
| 67 } | |
| 68 | |
| 69 @MediumTest | |
| 70 @Restriction(Restriction.RESTRICTION_TYPE_INTERNET) | |
| 71 public void testIsSignedInOnGoogleOS() { | |
| 72 mSigninUtil.addGoogleAccountToOs(GOOGLE_ACCOUNT_USERNAME, GOOGLE_ACCOUNT
_PASSWORD, | |
| 73 GOOGLE_ACCOUNT_TYPE); | |
| 74 assertFalse("Should not be signed into app.", | |
| 75 mSigninController.isSignedIn()); | |
| 76 assertFalse("Should not be signed into OS with fake account.", | |
| 77 mSigninUtil.isExistingFakeAccountOnOs(FAKE_ACCOUNT_USERNAME)); | |
| 78 assertTrue("Should be signed in on OS with Google account.", | |
| 79 mSigninUtil.isExistingGoogleAccountOnOs(GOOGLE_ACCOUNT_USERNAME)
); | |
| 80 } | |
| 81 | |
| 82 @SmallTest | |
| 83 public void testIsSignedInOnFakeOSandApp() { | |
| 84 mSigninUtil.addAccountToApp(FAKE_ACCOUNT_USERNAME); | |
| 85 mSigninUtil.addFakeAccountToOs(FAKE_ACCOUNT_USERNAME, FAKE_ACCOUNT_PASSW
ORD); | |
| 86 assertTrue("Should be signed in on app.", | |
| 87 mSigninController.isSignedIn()); | |
| 88 assertTrue("Should be signed in on OS with fake account.", | |
| 89 mSigninUtil.isExistingFakeAccountOnOs(FAKE_ACCOUNT_USERNAME)); | |
| 90 assertFalse("Should not be signed in on OS with Google account.", | |
| 91 mSigninUtil.isExistingGoogleAccountOnOs(GOOGLE_ACCOUNT_USERNAME)
); | |
| 92 } | |
| 93 | |
| 94 @MediumTest | |
| 95 @Restriction(Restriction.RESTRICTION_TYPE_INTERNET) | |
| 96 public void testIsSignedInOnAppAndGoogleOS() { | |
| 97 mSigninUtil.addAccountToApp(FAKE_ACCOUNT_USERNAME); | |
| 98 mSigninUtil.addGoogleAccountToOs(GOOGLE_ACCOUNT_USERNAME, GOOGLE_ACCOUNT
_PASSWORD, | |
| 99 GOOGLE_ACCOUNT_TYPE); | |
| 100 assertTrue("Should be signed into app.", | |
| 101 mSigninController.isSignedIn()); | |
| 102 assertFalse("Should not be signed into OS with fake account.", | |
| 103 mSigninUtil.isExistingFakeAccountOnOs(FAKE_ACCOUNT_USERNAME)); | |
| 104 assertTrue("Should be signed in on OS with Google account.", | |
| 105 mSigninUtil.isExistingGoogleAccountOnOs(GOOGLE_ACCOUNT_USERNAME)
); | |
| 106 } | |
| 107 | |
| 108 @MediumTest | |
| 109 @Restriction(Restriction.RESTRICTION_TYPE_INTERNET) | |
| 110 public void testIsSignedInOnFakeOSandGoogleOS() { | |
| 111 mSigninUtil.addFakeAccountToOs(FAKE_ACCOUNT_USERNAME, FAKE_ACCOUNT_PASSW
ORD); | |
| 112 mSigninUtil.addGoogleAccountToOs(GOOGLE_ACCOUNT_USERNAME, GOOGLE_ACCOUNT
_PASSWORD, | |
| 113 GOOGLE_ACCOUNT_TYPE); | |
| 114 assertFalse("Should not be signed into app.", | |
| 115 mSigninController.isSignedIn()); | |
| 116 assertTrue("Should be signed into OS with fake account.", | |
| 117 mSigninUtil.isExistingFakeAccountOnOs(FAKE_ACCOUNT_USERNAME)); | |
| 118 assertTrue("Should be signed in on OS with Google account.", | |
| 119 mSigninUtil.isExistingGoogleAccountOnOs(GOOGLE_ACCOUNT_USERNAME)
); | |
| 120 } | |
| 121 | |
| 122 @MediumTest | |
| 123 @Restriction(Restriction.RESTRICTION_TYPE_INTERNET) | |
| 124 public void testIsSignedInOnAppAndFakeOSandGoogleOS() { | |
| 125 mSigninUtil.addAccountToApp(FAKE_ACCOUNT_USERNAME); | |
| 126 mSigninUtil.addFakeAccountToOs(FAKE_ACCOUNT_USERNAME, FAKE_ACCOUNT_PASSW
ORD); | |
| 127 mSigninUtil.addGoogleAccountToOs(GOOGLE_ACCOUNT_USERNAME, GOOGLE_ACCOUNT
_PASSWORD, | |
| 128 GOOGLE_ACCOUNT_TYPE); | |
| 129 assertTrue("Should be signed into app.", | |
| 130 mSigninController.isSignedIn()); | |
| 131 assertTrue("Should be signed into OS with fake account.", | |
| 132 mSigninUtil.isExistingFakeAccountOnOs(FAKE_ACCOUNT_USERNAME)); | |
| 133 assertTrue("Should be signed in on OS with Google account.", | |
| 134 mSigninUtil.isExistingGoogleAccountOnOs(GOOGLE_ACCOUNT_USERNAME)
); | |
| 135 } | |
| 136 | |
| 137 @Override | |
| 138 protected void tearDown() throws Exception { | |
| 139 mSigninController.clearSignedInUser(); | |
| 140 mSigninUtil.removeAllFakeAccountsFromOs(); | |
| 141 mSigninUtil.removeAllGoogleAccountsFromOs(); | |
| 142 super.tearDown(); | |
| 143 } | |
| 144 } | |
| OLD | NEW |