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 <UIKit/UIKit.h> | 6 #import <UIKit/UIKit.h> |
| 7 #import <XCTest/XCTest.h> | 7 #import <XCTest/XCTest.h> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY); | 115 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY); |
| 116 } | 116 } |
| 117 // Matcher for the Clear Browsing Data cell on the Privacy screen. | 117 // Matcher for the Clear Browsing Data cell on the Privacy screen. |
| 118 id<GREYMatcher> ClearBrowsingDataCell() { | 118 id<GREYMatcher> ClearBrowsingDataCell() { |
| 119 return ButtonWithAccessibilityLabelId(IDS_IOS_CLEAR_BROWSING_DATA_TITLE); | 119 return ButtonWithAccessibilityLabelId(IDS_IOS_CLEAR_BROWSING_DATA_TITLE); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Matcher for the Search Engine cell on the main Settings screen. | 122 // Matcher for the Search Engine cell on the main Settings screen. |
| 123 id<GREYMatcher> SearchEngineButton() { | 123 id<GREYMatcher> SearchEngineButton() { |
| 124 return ButtonWithAccessibilityLabelId(IDS_IOS_SEARCH_ENGINE_SETTING_TITLE); | 124 return ButtonWithAccessibilityLabelId(IDS_IOS_SEARCH_ENGINE_SETTING_TITLE); |
| 125 } | 125 } |
|
baxley
2017/02/17 15:38:00
Thank you for the clean up, outside of your code!
lindsayw
2017/02/17 22:01:57
Done.
| |
| 126 | |
| 127 // Matcher for the Autofill Forms cell on the main Settings screen. | 126 // Matcher for the Autofill Forms cell on the main Settings screen. |
| 128 id<GREYMatcher> AutofillButton() { | 127 id<GREYMatcher> AutofillButton() { |
| 129 return ButtonWithAccessibilityLabelId(IDS_IOS_AUTOFILL); | 128 return ButtonWithAccessibilityLabelId(IDS_IOS_AUTOFILL); |
| 130 } | 129 } |
| 131 | |
| 132 // Matcher for the Google Apps cell on the main Settings screen. | 130 // Matcher for the Google Apps cell on the main Settings screen. |
| 133 id<GREYMatcher> GoogleAppsButton() { | 131 id<GREYMatcher> GoogleAppsButton() { |
| 134 return ButtonWithAccessibilityLabelId(IDS_IOS_GOOGLE_APPS_SM_SETTINGS); | 132 return ButtonWithAccessibilityLabelId(IDS_IOS_GOOGLE_APPS_SM_SETTINGS); |
| 135 } | 133 } |
| 136 | |
| 137 // Matcher for the Google Chrome cell on the main Settings screen. | 134 // Matcher for the Google Chrome cell on the main Settings screen. |
| 138 id<GREYMatcher> GoogleChromeButton() { | 135 id<GREYMatcher> GoogleChromeButton() { |
| 139 return ButtonWithAccessibilityLabelId(IDS_IOS_PRODUCT_NAME); | 136 return ButtonWithAccessibilityLabelId(IDS_IOS_PRODUCT_NAME); |
| 140 } | 137 } |
| 141 | 138 |
| 142 // Matcher for the Google Chrome cell on the main Settings screen. | 139 // Matcher for the Google Chrome cell on the main Settings screen. |
| 143 id<GREYMatcher> VoiceSearchButton() { | 140 id<GREYMatcher> VoiceSearchButton() { |
| 144 return grey_allOf(grey_accessibilityID(kSettingsVoiceSearchCellId), | 141 return grey_allOf(grey_accessibilityID(kSettingsVoiceSearchCellId), |
| 145 grey_accessibilityTrait(UIAccessibilityTraitButton), nil); | 142 grey_accessibilityTrait(UIAccessibilityTraitButton), nil); |
| 146 } | 143 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 159 // Matcher for the Privacy Block Popups button on the privacy UI. | 156 // Matcher for the Privacy Block Popups button on the privacy UI. |
| 160 id<GREYMatcher> BlockPopupsButton() { | 157 id<GREYMatcher> BlockPopupsButton() { |
| 161 return ButtonWithAccessibilityLabelId(IDS_IOS_BLOCK_POPUPS); | 158 return ButtonWithAccessibilityLabelId(IDS_IOS_BLOCK_POPUPS); |
| 162 } | 159 } |
| 163 | 160 |
| 164 // Matcher for the Privacy Translate Settings button on the privacy UI. | 161 // Matcher for the Privacy Translate Settings button on the privacy UI. |
| 165 id<GREYMatcher> TranslateSettingsButton() { | 162 id<GREYMatcher> TranslateSettingsButton() { |
| 166 return ButtonWithAccessibilityLabelId(IDS_IOS_TRANSLATE_SETTING); | 163 return ButtonWithAccessibilityLabelId(IDS_IOS_TRANSLATE_SETTING); |
| 167 } | 164 } |
| 168 | 165 |
| 166 // Matcher for the save button in the save password bar. | |
| 167 id<GREYMatcher> savePasswordButton() { | |
| 168 return ButtonWithAccessibilityLabelId(IDS_IOS_PASSWORD_MANAGER_SAVE_BUTTON); | |
| 169 } | |
|
baxley
2017/02/17 15:38:00
nit: blank line?
lindsayw
2017/02/17 22:01:56
Done.
| |
| 169 // Asserts that there is no cookie in current web state. | 170 // Asserts that there is no cookie in current web state. |
| 170 void AssertNoCookieExists() { | 171 void AssertNoCookieExists() { |
| 171 NSError* error = nil; | 172 NSError* error = nil; |
| 172 chrome_test_util::ExecuteJavaScript( | 173 chrome_test_util::ExecuteJavaScript( |
| 173 base::SysUTF8ToNSString(kJavaScriptGetCookies), &error); | 174 base::SysUTF8ToNSString(kJavaScriptGetCookies), &error); |
| 174 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 175 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| 175 kNoCookieText)] | 176 kNoCookieText)] |
| 176 assertWithMatcher:grey_notNil()]; | 177 assertWithMatcher:grey_notNil()]; |
| 177 } | 178 } |
| 178 | 179 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 saved ? grey_sufficientlyVisible() : grey_notVisible(); | 413 saved ? grey_sufficientlyVisible() : grey_notVisible(); |
| 413 [[EarlGrey selectElementWithMatcher: | 414 [[EarlGrey selectElementWithMatcher: |
| 414 grey_text(l10n_util::GetNSString( | 415 grey_text(l10n_util::GetNSString( |
| 415 IDS_PASSWORD_MANAGER_SHOW_PASSWORDS_TAB_TITLE))] | 416 IDS_PASSWORD_MANAGER_SHOW_PASSWORDS_TAB_TITLE))] |
| 416 assertWithMatcher:visibilityMatcher]; | 417 assertWithMatcher:visibilityMatcher]; |
| 417 | 418 |
| 418 // Close the Settings. | 419 // Close the Settings. |
| 419 [self closeSubSettingsMenu]; | 420 [self closeSubSettingsMenu]; |
| 420 } | 421 } |
| 421 | 422 |
| 423 // Helper to load a page with a login and submit it. | |
|
baxley
2017/02/17 15:38:00
nit:s/Helper to load/Loads
lindsayw
2017/02/17 22:01:57
Done.
| |
| 424 - (void)loadAndSubmitTheForm { | |
|
baxley
2017/02/17 15:38:00
Would it be okay to call it loadFormAndLogin ?
"A
lindsayw
2017/02/17 22:01:57
Done.
| |
| 425 std::map<GURL, std::string> responses; | |
| 426 const GURL URL = web::test::HttpServer::MakeUrl("http://testClearPasswords"); | |
| 427 // TODO(crbug.com/432596): There looks to be a bug where the save password | |
| 428 // infobar is not displayed if the action is about:blank. | |
| 429 responses[URL] = | |
| 430 "<form method=\"POST\" action=\"dest\">" | |
| 431 "Username:<input type=\"text\" name=\"username\" value=\"name\" /><br />" | |
| 432 "Password:<input type=\"password\"" | |
| 433 "name=\"password\" value=\"pass\"/><br />" | |
| 434 "<input type=\"submit\" value=\"Login\" id=\"Login\"/>" | |
| 435 "</form>"; | |
| 436 const GURL destinationURL = | |
| 437 web::test::HttpServer::MakeUrl("http://testClearPasswords/dest"); | |
| 438 responses[destinationURL] = "Logged in!"; | |
| 439 web::test::SetUpSimpleHttpServer(responses); | |
| 440 // Login to page and click to save password and check that its saved. | |
| 441 [ChromeEarlGrey loadURL:URL]; | |
| 442 chrome_test_util::TapWebViewElementWithId("Login"); | |
| 443 [[EarlGrey selectElementWithMatcher:savePasswordButton()] | |
| 444 performAction:grey_tap()]; | |
| 445 } | |
| 446 | |
| 447 // Helper to open the passwords page. | |
|
baxley
2017/02/17 15:38:00
nit: "Opens the passwords page. It requires no men
lindsayw
2017/02/17 22:01:57
Done.
| |
| 448 - (void)openPasswordSettings { | |
| 449 // Open settings and verify data in the view controller. | |
| 450 [ChromeEarlGreyUI openToolsMenu]; | |
| 451 [[EarlGrey | |
| 452 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)] | |
| 453 performAction:grey_tap()]; | |
| 454 [[EarlGrey selectElementWithMatcher:PasswordsButton()] | |
| 455 performAction:grey_tap()]; | |
| 456 } | |
| 457 | |
| 422 // Checks for a given service that it is both recording and uploading, where | 458 // Checks for a given service that it is both recording and uploading, where |
| 423 // appropriate. | 459 // appropriate. |
| 424 - (void)assertMetricsServiceEnabled:(MetricsServiceType)serviceType { | 460 - (void)assertMetricsServiceEnabled:(MetricsServiceType)serviceType { |
| 425 switch (serviceType) { | 461 switch (serviceType) { |
| 426 case kMetrics: | 462 case kMetrics: |
| 427 GREYAssertTrue(chrome_test_util::IsMetricsRecordingEnabled(), | 463 GREYAssertTrue(chrome_test_util::IsMetricsRecordingEnabled(), |
| 428 @"Metrics recording should be enabled."); | 464 @"Metrics recording should be enabled."); |
| 429 GREYAssertTrue(chrome_test_util::IsMetricsReportingEnabled(), | 465 GREYAssertTrue(chrome_test_util::IsMetricsReportingEnabled(), |
| 430 @"Metrics reporting should be enabled."); | 466 @"Metrics reporting should be enabled."); |
| 431 break; | 467 break; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 687 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| 652 kResponse)] | 688 kResponse)] |
| 653 assertWithMatcher:grey_notNil()]; | 689 assertWithMatcher:grey_notNil()]; |
| 654 AssertNoCookieExists(); | 690 AssertNoCookieExists(); |
| 655 chrome_test_util::CloseAllTabs(); | 691 chrome_test_util::CloseAllTabs(); |
| 656 } | 692 } |
| 657 | 693 |
| 658 // Verifies that logging into a form on a web page allows the user to save and | 694 // Verifies that logging into a form on a web page allows the user to save and |
| 659 // then clear a password. | 695 // then clear a password. |
| 660 - (void)testClearPasswords { | 696 - (void)testClearPasswords { |
| 661 std::map<GURL, std::string> responses; | |
| 662 const GURL URL = web::test::HttpServer::MakeUrl("http://testClearPasswords"); | |
| 663 // TODO(crbug.com/432596): There looks to be a bug where the save password | |
| 664 // infobar is not displayed if the action is about:blank. | |
| 665 responses[URL] = | |
| 666 "<form method=\"POST\" action=\"dest\">" | |
| 667 "Username:<input type=\"text\" name=\"username\" value=\"name\" /><br />" | |
| 668 "Password:<input type=\"password\"" | |
| 669 "name=\"password\" value=\"pass\"/><br />" | |
| 670 "<input type=\"submit\" value=\"Login\" id=\"Login\"/>" | |
| 671 "</form>"; | |
| 672 const GURL destinationURL = | |
| 673 web::test::HttpServer::MakeUrl("http://testClearPasswords/dest"); | |
| 674 responses[destinationURL] = "Logged in!"; | |
| 675 web::test::SetUpSimpleHttpServer(responses); | |
| 676 | 697 |
| 677 // Enable password management. | 698 // Enable password management. |
| 678 ios::ChromeBrowserState* browserState = | 699 ios::ChromeBrowserState* browserState = |
| 679 chrome_test_util::GetOriginalBrowserState(); | 700 chrome_test_util::GetOriginalBrowserState(); |
| 680 PrefService* preferences = browserState->GetPrefs(); | 701 PrefService* preferences = browserState->GetPrefs(); |
| 681 bool originalPasswordManagerSavingEnabled = preferences->GetBoolean( | 702 bool originalPasswordManagerSavingEnabled = preferences->GetBoolean( |
| 682 password_manager::prefs::kPasswordManagerSavingEnabled); | 703 password_manager::prefs::kPasswordManagerSavingEnabled); |
| 683 preferences->SetBoolean( | 704 preferences->SetBoolean( |
| 684 password_manager::prefs::kPasswordManagerSavingEnabled, true); | 705 password_manager::prefs::kPasswordManagerSavingEnabled, true); |
| 685 [self setTearDownHandler:^{ | 706 [self setTearDownHandler:^{ |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 697 preferences->SetBoolean(browsing_data::prefs::kDeleteCookies, true); | 718 preferences->SetBoolean(browsing_data::prefs::kDeleteCookies, true); |
| 698 preferences->SetBoolean(browsing_data::prefs::kDeletePasswords, false); | 719 preferences->SetBoolean(browsing_data::prefs::kDeletePasswords, false); |
| 699 preferences->SetBoolean(browsing_data::prefs::kDeleteFormData, false); | 720 preferences->SetBoolean(browsing_data::prefs::kDeleteFormData, false); |
| 700 }]; | 721 }]; |
| 701 | 722 |
| 702 // Clear passwords and check that none are saved. | 723 // Clear passwords and check that none are saved. |
| 703 [self clearPasswords]; | 724 [self clearPasswords]; |
| 704 [self checkIfPasswordsSaved:NO]; | 725 [self checkIfPasswordsSaved:NO]; |
| 705 | 726 |
| 706 // Login to page and click to save password and check that its saved. | 727 // Login to page and click to save password and check that its saved. |
| 707 [ChromeEarlGrey loadURL:URL]; | 728 [self loadAndSubmitTheForm]; |
| 708 chrome_test_util::TapWebViewElementWithId("Login"); | |
| 709 [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId( | |
| 710 IDS_IOS_PASSWORD_MANAGER_SAVE_BUTTON)] | |
| 711 performAction:grey_tap()]; | |
| 712 | |
| 713 [self checkIfPasswordsSaved:YES]; | 729 [self checkIfPasswordsSaved:YES]; |
| 714 | 730 |
| 715 // Clear passwords and check that none are saved. | 731 // Clear passwords and check that none are saved. |
| 716 [self clearPasswords]; | 732 [self clearPasswords]; |
| 717 [self checkIfPasswordsSaved:NO]; | 733 [self checkIfPasswordsSaved:NO]; |
| 718 } | 734 } |
| 719 | 735 |
| 720 // Verifies that metrics reporting works properly under possible settings of the | 736 // Verifies that metrics reporting works properly under possible settings of the |
| 721 // preferences kMetricsReportingEnabled and kMetricsReportingWifiOnly. | 737 // preferences kMetricsReportingEnabled and kMetricsReportingWifiOnly. |
| 722 - (void)testMetricsReporting { | 738 - (void)testMetricsReporting { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 958 chrome_test_util::VerifyAccessibilityForCurrentScreen(); |
| 943 [self closeSubSettingsMenu]; | 959 [self closeSubSettingsMenu]; |
| 944 } | 960 } |
| 945 | 961 |
| 946 // Verifies the UI elements are accessible on the Passwords page. | 962 // Verifies the UI elements are accessible on the Passwords page. |
| 947 - (void)testAccessibilityOnPasswords { | 963 - (void)testAccessibilityOnPasswords { |
| 948 [ChromeEarlGreyUI openToolsMenu]; | 964 [ChromeEarlGreyUI openToolsMenu]; |
| 949 [[EarlGrey selectElementWithMatcher:SettingsButton()] | 965 [[EarlGrey selectElementWithMatcher:SettingsButton()] |
| 950 performAction:grey_tap()]; | 966 performAction:grey_tap()]; |
| 951 [[EarlGrey selectElementWithMatcher:PasswordsButton()] | 967 [[EarlGrey selectElementWithMatcher:PasswordsButton()] |
| 952 performAction:grey_tap()]; | 968 performAction:grey_tap()]; |
|
baxley
2017/02/17 15:38:00
Could we make this test match the new test you wro
lindsayw
2017/02/17 22:01:56
Done, Option 1.
| |
| 953 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 969 chrome_test_util::VerifyAccessibilityForCurrentScreen(); |
| 954 [self closeSubSettingsMenu]; | 970 [self closeSubSettingsMenu]; |
| 955 } | 971 } |
| 956 | 972 |
| 973 // Add a saved password and verify the edit password page is accessible. | |
|
baxley
2017/02/17 15:38:00
nit: should start with an active verb. What about
lindsayw
2017/02/17 22:01:56
Done. "Verifies that saved passwords are accessibl
| |
| 974 - (void)testAccessibilityOnPasswordEditing { | |
| 975 [self clearPasswords]; | |
| 976 [self checkIfPasswordsSaved:NO]; | |
| 977 | |
| 978 [self loadAndSubmitTheForm]; | |
| 979 [self openPasswordSettings]; | |
| 980 | |
| 981 // Switch on edit mode. | |
| 982 [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId( | |
| 983 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)] | |
| 984 performAction:grey_tap()]; | |
| 985 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | |
| 986 | |
| 987 // Exit settings. | |
| 988 [[EarlGrey | |
| 989 selectElementWithMatcher:grey_allOf( | |
| 990 grey_accessibilityID(@"ic_arrow_back"), | |
| 991 grey_accessibilityTrait( | |
| 992 UIAccessibilityTraitButton), | |
| 993 nil)] performAction:grey_tap()]; | |
| 994 | |
| 995 [[EarlGrey | |
| 996 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId( | |
| 997 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)] | |
|
baxley
2017/02/17 15:38:00
I filed a bug to create a custom matcher (crbug.co
lindsayw
2017/02/17 22:01:56
Acknowledged.
| |
| 998 performAction:grey_tap()]; | |
| 999 | |
| 1000 [self clearPasswords]; | |
|
baxley
2017/02/17 15:38:00
Is this safe to call if there are no saved passwor
lindsayw
2017/02/17 22:01:56
No, clearPasswords has the limitation discussed in
| |
| 1001 } | |
| 1002 | |
| 957 @end | 1003 @end |
| OLD | NEW |