| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #import "ios/web/public/web_state/web_state.h" | 44 #import "ios/web/public/web_state/web_state.h" |
| 45 #include "ios/web/public/web_thread.h" | 45 #include "ios/web/public/web_thread.h" |
| 46 #include "net/ssl/channel_id_service.h" | 46 #include "net/ssl/channel_id_service.h" |
| 47 #include "net/ssl/channel_id_store.h" | 47 #include "net/ssl/channel_id_store.h" |
| 48 #include "net/url_request/url_request_context.h" | 48 #include "net/url_request/url_request_context.h" |
| 49 #include "net/url_request/url_request_context_getter.h" | 49 #include "net/url_request/url_request_context_getter.h" |
| 50 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
| 51 #include "url/gurl.h" | 51 #include "url/gurl.h" |
| 52 | 52 |
| 53 using chrome_test_util::ButtonWithAccessibilityLabelId; | 53 using chrome_test_util::ButtonWithAccessibilityLabelId; |
| 54 using chrome_test_util::NavigationBarDoneButton; |
| 54 | 55 |
| 55 namespace { | 56 namespace { |
| 56 | 57 |
| 57 const char kTestOrigin1[] = "http://host1:1/"; | 58 const char kTestOrigin1[] = "http://host1:1/"; |
| 58 | 59 |
| 59 const char kUrl[] = "http://foo/browsing"; | 60 const char kUrl[] = "http://foo/browsing"; |
| 60 const char kUrlWithSetCookie[] = "http://foo/set_cookie"; | 61 const char kUrlWithSetCookie[] = "http://foo/set_cookie"; |
| 61 const char kResponse[] = "bar"; | 62 const char kResponse[] = "bar"; |
| 62 const char kResponseWithSetCookie[] = "bar with set cookie"; | 63 const char kResponseWithSetCookie[] = "bar with set cookie"; |
| 63 const char kNoCookieText[] = "No cookies"; | 64 const char kNoCookieText[] = "No cookies"; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 92 } | 93 } |
| 93 // Matcher for the clear saved passwords cell on the clear browsing data panel. | 94 // Matcher for the clear saved passwords cell on the clear browsing data panel. |
| 94 id<GREYMatcher> ClearSavedPasswordsButton() { | 95 id<GREYMatcher> ClearSavedPasswordsButton() { |
| 95 return grey_allOf(grey_accessibilityID(kClearSavedPasswordsCellId), | 96 return grey_allOf(grey_accessibilityID(kClearSavedPasswordsCellId), |
| 96 grey_sufficientlyVisible(), nil); | 97 grey_sufficientlyVisible(), nil); |
| 97 } | 98 } |
| 98 // Matcher for the clear browsing data button on the clear browsing data panel. | 99 // Matcher for the clear browsing data button on the clear browsing data panel. |
| 99 id<GREYMatcher> ClearBrowsingDataButton() { | 100 id<GREYMatcher> ClearBrowsingDataButton() { |
| 100 return ButtonWithAccessibilityLabelId(IDS_IOS_CLEAR_BUTTON); | 101 return ButtonWithAccessibilityLabelId(IDS_IOS_CLEAR_BUTTON); |
| 101 } | 102 } |
| 102 // Matcher for the done button in the navigation bar. | |
| 103 id<GREYMatcher> NavigationDoneButton() { | |
| 104 return ButtonWithAccessibilityLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); | |
| 105 } | |
| 106 // Matcher for the Settings button in the tools menu. | 103 // Matcher for the Settings button in the tools menu. |
| 107 id<GREYMatcher> SettingsButton() { | 104 id<GREYMatcher> SettingsButton() { |
| 108 return grey_accessibilityID(kToolsMenuSettingsId); | 105 return grey_accessibilityID(kToolsMenuSettingsId); |
| 109 } | 106 } |
| 110 // Matcher for the Save Passwords cell on the main Settings screen. | 107 // Matcher for the Save Passwords cell on the main Settings screen. |
| 111 id<GREYMatcher> PasswordsButton() { | 108 id<GREYMatcher> PasswordsButton() { |
| 112 return ButtonWithAccessibilityLabelId(IDS_IOS_SAVE_PASSWORDS); | 109 return ButtonWithAccessibilityLabelId(IDS_IOS_SAVE_PASSWORDS); |
| 113 } | 110 } |
| 114 // Matcher for the Privacy cell on the main Settings screen. | 111 // Matcher for the Privacy cell on the main Settings screen. |
| 115 id<GREYMatcher> PrivacyButton() { | 112 id<GREYMatcher> PrivacyButton() { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 } | 295 } |
| 299 | 296 |
| 300 // Closes a sub-settings menu, and then the general Settings menu. | 297 // Closes a sub-settings menu, and then the general Settings menu. |
| 301 - (void)closeSubSettingsMenu { | 298 - (void)closeSubSettingsMenu { |
| 302 [[EarlGrey | 299 [[EarlGrey |
| 303 selectElementWithMatcher:grey_allOf( | 300 selectElementWithMatcher:grey_allOf( |
| 304 grey_accessibilityID(@"ic_arrow_back"), | 301 grey_accessibilityID(@"ic_arrow_back"), |
| 305 grey_accessibilityTrait( | 302 grey_accessibilityTrait( |
| 306 UIAccessibilityTraitButton), | 303 UIAccessibilityTraitButton), |
| 307 nil)] performAction:grey_tap()]; | 304 nil)] performAction:grey_tap()]; |
| 308 [[EarlGrey | 305 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 309 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId( | |
| 310 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)] | |
| 311 performAction:grey_tap()]; | 306 performAction:grey_tap()]; |
| 312 } | 307 } |
| 313 | 308 |
| 314 // Performs the steps to clear browsing data. Must be called on the | 309 // Performs the steps to clear browsing data. Must be called on the |
| 315 // Clear Browsing Data settings screen, after having selected the data types | 310 // Clear Browsing Data settings screen, after having selected the data types |
| 316 // scheduled for removal. | 311 // scheduled for removal. |
| 317 - (void)clearBrowsingData { | 312 - (void)clearBrowsingData { |
| 318 [[EarlGrey selectElementWithMatcher:ClearBrowsingDataButton()] | 313 [[EarlGrey selectElementWithMatcher:ClearBrowsingDataButton()] |
| 319 performAction:grey_tap()]; | 314 performAction:grey_tap()]; |
| 320 | 315 |
| 321 // There is not currently a matcher for accessibilityElementIsFocused or | 316 // There is not currently a matcher for accessibilityElementIsFocused or |
| 322 // userInteractionEnabled which could be used here instead of checking that | 317 // userInteractionEnabled which could be used here instead of checking that |
| 323 // the button is not a MDCCollectionViewTextCell. Use when available. | 318 // the button is not a MDCCollectionViewTextCell. Use when available. |
| 324 // TODO(crbug.com/638674): Evaluate if this can move to shared code. | 319 // TODO(crbug.com/638674): Evaluate if this can move to shared code. |
| 325 id<GREYMatcher> confirmClear = grey_allOf( | 320 id<GREYMatcher> confirmClear = grey_allOf( |
| 326 ClearBrowsingDataButton(), | 321 ClearBrowsingDataButton(), |
| 327 grey_not(grey_kindOfClass([MDCCollectionViewTextCell class])), nil); | 322 grey_not(grey_kindOfClass([MDCCollectionViewTextCell class])), nil); |
| 328 [[EarlGrey selectElementWithMatcher:confirmClear] performAction:grey_tap()]; | 323 [[EarlGrey selectElementWithMatcher:confirmClear] performAction:grey_tap()]; |
| 329 } | 324 } |
| 330 | 325 |
| 331 // Exits Settings by clicking on the Done button. | 326 // Exits Settings by clicking on the Done button. |
| 332 - (void)dismissSettings { | 327 - (void)dismissSettings { |
| 333 // Dismiss the settings. | 328 // Dismiss the settings. |
| 334 [[EarlGrey selectElementWithMatcher:NavigationDoneButton()] | 329 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 335 performAction:grey_tap()]; | 330 performAction:grey_tap()]; |
| 336 | 331 |
| 337 // Wait for UI components to finish loading. | 332 // Wait for UI components to finish loading. |
| 338 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 333 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 339 } | 334 } |
| 340 | 335 |
| 341 // From the NTP, clears the cookies and site data via the UI. | 336 // From the NTP, clears the cookies and site data via the UI. |
| 342 - (void)clearCookiesAndSiteData { | 337 - (void)clearCookiesAndSiteData { |
| 343 [ChromeEarlGreyUI openToolsMenu]; | 338 [ChromeEarlGreyUI openToolsMenu]; |
| 344 [[EarlGrey selectElementWithMatcher:SettingsButton()] | 339 [[EarlGrey selectElementWithMatcher:SettingsButton()] |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 - (void)testSettingsSignedOutIncognito { | 800 - (void)testSettingsSignedOutIncognito { |
| 806 chrome_test_util::OpenNewIncognitoTab(); | 801 chrome_test_util::OpenNewIncognitoTab(); |
| 807 | 802 |
| 808 [ChromeEarlGreyUI openToolsMenu]; | 803 [ChromeEarlGreyUI openToolsMenu]; |
| 809 [[EarlGrey selectElementWithMatcher:SettingsButton()] | 804 [[EarlGrey selectElementWithMatcher:SettingsButton()] |
| 810 performAction:grey_tap()]; | 805 performAction:grey_tap()]; |
| 811 [[EarlGrey | 806 [[EarlGrey |
| 812 selectElementWithMatcher:grey_accessibilityID(kSettingsCollectionViewId)] | 807 selectElementWithMatcher:grey_accessibilityID(kSettingsCollectionViewId)] |
| 813 assertWithMatcher:grey_notNil()]; | 808 assertWithMatcher:grey_notNil()]; |
| 814 | 809 |
| 815 [[EarlGrey selectElementWithMatcher:NavigationDoneButton()] | 810 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 816 performAction:grey_tap()]; | 811 performAction:grey_tap()]; |
| 817 chrome_test_util::CloseAllIncognitoTabs(); | 812 chrome_test_util::CloseAllIncognitoTabs(); |
| 818 } | 813 } |
| 819 | 814 |
| 820 // Verifies the UI elements are accessible on the Settings page. | 815 // Verifies the UI elements are accessible on the Settings page. |
| 821 - (void)testAccessibilityOnSettingsPage { | 816 - (void)testAccessibilityOnSettingsPage { |
| 822 [ChromeEarlGreyUI openToolsMenu]; | 817 [ChromeEarlGreyUI openToolsMenu]; |
| 823 [[EarlGrey selectElementWithMatcher:SettingsButton()] | 818 [[EarlGrey selectElementWithMatcher:SettingsButton()] |
| 824 performAction:grey_tap()]; | 819 performAction:grey_tap()]; |
| 825 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 820 chrome_test_util::VerifyAccessibilityForCurrentScreen(); |
| 826 [[EarlGrey | 821 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 827 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId( | |
| 828 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)] | |
| 829 performAction:grey_tap()]; | 822 performAction:grey_tap()]; |
| 830 } | 823 } |
| 831 | 824 |
| 832 // Verifies the UI elements are accessible on the Content Settings page. | 825 // Verifies the UI elements are accessible on the Content Settings page. |
| 833 - (void)testAccessibilityOnContentSettingsPage { | 826 - (void)testAccessibilityOnContentSettingsPage { |
| 834 [self openSubSettingMenu:chrome_test_util::ButtonWithAccessibilityLabelId( | 827 [self openSubSettingMenu:chrome_test_util::ButtonWithAccessibilityLabelId( |
| 835 IDS_IOS_CONTENT_SETTINGS_TITLE)]; | 828 IDS_IOS_CONTENT_SETTINGS_TITLE)]; |
| 836 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 829 chrome_test_util::VerifyAccessibilityForCurrentScreen(); |
| 837 [self closeSubSettingsMenu]; | 830 [self closeSubSettingsMenu]; |
| 838 } | 831 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 993 chrome_test_util::VerifyAccessibilityForCurrentScreen(); |
| 1001 | 994 |
| 1002 // Exit settings. | 995 // Exit settings. |
| 1003 [[EarlGrey | 996 [[EarlGrey |
| 1004 selectElementWithMatcher:grey_allOf( | 997 selectElementWithMatcher:grey_allOf( |
| 1005 grey_accessibilityID(@"ic_arrow_back"), | 998 grey_accessibilityID(@"ic_arrow_back"), |
| 1006 grey_accessibilityTrait( | 999 grey_accessibilityTrait( |
| 1007 UIAccessibilityTraitButton), | 1000 UIAccessibilityTraitButton), |
| 1008 nil)] performAction:grey_tap()]; | 1001 nil)] performAction:grey_tap()]; |
| 1009 | 1002 |
| 1010 [[EarlGrey | 1003 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 1011 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId( | |
| 1012 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)] | |
| 1013 performAction:grey_tap()]; | 1004 performAction:grey_tap()]; |
| 1014 } | 1005 } |
| 1015 | 1006 |
| 1016 // Verifies that the Settings UI registers keyboard commands when presented, but | 1007 // Verifies that the Settings UI registers keyboard commands when presented, but |
| 1017 // not when it itslef presents something. | 1008 // not when it itslef presents something. |
| 1018 - (void)testSettingsKeyboardCommands { | 1009 - (void)testSettingsKeyboardCommands { |
| 1019 // Open Settings. | 1010 // Open Settings. |
| 1020 [ChromeEarlGreyUI openToolsMenu]; | 1011 [ChromeEarlGreyUI openToolsMenu]; |
| 1021 [[EarlGrey selectElementWithMatcher:SettingsButton()] | 1012 [[EarlGrey selectElementWithMatcher:SettingsButton()] |
| 1022 performAction:grey_tap()]; | 1013 performAction:grey_tap()]; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 performAction:grey_tap()]; | 1055 performAction:grey_tap()]; |
| 1065 [[EarlGrey selectElementWithMatcher:PrivacyButton()] | 1056 [[EarlGrey selectElementWithMatcher:PrivacyButton()] |
| 1066 performAction:grey_tap()]; | 1057 performAction:grey_tap()]; |
| 1067 [[EarlGrey selectElementWithMatcher:SendUsageDataButton()] | 1058 [[EarlGrey selectElementWithMatcher:SendUsageDataButton()] |
| 1068 performAction:grey_tap()]; | 1059 performAction:grey_tap()]; |
| 1069 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 1060 chrome_test_util::VerifyAccessibilityForCurrentScreen(); |
| 1070 [self closeSubSettingsMenu]; | 1061 [self closeSubSettingsMenu]; |
| 1071 } | 1062 } |
| 1072 | 1063 |
| 1073 @end | 1064 @end |
| OLD | NEW |