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

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

Issue 2642193012: Make EarlGrey matchers compliant with Chromium style. (Closed)
Patch Set: build.gn and rebase Created 3 years, 10 months 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
« no previous file with comments | « ios/chrome/browser/web/cache_egtest.mm ('k') | ios/chrome/browser/web/forms_egtest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ios/ios_util.h" 7 #include "base/ios/ios_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::TapWebViewElementWithId; 20 using chrome_test_util::TapWebViewElementWithId;
21 using chrome_test_util::webViewContainingText; 21 using chrome_test_util::WebViewContainingText;
22 using web::test::HttpServer; 22 using web::test::HttpServer;
23 23
24 namespace { 24 namespace {
25 // Test link text and ids. 25 // Test link text and ids.
26 const char kNamedWindowLink[] = "openWindowWithName"; 26 const char kNamedWindowLink[] = "openWindowWithName";
27 const char kUnnamedWindowLink[] = "openWindowNoName"; 27 const char kUnnamedWindowLink[] = "openWindowNoName";
28 28
29 // Web view text that indicates window's closed state. 29 // Web view text that indicates window's closed state.
30 const char kWindow2NeverOpen[] = "window2.closed: never opened"; 30 const char kWindow2NeverOpen[] = "window2.closed: never opened";
31 const char kWindow1Open[] = "window1.closed: false"; 31 const char kWindow1Open[] = "window1.closed: false";
(...skipping 19 matching lines...) Expand all
51 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_DEFAULT); 51 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_DEFAULT);
52 [super tearDown]; 52 [super tearDown];
53 } 53 }
54 54
55 - (void)setUp { 55 - (void)setUp {
56 [super setUp]; 56 [super setUp];
57 // Open the test page. There should only be one tab open. 57 // Open the test page. There should only be one tab open.
58 const char kChildWindowTestURL[] = 58 const char kChildWindowTestURL[] =
59 "http://ios/testing/data/http_server_files/window_proxy.html"; 59 "http://ios/testing/data/http_server_files/window_proxy.html";
60 [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kChildWindowTestURL)]; 60 [ChromeEarlGrey loadURL:HttpServer::MakeUrl(kChildWindowTestURL)];
61 [[EarlGrey selectElementWithMatcher:webViewContainingText(kNamedWindowLink)] 61 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kNamedWindowLink)]
62 assertWithMatcher:grey_notNil()]; 62 assertWithMatcher:grey_notNil()];
63 AssertMainTabCount(1); 63 AssertMainTabCount(1);
64 } 64 }
65 65
66 // Tests that multiple calls to window.open() with the same window name returns 66 // Tests that multiple calls to window.open() with the same window name returns
67 // the same window object. 67 // the same window object.
68 - (void)test2ChildWindowsWithName { 68 - (void)test2ChildWindowsWithName {
69 // Open two windows with the same name. 69 // Open two windows with the same name.
70 TapWebViewElementWithId(kNamedWindowLink); 70 TapWebViewElementWithId(kNamedWindowLink);
71 AssertMainTabCount(2); 71 AssertMainTabCount(2);
72 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 72 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
73 73
74 TapWebViewElementWithId(kNamedWindowLink); 74 TapWebViewElementWithId(kNamedWindowLink);
75 AssertMainTabCount(2); 75 AssertMainTabCount(2);
76 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 76 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
77 77
78 // Check that they're the same window. 78 // Check that they're the same window.
79 TapWebViewElementWithId("compareNamedWindows"); 79 TapWebViewElementWithId("compareNamedWindows");
80 const char kWindowsEqualText[] = "named windows equal: true"; 80 const char kWindowsEqualText[] = "named windows equal: true";
81 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindowsEqualText)] 81 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindowsEqualText)]
82 assertWithMatcher:grey_notNil()]; 82 assertWithMatcher:grey_notNil()];
83 } 83 }
84 84
85 // Tests that multiple calls to window.open() with no window name passed in 85 // Tests that multiple calls to window.open() with no window name passed in
86 // returns a unique window object each time. 86 // returns a unique window object each time.
87 - (void)test2ChildWindowsWithoutName { 87 - (void)test2ChildWindowsWithoutName {
88 // Open two unnamed windows. 88 // Open two unnamed windows.
89 TapWebViewElementWithId(kUnnamedWindowLink); 89 TapWebViewElementWithId(kUnnamedWindowLink);
90 AssertMainTabCount(2); 90 AssertMainTabCount(2);
91 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 91 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
92 92
93 TapWebViewElementWithId(kUnnamedWindowLink); 93 TapWebViewElementWithId(kUnnamedWindowLink);
94 AssertMainTabCount(3); 94 AssertMainTabCount(3);
95 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 95 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
96 96
97 // Check that they aren't the same window object. 97 // Check that they aren't the same window object.
98 TapWebViewElementWithId("compareUnnamedWindows"); 98 TapWebViewElementWithId("compareUnnamedWindows");
99 const char kWindowsEqualText[] = "unnamed windows equal: false"; 99 const char kWindowsEqualText[] = "unnamed windows equal: false";
100 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindowsEqualText)] 100 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindowsEqualText)]
101 assertWithMatcher:grey_notNil()]; 101 assertWithMatcher:grey_notNil()];
102 } 102 }
103 103
104 // Tests that calling window.open() with a name returns a different window 104 // Tests that calling window.open() with a name returns a different window
105 // object than a subsequent call to window.open() without a name. 105 // object than a subsequent call to window.open() without a name.
106 - (void)testChildWindowsWithAndWithoutName { 106 - (void)testChildWindowsWithAndWithoutName {
107 // Open a named window. 107 // Open a named window.
108 TapWebViewElementWithId(kNamedWindowLink); 108 TapWebViewElementWithId(kNamedWindowLink);
109 AssertMainTabCount(2); 109 AssertMainTabCount(2);
110 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 110 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
111 111
112 // Open an unnamed window. 112 // Open an unnamed window.
113 TapWebViewElementWithId(kUnnamedWindowLink); 113 TapWebViewElementWithId(kUnnamedWindowLink);
114 AssertMainTabCount(3); 114 AssertMainTabCount(3);
115 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 115 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
116 116
117 // Check that they aren't the same window object. 117 // Check that they aren't the same window object.
118 TapWebViewElementWithId("compareNamedAndUnnamedWindows"); 118 TapWebViewElementWithId("compareNamedAndUnnamedWindows");
119 const char kWindowsEqualText[] = "named and unnamed equal: false"; 119 const char kWindowsEqualText[] = "named and unnamed equal: false";
120 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindowsEqualText)] 120 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindowsEqualText)]
121 assertWithMatcher:grey_notNil()]; 121 assertWithMatcher:grey_notNil()];
122 } 122 }
123 123
124 // Tests that window.closed is correctly set to true when the corresponding tab 124 // Tests that window.closed is correctly set to true when the corresponding tab
125 // is closed. Verifies that calling window.open() multiple times with the same 125 // is closed. Verifies that calling window.open() multiple times with the same
126 // name returns the same window object, and thus closing the corresponding tab 126 // name returns the same window object, and thus closing the corresponding tab
127 // results in window.closed being set to true for all references to the window 127 // results in window.closed being set to true for all references to the window
128 // object for that tab. 128 // object for that tab.
129 - (void)testWindowClosedWithName { 129 - (void)testWindowClosedWithName {
130 TapWebViewElementWithId("openWindowWithName"); 130 TapWebViewElementWithId("openWindowWithName");
131 AssertMainTabCount(2); 131 AssertMainTabCount(2);
132 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 132 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
133 133
134 // Check that named window 1 is opened and named window 2 isn't. 134 // Check that named window 1 is opened and named window 2 isn't.
135 const char kCheckWindow1Link[] = "checkNamedWindow1Closed"; 135 const char kCheckWindow1Link[] = "checkNamedWindow1Closed";
136 [[EarlGrey selectElementWithMatcher:webViewContainingText(kCheckWindow1Link)] 136 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kCheckWindow1Link)]
137 assertWithMatcher:grey_notNil()]; 137 assertWithMatcher:grey_notNil()];
138 TapWebViewElementWithId(kCheckWindow1Link); 138 TapWebViewElementWithId(kCheckWindow1Link);
139 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindow1Open)] 139 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindow1Open)]
140 assertWithMatcher:grey_notNil()]; 140 assertWithMatcher:grey_notNil()];
141 const char kCheckWindow2Link[] = "checkNamedWindow2Closed"; 141 const char kCheckWindow2Link[] = "checkNamedWindow2Closed";
142 TapWebViewElementWithId(kCheckWindow2Link); 142 TapWebViewElementWithId(kCheckWindow2Link);
143 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindow2NeverOpen)] 143 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindow2NeverOpen)]
144 assertWithMatcher:grey_notNil()]; 144 assertWithMatcher:grey_notNil()];
145 145
146 // Open another window with the same name. Check that named window 2 is now 146 // Open another window with the same name. Check that named window 2 is now
147 // opened. 147 // opened.
148 TapWebViewElementWithId("openWindowWithName"); 148 TapWebViewElementWithId("openWindowWithName");
149 AssertMainTabCount(2); 149 AssertMainTabCount(2);
150 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 150 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
151 TapWebViewElementWithId(kCheckWindow2Link); 151 TapWebViewElementWithId(kCheckWindow2Link);
152 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindow2Open)] 152 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindow2Open)]
153 assertWithMatcher:grey_notNil()]; 153 assertWithMatcher:grey_notNil()];
154 154
155 // Close the opened window. Check that named window 1 and 2 are both closed. 155 // Close the opened window. Check that named window 1 and 2 are both closed.
156 chrome_test_util::CloseTabAtIndex(1); 156 chrome_test_util::CloseTabAtIndex(1);
157 AssertMainTabCount(1); 157 AssertMainTabCount(1);
158 TapWebViewElementWithId(kCheckWindow1Link); 158 TapWebViewElementWithId(kCheckWindow1Link);
159 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindow1Closed)] 159 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindow1Closed)]
160 assertWithMatcher:grey_notNil()]; 160 assertWithMatcher:grey_notNil()];
161 TapWebViewElementWithId(kCheckWindow2Link); 161 TapWebViewElementWithId(kCheckWindow2Link);
162 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindow2Closed)] 162 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindow2Closed)]
163 assertWithMatcher:grey_notNil()]; 163 assertWithMatcher:grey_notNil()];
164 } 164 }
165 165
166 // Tests that closing a tab will set window.closed to true for only 166 // Tests that closing a tab will set window.closed to true for only
167 // corresponding window object and not for any other window objects. 167 // corresponding window object and not for any other window objects.
168 - (void)testWindowClosedWithoutName { 168 - (void)testWindowClosedWithoutName {
169 TapWebViewElementWithId("openWindowNoName"); 169 TapWebViewElementWithId("openWindowNoName");
170 AssertMainTabCount(2); 170 AssertMainTabCount(2);
171 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 171 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
172 172
173 // Check that unnamed window 1 is opened and unnamed window 2 isn't. 173 // Check that unnamed window 1 is opened and unnamed window 2 isn't.
174 const char kCheckWindow1Link[] = "checkUnnamedWindow1Closed"; 174 const char kCheckWindow1Link[] = "checkUnnamedWindow1Closed";
175 [[EarlGrey selectElementWithMatcher:webViewContainingText(kCheckWindow1Link)] 175 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kCheckWindow1Link)]
176 assertWithMatcher:grey_notNil()]; 176 assertWithMatcher:grey_notNil()];
177 TapWebViewElementWithId(kCheckWindow1Link); 177 TapWebViewElementWithId(kCheckWindow1Link);
178 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindow1Open)] 178 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindow1Open)]
179 assertWithMatcher:grey_notNil()]; 179 assertWithMatcher:grey_notNil()];
180 const char kCheckWindow2Link[] = "checkUnnamedWindow2Closed"; 180 const char kCheckWindow2Link[] = "checkUnnamedWindow2Closed";
181 TapWebViewElementWithId(kCheckWindow2Link); 181 TapWebViewElementWithId(kCheckWindow2Link);
182 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindow2NeverOpen)] 182 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindow2NeverOpen)]
183 assertWithMatcher:grey_notNil()]; 183 assertWithMatcher:grey_notNil()];
184 184
185 // Open another unnamed window. Check that unnamed window 2 is now opened. 185 // Open another unnamed window. Check that unnamed window 2 is now opened.
186 TapWebViewElementWithId("openWindowNoName"); 186 TapWebViewElementWithId("openWindowNoName");
187 AssertMainTabCount(3); 187 AssertMainTabCount(3);
188 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 188 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
189 TapWebViewElementWithId(kCheckWindow2Link); 189 TapWebViewElementWithId(kCheckWindow2Link);
190 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindow2Open)] 190 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindow2Open)]
191 assertWithMatcher:grey_notNil()]; 191 assertWithMatcher:grey_notNil()];
192 192
193 // Close the first opened window. Check that unnamed window 1 is closed and 193 // Close the first opened window. Check that unnamed window 1 is closed and
194 // unnamed window 2 is still open. 194 // unnamed window 2 is still open.
195 chrome_test_util::CloseTabAtIndex(1); 195 chrome_test_util::CloseTabAtIndex(1);
196 TapWebViewElementWithId(kCheckWindow1Link); 196 TapWebViewElementWithId(kCheckWindow1Link);
197 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindow1Closed)] 197 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindow1Closed)]
198 assertWithMatcher:grey_notNil()]; 198 assertWithMatcher:grey_notNil()];
199 TapWebViewElementWithId(kCheckWindow2Link); 199 TapWebViewElementWithId(kCheckWindow2Link);
200 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindow2Open)] 200 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindow2Open)]
201 assertWithMatcher:grey_notNil()]; 201 assertWithMatcher:grey_notNil()];
202 202
203 // Close the second opened window. Check that unnamed window 2 is closed. 203 // Close the second opened window. Check that unnamed window 2 is closed.
204 chrome_test_util::CloseTabAtIndex(1); 204 chrome_test_util::CloseTabAtIndex(1);
205 TapWebViewElementWithId(kCheckWindow2Link); 205 TapWebViewElementWithId(kCheckWindow2Link);
206 [[EarlGrey selectElementWithMatcher:webViewContainingText(kWindow2Closed)] 206 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kWindow2Closed)]
207 assertWithMatcher:grey_notNil()]; 207 assertWithMatcher:grey_notNil()];
208 } 208 }
209 209
210 @end 210 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/cache_egtest.mm ('k') | ios/chrome/browser/web/forms_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698