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 #import "base/test/ios/wait_util.h" | |
| 9 #include "components/metrics/metrics_pref_names.h" | 10 #include "components/metrics/metrics_pref_names.h" |
| 10 #include "components/metrics/metrics_reporting_default_state.h" | 11 #include "components/metrics/metrics_reporting_default_state.h" |
| 11 #include "components/prefs/pref_member.h" | 12 #include "components/prefs/pref_member.h" |
| 12 #include "components/prefs/pref_service.h" | 13 #include "components/prefs/pref_service.h" |
| 13 #include "components/signin/core/browser/signin_manager.h" | 14 #include "components/signin/core/browser/signin_manager.h" |
| 14 #import "ios/chrome/app/main_controller.h" | 15 #import "ios/chrome/app/main_controller.h" |
| 15 #include "ios/chrome/browser/application_context.h" | 16 #include "ios/chrome/browser/application_context.h" |
| 16 #import "ios/chrome/browser/geolocation/omnibox_geolocation_controller+Testing.h " | 17 #import "ios/chrome/browser/geolocation/omnibox_geolocation_controller+Testing.h " |
| 17 #import "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h" | 18 #import "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h" |
| 18 #import "ios/chrome/browser/geolocation/test_location_manager.h" | 19 #import "ios/chrome/browser/geolocation/test_location_manager.h" |
| 19 #include "ios/chrome/browser/signin/signin_manager_factory.h" | 20 #include "ios/chrome/browser/signin/signin_manager_factory.h" |
| 20 #include "ios/chrome/browser/sync/sync_setup_service.h" | 21 #include "ios/chrome/browser/sync/sync_setup_service.h" |
| 21 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" | 22 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" |
| 22 #import "ios/chrome/browser/ui/first_run/first_run_chrome_signin_view_controller .h" | 23 #import "ios/chrome/browser/ui/first_run/first_run_chrome_signin_view_controller .h" |
| 23 #include "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h" | 24 #include "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h" |
| 24 #include "ios/chrome/grit/ios_chromium_strings.h" | 25 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 25 #include "ios/chrome/grit/ios_strings.h" | 26 #include "ios/chrome/grit/ios_strings.h" |
| 26 #import "ios/chrome/test/app/chrome_test_util.h" | 27 #import "ios/chrome/test/app/chrome_test_util.h" |
| 27 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 28 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 28 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 29 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 29 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" | 30 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" |
| 30 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. h" | 31 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. h" |
| 32 #import "ios/testing/wait_util.h" | |
| 31 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 32 | 34 |
| 33 #if !defined(__has_feature) || !__has_feature(objc_arc) | 35 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 34 #error "This file requires ARC support." | 36 #error "This file requires ARC support." |
| 35 #endif | 37 #endif |
| 36 | 38 |
| 37 using chrome_test_util::AccountConsistencySetupSigninButton; | 39 using chrome_test_util::AccountConsistencySetupSigninButton; |
| 38 using chrome_test_util::ButtonWithAccessibilityLabel; | 40 using chrome_test_util::ButtonWithAccessibilityLabel; |
| 39 using chrome_test_util::ButtonWithAccessibilityLabelId; | 41 using chrome_test_util::ButtonWithAccessibilityLabelId; |
| 40 using chrome_test_util::NavigationBarDoneButton; | 42 using chrome_test_util::NavigationBarDoneButton; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 chrome_test_util::GetOriginalBrowserState(); | 81 chrome_test_util::GetOriginalBrowserState(); |
| 80 AccountInfo info = | 82 AccountInfo info = |
| 81 ios::SigninManagerFactory::GetForBrowserState(browser_state) | 83 ios::SigninManagerFactory::GetForBrowserState(browser_state) |
| 82 ->GetAuthenticatedAccountInfo(); | 84 ->GetAuthenticatedAccountInfo(); |
| 83 | 85 |
| 84 GREYAssertEqual(base::SysNSStringToUTF8(identity.gaiaID), info.gaia, | 86 GREYAssertEqual(base::SysNSStringToUTF8(identity.gaiaID), info.gaia, |
| 85 @"Unexpected Gaia ID of the signed in user [expected = " | 87 @"Unexpected Gaia ID of the signed in user [expected = " |
| 86 @"\"%@\", actual = \"%s\"]", | 88 @"\"%@\", actual = \"%s\"]", |
| 87 identity.gaiaID, info.gaia.c_str()); | 89 identity.gaiaID, info.gaia.c_str()); |
| 88 } | 90 } |
| 91 | |
| 92 // Wait until |matcher| is accessible (not nil) | |
| 93 void WaitForMatcher(id<GREYMatcher> matcher) { | |
| 94 ConditionBlock condition = ^{ | |
| 95 NSError* error = nil; | |
| 96 [[EarlGrey selectElementWithMatcher:matcher] assertWithMatcher:grey_notNil() | |
| 97 error:&error]; | |
| 98 return error == nil; | |
| 99 }; | |
| 100 GREYAssert(testing::WaitUntilConditionOrTimeout( | |
| 101 testing::kWaitForUIElementTimeout, condition), | |
| 102 @"Waiting for matcher %@ failed.", matcher); | |
| 103 } | |
| 89 } | 104 } |
| 90 | 105 |
| 91 @interface MainController (ExposedForTesting) | 106 @interface MainController (ExposedForTesting) |
| 92 - (void)showFirstRunUI; | 107 - (void)showFirstRunUI; |
| 93 @end | 108 @end |
| 94 | 109 |
| 95 // Tests first run settings and navigation. | 110 // Tests first run settings and navigation. |
| 96 @interface FirstRunTestCase : ChromeTestCase | 111 @interface FirstRunTestCase : ChromeTestCase |
| 97 @end | 112 @end |
| 98 | 113 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 // Undo the sign-in and dismiss the Sign In screen. | 223 // Undo the sign-in and dismiss the Sign In screen. |
| 209 [[EarlGrey selectElementWithMatcher:UndoAccountConsistencyButton()] | 224 [[EarlGrey selectElementWithMatcher:UndoAccountConsistencyButton()] |
| 210 performAction:grey_tap()]; | 225 performAction:grey_tap()]; |
| 211 [[EarlGrey selectElementWithMatcher:FirstRunAccountConsistencySkipButton()] | 226 [[EarlGrey selectElementWithMatcher:FirstRunAccountConsistencySkipButton()] |
| 212 performAction:grey_tap()]; | 227 performAction:grey_tap()]; |
| 213 | 228 |
| 214 // |identity| shouldn't be signed in. | 229 // |identity| shouldn't be signed in. |
| 215 AssertAuthenticatedIdentityInActiveProfile(nil); | 230 AssertAuthenticatedIdentityInActiveProfile(nil); |
| 216 } | 231 } |
| 217 | 232 |
| 218 // Signs in to an account and then taps the Advanced link to go to settings. | 233 - (void)FLAKY_testSignInAndTapSettingsLink { |
|
baxley
2017/06/01 17:16:25
This is the test comment, so it should stay.
jlebel
2017/06/02 09:28:26
Done.
|
baxley
2017/06/01 17:16:25
Could you keep the TODO?
jlebel
2017/06/02 09:28:26
Done.
|
| 219 // TODO(crbug.com/718023): Re-enable test. | |
| 220 - (void)DISABLED_testSignInAndTapSettingsLink { | |
| 221 ChromeIdentity* identity = GetFakeIdentity(); | 234 ChromeIdentity* identity = GetFakeIdentity(); |
| 222 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( | 235 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( |
| 223 identity); | 236 identity); |
| 224 | 237 |
| 225 // Launch First Run and accept tems of services. | 238 // Launch First Run and accept tems of services. |
| 226 [chrome_test_util::GetMainController() showFirstRunUI]; | 239 [chrome_test_util::GetMainController() showFirstRunUI]; |
| 227 [[EarlGrey selectElementWithMatcher:FirstRunOptInAcceptButton()] | 240 [[EarlGrey selectElementWithMatcher:FirstRunOptInAcceptButton()] |
| 228 performAction:grey_tap()]; | 241 performAction:grey_tap()]; |
| 229 | 242 |
| 230 // Sign In |identity|. | 243 // Sign In |identity|. |
| 231 [[EarlGrey selectElementWithMatcher:AccountConsistencySetupSigninButton()] | 244 [[EarlGrey selectElementWithMatcher:AccountConsistencySetupSigninButton()] |
| 232 performAction:grey_tap()]; | 245 performAction:grey_tap()]; |
| 233 AssertAuthenticatedIdentityInActiveProfile(identity); | 246 AssertAuthenticatedIdentityInActiveProfile(identity); |
| 234 | 247 |
| 235 // Tap Settings link. | 248 // Tap Settings link. |
| 236 id<GREYMatcher> settings_link_matcher = grey_allOf( | 249 id<GREYMatcher> settings_link_matcher = grey_allOf( |
| 237 grey_accessibilityLabel(@"Settings"), grey_sufficientlyVisible(), nil); | 250 grey_accessibilityLabel(@"Settings"), grey_sufficientlyVisible(), |
| 251 grey_enabled(), grey_interactable(), nil); | |
| 252 WaitForMatcher(settings_link_matcher); | |
|
baxley
2017/06/01 17:16:25
Similar to in the other file, do we need the extra
jlebel
2017/06/02 09:28:26
Done.
| |
| 238 [[EarlGrey selectElementWithMatcher:settings_link_matcher] | 253 [[EarlGrey selectElementWithMatcher:settings_link_matcher] |
| 239 performAction:grey_tap()]; | 254 performAction:grey_tap()]; |
| 240 | 255 |
| 241 // Check Sync hasn't started yet, allowing the user to change somes settings. | 256 // Check Sync hasn't started yet, allowing the user to change somes settings. |
| 242 SyncSetupService* sync_service = SyncSetupServiceFactory::GetForBrowserState( | 257 SyncSetupService* sync_service = SyncSetupServiceFactory::GetForBrowserState( |
| 243 chrome_test_util::GetOriginalBrowserState()); | 258 chrome_test_util::GetOriginalBrowserState()); |
| 244 GREYAssertFalse(sync_service->HasFinishedInitialSetup(), | 259 GREYAssertFalse(sync_service->HasFinishedInitialSetup(), |
| 245 @"Sync shouldn't have finished its original setup yet"); | 260 @"Sync shouldn't have finished its original setup yet"); |
| 246 | 261 |
| 247 // Close Settings, user is still signed in and sync is now starting. | 262 // Close Settings, user is still signed in and sync is now starting. |
| 248 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] | 263 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 249 performAction:grey_tap()]; | 264 performAction:grey_tap()]; |
| 250 AssertAuthenticatedIdentityInActiveProfile(identity); | 265 AssertAuthenticatedIdentityInActiveProfile(identity); |
| 251 GREYAssertTrue(sync_service->HasFinishedInitialSetup(), | 266 GREYAssertTrue(sync_service->HasFinishedInitialSetup(), |
| 252 @"Sync should have finished its original setup"); | 267 @"Sync should have finished its original setup"); |
| 253 } | 268 } |
| 254 | 269 |
| 255 @end | 270 @end |
| OLD | NEW |