| 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 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "ios/web/public/test/http_server/http_server_util.h" | 22 #include "ios/web/public/test/http_server/http_server_util.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 | 24 |
| 25 #if !defined(__has_feature) || !__has_feature(objc_arc) | 25 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 26 #error "This file requires ARC support." | 26 #error "This file requires ARC support." |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 using chrome_test_util::AssertMainTabCount; | 29 using chrome_test_util::AssertMainTabCount; |
| 30 using chrome_test_util::OmniboxText; | 30 using chrome_test_util::OmniboxText; |
| 31 using chrome_test_util::TapWebViewElementWithId; | 31 using chrome_test_util::TapWebViewElementWithId; |
| 32 using chrome_test_util::WebViewContainingText; | |
| 33 using web::test::HttpServer; | 32 using web::test::HttpServer; |
| 34 | 33 |
| 35 namespace { | 34 namespace { |
| 36 // URL of the file-based page supporting these tests. | 35 // URL of the file-based page supporting these tests. |
| 37 const char kTestURL[] = | 36 const char kTestURL[] = |
| 38 "http://ios/testing/data/http_server_files/window_open.html"; | 37 "http://ios/testing/data/http_server_files/window_open.html"; |
| 39 // Returns the text used for the blocked popup infobar when |blocked_count| | 38 // Returns the text used for the blocked popup infobar when |blocked_count| |
| 40 // popups are blocked. | 39 // popups are blocked. |
| 41 NSString* GetBlockedPopupInfobarText(size_t blocked_count) { | 40 NSString* GetBlockedPopupInfobarText(size_t blocked_count) { |
| 42 return base::SysUTF16ToNSString(l10n_util::GetStringFUTF16( | 41 return base::SysUTF16ToNSString(l10n_util::GetStringFUTF16( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 59 | 58 |
| 60 + (void)tearDown { | 59 + (void)tearDown { |
| 61 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_DEFAULT); | 60 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_DEFAULT); |
| 62 [super tearDown]; | 61 [super tearDown]; |
| 63 } | 62 } |
| 64 | 63 |
| 65 - (void)setUp { | 64 - (void)setUp { |
| 66 [super setUp]; | 65 [super setUp]; |
| 67 // Open the test page. There should only be one tab open. | 66 // Open the test page. There should only be one tab open. |
| 68 [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kTestURL)]; | 67 [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kTestURL)]; |
| 69 [[EarlGrey selectElementWithMatcher:WebViewContainingText("Expected result")] | 68 [ChromeEarlGrey waitForWebViewContainingText:"Expected result"]; |
| 70 assertWithMatcher:grey_notNil()]; | |
| 71 AssertMainTabCount(1); | 69 AssertMainTabCount(1); |
| 72 } | 70 } |
| 73 | 71 |
| 74 // Tests that opening a link with target=_blank which then immediately closes | 72 // Tests that opening a link with target=_blank which then immediately closes |
| 75 // itself works. | 73 // itself works. |
| 76 - (void)testLinkWithBlankTargetWithImmediateClose { | 74 - (void)testLinkWithBlankTargetWithImmediateClose { |
| 77 TapWebViewElementWithId("webScenarioWindowOpenBlankTargetWithImmediateClose"); | 75 TapWebViewElementWithId("webScenarioWindowOpenBlankTargetWithImmediateClose"); |
| 78 AssertMainTabCount(1); | 76 AssertMainTabCount(1); |
| 79 } | 77 } |
| 80 | 78 |
| 81 // Tests that sessionStorage content is available for windows opened by DOM via | 79 // Tests that sessionStorage content is available for windows opened by DOM via |
| 82 // target="_blank" links. | 80 // target="_blank" links. |
| 83 - (void)testLinkWithBlankTargetSessionStorage { | 81 - (void)testLinkWithBlankTargetSessionStorage { |
| 84 using chrome_test_util::ExecuteJavaScript; | 82 using chrome_test_util::ExecuteJavaScript; |
| 85 | 83 |
| 86 __unsafe_unretained NSError* error = nil; | 84 __unsafe_unretained NSError* error = nil; |
| 87 ExecuteJavaScript(@"sessionStorage.setItem('key', 'value');", &error); | 85 ExecuteJavaScript(@"sessionStorage.setItem('key', 'value');", &error); |
| 88 GREYAssert(!error, @"Error during script execution: %@", error); | 86 GREYAssert(!error, @"Error during script execution: %@", error); |
| 89 | 87 |
| 90 TapWebViewElementWithId("webScenarioWindowOpenSameURLWithBlankTarget"); | 88 TapWebViewElementWithId("webScenarioWindowOpenSameURLWithBlankTarget"); |
| 91 AssertMainTabCount(2); | 89 AssertMainTabCount(2); |
| 92 [[EarlGrey selectElementWithMatcher:WebViewContainingText("Expected result")] | 90 [ChromeEarlGrey waitForWebViewContainingText:"Expected result"]; |
| 93 assertWithMatcher:grey_notNil()]; | |
| 94 | 91 |
| 95 id value = ExecuteJavaScript(@"sessionStorage.getItem('key');", &error); | 92 id value = ExecuteJavaScript(@"sessionStorage.getItem('key');", &error); |
| 96 GREYAssert(!error, @"Error during script execution: %@", error); | 93 GREYAssert(!error, @"Error during script execution: %@", error); |
| 97 GREYAssert([value isEqual:@"value"], @"sessionStorage is not shared"); | 94 GREYAssert([value isEqual:@"value"], @"sessionStorage is not shared"); |
| 98 } | 95 } |
| 99 | 96 |
| 100 // Tests a link with target="_blank". | 97 // Tests a link with target="_blank". |
| 101 - (void)testLinkWithBlankTarget { | 98 - (void)testLinkWithBlankTarget { |
| 102 TapWebViewElementWithId("webScenarioWindowOpenRegularLink"); | 99 TapWebViewElementWithId("webScenarioWindowOpenRegularLink"); |
| 103 AssertMainTabCount(2); | 100 AssertMainTabCount(2); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 - (void)testBlockPopupInjectedIntoOpenedWindow { | 218 - (void)testBlockPopupInjectedIntoOpenedWindow { |
| 222 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_BLOCK); | 219 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_BLOCK); |
| 223 TapWebViewElementWithId("webScenarioOpenWindowAndInjectPopup"); | 220 TapWebViewElementWithId("webScenarioOpenWindowAndInjectPopup"); |
| 224 NSString* infobarText = GetBlockedPopupInfobarText(1); | 221 NSString* infobarText = GetBlockedPopupInfobarText(1); |
| 225 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(infobarText)] | 222 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(infobarText)] |
| 226 assertWithMatcher:grey_notNil()]; | 223 assertWithMatcher:grey_notNil()]; |
| 227 AssertMainTabCount(2); | 224 AssertMainTabCount(2); |
| 228 } | 225 } |
| 229 | 226 |
| 230 @end | 227 @end |
| OLD | NEW |