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

Side by Side Diff: ios/chrome/browser/web/window_open_by_dom_egtest.mm

Issue 2580333003: Upstream Chrome on iOS source code [10/11]. (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import <EarlGrey/EarlGrey.h>
6
7 #import "base/test/ios/wait_util.h"
8 #include "components/content_settings/core/common/content_settings.h"
9 #include "ios/chrome/test/app/settings_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"
12 #import "ios/chrome/test/earl_grey/chrome_assertions.h"
13 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
14 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
15 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
16 #import "ios/web/public/test/http_server.h"
17 #include "ios/web/public/test/http_server_util.h"
18
19 using chrome_test_util::AssertMainTabCount;
20 using chrome_test_util::omniboxText;
21 using chrome_test_util::TapWebViewElementWithId;
22 using chrome_test_util::webViewContainingText;
23 using web::test::HttpServer;
24
25 namespace {
26 const char kTestURL[] =
27 "http://ios/testing/data/http_server_files/window_open.html";
28 } // namespace
29
30 // Test case for opening child windows by DOM.
31 @interface WindowOpenByDOMTestCase : ChromeTestCase
32 @end
33
34 @implementation WindowOpenByDOMTestCase
35
36 + (void)setUp {
37 [super setUp];
38 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW);
39 web::test::SetUpFileBasedHttpServer();
40 }
41
42 + (void)tearDown {
43 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_DEFAULT);
44 [super tearDown];
45 }
46
47 - (void)setUp {
48 [super setUp];
49 // Open the test page. There should only be one tab open.
50 [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kTestURL)];
51 [[EarlGrey selectElementWithMatcher:webViewContainingText("Expected result")]
52 assertWithMatcher:grey_notNil()];
53 AssertMainTabCount(1);
54 }
55
56 // Tests that opening a link with target=_blank which then immediately closes
57 // itself works.
58 - (void)testLinkWithBlankTargetWithImmediateClose {
59 TapWebViewElementWithId("webScenarioWindowOpenBlankTargetWithImmediateClose");
60 AssertMainTabCount(1);
61 }
62
63 // Tests a link with target="_blank".
64 - (void)testLinkWithBlankTarget {
65 TapWebViewElementWithId("webScenarioWindowOpenRegularLink");
66 AssertMainTabCount(2);
67 }
68
69 // Tests a link with target="_blank" multiple times.
70 - (void)testLinkWithBlankTargetMultipleTimes {
71 TapWebViewElementWithId("webScenarioWindowOpenRegularLinkMultipleTimes");
72 AssertMainTabCount(2);
73 chrome_test_util::OpenNewTab();
74 AssertMainTabCount(3);
75 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
76 TapWebViewElementWithId("webScenarioWindowOpenRegularLinkMultipleTimes");
77 AssertMainTabCount(4);
78 }
79
80 // Tests a window.open by assigning to window.location.
81 - (void)testWindowOpenAndAssignToHref {
82 TapWebViewElementWithId("webScenarioWindowOpenTabWithAssignmentToHref");
83 AssertMainTabCount(2);
84 }
85
86 // Tests that opening a window and calling window.location.assign works.
87 - (void)testWindowOpenAndCallLocationAssign {
88 // Open a child tab.
89 TapWebViewElementWithId("webScenarioWindowOpenAndCallLocationAssign");
90 AssertMainTabCount(2);
91
92 // Ensure that the resulting tab is updated as expected.
93 const GURL targetURL =
94 HttpServer::MakeUrl(std::string(kTestURL) + "#assigned");
95 [[EarlGrey selectElementWithMatcher:omniboxText(targetURL.GetContent())]
96 assertWithMatcher:grey_notNil()];
97 }
98
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.)
101 - (void)testWindowOpenAndSetLocation {
102 // Open a child tab.
103 TapWebViewElementWithId("webScenarioWindowOpenAndSetLocation");
104 AssertMainTabCount(2);
105
106 // Ensure that the resulting tab is updated as expected.
107 const GURL targetURL =
108 HttpServer::MakeUrl(std::string(kTestURL) + "#updated");
109 [[EarlGrey selectElementWithMatcher:omniboxText(targetURL.GetContent())]
110 assertWithMatcher:grey_notNil()];
111 }
112
113 // Tests a button that invokes window.open() with "_blank" target parameter.
114 - (void)testWindowOpenWithBlankTarget {
115 TapWebViewElementWithId("webScenarioWindowOpenWithBlankTarget");
116 AssertMainTabCount(2);
117 }
118
119 // Tests that opening a window with target=_blank which closes itself after 1
120 // second delay.
121 - (void)testLinkWithBlankTargetWithDelayedClose {
122 TapWebViewElementWithId("webScenarioWindowOpenWithDelayedClose");
123 AssertMainTabCount(2);
124 base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(1));
125 AssertMainTabCount(1);
126 }
127
128 // Tests a window.open used in a <button onClick> element.
129 - (void)testWindowOpenWithButtonOnClick {
130 TapWebViewElementWithId("webScenarioWindowOpenWithButtonOnClick");
131 AssertMainTabCount(2);
132 }
133
134 // Tests a button that invokes window.open with an empty target parameter.
135 - (void)testWindowOpenWithEmptyTarget {
136 TapWebViewElementWithId("webScenarioWindowOpenWithEmptyTarget");
137 AssertMainTabCount(2);
138 }
139
140 // Tests a link with JavaScript in the href.
141 + (void)testWindowOpenWithJavaScriptInHref {
142 TapWebViewElementWithId("webScenarioWindowOpenWithJavaScriptInHref");
143 AssertMainTabCount(2);
144 }
145
146 // Tests a window.open by running Meta-Refresh.
147 - (void)testWindowOpenWithMetaRefresh {
148 TapWebViewElementWithId("webScenarioWindowOpenWithMetaRefresh");
149 AssertMainTabCount(2);
150 }
151
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.
154 - (void)testWindowOpenWithPreventDefaultLink {
155 // Open a child tab.
156 TapWebViewElementWithId("webScenarioWindowOpenWithPreventDefaultLink");
157 AssertMainTabCount(2);
158
159 // Ensure that the starting tab hasn't navigated.
160 chrome_test_util::CloseCurrentTab();
161 const GURL URL = HttpServer::MakeUrl(kTestURL);
162 [[EarlGrey selectElementWithMatcher:omniboxText(URL.GetContent())]
163 assertWithMatcher:grey_notNil()];
164 }
165
166 // Tests that closing the current window using DOM fails.
167 - (void)testCloseWindowNotOpenByDOM {
168 TapWebViewElementWithId("webScenarioWindowClose");
169 AssertMainTabCount(1);
170 }
171
172 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/web_mediator+internal.h ('k') | ios/chrome/test/app/bookmarks_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698