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

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 comments. Created 3 years, 10 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 saved ? grey_sufficientlyVisible() : grey_notVisible(); 407 saved ? grey_sufficientlyVisible() : grey_notVisible();
413 [[EarlGrey selectElementWithMatcher: 408 [[EarlGrey selectElementWithMatcher:
414 grey_text(l10n_util::GetNSString( 409 grey_text(l10n_util::GetNSString(
415 IDS_PASSWORD_MANAGER_SHOW_PASSWORDS_TAB_TITLE))] 410 IDS_PASSWORD_MANAGER_SHOW_PASSWORDS_TAB_TITLE))]
416 assertWithMatcher:visibilityMatcher]; 411 assertWithMatcher:visibilityMatcher];
417 412
418 // Close the Settings. 413 // Close the Settings.
419 [self closeSubSettingsMenu]; 414 [self closeSubSettingsMenu];
420 } 415 }
421 416
417 // Loads a page with a login and submits it.
418 - (void)loadFormAndLogin {
419 std::map<GURL, std::string> responses;
420 const GURL URL = web::test::HttpServer::MakeUrl("http://testClearPasswords");
421 // TODO(crbug.com/432596): There looks to be a bug where the save password
422 // infobar is not displayed if the action is about:blank.
423 responses[URL] =
424 "<form method=\"POST\" action=\"dest\">"
425 "Username:<input type=\"text\" name=\"username\" value=\"name\" /><br />"
426 "Password:<input type=\"password\""
427 "name=\"password\" value=\"pass\"/><br />"
428 "<input type=\"submit\" value=\"Login\" id=\"Login\"/>"
429 "</form>";
430 const GURL destinationURL =
431 web::test::HttpServer::MakeUrl("http://testClearPasswords/dest");
432 responses[destinationURL] = "Logged in!";
433 web::test::SetUpSimpleHttpServer(responses);
434 // Login to page and click to save password and check that its saved.
435 [ChromeEarlGrey loadURL:URL];
436 chrome_test_util::TapWebViewElementWithId("Login");
437 [[EarlGrey selectElementWithMatcher:savePasswordButton()]
438 performAction:grey_tap()];
439 }
440
441 // Opens the passwords page from the NTP. It requires no menus to be open.
442 - (void)openPasswordSettings {
443 // Open settings and verify data in the view controller.
444 [ChromeEarlGreyUI openToolsMenu];
445 [[EarlGrey
446 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)]
447 performAction:grey_tap()];
448 [[EarlGrey selectElementWithMatcher:PasswordsButton()]
449 performAction:grey_tap()];
450 }
451
422 // Checks for a given service that it is both recording and uploading, where 452 // Checks for a given service that it is both recording and uploading, where
423 // appropriate. 453 // appropriate.
424 - (void)assertMetricsServiceEnabled:(MetricsServiceType)serviceType { 454 - (void)assertMetricsServiceEnabled:(MetricsServiceType)serviceType {
425 switch (serviceType) { 455 switch (serviceType) {
426 case kMetrics: 456 case kMetrics:
427 GREYAssertTrue(chrome_test_util::IsMetricsRecordingEnabled(), 457 GREYAssertTrue(chrome_test_util::IsMetricsRecordingEnabled(),
428 @"Metrics recording should be enabled."); 458 @"Metrics recording should be enabled.");
429 GREYAssertTrue(chrome_test_util::IsMetricsReportingEnabled(), 459 GREYAssertTrue(chrome_test_util::IsMetricsReportingEnabled(),
430 @"Metrics reporting should be enabled."); 460 @"Metrics reporting should be enabled.");
431 break; 461 break;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( 681 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
652 kResponse)] 682 kResponse)]
653 assertWithMatcher:grey_notNil()]; 683 assertWithMatcher:grey_notNil()];
654 AssertNoCookieExists(); 684 AssertNoCookieExists();
655 chrome_test_util::CloseAllTabs(); 685 chrome_test_util::CloseAllTabs();
656 } 686 }
657 687
658 // Verifies that logging into a form on a web page allows the user to save and 688 // Verifies that logging into a form on a web page allows the user to save and
659 // then clear a password. 689 // then clear a password.
660 - (void)testClearPasswords { 690 - (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 691
677 // Enable password management. 692 // Enable password management.
678 ios::ChromeBrowserState* browserState = 693 ios::ChromeBrowserState* browserState =
679 chrome_test_util::GetOriginalBrowserState(); 694 chrome_test_util::GetOriginalBrowserState();
680 PrefService* preferences = browserState->GetPrefs(); 695 PrefService* preferences = browserState->GetPrefs();
681 bool originalPasswordManagerSavingEnabled = preferences->GetBoolean( 696 bool originalPasswordManagerSavingEnabled = preferences->GetBoolean(
682 password_manager::prefs::kPasswordManagerSavingEnabled); 697 password_manager::prefs::kPasswordManagerSavingEnabled);
683 preferences->SetBoolean( 698 preferences->SetBoolean(
684 password_manager::prefs::kPasswordManagerSavingEnabled, true); 699 password_manager::prefs::kPasswordManagerSavingEnabled, true);
685 [self setTearDownHandler:^{ 700 [self setTearDownHandler:^{
(...skipping 11 matching lines...) Expand all
697 preferences->SetBoolean(browsing_data::prefs::kDeleteCookies, true); 712 preferences->SetBoolean(browsing_data::prefs::kDeleteCookies, true);
698 preferences->SetBoolean(browsing_data::prefs::kDeletePasswords, false); 713 preferences->SetBoolean(browsing_data::prefs::kDeletePasswords, false);
699 preferences->SetBoolean(browsing_data::prefs::kDeleteFormData, false); 714 preferences->SetBoolean(browsing_data::prefs::kDeleteFormData, false);
700 }]; 715 }];
701 716
702 // Clear passwords and check that none are saved. 717 // Clear passwords and check that none are saved.
703 [self clearPasswords]; 718 [self clearPasswords];
704 [self checkIfPasswordsSaved:NO]; 719 [self checkIfPasswordsSaved:NO];
705 720
706 // Login to page and click to save password and check that its saved. 721 // Login to page and click to save password and check that its saved.
707 [ChromeEarlGrey loadURL:URL]; 722 [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]; 723 [self checkIfPasswordsSaved:YES];
714 724
715 // Clear passwords and check that none are saved. 725 // Clear passwords and check that none are saved.
716 [self clearPasswords]; 726 [self clearPasswords];
717 [self checkIfPasswordsSaved:NO]; 727 [self checkIfPasswordsSaved:NO];
718 } 728 }
719 729
720 // Verifies that metrics reporting works properly under possible settings of the 730 // Verifies that metrics reporting works properly under possible settings of the
721 // preferences kMetricsReportingEnabled and kMetricsReportingWifiOnly. 731 // preferences kMetricsReportingEnabled and kMetricsReportingWifiOnly.
722 - (void)testMetricsReporting { 732 - (void)testMetricsReporting {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 948
939 // Verifies the UI elements are accessible on the Voice Search page. 949 // Verifies the UI elements are accessible on the Voice Search page.
940 - (void)testAccessibilityOnVoiceSearch { 950 - (void)testAccessibilityOnVoiceSearch {
941 [self openSubSettingMenu:VoiceSearchButton()]; 951 [self openSubSettingMenu:VoiceSearchButton()];
942 chrome_test_util::VerifyAccessibilityForCurrentScreen(); 952 chrome_test_util::VerifyAccessibilityForCurrentScreen();
943 [self closeSubSettingsMenu]; 953 [self closeSubSettingsMenu];
944 } 954 }
945 955
946 // Verifies the UI elements are accessible on the Passwords page. 956 // Verifies the UI elements are accessible on the Passwords page.
947 - (void)testAccessibilityOnPasswords { 957 - (void)testAccessibilityOnPasswords {
948 [ChromeEarlGreyUI openToolsMenu]; 958 [self openPasswordSettings];
949 [[EarlGrey selectElementWithMatcher:SettingsButton()]
950 performAction:grey_tap()];
951 [[EarlGrey selectElementWithMatcher:PasswordsButton()]
952 performAction:grey_tap()];
953 chrome_test_util::VerifyAccessibilityForCurrentScreen(); 959 chrome_test_util::VerifyAccessibilityForCurrentScreen();
954 [self closeSubSettingsMenu]; 960 [self closeSubSettingsMenu];
955 } 961 }
956 962
963 // Verifies that saved passwords are accessible in Passwords page.
964 - (void)testAccessibilityOnPasswordEditing {
965 [self clearPasswords];
966 [self checkIfPasswordsSaved:NO];
967
968 // Enable password management.
969 ios::ChromeBrowserState* browserState =
970 chrome_test_util::GetOriginalBrowserState();
971 PrefService* preferences = browserState->GetPrefs();
972 bool originalPasswordManagerSavingEnabled = preferences->GetBoolean(
973 password_manager::prefs::kPasswordManagerSavingEnabled);
974 preferences->SetBoolean(
975 password_manager::prefs::kPasswordManagerSavingEnabled, true);
976 [self setTearDownHandler:^{
977 // Restore the password management pref state.
978 ios::ChromeBrowserState* browserState =
979 chrome_test_util::GetOriginalBrowserState();
980 PrefService* preferences = browserState->GetPrefs();
981 preferences->SetBoolean(
982 password_manager::prefs::kPasswordManagerSavingEnabled,
983 originalPasswordManagerSavingEnabled);
984
985 // Restore the Clear Browsing Data checkmarks prefs to their default state.
986 preferences->SetBoolean(browsing_data::prefs::kDeleteBrowsingHistory, true);
987 preferences->SetBoolean(browsing_data::prefs::kDeleteCache, true);
988 preferences->SetBoolean(browsing_data::prefs::kDeleteCookies, true);
989 preferences->SetBoolean(browsing_data::prefs::kDeletePasswords, false);
990 preferences->SetBoolean(browsing_data::prefs::kDeleteFormData, false);
991 }];
baxley 2017/02/18 06:02:12 Is this the same as in the method above? Should we
lindsayw 2017/02/23 02:39:39 Done.
992
993 [self loadFormAndLogin];
994 [self openPasswordSettings];
995
996 // Switch on edit mode.
997 [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
998 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)]
999 performAction:grey_tap()];
1000 chrome_test_util::VerifyAccessibilityForCurrentScreen();
1001
1002 // Exit settings.
1003 [[EarlGrey
1004 selectElementWithMatcher:grey_allOf(
1005 grey_accessibilityID(@"ic_arrow_back"),
1006 grey_accessibilityTrait(
1007 UIAccessibilityTraitButton),
1008 nil)] performAction:grey_tap()];
1009
1010 [[EarlGrey
1011 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId(
1012 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
1013 performAction:grey_tap()];
1014 [self clearPasswords];
baxley 2017/02/18 06:02:12 Similar to last review, it'd be nice if we could d
lindsayw 2017/02/23 02:39:39 I was finally able to get this to work, not sure w
1015 }
1016
957 @end 1017 @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