| 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 #import "base/test/ios/wait_util.h" |
| 10 #include "components/signin/core/browser/signin_manager.h" | 10 #include "components/signin/core/browser/signin_manager.h" |
| 11 #include "ios/chrome/browser/experimental_flags.h" | 11 #include "ios/chrome/browser/experimental_flags.h" |
| 12 #include "ios/chrome/browser/signin/signin_manager_factory.h" | 12 #include "ios/chrome/browser/signin/signin_manager_factory.h" |
| 13 #import "ios/chrome/browser/ui/commands/open_url_command.h" | 13 #import "ios/chrome/browser/ui/commands/open_url_command.h" |
| 14 #import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h" | 14 #import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h" |
| 15 #import "ios/chrome/browser/ui/settings/import_data_collection_view_controller.h
" | 15 #import "ios/chrome/browser/ui/settings/import_data_collection_view_controller.h
" |
| 16 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h" | 16 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h" |
| 17 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h" | 17 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h" |
| 18 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" | 18 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" |
| 19 #include "ios/chrome/browser/ui/ui_util.h" | 19 #include "ios/chrome/browser/ui/ui_util.h" |
| 20 #include "ios/chrome/grit/ios_strings.h" | 20 #include "ios/chrome/grit/ios_strings.h" |
| 21 #import "ios/chrome/test/app/chrome_test_util.h" | 21 #import "ios/chrome/test/app/chrome_test_util.h" |
| 22 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | 22 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" |
| 23 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 23 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 24 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 24 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 25 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" | 25 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" |
| 26 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" | 26 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" |
| 27 #import "ios/testing/earl_grey/disabled_test_macros.h" | 27 #import "ios/testing/earl_grey/disabled_test_macros.h" |
| 28 #import "ios/testing/wait_util.h" | 28 #import "ios/testing/wait_util.h" |
| 29 | 29 |
| 30 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 31 #error "This file requires ARC support." |
| 32 #endif |
| 33 |
| 30 namespace { | 34 namespace { |
| 31 | 35 |
| 32 // Returns a fake identity. | 36 // Returns a fake identity. |
| 33 ChromeIdentity* GetFakeIdentity1() { | 37 ChromeIdentity* GetFakeIdentity1() { |
| 34 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" | 38 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" |
| 35 gaiaID:@"fooID" | 39 gaiaID:@"fooID" |
| 36 name:@"Fake Foo"]; | 40 name:@"Fake Foo"]; |
| 37 } | 41 } |
| 38 | 42 |
| 39 // Returns a second fake identity. | 43 // Returns a second fake identity. |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 - (void)testSignInCancelIdentityPicker { | 403 - (void)testSignInCancelIdentityPicker { |
| 400 // Add an identity to avoid arriving on the Add Account screen when opening | 404 // Add an identity to avoid arriving on the Add Account screen when opening |
| 401 // sign-in. | 405 // sign-in. |
| 402 ChromeIdentity* identity = GetFakeIdentity1(); | 406 ChromeIdentity* identity = GetFakeIdentity1(); |
| 403 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( | 407 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( |
| 404 identity); | 408 identity); |
| 405 | 409 |
| 406 OpenSignInFromSettings(); | 410 OpenSignInFromSettings(); |
| 407 | 411 |
| 408 // Open new tab to cancel sign-in. | 412 // Open new tab to cancel sign-in. |
| 409 base::scoped_nsobject<OpenUrlCommand> command( | 413 OpenUrlCommand* command = |
| 410 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL("about:blank")]); | 414 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL("about:blank")]; |
| 411 chrome_test_util::RunCommandWithActiveViewController(command); | 415 chrome_test_util::RunCommandWithActiveViewController(command); |
| 412 | 416 |
| 413 // Re-open the sign-in screen. If it wasn't correctly dismissed previously, | 417 // Re-open the sign-in screen. If it wasn't correctly dismissed previously, |
| 414 // this will fail. | 418 // this will fail. |
| 415 OpenSignInFromSettings(); | 419 OpenSignInFromSettings(); |
| 416 id<GREYMatcher> signin_matcher = | 420 id<GREYMatcher> signin_matcher = |
| 417 chrome_test_util::StaticTextWithAccessibilityLabelId( | 421 chrome_test_util::StaticTextWithAccessibilityLabelId( |
| 418 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION); | 422 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION); |
| 419 [[EarlGrey selectElementWithMatcher:signin_matcher] | 423 [[EarlGrey selectElementWithMatcher:signin_matcher] |
| 420 assertWithMatcher:grey_sufficientlyVisible()]; | 424 assertWithMatcher:grey_sufficientlyVisible()]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 437 | 441 |
| 438 // Open Add Account screen. | 442 // Open Add Account screen. |
| 439 id<GREYMatcher> add_account_matcher = | 443 id<GREYMatcher> add_account_matcher = |
| 440 chrome_test_util::StaticTextWithAccessibilityLabelId( | 444 chrome_test_util::StaticTextWithAccessibilityLabelId( |
| 441 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_ADD_ACCOUNT_BUTTON); | 445 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_ADD_ACCOUNT_BUTTON); |
| 442 [[EarlGrey selectElementWithMatcher:add_account_matcher] | 446 [[EarlGrey selectElementWithMatcher:add_account_matcher] |
| 443 performAction:grey_tap()]; | 447 performAction:grey_tap()]; |
| 444 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 448 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 445 | 449 |
| 446 // Open new tab to cancel sign-in. | 450 // Open new tab to cancel sign-in. |
| 447 base::scoped_nsobject<OpenUrlCommand> command( | 451 OpenUrlCommand* command = |
| 448 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL("about:blank")]); | 452 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL("about:blank")]; |
| 449 chrome_test_util::RunCommandWithActiveViewController(command); | 453 chrome_test_util::RunCommandWithActiveViewController(command); |
| 450 | 454 |
| 451 // Re-open the sign-in screen. If it wasn't correctly dismissed previously, | 455 // Re-open the sign-in screen. If it wasn't correctly dismissed previously, |
| 452 // this will fail. | 456 // this will fail. |
| 453 OpenSignInFromSettings(); | 457 OpenSignInFromSettings(); |
| 454 id<GREYMatcher> signin_matcher = | 458 id<GREYMatcher> signin_matcher = |
| 455 chrome_test_util::StaticTextWithAccessibilityLabelId( | 459 chrome_test_util::StaticTextWithAccessibilityLabelId( |
| 456 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION); | 460 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION); |
| 457 [[EarlGrey selectElementWithMatcher:signin_matcher] | 461 [[EarlGrey selectElementWithMatcher:signin_matcher] |
| 458 assertWithMatcher:grey_sufficientlyVisible()]; | 462 assertWithMatcher:grey_sufficientlyVisible()]; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 TapButtonWithLabelId(IDS_IOS_DISCONNECT_DIALOG_CONTINUE_BUTTON_MOBILE); | 500 TapButtonWithLabelId(IDS_IOS_DISCONNECT_DIALOG_CONTINUE_BUTTON_MOBILE); |
| 497 AssertAuthenticatedIdentityInActiveProfile(nil); | 501 AssertAuthenticatedIdentityInActiveProfile(nil); |
| 498 | 502 |
| 499 // Start sign-in with |identity1|. | 503 // Start sign-in with |identity1|. |
| 500 WaitForMatcher(grey_accessibilityID(kSettingsSignInCellId)); | 504 WaitForMatcher(grey_accessibilityID(kSettingsSignInCellId)); |
| 501 TapViewWithAccessibilityId(kSettingsSignInCellId); | 505 TapViewWithAccessibilityId(kSettingsSignInCellId); |
| 502 TapButtonWithAccessibilityLabel(identity1.userEmail); | 506 TapButtonWithAccessibilityLabel(identity1.userEmail); |
| 503 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON); | 507 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON); |
| 504 | 508 |
| 505 // Open new tab to cancel sign-in. | 509 // Open new tab to cancel sign-in. |
| 506 base::scoped_nsobject<OpenUrlCommand> command( | 510 OpenUrlCommand* command = |
| 507 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL("about:blank")]); | 511 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL("about:blank")]; |
| 508 chrome_test_util::RunCommandWithActiveViewController(command); | 512 chrome_test_util::RunCommandWithActiveViewController(command); |
| 509 | 513 |
| 510 // Re-open the sign-in screen. If it wasn't correctly dismissed previously, | 514 // Re-open the sign-in screen. If it wasn't correctly dismissed previously, |
| 511 // this will fail. | 515 // this will fail. |
| 512 OpenSignInFromSettings(); | 516 OpenSignInFromSettings(); |
| 513 id<GREYMatcher> signin_matcher = | 517 id<GREYMatcher> signin_matcher = |
| 514 chrome_test_util::StaticTextWithAccessibilityLabelId( | 518 chrome_test_util::StaticTextWithAccessibilityLabelId( |
| 515 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION); | 519 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION); |
| 516 [[EarlGrey selectElementWithMatcher:signin_matcher] | 520 [[EarlGrey selectElementWithMatcher:signin_matcher] |
| 517 assertWithMatcher:grey_sufficientlyVisible()]; | 521 assertWithMatcher:grey_sufficientlyVisible()]; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 TapButtonWithLabelId(IDS_IOS_BOOKMARK_PROMO_SIGN_IN_BUTTON); | 561 TapButtonWithLabelId(IDS_IOS_BOOKMARK_PROMO_SIGN_IN_BUTTON); |
| 558 | 562 |
| 559 // Assert sign-in screen was shown. | 563 // Assert sign-in screen was shown. |
| 560 id<GREYMatcher> signin_matcher = | 564 id<GREYMatcher> signin_matcher = |
| 561 chrome_test_util::StaticTextWithAccessibilityLabelId( | 565 chrome_test_util::StaticTextWithAccessibilityLabelId( |
| 562 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION); | 566 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION); |
| 563 [[EarlGrey selectElementWithMatcher:signin_matcher] | 567 [[EarlGrey selectElementWithMatcher:signin_matcher] |
| 564 assertWithMatcher:grey_sufficientlyVisible()]; | 568 assertWithMatcher:grey_sufficientlyVisible()]; |
| 565 | 569 |
| 566 // Open new tab to cancel sign-in. | 570 // Open new tab to cancel sign-in. |
| 567 base::scoped_nsobject<OpenUrlCommand> command( | 571 OpenUrlCommand* command = |
| 568 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL("about:blank")]); | 572 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL("about:blank")]; |
| 569 chrome_test_util::RunCommandWithActiveViewController(command); | 573 chrome_test_util::RunCommandWithActiveViewController(command); |
| 570 | 574 |
| 571 // Re-open the sign-in screen. If it wasn't correctly dismissed previously, | 575 // Re-open the sign-in screen. If it wasn't correctly dismissed previously, |
| 572 // this will fail. | 576 // this will fail. |
| 573 [ChromeEarlGreyUI openToolsMenu]; | 577 [ChromeEarlGreyUI openToolsMenu]; |
| 574 [[[EarlGrey | 578 [[[EarlGrey |
| 575 selectElementWithMatcher:grey_accessibilityID(kToolsMenuBookmarksId)] | 579 selectElementWithMatcher:grey_accessibilityID(kToolsMenuBookmarksId)] |
| 576 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, | 580 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, |
| 577 scroll_displacement) | 581 scroll_displacement) |
| 578 onElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)] | 582 onElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)] |
| 579 performAction:grey_tap()]; | 583 performAction:grey_tap()]; |
| 580 if (!IsIPadIdiom()) { | 584 if (!IsIPadIdiom()) { |
| 581 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Menu")] | 585 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Menu")] |
| 582 performAction:grey_tap()]; | 586 performAction:grey_tap()]; |
| 583 } | 587 } |
| 584 [[EarlGrey selectElementWithMatcher:all_bookmarks_matcher] | 588 [[EarlGrey selectElementWithMatcher:all_bookmarks_matcher] |
| 585 performAction:grey_tap()]; | 589 performAction:grey_tap()]; |
| 586 TapButtonWithLabelId(IDS_IOS_BOOKMARK_PROMO_SIGN_IN_BUTTON); | 590 TapButtonWithLabelId(IDS_IOS_BOOKMARK_PROMO_SIGN_IN_BUTTON); |
| 587 [[EarlGrey selectElementWithMatcher:signin_matcher] | 591 [[EarlGrey selectElementWithMatcher:signin_matcher] |
| 588 assertWithMatcher:grey_sufficientlyVisible()]; | 592 assertWithMatcher:grey_sufficientlyVisible()]; |
| 589 | 593 |
| 590 // Close sign-in screen and Bookmarks. | 594 // Close sign-in screen and Bookmarks. |
| 591 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON); | 595 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON); |
| 592 if (!IsIPadIdiom()) { | 596 if (!IsIPadIdiom()) { |
| 593 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); | 597 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); |
| 594 } | 598 } |
| 595 } | 599 } |
| 596 | 600 |
| 597 @end | 601 @end |
| OLD | NEW |