| 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; | 22 using chrome_test_util::WebViewContainingText; |
| 23 using web::test::HttpServer; | 23 using web::test::HttpServer; |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 const char kTestURL[] = | 26 const char kTestURL[] = |
| 27 "http://ios/testing/data/http_server_files/window_open.html"; | 27 "http://ios/testing/data/http_server_files/window_open.html"; |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 // Test case for opening child windows by DOM. | 30 // Test case for opening child windows by DOM. |
| 31 @interface WindowOpenByDOMTestCase : ChromeTestCase | 31 @interface WindowOpenByDOMTestCase : ChromeTestCase |
| 32 @end | 32 @end |
| 33 | 33 |
| 34 @implementation WindowOpenByDOMTestCase | 34 @implementation WindowOpenByDOMTestCase |
| 35 | 35 |
| 36 + (void)setUp { | 36 + (void)setUp { |
| 37 [super setUp]; | 37 [super setUp]; |
| 38 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW); | 38 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW); |
| 39 web::test::SetUpFileBasedHttpServer(); | 39 web::test::SetUpFileBasedHttpServer(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 + (void)tearDown { | 42 + (void)tearDown { |
| 43 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_DEFAULT); | 43 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_DEFAULT); |
| 44 [super tearDown]; | 44 [super tearDown]; |
| 45 } | 45 } |
| 46 | 46 |
| 47 - (void)setUp { | 47 - (void)setUp { |
| 48 [super setUp]; | 48 [super setUp]; |
| 49 // Open the test page. There should only be one tab open. | 49 // Open the test page. There should only be one tab open. |
| 50 [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kTestURL)]; | 50 [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kTestURL)]; |
| 51 [[EarlGrey selectElementWithMatcher:webViewContainingText("Expected result")] | 51 [[EarlGrey selectElementWithMatcher:WebViewContainingText("Expected result")] |
| 52 assertWithMatcher:grey_notNil()]; | 52 assertWithMatcher:grey_notNil()]; |
| 53 AssertMainTabCount(1); | 53 AssertMainTabCount(1); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Tests that opening a link with target=_blank which then immediately closes | 56 // Tests that opening a link with target=_blank which then immediately closes |
| 57 // itself works. | 57 // itself works. |
| 58 - (void)testLinkWithBlankTargetWithImmediateClose { | 58 - (void)testLinkWithBlankTargetWithImmediateClose { |
| 59 TapWebViewElementWithId("webScenarioWindowOpenBlankTargetWithImmediateClose"); | 59 TapWebViewElementWithId("webScenarioWindowOpenBlankTargetWithImmediateClose"); |
| 60 AssertMainTabCount(1); | 60 AssertMainTabCount(1); |
| 61 } | 61 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 85 | 85 |
| 86 // Tests that opening a window and calling window.location.assign works. | 86 // Tests that opening a window and calling window.location.assign works. |
| 87 - (void)testWindowOpenAndCallLocationAssign { | 87 - (void)testWindowOpenAndCallLocationAssign { |
| 88 // Open a child tab. | 88 // Open a child tab. |
| 89 TapWebViewElementWithId("webScenarioWindowOpenAndCallLocationAssign"); | 89 TapWebViewElementWithId("webScenarioWindowOpenAndCallLocationAssign"); |
| 90 AssertMainTabCount(2); | 90 AssertMainTabCount(2); |
| 91 | 91 |
| 92 // Ensure that the resulting tab is updated as expected. | 92 // Ensure that the resulting tab is updated as expected. |
| 93 const GURL targetURL = | 93 const GURL targetURL = |
| 94 HttpServer::MakeUrl(std::string(kTestURL) + "#assigned"); | 94 HttpServer::MakeUrl(std::string(kTestURL) + "#assigned"); |
| 95 [[EarlGrey selectElementWithMatcher:omniboxText(targetURL.GetContent())] | 95 [[EarlGrey selectElementWithMatcher:OmniboxText(targetURL.GetContent())] |
| 96 assertWithMatcher:grey_notNil()]; | 96 assertWithMatcher:grey_notNil()]; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Tests that opening a window, reading its title, and updating its location | 99 // Tests that opening a window, reading its title, and updating its location |
| 100 // completes and causes a navigation. (Reduced test case from actual site.) | 100 // completes and causes a navigation. (Reduced test case from actual site.) |
| 101 - (void)testWindowOpenAndSetLocation { | 101 - (void)testWindowOpenAndSetLocation { |
| 102 // Open a child tab. | 102 // Open a child tab. |
| 103 TapWebViewElementWithId("webScenarioWindowOpenAndSetLocation"); | 103 TapWebViewElementWithId("webScenarioWindowOpenAndSetLocation"); |
| 104 AssertMainTabCount(2); | 104 AssertMainTabCount(2); |
| 105 | 105 |
| 106 // Ensure that the resulting tab is updated as expected. | 106 // Ensure that the resulting tab is updated as expected. |
| 107 const GURL targetURL = | 107 const GURL targetURL = |
| 108 HttpServer::MakeUrl(std::string(kTestURL) + "#updated"); | 108 HttpServer::MakeUrl(std::string(kTestURL) + "#updated"); |
| 109 [[EarlGrey selectElementWithMatcher:omniboxText(targetURL.GetContent())] | 109 [[EarlGrey selectElementWithMatcher:OmniboxText(targetURL.GetContent())] |
| 110 assertWithMatcher:grey_notNil()]; | 110 assertWithMatcher:grey_notNil()]; |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Tests a button that invokes window.open() with "_blank" target parameter. | 113 // Tests a button that invokes window.open() with "_blank" target parameter. |
| 114 - (void)testWindowOpenWithBlankTarget { | 114 - (void)testWindowOpenWithBlankTarget { |
| 115 TapWebViewElementWithId("webScenarioWindowOpenWithBlankTarget"); | 115 TapWebViewElementWithId("webScenarioWindowOpenWithBlankTarget"); |
| 116 AssertMainTabCount(2); | 116 AssertMainTabCount(2); |
| 117 } | 117 } |
| 118 | 118 |
| 119 // Tests that opening a window with target=_blank which closes itself after 1 | 119 // Tests that opening a window with target=_blank which closes itself after 1 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // Tests that a link with an onclick that opens a tab and calls preventDefault | 152 // Tests that a link with an onclick that opens a tab and calls preventDefault |
| 153 // opens the tab, but doesn't navigate the main tab. | 153 // opens the tab, but doesn't navigate the main tab. |
| 154 - (void)testWindowOpenWithPreventDefaultLink { | 154 - (void)testWindowOpenWithPreventDefaultLink { |
| 155 // Open a child tab. | 155 // Open a child tab. |
| 156 TapWebViewElementWithId("webScenarioWindowOpenWithPreventDefaultLink"); | 156 TapWebViewElementWithId("webScenarioWindowOpenWithPreventDefaultLink"); |
| 157 AssertMainTabCount(2); | 157 AssertMainTabCount(2); |
| 158 | 158 |
| 159 // Ensure that the starting tab hasn't navigated. | 159 // Ensure that the starting tab hasn't navigated. |
| 160 chrome_test_util::CloseCurrentTab(); | 160 chrome_test_util::CloseCurrentTab(); |
| 161 const GURL URL = HttpServer::MakeUrl(kTestURL); | 161 const GURL URL = HttpServer::MakeUrl(kTestURL); |
| 162 [[EarlGrey selectElementWithMatcher:omniboxText(URL.GetContent())] | 162 [[EarlGrey selectElementWithMatcher:OmniboxText(URL.GetContent())] |
| 163 assertWithMatcher:grey_notNil()]; | 163 assertWithMatcher:grey_notNil()]; |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Tests that closing the current window using DOM fails. | 166 // Tests that closing the current window using DOM fails. |
| 167 - (void)testCloseWindowNotOpenByDOM { | 167 - (void)testCloseWindowNotOpenByDOM { |
| 168 TapWebViewElementWithId("webScenarioWindowClose"); | 168 TapWebViewElementWithId("webScenarioWindowClose"); |
| 169 AssertMainTabCount(1); | 169 AssertMainTabCount(1); |
| 170 } | 170 } |
| 171 | 171 |
| 172 @end | 172 @end |
| OLD | NEW |