| 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 | 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 13 matching lines...) Expand all Loading... |
| 24 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 24 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 25 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | 25 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" |
| 26 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 26 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 27 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 27 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 28 #import "ios/web/public/test/http_server.h" | 28 #import "ios/web/public/test/http_server.h" |
| 29 #include "ios/web/public/test/http_server_util.h" | 29 #include "ios/web/public/test/http_server_util.h" |
| 30 #import "ios/web/public/test/web_view_interaction_test_util.h" | 30 #import "ios/web/public/test/web_view_interaction_test_util.h" |
| 31 #include "ui/base/l10n/l10n_util_mac.h" | 31 #include "ui/base/l10n/l10n_util_mac.h" |
| 32 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 33 | 33 |
| 34 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 35 #error "This file requires ARC support." |
| 36 #endif |
| 37 |
| 34 using chrome_test_util::NavigationBarDoneButton; | 38 using chrome_test_util::NavigationBarDoneButton; |
| 35 | 39 |
| 36 namespace { | 40 namespace { |
| 37 | 41 |
| 38 // URLs used in the tests. | 42 // URLs used in the tests. |
| 39 const char* kBlockPopupsUrl = "http://blockpopups"; | 43 const char* kBlockPopupsUrl = "http://blockpopups"; |
| 40 const char* kOpenedWindowUrl = "http://openedwindow"; | 44 const char* kOpenedWindowUrl = "http://openedwindow"; |
| 41 | 45 |
| 42 // Page with a button that opens a new window after a short delay. | 46 // Page with a button that opens a new window after a short delay. |
| 43 NSString* kBlockPopupsResponseTemplate = | 47 NSString* kBlockPopupsResponseTemplate = |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 responses[blockPopupsURL] = base::SysNSStringToUTF8([NSString | 201 responses[blockPopupsURL] = base::SysNSStringToUTF8([NSString |
| 198 stringWithFormat:kBlockPopupsResponseTemplate, openedWindowURLString]); | 202 stringWithFormat:kBlockPopupsResponseTemplate, openedWindowURLString]); |
| 199 responses[openedWindowURL] = kOpenedWindowResponse; | 203 responses[openedWindowURL] = kOpenedWindowResponse; |
| 200 web::test::SetUpSimpleHttpServer(responses); | 204 web::test::SetUpSimpleHttpServer(responses); |
| 201 | 205 |
| 202 ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW); | 206 ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW); |
| 203 [ChromeEarlGrey loadURL:blockPopupsURL]; | 207 [ChromeEarlGrey loadURL:blockPopupsURL]; |
| 204 chrome_test_util::AssertMainTabCount(1U); | 208 chrome_test_util::AssertMainTabCount(1U); |
| 205 | 209 |
| 206 // Request popup and make sure the popup opened in a new tab. | 210 // Request popup and make sure the popup opened in a new tab. |
| 207 NSError* error = nil; | 211 __unsafe_unretained NSError* error = nil; |
| 208 chrome_test_util::ExecuteJavaScript(kOpenPopupScript, &error); | 212 chrome_test_util::ExecuteJavaScript(kOpenPopupScript, &error); |
| 209 GREYAssert(!error, @"Error during script execution: %@", error); | 213 GREYAssert(!error, @"Error during script execution: %@", error); |
| 210 chrome_test_util::AssertMainTabCount(2U); | 214 chrome_test_util::AssertMainTabCount(2U); |
| 211 | 215 |
| 212 // No infobar should be displayed. | 216 // No infobar should be displayed. |
| 213 [[EarlGrey selectElementWithMatcher:chrome_test_util:: | 217 [[EarlGrey selectElementWithMatcher:chrome_test_util:: |
| 214 StaticTextWithAccessibilityLabel( | 218 StaticTextWithAccessibilityLabel( |
| 215 @"Pop-ups blocked (1)")] | 219 @"Pop-ups blocked (1)")] |
| 216 assertWithMatcher:grey_notVisible()]; | 220 assertWithMatcher:grey_notVisible()]; |
| 217 } | 221 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 229 responses[openedWindowURL] = kOpenedWindowResponse; | 233 responses[openedWindowURL] = kOpenedWindowResponse; |
| 230 web::test::SetUpSimpleHttpServer(responses); | 234 web::test::SetUpSimpleHttpServer(responses); |
| 231 | 235 |
| 232 ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_BLOCK); | 236 ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_BLOCK); |
| 233 [ChromeEarlGrey loadURL:blockPopupsURL]; | 237 [ChromeEarlGrey loadURL:blockPopupsURL]; |
| 234 chrome_test_util::AssertMainTabCount(1U); | 238 chrome_test_util::AssertMainTabCount(1U); |
| 235 | 239 |
| 236 // Request popup, then make sure it was blocked and an infobar was displayed. | 240 // Request popup, then make sure it was blocked and an infobar was displayed. |
| 237 // The window.open() call is run via async JS, so the infobar may not open | 241 // The window.open() call is run via async JS, so the infobar may not open |
| 238 // immediately. | 242 // immediately. |
| 239 NSError* error = nil; | 243 __unsafe_unretained NSError* error = nil; |
| 240 chrome_test_util::ExecuteJavaScript(kOpenPopupScript, &error); | 244 chrome_test_util::ExecuteJavaScript(kOpenPopupScript, &error); |
| 241 GREYAssert(!error, @"Error during script execution: %@", error); | 245 GREYAssert(!error, @"Error during script execution: %@", error); |
| 242 | 246 |
| 243 [[GREYCondition | 247 [[GREYCondition |
| 244 conditionWithName:@"Wait for blocked popups infobar to show" | 248 conditionWithName:@"Wait for blocked popups infobar to show" |
| 245 block:^BOOL { | 249 block:^BOOL { |
| 246 NSError* error = nil; | 250 NSError* error = nil; |
| 247 [[EarlGrey | 251 [[EarlGrey |
| 248 selectElementWithMatcher: | 252 selectElementWithMatcher: |
| 249 chrome_test_util::StaticTextWithAccessibilityLabel( | 253 chrome_test_util::StaticTextWithAccessibilityLabel( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 assertWithMatcher:grey_sufficientlyVisible()]; | 300 assertWithMatcher:grey_sufficientlyVisible()]; |
| 297 [[EarlGrey | 301 [[EarlGrey |
| 298 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString( | 302 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString( |
| 299 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON))] | 303 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON))] |
| 300 assertWithMatcher:grey_sufficientlyVisible()]; | 304 assertWithMatcher:grey_sufficientlyVisible()]; |
| 301 | 305 |
| 302 CloseSettings(); | 306 CloseSettings(); |
| 303 } | 307 } |
| 304 | 308 |
| 305 @end | 309 @end |
| OLD | NEW |