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

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

Issue 2661473004: Adding a11y test coverage for passwords edit page. (Closed)
Patch Set: Added a todo 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 | « ios/chrome/browser/ui/settings/BUILD.gn ('k') | 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import <XCTest/XCTest.h>
6
7 #import "base/mac/bind_objc_block.h"
8 #include "components/strings/grit/components_strings.h"
9 #import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_cont roller.h"
10 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h"
11 #include "ios/chrome/grit/ios_chromium_strings.h"
12 #include "ios/chrome/grit/ios_strings.h"
13 #include "ios/chrome/test/app/web_view_interaction_test_util.h"
14 #include "ios/chrome/test/earl_grey/accessibility_util.h"
15 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
16 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
17 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
18 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
19 #import "ios/web/public/test/http_server.h"
20 #include "ios/web/public/test/http_server_util.h"
21 #include "ui/base/l10n/l10n_util.h"
22
23 using chrome_test_util::ButtonWithAccessibilityLabel;
24 using chrome_test_util::ButtonWithAccessibilityLabelId;
25
26 namespace {
27
28 // Matcher for the clear browsing history cell on the clear browsing data panel.
29 id<GREYMatcher> ClearBrowsingHistoryButton() {
30 return grey_allOf(grey_accessibilityID(kClearBrowsingHistoryCellId),
31 grey_sufficientlyVisible(), nil);
32 }
33 // Matcher for the clear browsing data button on the clear browsing data panel.
34 id<GREYMatcher> ClearBrowsingDataButton() {
35 return ButtonWithAccessibilityLabelId(IDS_IOS_CLEAR_BUTTON);
36 }
37 // Matcher for the clear cookies cell on the clear browsing data panel.
38 id<GREYMatcher> ClearCookiesButton() {
baxley 2017/02/14 19:42:11 High level question, it looks that a lot of these
39 return grey_accessibilityID(kClearCookiesCellId);
40 }
41 // Matcher for the clear cache cell on the clear browsing data panel.
42 id<GREYMatcher> ClearCacheButton() {
43 return grey_allOf(grey_accessibilityID(kClearCacheCellId),
44 grey_sufficientlyVisible(), nil);
45 }
46 // Matcher for the clear saved passwords cell on the clear browsing data panel.
47 id<GREYMatcher> ClearSavedPasswordsButton() {
48 return grey_allOf(grey_accessibilityID(kClearSavedPasswordsCellId),
49 grey_sufficientlyVisible(), nil);
50 }
51
52 // Matcher for the Clear Browsing Data cell on the Privacy screen.
53 id<GREYMatcher> ClearBrowsingDataCell() {
54 return ButtonWithAccessibilityLabelId(IDS_IOS_CLEAR_BROWSING_DATA_TITLE);
55 }
56 // Matcher for the done button in the navigation bar.
57 id<GREYMatcher> NavigationDoneButton() {
58 return ButtonWithAccessibilityLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
59 }
60 // Matcher for the saved passwords cell on the main Settings screen.
61 id<GREYMatcher> PasswordsButton() {
62 return ButtonWithAccessibilityLabelId(IDS_IOS_SAVE_PASSWORDS);
63 }
64
65 // Matcher for the Privacy cell on the main Settings screen.
66 id<GREYMatcher> PrivacyButton() {
67 return ButtonWithAccessibilityLabelId(
68 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY);
69 }
70
71 // Matcher for the save button in the save password bar.
72 id<GREYMatcher> savePasswordButton() {
73 return ButtonWithAccessibilityLabelId(IDS_IOS_PASSWORD_MANAGER_SAVE_BUTTON);
74 }
75 // Matcher for the Settings button in the tools menu.
76 id<GREYMatcher> SettingsButton() {
77 return grey_accessibilityID(kToolsMenuSettingsId);
78 }
79
80 } // namespace
81
82 // Various tests for the Password section of the settings.
83 @interface PasswordSettingsTestCase : ChromeTestCase
84 @end
85
86 @implementation PasswordSettingsTestCase
87
88 // From the NTP, clears the saved passwords via the UI.
89 // TODO (crbug.com/689663): This method should be imporved to first check
90 // selection status for each item.
91 - (void)clearPasswords {
92 [ChromeEarlGreyUI openToolsMenu];
93 [[EarlGrey selectElementWithMatcher:SettingsButton()]
94 performAction:grey_tap()];
95 [[EarlGrey selectElementWithMatcher:PrivacyButton()]
96 performAction:grey_tap()];
97 [[EarlGrey selectElementWithMatcher:ClearBrowsingDataCell()]
98 performAction:grey_tap()];
99
baxley 2017/02/14 19:42:11 Could you add a comment as to why we have to unche
100 // "Browsing history", "Cookies, Site Data" and "Cached Images and Files"
101 // are the default checked options when the prefs are registered. Unckeck all
102 // of them and check "Passwords".
103 [[EarlGrey selectElementWithMatcher:ClearBrowsingHistoryButton()]
104 performAction:grey_tap()];
105 [[EarlGrey selectElementWithMatcher:ClearCookiesButton()]
106 performAction:grey_tap()];
107 [[EarlGrey selectElementWithMatcher:ClearCacheButton()]
108 performAction:grey_tap()];
109 [[EarlGrey selectElementWithMatcher:ClearSavedPasswordsButton()]
110 performAction:grey_tap()];
111 [self clearBrowsingData];
112
113 // Re-tap all the previously tapped cells, so that the default state of the
114 // checkmarks is preserved.
115 [[EarlGrey selectElementWithMatcher:ClearBrowsingHistoryButton()]
116 performAction:grey_tap()];
117 [[EarlGrey selectElementWithMatcher:ClearCookiesButton()]
118 performAction:grey_tap()];
119 [[EarlGrey selectElementWithMatcher:ClearCacheButton()]
120 performAction:grey_tap()];
121 [[EarlGrey selectElementWithMatcher:ClearSavedPasswordsButton()]
122 performAction:grey_tap()];
123 [self clearBrowsingData];
124
125 [self dismissSettings];
126 }
127
128 - (void)clearBrowsingData {
129 [[EarlGrey selectElementWithMatcher:ClearBrowsingDataButton()]
130 performAction:grey_tap()];
131
132 // There is not currently a matcher for accessibilityElementIsFocused or
133 // userInteractionEnabled which could be used here instead of checking that
134 // the button is not a MDCCollectionViewTextCell. Use when available.
135 // TODO(crbug.com/638674): Evaluate if this can move to shared code.
136 id<GREYMatcher> confirmClear = grey_allOf(
137 ClearBrowsingDataButton(),
138 grey_not(grey_kindOfClass([MDCCollectionViewTextCell class])), nil);
139 [[EarlGrey selectElementWithMatcher:confirmClear] performAction:grey_tap()];
140 }
141
142 // Exits Settings by clicking on the Done button.
143 - (void)dismissSettings {
144 // Dismiss the settings.
145 [[EarlGrey selectElementWithMatcher:NavigationDoneButton()]
146 performAction:grey_tap()];
147
148 // Wait for UI components to finish loading.
149 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
150 }
151
152 // Checks the presence (or absence) of saved passwords.
153 // If |saved| is YES, it checks that there is a Saved Passwords section.
154 // If |saved| is NO, it checks that there is no Saved Passwords section.
155 - (void)checkIfPasswordsSaved:(BOOL)saved {
156 [ChromeEarlGreyUI openToolsMenu];
157 [[EarlGrey selectElementWithMatcher:SettingsButton()]
158 performAction:grey_tap()];
159 [[EarlGrey selectElementWithMatcher:PasswordsButton()]
160 performAction:grey_tap()];
161
162 id<GREYMatcher> visibilityMatcher =
163 saved ? grey_sufficientlyVisible() : grey_notVisible();
164 [[EarlGrey selectElementWithMatcher:
165 grey_text(l10n_util::GetNSString(
166 IDS_PASSWORD_MANAGER_SHOW_PASSWORDS_TAB_TITLE))]
167 assertWithMatcher:visibilityMatcher];
168
169 // Close the Settings.
170 [self closeSubSettingsMenu];
171 }
172
173 // Closes a sub-settings menu, and then the general Settings menu.
174 - (void)closeSubSettingsMenu {
175 [[EarlGrey
176 selectElementWithMatcher:grey_allOf(
177 grey_accessibilityID(@"ic_arrow_back"),
178 grey_accessibilityTrait(
179 UIAccessibilityTraitButton),
180 nil)] performAction:grey_tap()];
181 [[EarlGrey
182 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId(
183 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
184 performAction:grey_tap()];
185 }
186
187 // Helper to load a page with a login and submit it.
188 - (void)loadAndSubmitTheForm {
189 std::map<GURL, std::string> responses;
190 const GURL URL = web::test::HttpServer::MakeUrl("http://testClearPasswords");
191 // TODO(crbug.com/432596): There looks to be a bug where the save password
192 // infobar is not displayed if the action is about:blank.
193 responses[URL] =
194 "<form method=\"POST\" action=\"dest\">"
195 "Username:<input type=\"text\" name=\"username\" value=\"name\" /><br />"
196 "Password:<input type=\"password\""
197 "name=\"password\" value=\"pass\"/><br />"
198 "<input type=\"submit\" value=\"Login\" id=\"Login\"/>"
199 "</form>";
200 const GURL destinationURL =
201 web::test::HttpServer::MakeUrl("http://testClearPasswords/dest");
202 responses[destinationURL] = "Logged in!";
203 web::test::SetUpSimpleHttpServer(responses);
204 // Login to page and click to save password and check that its saved.
205 [ChromeEarlGrey loadURL:URL];
206 chrome_test_util::TapWebViewElementWithId("Login");
207 [[EarlGrey selectElementWithMatcher:savePasswordButton()]
208 performAction:grey_tap()];
209 }
210
211 // Helper to open the passwords page.
212 - (void)openPasswordSettings {
213 // Open settings and verify data in the view controller.
214 [ChromeEarlGreyUI openToolsMenu];
215 [[EarlGrey
216 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)]
217 performAction:grey_tap()];
218 [[EarlGrey selectElementWithMatcher:PasswordsButton()]
219 performAction:grey_tap()];
220 }
221
222 // Add a saved password and verify the edit password page is accessible.
223 - (void)testAccessibilityOnPasswordEditing {
baxley 2017/02/14 19:42:11 nit: could you have all the test methods next to e
224 [self clearPasswords];
225 [self checkIfPasswordsSaved:NO];
226
227 [self loadAndSubmitTheForm];
228 [self openPasswordSettings];
229
230 // Switch on edit mode.
231 [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
232 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)]
233 performAction:grey_tap()];
234 chrome_test_util::VerifyAccessibilityForCurrentScreen();
235
236 // Exit settings.
237 [[EarlGrey
238 selectElementWithMatcher:grey_allOf(
239 grey_accessibilityID(@"ic_arrow_back"),
240 grey_accessibilityTrait(
241 UIAccessibilityTraitButton),
242 nil)] performAction:grey_tap()];
243
244 [[EarlGrey
245 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId(
246 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
247 performAction:grey_tap()];
248
249 [self clearPasswords];
250 }
251
252 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/settings/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698