Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
| 6 #import <XCTest/XCTest.h> | 6 #import <XCTest/XCTest.h> |
| 7 | 7 |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "components/metrics/metrics_pref_names.h" | 9 #include "components/metrics/metrics_pref_names.h" |
| 10 #include "components/metrics/metrics_reporting_default_state.h" | 10 #include "components/metrics/metrics_reporting_default_state.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 27 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 28 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 28 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 29 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" | 29 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" |
| 30 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. h" | 30 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 | 32 |
| 33 #if !defined(__has_feature) || !__has_feature(objc_arc) | 33 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 34 #error "This file requires ARC support." | 34 #error "This file requires ARC support." |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 using chrome_test_util::AccountConsistencySetupSigninButton; | |
| 38 using chrome_test_util::ButtonWithAccessibilityLabelId; | |
| 39 using chrome_test_util::NavigationBarDoneButton; | |
| 40 | |
| 37 namespace { | 41 namespace { |
| 38 | 42 |
| 39 // Returns a fake identity. | 43 // Returns a fake identity. |
| 40 ChromeIdentity* GetFakeIdentity() { | 44 ChromeIdentity* GetFakeIdentity() { |
| 41 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" | 45 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" |
| 42 gaiaID:@"fooID" | 46 gaiaID:@"fooID" |
| 43 name:@"Fake Foo"]; | 47 name:@"Fake Foo"]; |
| 44 } | 48 } |
| 45 | 49 |
| 46 // Taps the button with accessibility labelId |message_id|. | 50 // Returns matcher for the opt in accept button. |
| 47 void TapButtonWithLabelId(int message_id) { | 51 id<GREYMatcher> FirstRunOptInAcceptButton() { |
| 48 id<GREYMatcher> matcher = chrome_test_util::ButtonWithAccessibilityLabel( | 52 return ButtonWithAccessibilityLabelId(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON); |
| 49 l10n_util::GetNSString(message_id)); | 53 } |
| 50 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; | 54 |
| 55 // Returns matcher for the skip sign in button. | |
| 56 id<GREYMatcher> SkipSigninButton() { | |
|
Eugene But (OOO till 7-30)
2017/04/18 01:17:33
nit: s/SkipSigninButton/SkipSignInButton
baxley
2017/04/18 18:44:24
In most of our code, we refer to "signin" as a one
| |
| 57 return grey_accessibilityID(kSignInSkipButtonAccessibilityIdentifier); | |
| 58 } | |
| 59 | |
| 60 // Returns matcher for the first run account consistency skip button. | |
| 61 id<GREYMatcher> FirstRunAccountConsistencySkipButton() { | |
| 62 return ButtonWithAccessibilityLabelId( | |
| 63 IDS_IOS_FIRSTRUN_ACCOUNT_CONSISTENCY_SKIP_BUTTON); | |
| 64 } | |
| 65 | |
| 66 // Returns matcher for the undo sign in button. | |
| 67 id<GREYMatcher> UndoAccountConsistencyButton() { | |
| 68 return ButtonWithAccessibilityLabelId( | |
| 69 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_UNDO_BUTTON); | |
| 51 } | 70 } |
| 52 | 71 |
| 53 // Asserts that |identity| is actually signed in to the active profile. | 72 // Asserts that |identity| is actually signed in to the active profile. |
| 54 void AssertAuthenticatedIdentityInActiveProfile(ChromeIdentity* identity) { | 73 void AssertAuthenticatedIdentityInActiveProfile(ChromeIdentity* identity) { |
| 55 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 74 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 56 | 75 |
| 57 ios::ChromeBrowserState* browser_state = | 76 ios::ChromeBrowserState* browser_state = |
| 58 chrome_test_util::GetOriginalBrowserState(); | 77 chrome_test_util::GetOriginalBrowserState(); |
| 59 AccountInfo info = | 78 AccountInfo info = |
| 60 ios::SigninManagerFactory::GetForBrowserState(browser_state) | 79 ios::SigninManagerFactory::GetForBrowserState(browser_state) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 } | 147 } |
| 129 | 148 |
| 130 // Toggle the UMA checkbox. | 149 // Toggle the UMA checkbox. |
| 131 - (void)testToggleMetricsOn { | 150 - (void)testToggleMetricsOn { |
| 132 [chrome_test_util::GetMainController() showFirstRunUI]; | 151 [chrome_test_util::GetMainController() showFirstRunUI]; |
| 133 | 152 |
| 134 id<GREYMatcher> metrics = | 153 id<GREYMatcher> metrics = |
| 135 grey_accessibilityID(kUMAMetricsButtonAccessibilityIdentifier); | 154 grey_accessibilityID(kUMAMetricsButtonAccessibilityIdentifier); |
| 136 [[EarlGrey selectElementWithMatcher:metrics] performAction:grey_tap()]; | 155 [[EarlGrey selectElementWithMatcher:metrics] performAction:grey_tap()]; |
| 137 | 156 |
| 138 id<GREYMatcher> optInAccept = chrome_test_util::ButtonWithAccessibilityLabel( | 157 [[EarlGrey selectElementWithMatcher:FirstRunOptInAcceptButton()] |
| 139 l10n_util::GetNSString(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON)); | 158 performAction:grey_tap()]; |
| 140 [[EarlGrey selectElementWithMatcher:optInAccept] performAction:grey_tap()]; | |
| 141 | 159 |
| 142 BOOL metricsOptIn = GetApplicationContext()->GetLocalState()->GetBoolean( | 160 BOOL metricsOptIn = GetApplicationContext()->GetLocalState()->GetBoolean( |
| 143 metrics::prefs::kMetricsReportingEnabled); | 161 metrics::prefs::kMetricsReportingEnabled); |
| 144 GREYAssert( | 162 GREYAssert( |
| 145 metricsOptIn != [WelcomeToChromeViewController defaultStatsCheckboxValue], | 163 metricsOptIn != [WelcomeToChromeViewController defaultStatsCheckboxValue], |
| 146 @"Metrics reporting pref is incorrect."); | 164 @"Metrics reporting pref is incorrect."); |
| 147 } | 165 } |
| 148 | 166 |
| 149 // Dismisses the first run screens. | 167 // Dismisses the first run screens. |
| 150 - (void)testDismissFirstRun { | 168 - (void)testDismissFirstRun { |
| 151 [chrome_test_util::GetMainController() showFirstRunUI]; | 169 [chrome_test_util::GetMainController() showFirstRunUI]; |
| 152 | 170 |
| 153 id<GREYMatcher> optInAccept = chrome_test_util::ButtonWithAccessibilityLabel( | 171 [[EarlGrey selectElementWithMatcher:FirstRunOptInAcceptButton()] |
| 154 l10n_util::GetNSString(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON)); | 172 performAction:grey_tap()]; |
| 155 [[EarlGrey selectElementWithMatcher:optInAccept] performAction:grey_tap()]; | |
| 156 | 173 |
| 157 PrefService* preferences = GetApplicationContext()->GetLocalState(); | 174 PrefService* preferences = GetApplicationContext()->GetLocalState(); |
| 158 GREYAssert( | 175 GREYAssert( |
| 159 preferences->GetBoolean(metrics::prefs::kMetricsReportingEnabled) == | 176 preferences->GetBoolean(metrics::prefs::kMetricsReportingEnabled) == |
| 160 [WelcomeToChromeViewController defaultStatsCheckboxValue], | 177 [WelcomeToChromeViewController defaultStatsCheckboxValue], |
| 161 @"Metrics reporting does not match."); | 178 @"Metrics reporting does not match."); |
| 162 | 179 |
| 163 id<GREYMatcher> skipSignIn = | 180 [[EarlGrey selectElementWithMatcher:SkipSigninButton()] |
| 164 grey_accessibilityID(kSignInSkipButtonAccessibilityIdentifier); | 181 performAction:grey_tap()]; |
| 165 [[EarlGrey selectElementWithMatcher:skipSignIn] performAction:grey_tap()]; | |
| 166 | 182 |
| 167 id<GREYMatcher> newTab = | 183 id<GREYMatcher> newTab = |
| 168 grey_kindOfClass(NSClassFromString(@"NewTabPageView")); | 184 grey_kindOfClass(NSClassFromString(@"NewTabPageView")); |
| 169 [[EarlGrey selectElementWithMatcher:newTab] | 185 [[EarlGrey selectElementWithMatcher:newTab] |
| 170 assertWithMatcher:grey_sufficientlyVisible()]; | 186 assertWithMatcher:grey_sufficientlyVisible()]; |
| 171 } | 187 } |
| 172 | 188 |
| 173 // Signs in to an account and then taps the Undo button to sign out. | 189 // Signs in to an account and then taps the Undo button to sign out. |
| 174 - (void)testSignInAndUndo { | 190 - (void)testSignInAndUndo { |
| 175 ChromeIdentity* identity = GetFakeIdentity(); | 191 ChromeIdentity* identity = GetFakeIdentity(); |
| 176 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( | 192 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( |
| 177 identity); | 193 identity); |
| 178 | 194 |
| 179 // Launch First Run and accept tems of services. | 195 // Launch First Run and accept tems of services. |
| 180 [chrome_test_util::GetMainController() showFirstRunUI]; | 196 [chrome_test_util::GetMainController() showFirstRunUI]; |
| 181 TapButtonWithLabelId(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON); | 197 [[EarlGrey selectElementWithMatcher:FirstRunOptInAcceptButton()] |
| 198 performAction:grey_tap()]; | |
| 182 | 199 |
| 183 // Sign In |identity|. | 200 // Sign In |identity|. |
| 184 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON); | 201 [[EarlGrey selectElementWithMatcher:AccountConsistencySetupSigninButton()] |
| 202 performAction:grey_tap()]; | |
| 203 | |
| 185 AssertAuthenticatedIdentityInActiveProfile(identity); | 204 AssertAuthenticatedIdentityInActiveProfile(identity); |
| 186 | 205 |
| 187 // Undo the sign-in and dismiss the Sign In screen. | 206 // Undo the sign-in and dismiss the Sign In screen. |
| 188 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_UNDO_BUTTON); | 207 [[EarlGrey selectElementWithMatcher:UndoAccountConsistencyButton()] |
| 189 TapButtonWithLabelId(IDS_IOS_FIRSTRUN_ACCOUNT_CONSISTENCY_SKIP_BUTTON); | 208 performAction:grey_tap()]; |
| 209 [[EarlGrey selectElementWithMatcher:FirstRunAccountConsistencySkipButton()] | |
| 210 performAction:grey_tap()]; | |
| 190 | 211 |
| 191 // |identity| shouldn't be signed in. | 212 // |identity| shouldn't be signed in. |
| 192 AssertAuthenticatedIdentityInActiveProfile(nil); | 213 AssertAuthenticatedIdentityInActiveProfile(nil); |
| 193 } | 214 } |
| 194 | 215 |
| 195 // Signs in to an account and then taps the Advanced link to go to settings. | 216 // Signs in to an account and then taps the Advanced link to go to settings. |
| 196 - (void)testSignInAndTapSettingsLink { | 217 - (void)testSignInAndTapSettingsLink { |
| 197 ChromeIdentity* identity = GetFakeIdentity(); | 218 ChromeIdentity* identity = GetFakeIdentity(); |
| 198 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( | 219 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( |
| 199 identity); | 220 identity); |
| 200 | 221 |
| 201 // Launch First Run and accept tems of services. | 222 // Launch First Run and accept tems of services. |
| 202 [chrome_test_util::GetMainController() showFirstRunUI]; | 223 [chrome_test_util::GetMainController() showFirstRunUI]; |
| 203 TapButtonWithLabelId(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON); | 224 [[EarlGrey selectElementWithMatcher:FirstRunOptInAcceptButton()] |
| 225 performAction:grey_tap()]; | |
| 204 | 226 |
| 205 // Sign In |identity|. | 227 // Sign In |identity|. |
| 206 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON); | 228 [[EarlGrey selectElementWithMatcher:AccountConsistencySetupSigninButton()] |
| 229 performAction:grey_tap()]; | |
| 207 AssertAuthenticatedIdentityInActiveProfile(identity); | 230 AssertAuthenticatedIdentityInActiveProfile(identity); |
| 208 | 231 |
| 209 // Tap Settings link. | 232 // Tap Settings link. |
| 210 id<GREYMatcher> settings_link_matcher = grey_allOf( | 233 id<GREYMatcher> settings_link_matcher = grey_allOf( |
| 211 grey_accessibilityLabel(@"Settings"), grey_sufficientlyVisible(), nil); | 234 grey_accessibilityLabel(@"Settings"), grey_sufficientlyVisible(), nil); |
| 212 [[EarlGrey selectElementWithMatcher:settings_link_matcher] | 235 [[EarlGrey selectElementWithMatcher:settings_link_matcher] |
| 213 performAction:grey_tap()]; | 236 performAction:grey_tap()]; |
| 214 | 237 |
| 215 // Check Sync hasn't started yet, allowing the user to change somes settings. | 238 // Check Sync hasn't started yet, allowing the user to change somes settings. |
| 216 SyncSetupService* sync_service = SyncSetupServiceFactory::GetForBrowserState( | 239 SyncSetupService* sync_service = SyncSetupServiceFactory::GetForBrowserState( |
| 217 chrome_test_util::GetOriginalBrowserState()); | 240 chrome_test_util::GetOriginalBrowserState()); |
| 218 GREYAssertFalse(sync_service->HasFinishedInitialSetup(), | 241 GREYAssertFalse(sync_service->HasFinishedInitialSetup(), |
| 219 @"Sync shouldn't have finished its original setup yet"); | 242 @"Sync shouldn't have finished its original setup yet"); |
| 220 | 243 |
| 221 // Close Settings, user is still signed in and sync is now starting. | 244 // Close Settings, user is still signed in and sync is now starting. |
| 222 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); | 245 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 246 performAction:grey_tap()]; | |
| 223 AssertAuthenticatedIdentityInActiveProfile(identity); | 247 AssertAuthenticatedIdentityInActiveProfile(identity); |
| 224 GREYAssertTrue(sync_service->HasFinishedInitialSetup(), | 248 GREYAssertTrue(sync_service->HasFinishedInitialSetup(), |
| 225 @"Sync should have finished its original setup"); | 249 @"Sync should have finished its original setup"); |
| 226 } | 250 } |
| 227 | 251 |
| 228 @end | 252 @end |
| OLD | NEW |