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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/ui/settings/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/settings/password_settings_egtest.mm
diff --git a/ios/chrome/browser/ui/settings/password_settings_egtest.mm b/ios/chrome/browser/ui/settings/password_settings_egtest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..fc5941b11b7982697b671cbb950c189cc8a8099c
--- /dev/null
+++ b/ios/chrome/browser/ui/settings/password_settings_egtest.mm
@@ -0,0 +1,252 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <XCTest/XCTest.h>
+
+#import "base/mac/bind_objc_block.h"
+#include "components/strings/grit/components_strings.h"
+#import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_controller.h"
+#import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h"
+#include "ios/chrome/grit/ios_chromium_strings.h"
+#include "ios/chrome/grit/ios_strings.h"
+#include "ios/chrome/test/app/web_view_interaction_test_util.h"
+#include "ios/chrome/test/earl_grey/accessibility_util.h"
+#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
+#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
+#import "ios/chrome/test/earl_grey/chrome_matchers.h"
+#import "ios/chrome/test/earl_grey/chrome_test_case.h"
+#import "ios/web/public/test/http_server.h"
+#include "ios/web/public/test/http_server_util.h"
+#include "ui/base/l10n/l10n_util.h"
+
+using chrome_test_util::ButtonWithAccessibilityLabel;
+using chrome_test_util::ButtonWithAccessibilityLabelId;
+
+namespace {
+
+// Matcher for the clear browsing history cell on the clear browsing data panel.
+id<GREYMatcher> ClearBrowsingHistoryButton() {
+ return grey_allOf(grey_accessibilityID(kClearBrowsingHistoryCellId),
+ grey_sufficientlyVisible(), nil);
+}
+// Matcher for the clear browsing data button on the clear browsing data panel.
+id<GREYMatcher> ClearBrowsingDataButton() {
+ return ButtonWithAccessibilityLabelId(IDS_IOS_CLEAR_BUTTON);
+}
+// Matcher for the clear cookies cell on the clear browsing data panel.
+id<GREYMatcher> ClearCookiesButton() {
baxley 2017/02/14 19:42:11 High level question, it looks that a lot of these
+ return grey_accessibilityID(kClearCookiesCellId);
+}
+// Matcher for the clear cache cell on the clear browsing data panel.
+id<GREYMatcher> ClearCacheButton() {
+ return grey_allOf(grey_accessibilityID(kClearCacheCellId),
+ grey_sufficientlyVisible(), nil);
+}
+// Matcher for the clear saved passwords cell on the clear browsing data panel.
+id<GREYMatcher> ClearSavedPasswordsButton() {
+ return grey_allOf(grey_accessibilityID(kClearSavedPasswordsCellId),
+ grey_sufficientlyVisible(), nil);
+}
+
+// Matcher for the Clear Browsing Data cell on the Privacy screen.
+id<GREYMatcher> ClearBrowsingDataCell() {
+ return ButtonWithAccessibilityLabelId(IDS_IOS_CLEAR_BROWSING_DATA_TITLE);
+}
+// Matcher for the done button in the navigation bar.
+id<GREYMatcher> NavigationDoneButton() {
+ return ButtonWithAccessibilityLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
+}
+// Matcher for the saved passwords cell on the main Settings screen.
+id<GREYMatcher> PasswordsButton() {
+ return ButtonWithAccessibilityLabelId(IDS_IOS_SAVE_PASSWORDS);
+}
+
+// Matcher for the Privacy cell on the main Settings screen.
+id<GREYMatcher> PrivacyButton() {
+ return ButtonWithAccessibilityLabelId(
+ IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY);
+}
+
+// Matcher for the save button in the save password bar.
+id<GREYMatcher> savePasswordButton() {
+ return ButtonWithAccessibilityLabelId(IDS_IOS_PASSWORD_MANAGER_SAVE_BUTTON);
+}
+// Matcher for the Settings button in the tools menu.
+id<GREYMatcher> SettingsButton() {
+ return grey_accessibilityID(kToolsMenuSettingsId);
+}
+
+} // namespace
+
+// Various tests for the Password section of the settings.
+@interface PasswordSettingsTestCase : ChromeTestCase
+@end
+
+@implementation PasswordSettingsTestCase
+
+// From the NTP, clears the saved passwords via the UI.
+// TODO (crbug.com/689663): This method should be imporved to first check
+// selection status for each item.
+- (void)clearPasswords {
+ [ChromeEarlGreyUI openToolsMenu];
+ [[EarlGrey selectElementWithMatcher:SettingsButton()]
+ performAction:grey_tap()];
+ [[EarlGrey selectElementWithMatcher:PrivacyButton()]
+ performAction:grey_tap()];
+ [[EarlGrey selectElementWithMatcher:ClearBrowsingDataCell()]
+ performAction:grey_tap()];
+
baxley 2017/02/14 19:42:11 Could you add a comment as to why we have to unche
+ // "Browsing history", "Cookies, Site Data" and "Cached Images and Files"
+ // are the default checked options when the prefs are registered. Unckeck all
+ // of them and check "Passwords".
+ [[EarlGrey selectElementWithMatcher:ClearBrowsingHistoryButton()]
+ performAction:grey_tap()];
+ [[EarlGrey selectElementWithMatcher:ClearCookiesButton()]
+ performAction:grey_tap()];
+ [[EarlGrey selectElementWithMatcher:ClearCacheButton()]
+ performAction:grey_tap()];
+ [[EarlGrey selectElementWithMatcher:ClearSavedPasswordsButton()]
+ performAction:grey_tap()];
+ [self clearBrowsingData];
+
+ // Re-tap all the previously tapped cells, so that the default state of the
+ // checkmarks is preserved.
+ [[EarlGrey selectElementWithMatcher:ClearBrowsingHistoryButton()]
+ performAction:grey_tap()];
+ [[EarlGrey selectElementWithMatcher:ClearCookiesButton()]
+ performAction:grey_tap()];
+ [[EarlGrey selectElementWithMatcher:ClearCacheButton()]
+ performAction:grey_tap()];
+ [[EarlGrey selectElementWithMatcher:ClearSavedPasswordsButton()]
+ performAction:grey_tap()];
+ [self clearBrowsingData];
+
+ [self dismissSettings];
+}
+
+- (void)clearBrowsingData {
+ [[EarlGrey selectElementWithMatcher:ClearBrowsingDataButton()]
+ performAction:grey_tap()];
+
+ // There is not currently a matcher for accessibilityElementIsFocused or
+ // userInteractionEnabled which could be used here instead of checking that
+ // the button is not a MDCCollectionViewTextCell. Use when available.
+ // TODO(crbug.com/638674): Evaluate if this can move to shared code.
+ id<GREYMatcher> confirmClear = grey_allOf(
+ ClearBrowsingDataButton(),
+ grey_not(grey_kindOfClass([MDCCollectionViewTextCell class])), nil);
+ [[EarlGrey selectElementWithMatcher:confirmClear] performAction:grey_tap()];
+}
+
+// Exits Settings by clicking on the Done button.
+- (void)dismissSettings {
+ // Dismiss the settings.
+ [[EarlGrey selectElementWithMatcher:NavigationDoneButton()]
+ performAction:grey_tap()];
+
+ // Wait for UI components to finish loading.
+ [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
+}
+
+// Checks the presence (or absence) of saved passwords.
+// If |saved| is YES, it checks that there is a Saved Passwords section.
+// If |saved| is NO, it checks that there is no Saved Passwords section.
+- (void)checkIfPasswordsSaved:(BOOL)saved {
+ [ChromeEarlGreyUI openToolsMenu];
+ [[EarlGrey selectElementWithMatcher:SettingsButton()]
+ performAction:grey_tap()];
+ [[EarlGrey selectElementWithMatcher:PasswordsButton()]
+ performAction:grey_tap()];
+
+ id<GREYMatcher> visibilityMatcher =
+ saved ? grey_sufficientlyVisible() : grey_notVisible();
+ [[EarlGrey selectElementWithMatcher:
+ grey_text(l10n_util::GetNSString(
+ IDS_PASSWORD_MANAGER_SHOW_PASSWORDS_TAB_TITLE))]
+ assertWithMatcher:visibilityMatcher];
+
+ // Close the Settings.
+ [self closeSubSettingsMenu];
+}
+
+// Closes a sub-settings menu, and then the general Settings menu.
+- (void)closeSubSettingsMenu {
+ [[EarlGrey
+ selectElementWithMatcher:grey_allOf(
+ grey_accessibilityID(@"ic_arrow_back"),
+ grey_accessibilityTrait(
+ UIAccessibilityTraitButton),
+ nil)] performAction:grey_tap()];
+ [[EarlGrey
+ selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId(
+ IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
+ performAction:grey_tap()];
+}
+
+// Helper to load a page with a login and submit it.
+- (void)loadAndSubmitTheForm {
+ std::map<GURL, std::string> responses;
+ const GURL URL = web::test::HttpServer::MakeUrl("http://testClearPasswords");
+ // TODO(crbug.com/432596): There looks to be a bug where the save password
+ // infobar is not displayed if the action is about:blank.
+ responses[URL] =
+ "<form method=\"POST\" action=\"dest\">"
+ "Username:<input type=\"text\" name=\"username\" value=\"name\" /><br />"
+ "Password:<input type=\"password\""
+ "name=\"password\" value=\"pass\"/><br />"
+ "<input type=\"submit\" value=\"Login\" id=\"Login\"/>"
+ "</form>";
+ const GURL destinationURL =
+ web::test::HttpServer::MakeUrl("http://testClearPasswords/dest");
+ responses[destinationURL] = "Logged in!";
+ web::test::SetUpSimpleHttpServer(responses);
+ // Login to page and click to save password and check that its saved.
+ [ChromeEarlGrey loadURL:URL];
+ chrome_test_util::TapWebViewElementWithId("Login");
+ [[EarlGrey selectElementWithMatcher:savePasswordButton()]
+ performAction:grey_tap()];
+}
+
+// Helper to open the passwords page.
+- (void)openPasswordSettings {
+ // Open settings and verify data in the view controller.
+ [ChromeEarlGreyUI openToolsMenu];
+ [[EarlGrey
+ selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)]
+ performAction:grey_tap()];
+ [[EarlGrey selectElementWithMatcher:PasswordsButton()]
+ performAction:grey_tap()];
+}
+
+// Add a saved password and verify the edit password page is accessible.
+- (void)testAccessibilityOnPasswordEditing {
baxley 2017/02/14 19:42:11 nit: could you have all the test methods next to e
+ [self clearPasswords];
+ [self checkIfPasswordsSaved:NO];
+
+ [self loadAndSubmitTheForm];
+ [self openPasswordSettings];
+
+ // Switch on edit mode.
+ [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
+ IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)]
+ performAction:grey_tap()];
+ chrome_test_util::VerifyAccessibilityForCurrentScreen();
+
+ // Exit settings.
+ [[EarlGrey
+ selectElementWithMatcher:grey_allOf(
+ grey_accessibilityID(@"ic_arrow_back"),
+ grey_accessibilityTrait(
+ UIAccessibilityTraitButton),
+ nil)] performAction:grey_tap()];
+
+ [[EarlGrey
+ selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId(
+ IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
+ performAction:grey_tap()];
+
+ [self clearPasswords];
+}
+
+@end
« 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