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

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

Issue 2642193012: Make EarlGrey matchers compliant with Chromium style. (Closed)
Patch Set: build.gn and rebase Created 3 years, 11 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
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/memory/ptr_util.h" 7 #include "base/memory/ptr_util.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 "ios/chrome/browser/experimental_flags.h" 10 #include "ios/chrome/browser/experimental_flags.h"
11 #include "ios/chrome/browser/ui/ui_util.h" 11 #include "ios/chrome/browser/ui/ui_util.h"
12 #import "ios/chrome/test/app/chrome_test_util.h" 12 #import "ios/chrome/test/app/chrome_test_util.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_earl_grey_ui.h" 14 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
15 #import "ios/chrome/test/earl_grey/chrome_matchers.h" 15 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
16 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 16 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
17 #import "ios/testing/earl_grey/disabled_test_macros.h" 17 #import "ios/testing/earl_grey/disabled_test_macros.h"
18 #import "ios/web/public/test/http_server.h" 18 #import "ios/web/public/test/http_server.h"
19 #include "ios/web/public/test/http_server_util.h" 19 #include "ios/web/public/test/http_server_util.h"
20 #include "ios/web/public/test/response_providers/html_response_provider.h" 20 #include "ios/web/public/test/response_providers/html_response_provider.h"
21 #include "url/gurl.h" 21 #include "url/gurl.h"
22 22
23 using chrome_test_util::webViewContainingText; 23 using chrome_test_util::WebViewContainingText;
24 using chrome_test_util::omniboxText; 24 using chrome_test_util::OmniboxText;
25 25
26 namespace { 26 namespace {
27 27
28 const char kTestPage1[] = "Test Page 1"; 28 const char kTestPage1[] = "Test Page 1";
29 const char kTestPage2[] = "Test Page 2"; 29 const char kTestPage2[] = "Test Page 2";
30 const char kTestPage3[] = "Test Page 3"; 30 const char kTestPage3[] = "Test Page 3";
31 const char kGoBackLink[] = "go-back"; 31 const char kGoBackLink[] = "go-back";
32 const char kGoForwardLink[] = "go-forward"; 32 const char kGoForwardLink[] = "go-forward";
33 const char kGoNegativeDeltaLink[] = "go-negative-delta"; 33 const char kGoNegativeDeltaLink[] = "go-negative-delta";
34 const char kGoPositiveDeltaLink[] = "go-positive-delta"; 34 const char kGoPositiveDeltaLink[] = "go-positive-delta";
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled"); 178 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
179 } 179 }
180 180
181 // Purge web view caches and pause the server to make sure that tests can 181 // Purge web view caches and pause the server to make sure that tests can
182 // verify omnibox state before server starts responding. 182 // verify omnibox state before server starts responding.
183 PurgeCachedWebViewPages(); 183 PurgeCachedWebViewPages();
184 [self setServerPaused:YES]; 184 [self setServerPaused:YES];
185 185
186 // Tap the back button in the toolbar and verify that URL2 (committed URL) is 186 // Tap the back button in the toolbar and verify that URL2 (committed URL) is
187 // displayed even though URL1 is a pending URL. 187 // displayed even though URL1 is a pending URL.
188 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()] 188 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
189 performAction:grey_tap()]; 189 performAction:grey_tap()];
190 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 190 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
191 @"Last request URL: %@", self.lastRequestURLSpec); 191 @"Last request URL: %@", self.lastRequestURLSpec);
192 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())] 192 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
193 assertWithMatcher:grey_notNil()]; 193 assertWithMatcher:grey_notNil()];
194 194
195 // Make server respond so URL1 becomes committed. 195 // Make server respond so URL1 becomes committed.
196 [self setServerPaused:NO]; 196 [self setServerPaused:NO];
197 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)] 197 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)]
198 assertWithMatcher:grey_notNil()]; 198 assertWithMatcher:grey_notNil()];
199 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())] 199 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
200 assertWithMatcher:grey_notNil()]; 200 assertWithMatcher:grey_notNil()];
201 201
202 // Purge web view caches and pause the server to make sure that tests can 202 // Purge web view caches and pause the server to make sure that tests can
203 // verify omnibox state before server starts responding. 203 // verify omnibox state before server starts responding.
204 PurgeCachedWebViewPages(); 204 PurgeCachedWebViewPages();
205 [self setServerPaused:YES]; 205 [self setServerPaused:YES];
206 206
207 // Tap the forward button in the toolbar and verify that URL1 (committed URL) 207 // Tap the forward button in the toolbar and verify that URL1 (committed URL)
208 // is displayed even though URL2 is a pending URL. 208 // is displayed even though URL2 is a pending URL.
209 [[EarlGrey selectElementWithMatcher:chrome_test_util::forwardButton()] 209 [[EarlGrey selectElementWithMatcher:chrome_test_util::ForwardButton()]
210 performAction:grey_tap()]; 210 performAction:grey_tap()];
211 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2], 211 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2],
212 @"Last request URL: %@", self.lastRequestURLSpec); 212 @"Last request URL: %@", self.lastRequestURLSpec);
213 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())] 213 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
214 assertWithMatcher:grey_notNil()]; 214 assertWithMatcher:grey_notNil()];
215 215
216 // Make server respond so URL2 becomes committed. 216 // Make server respond so URL2 becomes committed.
217 [self setServerPaused:NO]; 217 [self setServerPaused:NO];
218 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage2)] 218 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage2)]
219 assertWithMatcher:grey_notNil()]; 219 assertWithMatcher:grey_notNil()];
220 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())] 220 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
221 assertWithMatcher:grey_notNil()]; 221 assertWithMatcher:grey_notNil()];
222 } 222 }
223 223
224 // Tests that visible URL is always the same as last committed URL during 224 // Tests that visible URL is always the same as last committed URL during
225 // pending navigations initialted from back history popover. 225 // pending navigations initialted from back history popover.
226 - (void)testHistoryNavigation { 226 - (void)testHistoryNavigation {
227 if (!experimental_flags::IsPendingIndexNavigationEnabled()) { 227 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
228 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled"); 228 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
229 } 229 }
230 230
231 // Purge web view caches and pause the server to make sure that tests can 231 // Purge web view caches and pause the server to make sure that tests can
232 // verify omnibox state before server starts responding. 232 // verify omnibox state before server starts responding.
233 PurgeCachedWebViewPages(); 233 PurgeCachedWebViewPages();
234 [self setServerPaused:YES]; 234 [self setServerPaused:YES];
235 235
236 // Go back in history and verify that URL2 (committed URL) is displayed even 236 // Go back in history and verify that URL2 (committed URL) is displayed even
237 // though URL1 is a pending URL. 237 // though URL1 is a pending URL.
238 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()] 238 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
239 performAction:grey_longPress()]; 239 performAction:grey_longPress()];
240 NSString* URL1Spec = base::SysUTF8ToNSString(_testURL1.spec()); 240 NSString* URL1Spec = base::SysUTF8ToNSString(_testURL1.spec());
241 [[EarlGrey selectElementWithMatcher:grey_text(URL1Spec)] 241 [[EarlGrey selectElementWithMatcher:grey_text(URL1Spec)]
242 performAction:grey_tap()]; 242 performAction:grey_tap()];
243 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 243 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
244 @"Last request URL: %@", self.lastRequestURLSpec); 244 @"Last request URL: %@", self.lastRequestURLSpec);
245 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())] 245 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
246 assertWithMatcher:grey_notNil()]; 246 assertWithMatcher:grey_notNil()];
247 247
248 // Make server respond so URL1 becomes committed. 248 // Make server respond so URL1 becomes committed.
249 [self setServerPaused:NO]; 249 [self setServerPaused:NO];
250 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)] 250 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)]
251 assertWithMatcher:grey_notNil()]; 251 assertWithMatcher:grey_notNil()];
252 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())] 252 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
253 assertWithMatcher:grey_notNil()]; 253 assertWithMatcher:grey_notNil()];
254 } 254 }
255 255
256 // Tests that stopping a pending Back navigation and reloading reloads committed 256 // Tests that stopping a pending Back navigation and reloading reloads committed
257 // URL, not pending URL. 257 // URL, not pending URL.
258 - (void)testStoppingPendingBackNavigationAndReload { 258 - (void)testStoppingPendingBackNavigationAndReload {
259 if (!experimental_flags::IsPendingIndexNavigationEnabled()) { 259 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
260 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled"); 260 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
261 } 261 }
262 262
263 // Purge web view caches and pause the server to make sure that tests can 263 // Purge web view caches and pause the server to make sure that tests can
264 // verify omnibox state before server starts responding. 264 // verify omnibox state before server starts responding.
265 PurgeCachedWebViewPages(); 265 PurgeCachedWebViewPages();
266 [self setServerPaused:YES]; 266 [self setServerPaused:YES];
267 267
268 // Tap the back button, stop pending navigation and reload. 268 // Tap the back button, stop pending navigation and reload.
269 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()] 269 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
270 performAction:grey_tap()]; 270 performAction:grey_tap()];
271 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 271 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
272 @"Last request URL: %@", self.lastRequestURLSpec); 272 @"Last request URL: %@", self.lastRequestURLSpec);
273 // On iPhone Stop/Reload button is a part of tools menu, so open it. 273 // On iPhone Stop/Reload button is a part of tools menu, so open it.
274 if (!IsIPadIdiom()) { 274 if (!IsIPadIdiom()) {
275 // Enable EG synchronization to make test wait for popover animations. 275 // Enable EG synchronization to make test wait for popover animations.
276 [[GREYConfiguration sharedInstance] 276 [[GREYConfiguration sharedInstance]
277 setValue:@YES 277 setValue:@YES
278 forConfigKey:kGREYConfigKeySynchronizationEnabled]; 278 forConfigKey:kGREYConfigKeySynchronizationEnabled];
279 [ChromeEarlGreyUI openToolsMenu]; 279 [ChromeEarlGreyUI openToolsMenu];
280 } 280 }
281 [[EarlGrey selectElementWithMatcher:chrome_test_util::stopButton()] 281 [[EarlGrey selectElementWithMatcher:chrome_test_util::StopButton()]
282 performAction:grey_tap()]; 282 performAction:grey_tap()];
283 [ChromeEarlGreyUI reload]; 283 [ChromeEarlGreyUI reload];
284 284
285 // Make server respond and verify that page2 was reloaded, not page1. 285 // Make server respond and verify that page2 was reloaded, not page1.
286 [self setServerPaused:NO]; 286 [self setServerPaused:NO];
287 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage2)] 287 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage2)]
288 assertWithMatcher:grey_notNil()]; 288 assertWithMatcher:grey_notNil()];
289 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())] 289 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
290 assertWithMatcher:grey_notNil()]; 290 assertWithMatcher:grey_notNil()];
291 } 291 }
292 292
293 // Tests that visible URL is always the same as last committed URL during 293 // Tests that visible URL is always the same as last committed URL during
294 // back forward navigations initiated with JS. 294 // back forward navigations initiated with JS.
295 - (void)testJSBackForwardNavigation { 295 - (void)testJSBackForwardNavigation {
296 if (!experimental_flags::IsPendingIndexNavigationEnabled()) { 296 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
297 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled"); 297 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
298 } 298 }
299 299
300 // Purge web view caches and pause the server to make sure that tests can 300 // Purge web view caches and pause the server to make sure that tests can
301 // verify omnibox state before server starts responding. 301 // verify omnibox state before server starts responding.
302 PurgeCachedWebViewPages(); 302 PurgeCachedWebViewPages();
303 [self setServerPaused:YES]; 303 [self setServerPaused:YES];
304 304
305 // Tap the back button on the page and verify that URL2 (committed URL) is 305 // Tap the back button on the page and verify that URL2 (committed URL) is
306 // displayed even though URL1 is a pending URL. 306 // displayed even though URL1 is a pending URL.
307 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)]; 307 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)];
308 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 308 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
309 @"Last request URL: %@", self.lastRequestURLSpec); 309 @"Last request URL: %@", self.lastRequestURLSpec);
310 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())] 310 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
311 assertWithMatcher:grey_notNil()]; 311 assertWithMatcher:grey_notNil()];
312 312
313 // Make server respond so URL1 becomes committed. 313 // Make server respond so URL1 becomes committed.
314 [self setServerPaused:NO]; 314 [self setServerPaused:NO];
315 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)] 315 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)]
316 assertWithMatcher:grey_notNil()]; 316 assertWithMatcher:grey_notNil()];
317 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())] 317 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
318 assertWithMatcher:grey_notNil()]; 318 assertWithMatcher:grey_notNil()];
319 319
320 // Purge web view caches and pause the server to make sure that tests can 320 // Purge web view caches and pause the server to make sure that tests can
321 // verify omnibox state before server starts responding. 321 // verify omnibox state before server starts responding.
322 PurgeCachedWebViewPages(); 322 PurgeCachedWebViewPages();
323 [self setServerPaused:YES]; 323 [self setServerPaused:YES];
324 324
325 // Tap the forward button on the page and verify that URL1 (committed URL) 325 // Tap the forward button on the page and verify that URL1 (committed URL)
326 // is displayed even though URL2 is a pending URL. 326 // is displayed even though URL2 is a pending URL.
327 [ChromeEarlGrey 327 [ChromeEarlGrey
328 tapWebViewElementWithID:base::SysUTF8ToNSString(kGoForwardLink)]; 328 tapWebViewElementWithID:base::SysUTF8ToNSString(kGoForwardLink)];
329 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2], 329 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2],
330 @"Last request URL: %@", self.lastRequestURLSpec); 330 @"Last request URL: %@", self.lastRequestURLSpec);
331 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())] 331 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
332 assertWithMatcher:grey_notNil()]; 332 assertWithMatcher:grey_notNil()];
333 333
334 // Make server respond so URL2 becomes committed. 334 // Make server respond so URL2 becomes committed.
335 [self setServerPaused:NO]; 335 [self setServerPaused:NO];
336 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage2)] 336 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage2)]
337 assertWithMatcher:grey_notNil()]; 337 assertWithMatcher:grey_notNil()];
338 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())] 338 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
339 assertWithMatcher:grey_notNil()]; 339 assertWithMatcher:grey_notNil()];
340 } 340 }
341 341
342 // Tests that visible URL is always the same as last committed URL during go 342 // Tests that visible URL is always the same as last committed URL during go
343 // navigations initiated with JS. 343 // navigations initiated with JS.
344 - (void)testJSGoNavigation { 344 - (void)testJSGoNavigation {
345 if (!experimental_flags::IsPendingIndexNavigationEnabled()) { 345 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
346 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled"); 346 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
347 } 347 }
348 348
349 // Purge web view caches and pause the server to make sure that tests can 349 // Purge web view caches and pause the server to make sure that tests can
350 // verify omnibox state before server starts responding. 350 // verify omnibox state before server starts responding.
351 PurgeCachedWebViewPages(); 351 PurgeCachedWebViewPages();
352 [self setServerPaused:YES]; 352 [self setServerPaused:YES];
353 353
354 // Tap the go negative delta button on the page and verify that URL2 354 // Tap the go negative delta button on the page and verify that URL2
355 // (committed URL) is displayed even though URL1 is a pending URL. 355 // (committed URL) is displayed even though URL1 is a pending URL.
356 [ChromeEarlGrey 356 [ChromeEarlGrey
357 tapWebViewElementWithID:base::SysUTF8ToNSString(kGoNegativeDeltaLink)]; 357 tapWebViewElementWithID:base::SysUTF8ToNSString(kGoNegativeDeltaLink)];
358 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 358 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
359 @"Last request URL: %@", self.lastRequestURLSpec); 359 @"Last request URL: %@", self.lastRequestURLSpec);
360 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())] 360 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
361 assertWithMatcher:grey_notNil()]; 361 assertWithMatcher:grey_notNil()];
362 362
363 // Make server respond so URL1 becomes committed. 363 // Make server respond so URL1 becomes committed.
364 [self setServerPaused:NO]; 364 [self setServerPaused:NO];
365 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)] 365 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)]
366 assertWithMatcher:grey_notNil()]; 366 assertWithMatcher:grey_notNil()];
367 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())] 367 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
368 assertWithMatcher:grey_notNil()]; 368 assertWithMatcher:grey_notNil()];
369 369
370 // Purge web view caches and pause the server to make sure that tests can 370 // Purge web view caches and pause the server to make sure that tests can
371 // verify omnibox state before server starts responding. 371 // verify omnibox state before server starts responding.
372 PurgeCachedWebViewPages(); 372 PurgeCachedWebViewPages();
373 [self setServerPaused:YES]; 373 [self setServerPaused:YES];
374 374
375 // Tap go positive delta button on the page and verify that URL1 (committed 375 // Tap go positive delta button on the page and verify that URL1 (committed
376 // URL) is displayed even though URL2 is a pending URL. 376 // URL) is displayed even though URL2 is a pending URL.
377 [ChromeEarlGrey 377 [ChromeEarlGrey
378 tapWebViewElementWithID:base::SysUTF8ToNSString(kGoPositiveDeltaLink)]; 378 tapWebViewElementWithID:base::SysUTF8ToNSString(kGoPositiveDeltaLink)];
379 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2], 379 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2],
380 @"Last request URL: %@", self.lastRequestURLSpec); 380 @"Last request URL: %@", self.lastRequestURLSpec);
381 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())] 381 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
382 assertWithMatcher:grey_notNil()]; 382 assertWithMatcher:grey_notNil()];
383 383
384 // Make server respond so URL2 becomes committed. 384 // Make server respond so URL2 becomes committed.
385 [self setServerPaused:NO]; 385 [self setServerPaused:NO];
386 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage2)] 386 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage2)]
387 assertWithMatcher:grey_notNil()]; 387 assertWithMatcher:grey_notNil()];
388 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())] 388 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
389 assertWithMatcher:grey_notNil()]; 389 assertWithMatcher:grey_notNil()];
390 } 390 }
391 391
392 // Tests that visible URL is always the same as last committed URL during go 392 // Tests that visible URL is always the same as last committed URL during go
393 // back navigation started with pending reload in progress. 393 // back navigation started with pending reload in progress.
394 - (void)testBackNavigationWithPendingReload { 394 - (void)testBackNavigationWithPendingReload {
395 if (!experimental_flags::IsPendingIndexNavigationEnabled()) { 395 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
396 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled"); 396 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
397 } 397 }
398 398
399 // Purge web view caches and pause the server to make sure that tests can 399 // Purge web view caches and pause the server to make sure that tests can
400 // verify omnibox state before server starts responding. 400 // verify omnibox state before server starts responding.
401 PurgeCachedWebViewPages(); 401 PurgeCachedWebViewPages();
402 [self setServerPaused:YES]; 402 [self setServerPaused:YES];
403 403
404 // Start reloading the page. 404 // Start reloading the page.
405 if (!IsIPadIdiom()) { 405 if (!IsIPadIdiom()) {
406 // Enable EG synchronization to make test wait for popover animations. 406 // Enable EG synchronization to make test wait for popover animations.
407 [[GREYConfiguration sharedInstance] 407 [[GREYConfiguration sharedInstance]
408 setValue:@YES 408 setValue:@YES
409 forConfigKey:kGREYConfigKeySynchronizationEnabled]; 409 forConfigKey:kGREYConfigKeySynchronizationEnabled];
410 [ChromeEarlGreyUI openToolsMenu]; 410 [ChromeEarlGreyUI openToolsMenu];
411 } 411 }
412 [[EarlGrey selectElementWithMatcher:chrome_test_util::reloadButton()] 412 [[EarlGrey selectElementWithMatcher:chrome_test_util::ReloadButton()]
413 performAction:grey_tap()]; 413 performAction:grey_tap()];
414 414
415 // Do not wait until reload is finished, tap the back button in the toolbar 415 // Do not wait until reload is finished, tap the back button in the toolbar
416 // and verify that URL2 (committed URL) is displayed even though URL1 is a 416 // and verify that URL2 (committed URL) is displayed even though URL1 is a
417 // pending URL. 417 // pending URL.
418 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()] 418 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
419 performAction:grey_tap()]; 419 performAction:grey_tap()];
420 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 420 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
421 @"Last request URL: %@", self.lastRequestURLSpec); 421 @"Last request URL: %@", self.lastRequestURLSpec);
422 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())] 422 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
423 assertWithMatcher:grey_notNil()]; 423 assertWithMatcher:grey_notNil()];
424 424
425 // Make server respond so URL1 becomes committed. 425 // Make server respond so URL1 becomes committed.
426 [self setServerPaused:NO]; 426 [self setServerPaused:NO];
427 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)] 427 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)]
428 assertWithMatcher:grey_notNil()]; 428 assertWithMatcher:grey_notNil()];
429 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())] 429 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
430 assertWithMatcher:grey_notNil()]; 430 assertWithMatcher:grey_notNil()];
431 } 431 }
432 432
433 // Tests that visible URL is always the same as last committed URL during go 433 // Tests that visible URL is always the same as last committed URL during go
434 // back navigation initiated with pending renderer-initiated navigation in 434 // back navigation initiated with pending renderer-initiated navigation in
435 // progress. 435 // progress.
436 - (void)testBackNavigationWithPendingRendererInitiatedNavigation { 436 - (void)testBackNavigationWithPendingRendererInitiatedNavigation {
437 if (!experimental_flags::IsPendingIndexNavigationEnabled()) { 437 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
438 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled"); 438 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
439 } 439 }
440 440
441 // Purge web view caches and pause the server to make sure that tests can 441 // Purge web view caches and pause the server to make sure that tests can
442 // verify omnibox state before server starts responding. 442 // verify omnibox state before server starts responding.
443 PurgeCachedWebViewPages(); 443 PurgeCachedWebViewPages();
444 [self setServerPaused:YES]; 444 [self setServerPaused:YES];
445 445
446 // Start renderer initiated navigation. 446 // Start renderer initiated navigation.
447 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)]; 447 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)];
448 448
449 // Do not wait until renderer-initiated navigation is finished, tap the back 449 // Do not wait until renderer-initiated navigation is finished, tap the back
450 // button in the toolbar and verify that URL2 (committed URL) is displayed 450 // button in the toolbar and verify that URL2 (committed URL) is displayed
451 // even though URL1 is a pending URL. 451 // even though URL1 is a pending URL.
452 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()] 452 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
453 performAction:grey_tap()]; 453 performAction:grey_tap()];
454 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 454 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
455 @"Last request URL: %@", self.lastRequestURLSpec); 455 @"Last request URL: %@", self.lastRequestURLSpec);
456 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())] 456 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
457 assertWithMatcher:grey_notNil()]; 457 assertWithMatcher:grey_notNil()];
458 458
459 // Make server respond so URL1 becomes committed. 459 // Make server respond so URL1 becomes committed.
460 [self setServerPaused:NO]; 460 [self setServerPaused:NO];
461 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)] 461 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)]
462 assertWithMatcher:grey_notNil()]; 462 assertWithMatcher:grey_notNil()];
463 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())] 463 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
464 assertWithMatcher:grey_notNil()]; 464 assertWithMatcher:grey_notNil()];
465 } 465 }
466 466
467 // Tests that visible URL is always the same as last committed URL during 467 // Tests that visible URL is always the same as last committed URL during
468 // renderer-initiated navigation started with pending back navigation in 468 // renderer-initiated navigation started with pending back navigation in
469 // progress. 469 // progress.
470 - (void)testRendererInitiatedNavigationWithPendingBackNavigation { 470 - (void)testRendererInitiatedNavigationWithPendingBackNavigation {
471 if (!experimental_flags::IsPendingIndexNavigationEnabled()) { 471 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
472 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled"); 472 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
473 } 473 }
474 474
475 // Purge web view caches and pause the server to make sure that tests can 475 // Purge web view caches and pause the server to make sure that tests can
476 // verify omnibox state before server starts responding. 476 // verify omnibox state before server starts responding.
477 PurgeCachedWebViewPages(); 477 PurgeCachedWebViewPages();
478 [self setServerPaused:YES]; 478 [self setServerPaused:YES];
479 479
480 // Tap the back button in the toolbar and verify that URL2 (committed URL) is 480 // Tap the back button in the toolbar and verify that URL2 (committed URL) is
481 // displayed even though URL1 is a pending URL. 481 // displayed even though URL1 is a pending URL.
482 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()] 482 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
483 performAction:grey_tap()]; 483 performAction:grey_tap()];
484 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 484 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
485 @"Last request URL: %@", self.lastRequestURLSpec); 485 @"Last request URL: %@", self.lastRequestURLSpec);
486 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())] 486 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
487 assertWithMatcher:grey_notNil()]; 487 assertWithMatcher:grey_notNil()];
488 488
489 // Interrupt back navigation with renderer initiated navigation. 489 // Interrupt back navigation with renderer initiated navigation.
490 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)]; 490 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)];
491 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL2.GetContent())] 491 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
492 assertWithMatcher:grey_notNil()]; 492 assertWithMatcher:grey_notNil()];
493 493
494 // Make server respond so URL1 becomes committed. 494 // Make server respond so URL1 becomes committed.
495 [self setServerPaused:NO]; 495 [self setServerPaused:NO];
496 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage3)] 496 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage3)]
497 assertWithMatcher:grey_notNil()]; 497 assertWithMatcher:grey_notNil()];
498 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL3.GetContent())] 498 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())]
499 assertWithMatcher:grey_notNil()]; 499 assertWithMatcher:grey_notNil()];
500 } 500 }
501 501
502 // Tests that visible URL is always the same as last committed URL if user 502 // Tests that visible URL is always the same as last committed URL if user
503 // issues 2 go back commands. 503 // issues 2 go back commands.
504 - (void)testDoubleBackNavigation { 504 - (void)testDoubleBackNavigation {
505 if (!experimental_flags::IsPendingIndexNavigationEnabled()) { 505 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
506 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled"); 506 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
507 } 507 }
508 508
509 // Create 3rd entry in the history, to be able to go back twice. 509 // Create 3rd entry in the history, to be able to go back twice.
510 [ChromeEarlGrey loadURL:_testURL3]; 510 [ChromeEarlGrey loadURL:_testURL3];
511 511
512 // Purge web view caches and pause the server to make sure that tests can 512 // Purge web view caches and pause the server to make sure that tests can
513 // verify omnibox state before server starts responding. 513 // verify omnibox state before server starts responding.
514 PurgeCachedWebViewPages(); 514 PurgeCachedWebViewPages();
515 [self setServerPaused:YES]; 515 [self setServerPaused:YES];
516 516
517 // Tap the back button twice in the toolbar and verify that URL3 (committed 517 // Tap the back button twice in the toolbar and verify that URL3 (committed
518 // URL) is displayed even though URL1 is a pending URL. 518 // URL) is displayed even though URL1 is a pending URL.
519 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()] 519 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
520 performAction:grey_tap()]; 520 performAction:grey_tap()];
521 [[EarlGrey selectElementWithMatcher:chrome_test_util::backButton()] 521 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
522 performAction:grey_tap()]; 522 performAction:grey_tap()];
523 // Server will receive only one request either for |_testURL2| or for 523 // Server will receive only one request either for |_testURL2| or for
524 // |_testURL1| depending on load timing and then will pause. So there is no 524 // |_testURL1| depending on load timing and then will pause. So there is no
525 // need to wait for particular request. 525 // need to wait for particular request.
526 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL3.GetContent())] 526 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())]
527 assertWithMatcher:grey_notNil()]; 527 assertWithMatcher:grey_notNil()];
528 528
529 // Make server respond so URL1 becomes committed. 529 // Make server respond so URL1 becomes committed.
530 [self setServerPaused:NO]; 530 [self setServerPaused:NO];
531 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)] 531 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)]
532 assertWithMatcher:grey_notNil()]; 532 assertWithMatcher:grey_notNil()];
533 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())] 533 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
534 assertWithMatcher:grey_notNil()]; 534 assertWithMatcher:grey_notNil()];
535 } 535 }
536 536
537 // Tests that visible URL is always the same as last committed URL if page calls 537 // Tests that visible URL is always the same as last committed URL if page calls
538 // window.history.back() twice. 538 // window.history.back() twice.
539 - (void)testDoubleBackJSNavigation { 539 - (void)testDoubleBackJSNavigation {
540 if (!experimental_flags::IsPendingIndexNavigationEnabled()) { 540 if (!experimental_flags::IsPendingIndexNavigationEnabled()) {
541 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled"); 541 EARL_GREY_TEST_SKIPPED(@"Pending Index Navigation experiment is disabled");
542 } 542 }
543 543
544 // Create 3rd entry in the history, to be able to go back twice. 544 // Create 3rd entry in the history, to be able to go back twice.
545 [ChromeEarlGrey loadURL:_testURL3]; 545 [ChromeEarlGrey loadURL:_testURL3];
546 546
547 // Purge web view caches and pause the server to make sure that tests can 547 // Purge web view caches and pause the server to make sure that tests can
548 // verify omnibox state before server starts responding. 548 // verify omnibox state before server starts responding.
549 PurgeCachedWebViewPages(); 549 PurgeCachedWebViewPages();
550 [self setServerPaused:YES]; 550 [self setServerPaused:YES];
551 551
552 // Tap the back button twice on the page and verify that URL3 (committed URL) 552 // Tap the back button twice on the page and verify that URL3 (committed URL)
553 // is displayed even though URL1 is a pending URL. 553 // is displayed even though URL1 is a pending URL.
554 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)]; 554 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)];
555 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)]; 555 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)];
556 // Server will receive only one request either for |_testURL2| or for 556 // Server will receive only one request either for |_testURL2| or for
557 // |_testURL1| depending on load timing and then will pause. So there is no 557 // |_testURL1| depending on load timing and then will pause. So there is no
558 // need to wait for particular request. 558 // need to wait for particular request.
559 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL3.GetContent())] 559 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())]
560 assertWithMatcher:grey_notNil()]; 560 assertWithMatcher:grey_notNil()];
561 561
562 // Make server respond so URL1 becomes committed. 562 // Make server respond so URL1 becomes committed.
563 [self setServerPaused:NO]; 563 [self setServerPaused:NO];
564 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPage1)] 564 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)]
565 assertWithMatcher:grey_notNil()]; 565 assertWithMatcher:grey_notNil()];
566 [[EarlGrey selectElementWithMatcher:omniboxText(_testURL1.GetContent())] 566 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
567 assertWithMatcher:grey_notNil()]; 567 assertWithMatcher:grey_notNil()];
568 } 568 }
569 569
570 #pragma mark - 570 #pragma mark -
571 #pragma mark Private 571 #pragma mark Private
572 572
573 - (NSString*)lastRequestURLSpec { 573 - (NSString*)lastRequestURLSpec {
574 return base::SysUTF8ToNSString(_responseProvider->last_request_url().spec()); 574 return base::SysUTF8ToNSString(_responseProvider->last_request_url().spec());
575 } 575 }
576 576
(...skipping 12 matching lines...) Expand all
589 - (BOOL)waitForServerToReceiveRequestWithURL:(GURL)URL { 589 - (BOOL)waitForServerToReceiveRequestWithURL:(GURL)URL {
590 return [[GREYCondition 590 return [[GREYCondition
591 conditionWithName:@"Wait for received request" 591 conditionWithName:@"Wait for received request"
592 block:^{ 592 block:^{
593 return _responseProvider->last_request_url() == URL ? YES 593 return _responseProvider->last_request_url() == URL ? YES
594 : NO; 594 : NO;
595 }] waitWithTimeout:10]; 595 }] waitWithTimeout:10];
596 } 596 }
597 597
598 @end 598 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/stop_loading_egtest.mm ('k') | ios/chrome/browser/web/window_open_by_dom_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698