| 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 #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 "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 [ChromeEarlGreyUI openToolsMenu]; | 395 [ChromeEarlGreyUI openToolsMenu]; |
| 396 } | 396 } |
| 397 [[EarlGrey selectElementWithMatcher:chrome_test_util::ReloadButton()] | 397 [[EarlGrey selectElementWithMatcher:chrome_test_util::ReloadButton()] |
| 398 performAction:grey_tap()]; | 398 performAction:grey_tap()]; |
| 399 | 399 |
| 400 // Do not wait until reload is finished, tap the back button in the toolbar | 400 // Do not wait until reload is finished, tap the back button in the toolbar |
| 401 // and verify that URL2 (committed URL) is displayed even though URL1 is a | 401 // and verify that URL2 (committed URL) is displayed even though URL1 is a |
| 402 // pending URL. | 402 // pending URL. |
| 403 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 403 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |
| 404 performAction:grey_tap()]; | 404 performAction:grey_tap()]; |
| 405 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], | 405 // TODO(crbug.com/724560): Re-evaluate if necessary to check receiving URL1 |
| 406 @"Last request URL: %@", self.lastRequestURLSpec); | 406 // request here. |
| 407 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 407 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |
| 408 assertWithMatcher:grey_notNil()]; | 408 assertWithMatcher:grey_notNil()]; |
| 409 | 409 |
| 410 // Make server respond so URL1 becomes committed. | 410 // Make server respond so URL1 becomes committed. |
| 411 [self setServerPaused:NO]; | 411 [self setServerPaused:NO]; |
| 412 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] | 412 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] |
| 413 assertWithMatcher:grey_notNil()]; | 413 assertWithMatcher:grey_notNil()]; |
| 414 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 414 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |
| 415 assertWithMatcher:grey_notNil()]; | 415 assertWithMatcher:grey_notNil()]; |
| 416 } | 416 } |
| 417 | 417 |
| 418 // Tests that visible URL is always the same as last committed URL during go | 418 // Tests that visible URL is always the same as last committed URL during go |
| 419 // back navigation initiated with pending renderer-initiated navigation in | 419 // back navigation initiated with pending renderer-initiated navigation in |
| 420 // progress. | 420 // progress. |
| 421 - (void)testBackNavigationWithPendingRendererInitiatedNavigation { | 421 - (void)testBackNavigationWithPendingRendererInitiatedNavigation { |
| 422 // Purge web view caches and pause the server to make sure that tests can | 422 // Purge web view caches and pause the server to make sure that tests can |
| 423 // verify omnibox state before server starts responding. | 423 // verify omnibox state before server starts responding. |
| 424 PurgeCachedWebViewPages(); | 424 PurgeCachedWebViewPages(); |
| 425 [self setServerPaused:YES]; | 425 [self setServerPaused:YES]; |
| 426 | 426 |
| 427 // Start renderer initiated navigation. | 427 // Start renderer initiated navigation. |
| 428 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)]; | 428 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)]; |
| 429 | 429 |
| 430 // Do not wait until renderer-initiated navigation is finished, tap the back | 430 // Do not wait until renderer-initiated navigation is finished, tap the back |
| 431 // button in the toolbar and verify that URL2 (committed URL) is displayed | 431 // button in the toolbar and verify that URL2 (committed URL) is displayed |
| 432 // even though URL1 is a pending URL. | 432 // even though URL1 is a pending URL. |
| 433 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 433 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |
| 434 performAction:grey_tap()]; | 434 performAction:grey_tap()]; |
| 435 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], | 435 // TODO(crbug.com/724560): Re-evaluate if necessary to check receiving URL1 |
| 436 @"Last request URL: %@", self.lastRequestURLSpec); | 436 // request here. |
| 437 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] | 437 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] |
| 438 assertWithMatcher:grey_notNil()]; | 438 assertWithMatcher:grey_notNil()]; |
| 439 | 439 |
| 440 // Make server respond so URL1 becomes committed. | 440 // Make server respond so URL1 becomes committed. |
| 441 [self setServerPaused:NO]; | 441 [self setServerPaused:NO]; |
| 442 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] | 442 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] |
| 443 assertWithMatcher:grey_notNil()]; | 443 assertWithMatcher:grey_notNil()]; |
| 444 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] | 444 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] |
| 445 assertWithMatcher:grey_notNil()]; | 445 assertWithMatcher:grey_notNil()]; |
| 446 } | 446 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 - (BOOL)waitForServerToReceiveRequestWithURL:(GURL)URL { | 590 - (BOOL)waitForServerToReceiveRequestWithURL:(GURL)URL { |
| 591 return [[GREYCondition | 591 return [[GREYCondition |
| 592 conditionWithName:@"Wait for received request" | 592 conditionWithName:@"Wait for received request" |
| 593 block:^{ | 593 block:^{ |
| 594 return _responseProvider->last_request_url() == URL ? YES | 594 return _responseProvider->last_request_url() == URL ? YES |
| 595 : NO; | 595 : NO; |
| 596 }] waitWithTimeout:10]; | 596 }] waitWithTimeout:10]; |
| 597 } | 597 } |
| 598 | 598 |
| 599 @end | 599 @end |
| OLD | NEW |