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

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

Issue 2642193012: Make EarlGrey matchers compliant with Chromium style. (Closed)
Patch Set: build.gn and rebase Created 3 years, 11 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
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 8
9 #include "base/ios/ios_util.h" 9 #include "base/ios/ios_util.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 const std::string kOpenedWindowResponse = "Opened window"; 46 const std::string kOpenedWindowResponse = "Opened window";
47 47
48 // Opens the block popups settings page. Must be called from the NTP. 48 // Opens the block popups settings page. Must be called from the NTP.
49 void OpenBlockPopupsSettings() { 49 void OpenBlockPopupsSettings() {
50 const CGFloat scroll_displacement = 50.0; 50 const CGFloat scroll_displacement = 50.0;
51 id<GREYMatcher> tools_menu_table_view_matcher = 51 id<GREYMatcher> tools_menu_table_view_matcher =
52 grey_accessibilityID(kToolsMenuTableViewId); 52 grey_accessibilityID(kToolsMenuTableViewId);
53 id<GREYMatcher> settings_button_matcher = 53 id<GREYMatcher> settings_button_matcher =
54 grey_accessibilityID(kToolsMenuSettingsId); 54 grey_accessibilityID(kToolsMenuSettingsId);
55 id<GREYMatcher> content_settings_button_matcher = 55 id<GREYMatcher> content_settings_button_matcher =
56 chrome_test_util::buttonWithAccessibilityLabelId( 56 chrome_test_util::ButtonWithAccessibilityLabelId(
57 IDS_IOS_CONTENT_SETTINGS_TITLE); 57 IDS_IOS_CONTENT_SETTINGS_TITLE);
58 id<GREYMatcher> settings_collection_view_matcher = 58 id<GREYMatcher> settings_collection_view_matcher =
59 grey_accessibilityID(kSettingsCollectionViewId); 59 grey_accessibilityID(kSettingsCollectionViewId);
60 id<GREYMatcher> block_popups_button_matcher = 60 id<GREYMatcher> block_popups_button_matcher =
61 chrome_test_util::buttonWithAccessibilityLabelId(IDS_IOS_BLOCK_POPUPS); 61 chrome_test_util::ButtonWithAccessibilityLabelId(IDS_IOS_BLOCK_POPUPS);
62 62
63 [ChromeEarlGreyUI openToolsMenu]; 63 [ChromeEarlGreyUI openToolsMenu];
64 [[[EarlGrey selectElementWithMatcher:settings_button_matcher] 64 [[[EarlGrey selectElementWithMatcher:settings_button_matcher]
65 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 65 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
66 scroll_displacement) 66 scroll_displacement)
67 onElementWithMatcher:tools_menu_table_view_matcher] 67 onElementWithMatcher:tools_menu_table_view_matcher]
68 performAction:grey_tap()]; 68 performAction:grey_tap()];
69 69
70 [[[EarlGrey selectElementWithMatcher:content_settings_button_matcher] 70 [[[EarlGrey selectElementWithMatcher:content_settings_button_matcher]
71 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 71 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
(...skipping 13 matching lines...) Expand all
85 grey_accessibilityTrait( 85 grey_accessibilityTrait(
86 UIAccessibilityTraitButton), 86 UIAccessibilityTraitButton),
87 nil)] performAction:grey_tap()]; 87 nil)] performAction:grey_tap()];
88 [[EarlGrey 88 [[EarlGrey
89 selectElementWithMatcher:grey_allOf( 89 selectElementWithMatcher:grey_allOf(
90 grey_accessibilityID(@"ic_arrow_back"), 90 grey_accessibilityID(@"ic_arrow_back"),
91 grey_accessibilityTrait( 91 grey_accessibilityTrait(
92 UIAccessibilityTraitButton), 92 UIAccessibilityTraitButton),
93 nil)] performAction:grey_tap()]; 93 nil)] performAction:grey_tap()];
94 [[EarlGrey 94 [[EarlGrey
95 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabelId( 95 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId(
96 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)] 96 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
97 performAction:grey_tap()]; 97 performAction:grey_tap()];
98 } 98 }
99 99
100 // ScopedBlockPopupsPref modifies the block popups preference and resets the 100 // ScopedBlockPopupsPref modifies the block popups preference and resets the
101 // preference to its original value when this object goes out of scope. 101 // preference to its original value when this object goes out of scope.
102 class ScopedBlockPopupsPref { 102 class ScopedBlockPopupsPref {
103 public: 103 public:
104 ScopedBlockPopupsPref(ContentSetting setting) { 104 ScopedBlockPopupsPref(ContentSetting setting) {
105 original_setting_ = GetPrefValue(); 105 original_setting_ = GetPrefValue();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW); 200 ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW);
201 [ChromeEarlGrey loadURL:blockPopupsURL]; 201 [ChromeEarlGrey loadURL:blockPopupsURL];
202 chrome_test_util::AssertMainTabCount(1U); 202 chrome_test_util::AssertMainTabCount(1U);
203 203
204 // Tap the "Open Window" link and make sure the popup opened in a new tab. 204 // Tap the "Open Window" link and make sure the popup opened in a new tab.
205 chrome_test_util::TapWebViewElementWithId("openWindow"); 205 chrome_test_util::TapWebViewElementWithId("openWindow");
206 chrome_test_util::AssertMainTabCount(2U); 206 chrome_test_util::AssertMainTabCount(2U);
207 207
208 // No infobar should be displayed. 208 // No infobar should be displayed.
209 [[EarlGrey selectElementWithMatcher:chrome_test_util:: 209 [[EarlGrey selectElementWithMatcher:chrome_test_util::
210 staticTextWithAccessibilityLabel( 210 StaticTextWithAccessibilityLabel(
211 @"Pop-ups blocked (1)")] 211 @"Pop-ups blocked (1)")]
212 assertWithMatcher:grey_notVisible()]; 212 assertWithMatcher:grey_notVisible()];
213 } 213 }
214 214
215 // Tests that popups are prevented from opening and an infobar is displayed when 215 // Tests that popups are prevented from opening and an infobar is displayed when
216 // the preference is set to BLOCK. 216 // the preference is set to BLOCK.
217 - (void)testPopupsBlocked { 217 - (void)testPopupsBlocked {
218 std::map<GURL, std::string> responses; 218 std::map<GURL, std::string> responses;
219 const GURL blockPopupsURL = web::test::HttpServer::MakeUrl(kBlockPopupsUrl); 219 const GURL blockPopupsURL = web::test::HttpServer::MakeUrl(kBlockPopupsUrl);
220 const GURL openedWindowURL = web::test::HttpServer::MakeUrl(kOpenedWindowUrl); 220 const GURL openedWindowURL = web::test::HttpServer::MakeUrl(kOpenedWindowUrl);
(...skipping 11 matching lines...) Expand all
232 // Tap the "Open Window" link, then make sure the popup was blocked and an 232 // Tap the "Open Window" link, then make sure the popup was blocked and an
233 // infobar was displayed. The window.open() call is run via async JS, so the 233 // infobar was displayed. The window.open() call is run via async JS, so the
234 // infobar may not open immediately. 234 // infobar may not open immediately.
235 chrome_test_util::TapWebViewElementWithId("openWindow"); 235 chrome_test_util::TapWebViewElementWithId("openWindow");
236 [[GREYCondition 236 [[GREYCondition
237 conditionWithName:@"Wait for blocked popups infobar to show" 237 conditionWithName:@"Wait for blocked popups infobar to show"
238 block:^BOOL { 238 block:^BOOL {
239 NSError* error = nil; 239 NSError* error = nil;
240 [[EarlGrey 240 [[EarlGrey
241 selectElementWithMatcher: 241 selectElementWithMatcher:
242 chrome_test_util::staticTextWithAccessibilityLabel( 242 chrome_test_util::StaticTextWithAccessibilityLabel(
243 @"Pop-ups blocked (1)")] 243 @"Pop-ups blocked (1)")]
244 assertWithMatcher:grey_sufficientlyVisible() 244 assertWithMatcher:grey_sufficientlyVisible()
245 error:&error]; 245 error:&error];
246 return error == nil; 246 return error == nil;
247 }] waitWithTimeout:4.0]; 247 }] waitWithTimeout:4.0];
248 chrome_test_util::AssertMainTabCount(1U); 248 chrome_test_util::AssertMainTabCount(1U);
249 } 249 }
250 250
251 // Tests that the "exceptions" section on the settings page is hidden and 251 // Tests that the "exceptions" section on the settings page is hidden and
252 // revealed properly when the preference switch is toggled. 252 // revealed properly when the preference switch is toggled.
253 - (void)testSettingsPageWithExceptions { 253 - (void)testSettingsPageWithExceptions {
254 std::string allowedPattern = "[*.]example.com"; 254 std::string allowedPattern = "[*.]example.com";
255 ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_BLOCK); 255 ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_BLOCK);
256 ScopedBlockPopupsException exceptionSetter(allowedPattern); 256 ScopedBlockPopupsException exceptionSetter(allowedPattern);
257 257
258 OpenBlockPopupsSettings(); 258 OpenBlockPopupsSettings();
259 259
260 // Make sure that the "example.com" exception is listed. 260 // Make sure that the "example.com" exception is listed.
261 [[EarlGrey selectElementWithMatcher:grey_text(base::SysUTF8ToNSString( 261 [[EarlGrey selectElementWithMatcher:grey_text(base::SysUTF8ToNSString(
262 allowedPattern))] 262 allowedPattern))]
263 assertWithMatcher:grey_sufficientlyVisible()]; 263 assertWithMatcher:grey_sufficientlyVisible()];
264 264
265 // Toggle the switch off via the UI and make sure the exceptions are not 265 // Toggle the switch off via the UI and make sure the exceptions are not
266 // visible. 266 // visible.
267 [[EarlGrey 267 [[EarlGrey
268 selectElementWithMatcher:chrome_test_util::collectionViewSwitchCell( 268 selectElementWithMatcher:chrome_test_util::CollectionViewSwitchCell(
269 @"blockPopupsContentView_switch", YES)] 269 @"blockPopupsContentView_switch", YES)]
270 performAction:chrome_test_util::turnCollectionViewSwitchOn(NO)]; 270 performAction:chrome_test_util::turnCollectionViewSwitchOn(NO)];
271 [[EarlGrey selectElementWithMatcher:grey_text(base::SysUTF8ToNSString( 271 [[EarlGrey selectElementWithMatcher:grey_text(base::SysUTF8ToNSString(
272 allowedPattern))] 272 allowedPattern))]
273 assertWithMatcher:grey_notVisible()]; 273 assertWithMatcher:grey_notVisible()];
274 [[EarlGrey 274 [[EarlGrey
275 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString( 275 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
276 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON))] 276 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON))]
277 assertWithMatcher:grey_notVisible()]; 277 assertWithMatcher:grey_notVisible()];
278 [[EarlGrey 278 [[EarlGrey
279 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString( 279 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
280 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON))] 280 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON))]
281 assertWithMatcher:grey_sufficientlyVisible()]; 281 assertWithMatcher:grey_sufficientlyVisible()];
282 282
283 // Toggle the switch back on via the UI and make sure the exceptions are now 283 // Toggle the switch back on via the UI and make sure the exceptions are now
284 // visible. 284 // visible.
285 [[EarlGrey 285 [[EarlGrey
286 selectElementWithMatcher:chrome_test_util::collectionViewSwitchCell( 286 selectElementWithMatcher:chrome_test_util::CollectionViewSwitchCell(
287 @"blockPopupsContentView_switch", NO)] 287 @"blockPopupsContentView_switch", NO)]
288 performAction:chrome_test_util::turnCollectionViewSwitchOn(YES)]; 288 performAction:chrome_test_util::turnCollectionViewSwitchOn(YES)];
289 [[EarlGrey selectElementWithMatcher:grey_text(base::SysUTF8ToNSString( 289 [[EarlGrey selectElementWithMatcher:grey_text(base::SysUTF8ToNSString(
290 allowedPattern))] 290 allowedPattern))]
291 assertWithMatcher:grey_sufficientlyVisible()]; 291 assertWithMatcher:grey_sufficientlyVisible()];
292 [[EarlGrey 292 [[EarlGrey
293 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString( 293 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
294 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON))] 294 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON))]
295 assertWithMatcher:grey_sufficientlyVisible()]; 295 assertWithMatcher:grey_sufficientlyVisible()];
296 296
297 CloseSettings(); 297 CloseSettings();
298 } 298 }
299 299
300 @end 300 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698