Commit 3a2072b3 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Replace testHistoryForwardToErrorPage with ErrorPage tests.

New ErrorPage tests use EmbeddedTestServer instead of relying on DNS
resolution error. Also new tests work with enabled WebErrorPages flag.

Bug: 725241
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Iad495dac2c5e3111809cf460c151187089b20698
Reviewed-on: https://chromium-review.googlesource.com/1101930Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567714}
parent dd61f83e
...@@ -127,7 +127,8 @@ NSString* GetNSErrorMessage() { ...@@ -127,7 +127,8 @@ NSString* GetNSErrorMessage() {
} }
// Sucessfully loads the page, then loads the URL which fails to load, then // Sucessfully loads the page, then loads the URL which fails to load, then
// sucessfully goes back to the first page. // sucessfully goes back to the first page. Back-forward navigations are
// browser-initiated.
// TODO(crbug.com/840489): Remove this test. // TODO(crbug.com/840489): Remove this test.
- (void)testGoBackFromErrorPageAndForwardToErrorPage { - (void)testGoBackFromErrorPageAndForwardToErrorPage {
// First page loads sucessfully. // First page loads sucessfully.
...@@ -155,6 +156,38 @@ NSString* GetNSErrorMessage() { ...@@ -155,6 +156,38 @@ NSString* GetNSErrorMessage() {
} }
} }
// Sucessfully loads the page, then loads the URL which fails to load, then
// sucessfully goes back to the first page. Back-forward navigations are
// renderer-initiated.
// TODO(crbug.com/840489): Remove this test.
- (void)testRendererInitiatedGoBackFromErrorPageAndForwardToErrorPage {
// First page loads sucessfully.
[ChromeEarlGrey loadURL:self.testServer->GetURL("/echo")];
[ChromeEarlGrey waitForWebViewContainingText:"Echo"];
// Second page fails to load.
[ChromeEarlGrey loadURL:self.testServer->GetURL("/close-socket")];
if (base::FeatureList::IsEnabled(web::features::kWebErrorPages)) {
[ChromeEarlGrey waitForWebViewContainingText:GetErrorMessage()];
} else {
[ChromeEarlGrey waitForStaticHTMLViewContainingText:GetNSErrorMessage()];
}
// Going back should sucessfully load the first page.
[ChromeEarlGrey goBack];
[ChromeEarlGrey waitForWebViewContainingText:"Echo"];
// Going forward fails the load.
NSError* error = nil;
chrome_test_util::ExecuteJavaScript(@"window.history.forward()", &error);
GREYAssertTrue(!error, @"Unexpected error when executing JavaScript.");
if (base::FeatureList::IsEnabled(web::features::kWebErrorPages)) {
[ChromeEarlGrey waitForWebViewContainingText:GetErrorMessage()];
} else {
[ChromeEarlGrey waitForStaticHTMLViewContainingText:GetNSErrorMessage()];
}
}
// Loads the URL which redirects to unresponsive server. // Loads the URL which redirects to unresponsive server.
// TODO(crbug.com/840489): Remove this test. // TODO(crbug.com/840489): Remove this test.
- (void)testRedirectToFailingURL { - (void)testRedirectToFailingURL {
......
...@@ -342,36 +342,6 @@ std::unique_ptr<net::test_server::HttpResponse> WindowLocationHashHandlers( ...@@ -342,36 +342,6 @@ std::unique_ptr<net::test_server::HttpResponse> WindowLocationHashHandlers(
[ChromeEarlGrey waitForWebViewContainingText:"pony"]; [ChromeEarlGrey waitForWebViewContainingText:"pony"];
} }
// Tests navigating forward via window.history.forward() to an error page.
- (void)testHistoryForwardToErrorPage {
// TODO(crbug.com/694662): This test relies on external URL because of the bug.
// Re-enable this test on device once the bug is fixed.
#if !TARGET_IPHONE_SIMULATOR
EARL_GREY_TEST_DISABLED(@"Test disabled on device.");
#endif
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
// Go to page 1 with a button which calls window.history.forward().
const GURL forwardURL = self.testServer->GetURL(kWindowHistoryGoTestURL);
[ChromeEarlGrey loadURL:forwardURL];
// Go to page 2: 'www.badurljkljkljklfloofy.com'. This page should display a
// page not available error.
const GURL badURL("http://www.badurljkljkljklfloofy.com");
[ChromeEarlGrey loadURL:badURL];
[ChromeEarlGrey waitForErrorPage];
// Go back to page 1 by clicking back button.
[[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:OmniboxText(forwardURL.GetContent())]
assertWithMatcher:grey_notNil()];
// Go forward to page 2 by calling window.history.forward() and assert that
// the error page is shown.
[ChromeEarlGrey tapWebViewElementWithID:kGoForwardID];
[ChromeEarlGrey waitForErrorPage];
}
#pragma mark window.location.hash operations #pragma mark window.location.hash operations
// Loads a URL and modifies window.location.hash, then goes back and forward // Loads a URL and modifies window.location.hash, then goes back and forward
......
...@@ -136,7 +136,8 @@ TEST_F(ErrorPageTest, GoForwardAfterServerIsDownAndReload) { ...@@ -136,7 +136,8 @@ TEST_F(ErrorPageTest, GoForwardAfterServerIsDownAndReload) {
} }
// Sucessfully loads the page, then loads the URL which fails to load, then // Sucessfully loads the page, then loads the URL which fails to load, then
// sucessfully goes back to the first page. // sucessfully goes back to the first page and goes forward to error page.
// Back-forward navigations are browser-initiated.
TEST_F(ErrorPageTest, GoBackFromErrorPageAndForwardToErrorPage) { TEST_F(ErrorPageTest, GoBackFromErrorPageAndForwardToErrorPage) {
// First page loads sucessfully. // First page loads sucessfully.
test::LoadUrl(web_state(), server_.GetURL("/echo")); test::LoadUrl(web_state(), server_.GetURL("/echo"));
...@@ -157,6 +158,30 @@ TEST_F(ErrorPageTest, GoBackFromErrorPageAndForwardToErrorPage) { ...@@ -157,6 +158,30 @@ TEST_F(ErrorPageTest, GoBackFromErrorPageAndForwardToErrorPage) {
web_state(), "domain: NSURLErrorDomain code: -1005 post: 0 otr: 0")); web_state(), "domain: NSURLErrorDomain code: -1005 post: 0 otr: 0"));
} }
// Sucessfully loads the page, then loads the URL which fails to load, then
// sucessfully goes back to the first page and goes forward to error page.
// Back-forward navigations are renderer-initiated.
TEST_F(ErrorPageTest,
RendererInitiatedGoBackFromErrorPageAndForwardToErrorPage) {
// First page loads sucessfully.
test::LoadUrl(web_state(), server_.GetURL("/echo"));
ASSERT_TRUE(test::WaitForWebViewContainingText(web_state(), "Echo"));
// Second page fails to load.
test::LoadUrl(web_state(), server_.GetURL("/close-socket"));
ASSERT_TRUE(test::WaitForWebViewContainingText(
web_state(), "domain: NSURLErrorDomain code: -1005 post: 0 otr: 0"));
// Going back should sucessfully load the first page.
ExecuteJavaScript(@"window.history.back();");
ASSERT_TRUE(test::WaitForWebViewContainingText(web_state(), "Echo"));
// Going forward fails the load.
ExecuteJavaScript(@"window.history.forward();");
ASSERT_TRUE(test::WaitForWebViewContainingText(
web_state(), "domain: NSURLErrorDomain code: -1005 post: 0 otr: 0"));
}
// Loads the URL which redirects to unresponsive server. // Loads the URL which redirects to unresponsive server.
TEST_F(ErrorPageTest, RedirectToFailingURL) { TEST_F(ErrorPageTest, RedirectToFailingURL) {
// No response leads to -1005 error code. // No response leads to -1005 error code.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment