Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: ios/chrome/browser/ui/settings/settings_egtest.mm

Issue 2661473004: Adding a11y test coverage for passwords edit page. (Closed)
Patch Set: Addressed all remaining comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 111 }
112 // Matcher for the Privacy cell on the main Settings screen. 112 // Matcher for the Privacy cell on the main Settings screen.
113 id<GREYMatcher> PrivacyButton() { 113 id<GREYMatcher> PrivacyButton() {
114 return ButtonWithAccessibilityLabelId( 114 return ButtonWithAccessibilityLabelId(
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
122 // Matcher for the Search Engine cell on the main Settings screen. 121 // Matcher for the Search Engine cell on the main Settings screen.
123 id<GREYMatcher> SearchEngineButton() { 122 id<GREYMatcher> SearchEngineButton() {
124 return ButtonWithAccessibilityLabelId(IDS_IOS_SEARCH_ENGINE_SETTING_TITLE); 123 return ButtonWithAccessibilityLabelId(IDS_IOS_SEARCH_ENGINE_SETTING_TITLE);
125 } 124 }
126
127 // Matcher for the Autofill Forms cell on the main Settings screen. 125 // Matcher for the Autofill Forms cell on the main Settings screen.
128 id<GREYMatcher> AutofillButton() { 126 id<GREYMatcher> AutofillButton() {
129 return ButtonWithAccessibilityLabelId(IDS_IOS_AUTOFILL); 127 return ButtonWithAccessibilityLabelId(IDS_IOS_AUTOFILL);
130 } 128 }
131
132 // Matcher for the Google Apps cell on the main Settings screen. 129 // Matcher for the Google Apps cell on the main Settings screen.
133 id<GREYMatcher> GoogleAppsButton() { 130 id<GREYMatcher> GoogleAppsButton() {
134 return ButtonWithAccessibilityLabelId(IDS_IOS_GOOGLE_APPS_SM_SETTINGS); 131 return ButtonWithAccessibilityLabelId(IDS_IOS_GOOGLE_APPS_SM_SETTINGS);
135 } 132 }
136
137 // Matcher for the Google Chrome cell on the main Settings screen. 133 // Matcher for the Google Chrome cell on the main Settings screen.
138 id<GREYMatcher> GoogleChromeButton() { 134 id<GREYMatcher> GoogleChromeButton() {
139 return ButtonWithAccessibilityLabelId(IDS_IOS_PRODUCT_NAME); 135 return ButtonWithAccessibilityLabelId(IDS_IOS_PRODUCT_NAME);
140 } 136 }
141
142 // Matcher for the Google Chrome cell on the main Settings screen. 137 // Matcher for the Google Chrome cell on the main Settings screen.
143 id<GREYMatcher> VoiceSearchButton() { 138 id<GREYMatcher> VoiceSearchButton() {
144 return grey_allOf(grey_accessibilityID(kSettingsVoiceSearchCellId), 139 return grey_allOf(grey_accessibilityID(kSettingsVoiceSearchCellId),
145 grey_accessibilityTrait(UIAccessibilityTraitButton), nil); 140 grey_accessibilityTrait(UIAccessibilityTraitButton), nil);
146 } 141 }
147
148 // Matcher for the Preload Webpages button on the bandwidth UI. 142 // Matcher for the Preload Webpages button on the bandwidth UI.
149 id<GREYMatcher> BandwidthPreloadWebpagesButton() { 143 id<GREYMatcher> BandwidthPreloadWebpagesButton() {
150 return ButtonWithAccessibilityLabelId(IDS_IOS_OPTIONS_PRELOAD_WEBPAGES); 144 return ButtonWithAccessibilityLabelId(IDS_IOS_OPTIONS_PRELOAD_WEBPAGES);
151 } 145 }
152
153 // Matcher for the Privacy Handoff button on the privacy UI. 146 // Matcher for the Privacy Handoff button on the privacy UI.
154 id<GREYMatcher> PrivacyHandoffButton() { 147 id<GREYMatcher> PrivacyHandoffButton() {
155 return ButtonWithAccessibilityLabelId( 148 return ButtonWithAccessibilityLabelId(
156 IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES); 149 IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES);
157 } 150 }
158
159 // Matcher for the Privacy Block Popups button on the privacy UI. 151 // Matcher for the Privacy Block Popups button on the privacy UI.
160 id<GREYMatcher> BlockPopupsButton() { 152 id<GREYMatcher> BlockPopupsButton() {
161 return ButtonWithAccessibilityLabelId(IDS_IOS_BLOCK_POPUPS); 153 return ButtonWithAccessibilityLabelId(IDS_IOS_BLOCK_POPUPS);
162 } 154 }
163
164 // Matcher for the Privacy Translate Settings button on the privacy UI. 155 // Matcher for the Privacy Translate Settings button on the privacy UI.
165 id<GREYMatcher> TranslateSettingsButton() { 156 id<GREYMatcher> TranslateSettingsButton() {
166 return ButtonWithAccessibilityLabelId(IDS_IOS_TRANSLATE_SETTING); 157 return ButtonWithAccessibilityLabelId(IDS_IOS_TRANSLATE_SETTING);
167 } 158 }
159 // Matcher for the save button in the save password bar.
160 id<GREYMatcher> savePasswordButton() {
161 return ButtonWithAccessibilityLabelId(IDS_IOS_PASSWORD_MANAGER_SAVE_BUTTON);
162 }
168 163
169 // Asserts that there is no cookie in current web state. 164 // Asserts that there is no cookie in current web state.
170 void AssertNoCookieExists() { 165 void AssertNoCookieExists() {
171 NSError* error = nil; 166 NSError* error = nil;
172 chrome_test_util::ExecuteJavaScript( 167 chrome_test_util::ExecuteJavaScript(
173 base::SysUTF8ToNSString(kJavaScriptGetCookies), &error); 168 base::SysUTF8ToNSString(kJavaScriptGetCookies), &error);
174 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( 169 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
175 kNoCookieText)] 170 kNoCookieText)]
176 assertWithMatcher:grey_notNil()]; 171 assertWithMatcher:grey_notNil()];
177 } 172 }
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 [[EarlGrey selectElementWithMatcher:ClearCookiesButton()] 386 [[EarlGrey selectElementWithMatcher:ClearCookiesButton()]
392 performAction:grey_tap()]; 387 performAction:grey_tap()];
393 [[EarlGrey selectElementWithMatcher:ClearCacheButton()] 388 [[EarlGrey selectElementWithMatcher:ClearCacheButton()]
394 performAction:grey_tap()]; 389 performAction:grey_tap()];
395 [[EarlGrey selectElementWithMatcher:ClearSavedPasswordsButton()] 390 [[EarlGrey selectElementWithMatcher:ClearSavedPasswordsButton()]
396 performAction:grey_tap()]; 391 performAction:grey_tap()];
397 392
398 [self dismissSettings]; 393 [self dismissSettings];
399 } 394 }
400 395
396 - (void)enablePasswordManagement {
397 ios::ChromeBrowserState* browserState =
398 chrome_test_util::GetOriginalBrowserState();
399 PrefService* preferences = browserState->GetPrefs();
400 preferences->SetBoolean(
401 password_manager::prefs::kPasswordManagerSavingEnabled, true);
402 }
403
404 - (void)passwordsTearDown {
liaoyuke 2017/02/23 07:10:11 Some comments can be used to explain the intent of
lindsayw 2017/02/23 17:47:11 Done.
405 ios::ChromeBrowserState* browserState =
406 chrome_test_util::GetOriginalBrowserState();
407 PrefService* preferences = browserState->GetPrefs();
408 bool originalPasswordManagerSavingEnabled = preferences->GetBoolean(
409 password_manager::prefs::kPasswordManagerSavingEnabled);
410 preferences->SetBoolean(
411 password_manager::prefs::kPasswordManagerSavingEnabled, true);
412 [self clearPasswords];
liaoyuke 2017/02/23 07:10:11 Putting code and comment next to each other is con
lindsayw 2017/02/23 17:47:11 Done.
413 // Restore the password management pref state.
414 preferences->SetBoolean(
415 password_manager::prefs::kPasswordManagerSavingEnabled,
416 originalPasswordManagerSavingEnabled);
417
418 // Restore the Clear Browsing Data checkmarks prefs to their default state.
liaoyuke 2017/02/23 07:10:11 These are not specifically for password, could you
lindsayw 2017/02/23 17:47:10 Done.
419 preferences->SetBoolean(browsing_data::prefs::kDeleteBrowsingHistory, true);
420 preferences->SetBoolean(browsing_data::prefs::kDeleteCache, true);
421 preferences->SetBoolean(browsing_data::prefs::kDeleteCookies, true);
422 preferences->SetBoolean(browsing_data::prefs::kDeletePasswords, false);
423 preferences->SetBoolean(browsing_data::prefs::kDeleteFormData, false);
424 }
425
401 // Checks the presence (or absence) of saved passwords. 426 // Checks the presence (or absence) of saved passwords.
402 // If |saved| is YES, it checks that there is a Saved Passwords section. 427 // If |saved| is YES, it checks that there is a Saved Passwords section.
403 // If |saved| is NO, it checks that there is no Saved Passwords section. 428 // If |saved| is NO, it checks that there is no Saved Passwords section.
404 - (void)checkIfPasswordsSaved:(BOOL)saved { 429 - (void)checkIfPasswordsSaved:(BOOL)saved {
405 [ChromeEarlGreyUI openToolsMenu]; 430 [ChromeEarlGreyUI openToolsMenu];
406 [[EarlGrey selectElementWithMatcher:SettingsButton()] 431 [[EarlGrey selectElementWithMatcher:SettingsButton()]
407 performAction:grey_tap()]; 432 performAction:grey_tap()];
408 [[EarlGrey selectElementWithMatcher:PasswordsButton()] 433 [[EarlGrey selectElementWithMatcher:PasswordsButton()]
409 performAction:grey_tap()]; 434 performAction:grey_tap()];
410 435
411 id<GREYMatcher> visibilityMatcher = 436 id<GREYMatcher> visibilityMatcher =
412 saved ? grey_sufficientlyVisible() : grey_notVisible(); 437 saved ? grey_sufficientlyVisible() : grey_notVisible();
413 [[EarlGrey selectElementWithMatcher: 438 [[EarlGrey selectElementWithMatcher:
414 grey_text(l10n_util::GetNSString( 439 grey_text(l10n_util::GetNSString(
415 IDS_PASSWORD_MANAGER_SHOW_PASSWORDS_TAB_TITLE))] 440 IDS_PASSWORD_MANAGER_SHOW_PASSWORDS_TAB_TITLE))]
416 assertWithMatcher:visibilityMatcher]; 441 assertWithMatcher:visibilityMatcher];
417 442
418 // Close the Settings. 443 // Close the Settings.
419 [self closeSubSettingsMenu]; 444 [self closeSubSettingsMenu];
420 } 445 }
421 446
447 // Loads a page with a login and submits it.
448 - (void)loadFormAndLogin {
449 std::map<GURL, std::string> responses;
450 const GURL URL = web::test::HttpServer::MakeUrl("http://testClearPasswords");
451 // TODO(crbug.com/432596): There looks to be a bug where the save password
452 // infobar is not displayed if the action is about:blank.
453 responses[URL] =
454 "<form method=\"POST\" action=\"dest\">"
455 "Username:<input type=\"text\" name=\"username\" value=\"name\" /><br />"
456 "Password:<input type=\"password\""
457 "name=\"password\" value=\"pass\"/><br />"
458 "<input type=\"submit\" value=\"Login\" id=\"Login\"/>"
459 "</form>";
460 const GURL destinationURL =
461 web::test::HttpServer::MakeUrl("http://testClearPasswords/dest");
462 responses[destinationURL] = "Logged in!";
463 web::test::SetUpSimpleHttpServer(responses);
liaoyuke 2017/02/23 07:10:11 Could you please add some line breaks to this func
lindsayw 2017/02/23 17:47:11 Done.
464 // Login to page and click to save password and check that its saved.
465 [ChromeEarlGrey loadURL:URL];
466 chrome_test_util::TapWebViewElementWithId("Login");
467 [[EarlGrey selectElementWithMatcher:savePasswordButton()]
468 performAction:grey_tap()];
469 }
470
471 // Opens the passwords page from the NTP. It requires no menus to be open.
472 - (void)openPasswordSettings {
473 // Open settings and verify data in the view controller.
474 [ChromeEarlGreyUI openToolsMenu];
475 [[EarlGrey
476 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)]
477 performAction:grey_tap()];
478 [[EarlGrey selectElementWithMatcher:PasswordsButton()]
479 performAction:grey_tap()];
480 }
481
422 // Checks for a given service that it is both recording and uploading, where 482 // Checks for a given service that it is both recording and uploading, where
423 // appropriate. 483 // appropriate.
424 - (void)assertMetricsServiceEnabled:(MetricsServiceType)serviceType { 484 - (void)assertMetricsServiceEnabled:(MetricsServiceType)serviceType {
425 switch (serviceType) { 485 switch (serviceType) {
426 case kMetrics: 486 case kMetrics:
427 GREYAssertTrue(chrome_test_util::IsMetricsRecordingEnabled(), 487 GREYAssertTrue(chrome_test_util::IsMetricsRecordingEnabled(),
428 @"Metrics recording should be enabled."); 488 @"Metrics recording should be enabled.");
429 GREYAssertTrue(chrome_test_util::IsMetricsReportingEnabled(), 489 GREYAssertTrue(chrome_test_util::IsMetricsReportingEnabled(),
430 @"Metrics reporting should be enabled."); 490 @"Metrics reporting should be enabled.");
431 break; 491 break;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( 711 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
652 kResponse)] 712 kResponse)]
653 assertWithMatcher:grey_notNil()]; 713 assertWithMatcher:grey_notNil()];
654 AssertNoCookieExists(); 714 AssertNoCookieExists();
655 chrome_test_util::CloseAllTabs(); 715 chrome_test_util::CloseAllTabs();
656 } 716 }
657 717
658 // Verifies that logging into a form on a web page allows the user to save and 718 // Verifies that logging into a form on a web page allows the user to save and
659 // then clear a password. 719 // then clear a password.
660 - (void)testClearPasswords { 720 - (void)testClearPasswords {
661 std::map<GURL, std::string> responses; 721 [self enablePasswordManagement];
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
677 // Enable password management.
678 ios::ChromeBrowserState* browserState =
679 chrome_test_util::GetOriginalBrowserState();
680 PrefService* preferences = browserState->GetPrefs();
681 bool originalPasswordManagerSavingEnabled = preferences->GetBoolean(
682 password_manager::prefs::kPasswordManagerSavingEnabled);
683 preferences->SetBoolean(
684 password_manager::prefs::kPasswordManagerSavingEnabled, true);
685 [self setTearDownHandler:^{ 722 [self setTearDownHandler:^{
686 // Restore the password management pref state. 723 [self passwordsTearDown];
687 ios::ChromeBrowserState* browserState =
688 chrome_test_util::GetOriginalBrowserState();
689 PrefService* preferences = browserState->GetPrefs();
690 preferences->SetBoolean(
691 password_manager::prefs::kPasswordManagerSavingEnabled,
692 originalPasswordManagerSavingEnabled);
693
694 // Restore the Clear Browsing Data checkmarks prefs to their default state.
695 preferences->SetBoolean(browsing_data::prefs::kDeleteBrowsingHistory, true);
696 preferences->SetBoolean(browsing_data::prefs::kDeleteCache, true);
697 preferences->SetBoolean(browsing_data::prefs::kDeleteCookies, true);
698 preferences->SetBoolean(browsing_data::prefs::kDeletePasswords, false);
699 preferences->SetBoolean(browsing_data::prefs::kDeleteFormData, false);
700 }]; 724 }];
701 725
702 // Clear passwords and check that none are saved. 726 // Clear passwords and check that none are saved.
703 [self clearPasswords]; 727 [self clearPasswords];
704 [self checkIfPasswordsSaved:NO]; 728 [self checkIfPasswordsSaved:NO];
705 729
706 // Login to page and click to save password and check that its saved. 730 // Login to page and click to save password and check that its saved.
707 [ChromeEarlGrey loadURL:URL]; 731 [self loadFormAndLogin];
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]; 732 [self checkIfPasswordsSaved:YES];
714
715 // Clear passwords and check that none are saved.
716 [self clearPasswords];
717 [self checkIfPasswordsSaved:NO];
718 } 733 }
719 734
720 // Verifies that metrics reporting works properly under possible settings of the 735 // Verifies that metrics reporting works properly under possible settings of the
721 // preferences kMetricsReportingEnabled and kMetricsReportingWifiOnly. 736 // preferences kMetricsReportingEnabled and kMetricsReportingWifiOnly.
722 - (void)testMetricsReporting { 737 - (void)testMetricsReporting {
723 [self assertsMetricsPrefsForService:kMetrics]; 738 [self assertsMetricsPrefsForService:kMetrics];
724 } 739 }
725 740
726 // Verifies that breakpad reporting works properly under possible settings of 741 // Verifies that breakpad reporting works properly under possible settings of
727 // the preferences |kMetricsReportingEnabled| and |kMetricsReportingWifiOnly| 742 // the preferences |kMetricsReportingEnabled| and |kMetricsReportingWifiOnly|
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 953
939 // Verifies the UI elements are accessible on the Voice Search page. 954 // Verifies the UI elements are accessible on the Voice Search page.
940 - (void)testAccessibilityOnVoiceSearch { 955 - (void)testAccessibilityOnVoiceSearch {
941 [self openSubSettingMenu:VoiceSearchButton()]; 956 [self openSubSettingMenu:VoiceSearchButton()];
942 chrome_test_util::VerifyAccessibilityForCurrentScreen(); 957 chrome_test_util::VerifyAccessibilityForCurrentScreen();
943 [self closeSubSettingsMenu]; 958 [self closeSubSettingsMenu];
944 } 959 }
945 960
946 // Verifies the UI elements are accessible on the Passwords page. 961 // Verifies the UI elements are accessible on the Passwords page.
947 - (void)testAccessibilityOnPasswords { 962 - (void)testAccessibilityOnPasswords {
948 [ChromeEarlGreyUI openToolsMenu]; 963 [self openPasswordSettings];
949 [[EarlGrey selectElementWithMatcher:SettingsButton()]
950 performAction:grey_tap()];
951 [[EarlGrey selectElementWithMatcher:PasswordsButton()]
952 performAction:grey_tap()];
953 chrome_test_util::VerifyAccessibilityForCurrentScreen(); 964 chrome_test_util::VerifyAccessibilityForCurrentScreen();
954 [self closeSubSettingsMenu]; 965 [self closeSubSettingsMenu];
955 } 966 }
956 967
968 // Verifies that saved passwords are accessible in Passwords page.
969 - (void)testAccessibilityOnPasswordEditing {
970 [self clearPasswords];
971 [self checkIfPasswordsSaved:NO];
972
973 [self enablePasswordManagement];
liaoyuke 2017/02/23 07:10:11 |enablePasswordManagement| changes the value of |k
lindsayw 2017/02/23 17:47:11 Done.
974 [self setTearDownHandler:^{
975 [self passwordsTearDown];
976 }];
977
978 [self loadFormAndLogin];
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)]
998 performAction:grey_tap()];
999 }
1000
957 @end 1001 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698