| 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 #import "base/test/ios/wait_util.h" | 7 #import "base/test/ios/wait_util.h" |
| 8 #include "components/content_settings/core/common/content_settings.h" | 8 #include "components/content_settings/core/common/content_settings.h" |
| 9 #include "ios/chrome/test/app/settings_test_util.h" | 9 #include "ios/chrome/test/app/settings_test_util.h" |
| 10 #import "ios/chrome/test/app/tab_test_util.h" | 10 #import "ios/chrome/test/app/tab_test_util.h" |
| 11 #include "ios/chrome/test/app/web_view_interaction_test_util.h" | 11 #include "ios/chrome/test/app/web_view_interaction_test_util.h" |
| 12 #import "ios/chrome/test/earl_grey/chrome_assertions.h" | 12 #import "ios/chrome/test/earl_grey/chrome_assertions.h" |
| 13 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 13 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 14 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 14 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 15 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 15 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 16 #import "ios/web/public/test/http_server.h" | 16 #import "ios/web/public/test/http_server.h" |
| 17 #include "ios/web/public/test/http_server_util.h" | 17 #include "ios/web/public/test/http_server_util.h" |
| 18 | 18 |
| 19 using chrome_test_util::AssertMainTabCount; | 19 using chrome_test_util::AssertMainTabCount; |
| 20 using chrome_test_util::OmniboxText; | 20 using chrome_test_util::OmniboxText; |
| 21 using chrome_test_util::TapWebViewElementWithId; | 21 using chrome_test_util::TapWebViewElementWithId; |
| 22 using chrome_test_util::WebViewContainingText; | |
| 23 using web::test::HttpServer; | 22 using web::test::HttpServer; |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 const char kTestURL[] = | 25 const char kTestURL[] = |
| 27 "http://ios/testing/data/http_server_files/window_open.html"; | 26 "http://ios/testing/data/http_server_files/window_open.html"; |
| 28 } // namespace | 27 } // namespace |
| 29 | 28 |
| 30 // Test case for opening child windows by DOM. | 29 // Test case for opening child windows by DOM. |
| 31 @interface WindowOpenByDOMTestCase : ChromeTestCase | 30 @interface WindowOpenByDOMTestCase : ChromeTestCase |
| 32 @end | 31 @end |
| 33 | 32 |
| 34 @implementation WindowOpenByDOMTestCase | 33 @implementation WindowOpenByDOMTestCase |
| 35 | 34 |
| 36 + (void)setUp { | 35 + (void)setUp { |
| 37 [super setUp]; | 36 [super setUp]; |
| 38 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW); | 37 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW); |
| 39 web::test::SetUpFileBasedHttpServer(); | 38 web::test::SetUpFileBasedHttpServer(); |
| 40 } | 39 } |
| 41 | 40 |
| 42 + (void)tearDown { | 41 + (void)tearDown { |
| 43 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_DEFAULT); | 42 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_DEFAULT); |
| 44 [super tearDown]; | 43 [super tearDown]; |
| 45 } | 44 } |
| 46 | 45 |
| 47 - (void)setUp { | 46 - (void)setUp { |
| 48 [super setUp]; | 47 [super setUp]; |
| 49 // Open the test page. There should only be one tab open. | 48 // Open the test page. There should only be one tab open. |
| 50 [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kTestURL)]; | 49 [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kTestURL)]; |
| 51 [[EarlGrey selectElementWithMatcher:WebViewContainingText("Expected result")] | 50 [ChromeEarlGrey waitForWebViewContainingText:@"Expected result"]; |
| 52 assertWithMatcher:grey_notNil()]; | |
| 53 AssertMainTabCount(1); | 51 AssertMainTabCount(1); |
| 54 } | 52 } |
| 55 | 53 |
| 56 // Tests that opening a link with target=_blank which then immediately closes | 54 // Tests that opening a link with target=_blank which then immediately closes |
| 57 // itself works. | 55 // itself works. |
| 58 - (void)testLinkWithBlankTargetWithImmediateClose { | 56 - (void)testLinkWithBlankTargetWithImmediateClose { |
| 59 TapWebViewElementWithId("webScenarioWindowOpenBlankTargetWithImmediateClose"); | 57 TapWebViewElementWithId("webScenarioWindowOpenBlankTargetWithImmediateClose"); |
| 60 AssertMainTabCount(1); | 58 AssertMainTabCount(1); |
| 61 } | 59 } |
| 62 | 60 |
| 63 // Tests that sessionStorage content is available for windows opened by DOM via | 61 // Tests that sessionStorage content is available for windows opened by DOM via |
| 64 // target="_blank" links. | 62 // target="_blank" links. |
| 65 - (void)testLinkWithBlankTargetSessionStorage { | 63 - (void)testLinkWithBlankTargetSessionStorage { |
| 66 using chrome_test_util::ExecuteJavaScript; | 64 using chrome_test_util::ExecuteJavaScript; |
| 67 | 65 |
| 68 NSError* error = nil; | 66 NSError* error = nil; |
| 69 ExecuteJavaScript(@"sessionStorage.setItem('key', 'value');", &error); | 67 ExecuteJavaScript(@"sessionStorage.setItem('key', 'value');", &error); |
| 70 GREYAssert(!error, @"Error during script execution: %@", error); | 68 GREYAssert(!error, @"Error during script execution: %@", error); |
| 71 | 69 |
| 72 TapWebViewElementWithId("webScenarioWindowOpenSameURLWithBlankTarget"); | 70 TapWebViewElementWithId("webScenarioWindowOpenSameURLWithBlankTarget"); |
| 73 AssertMainTabCount(2); | 71 AssertMainTabCount(2); |
| 74 [[EarlGrey selectElementWithMatcher:WebViewContainingText("Expected result")] | 72 [ChromeEarlGrey waitForWebViewContainingText:@"Expected result"]; |
| 75 assertWithMatcher:grey_notNil()]; | |
| 76 | 73 |
| 77 id value = ExecuteJavaScript(@"sessionStorage.getItem('key');", &error); | 74 id value = ExecuteJavaScript(@"sessionStorage.getItem('key');", &error); |
| 78 GREYAssert(!error, @"Error during script execution: %@", error); | 75 GREYAssert(!error, @"Error during script execution: %@", error); |
| 79 GREYAssert([value isEqual:@"value"], @"sessionStorage is not shared"); | 76 GREYAssert([value isEqual:@"value"], @"sessionStorage is not shared"); |
| 80 } | 77 } |
| 81 | 78 |
| 82 // Tests a link with target="_blank". | 79 // Tests a link with target="_blank". |
| 83 - (void)testLinkWithBlankTarget { | 80 - (void)testLinkWithBlankTarget { |
| 84 TapWebViewElementWithId("webScenarioWindowOpenRegularLink"); | 81 TapWebViewElementWithId("webScenarioWindowOpenRegularLink"); |
| 85 AssertMainTabCount(2); | 82 AssertMainTabCount(2); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 assertWithMatcher:grey_notNil()]; | 179 assertWithMatcher:grey_notNil()]; |
| 183 } | 180 } |
| 184 | 181 |
| 185 // Tests that closing the current window using DOM fails. | 182 // Tests that closing the current window using DOM fails. |
| 186 - (void)testCloseWindowNotOpenByDOM { | 183 - (void)testCloseWindowNotOpenByDOM { |
| 187 TapWebViewElementWithId("webScenarioWindowClose"); | 184 TapWebViewElementWithId("webScenarioWindowClose"); |
| 188 AssertMainTabCount(1); | 185 AssertMainTabCount(1); |
| 189 } | 186 } |
| 190 | 187 |
| 191 @end | 188 @end |
| OLD | NEW |