Commit ba52eee8 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Extend ErrorPageTestCase with back-forward and reload navigation tests.

Added the following test cases:
 - testReloadPageAfterServerIsDown
 - testGoForwardAfterServerIsDownAndReload
 - testGoBackFromErrorPage

Bug: 725241
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I6a872e6691c66ff6facd100cdb90607488738ff6
Reviewed-on: https://chromium-review.googlesource.com/1043074Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556082}
parent 8fd2712a
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#include "ios/testing/embedded_test_server_handlers.h" #include "ios/testing/embedded_test_server_handlers.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/embedded_test_server/http_request.h" #include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h" #include "net/test/embedded_test_server/http_response.h"
#include "net/test/embedded_test_server/request_handler_util.h" #include "net/test/embedded_test_server/request_handler_util.h"
...@@ -61,12 +62,13 @@ NSString* GetErrorMessage() { ...@@ -61,12 +62,13 @@ NSString* GetErrorMessage() {
self.testServer->RegisterRequestHandler( self.testServer->RegisterRequestHandler(
base::BindRepeating(&net::test_server::HandlePrefixedRequest, "/iframe", base::BindRepeating(&net::test_server::HandlePrefixedRequest, "/iframe",
base::BindRepeating(&testing::HandleIFrame))); base::BindRepeating(&testing::HandleIFrame)));
RegisterDefaultHandlers(self.testServer);
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start."); GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
} }
// Loads the URL which fails to load, then sucessfully reloads the page. // Loads the URL which fails to load, then sucessfully reloads the page.
- (void)testReload { - (void)testReloadErrorPage {
// No response leads to ERR_INTERNET_DISCONNECTED error. // No response leads to ERR_INTERNET_DISCONNECTED error.
self.serverRespondsWithContent = NO; self.serverRespondsWithContent = NO;
[ChromeEarlGrey loadURL:self.testServer->GetURL("/echo-query?foo")]; [ChromeEarlGrey loadURL:self.testServer->GetURL("/echo-query?foo")];
...@@ -78,6 +80,65 @@ NSString* GetErrorMessage() { ...@@ -78,6 +80,65 @@ NSString* GetErrorMessage() {
[ChromeEarlGrey waitForWebViewContainingText:"foo"]; [ChromeEarlGrey waitForWebViewContainingText:"foo"];
} }
// Sucessfully loads the page, stops the server and reloads the page.
- (void)testReloadPageAfterServerIsDown {
// Sucessfully load the page.
self.serverRespondsWithContent = YES;
[ChromeEarlGrey loadURL:self.testServer->GetURL("/echo-query?foo")];
[ChromeEarlGrey waitForWebViewContainingText:"foo"];
// Reload the page, no response leads to ERR_INTERNET_DISCONNECTED error.
self.serverRespondsWithContent = NO;
[ChromeEarlGrey reload];
[ChromeEarlGrey waitForStaticHTMLViewContainingText:GetErrorMessage()];
}
// Sucessfully loads the page, goes back, stops the server, goes forward and
// reloads.
- (void)testGoForwardAfterServerIsDownAndReload {
// First page loads sucessfully.
[ChromeEarlGrey loadURL:self.testServer->GetURL("/echo")];
[ChromeEarlGrey waitForWebViewContainingText:"Echo"];
// Second page loads sucessfully.
self.serverRespondsWithContent = YES;
[ChromeEarlGrey loadURL:self.testServer->GetURL("/echo-query?foo")];
[ChromeEarlGrey waitForWebViewContainingText:"foo"];
// Go back to the first page.
[ChromeEarlGrey goBack];
[ChromeEarlGrey waitForWebViewContainingText:"Echo"];
#if TARGET_IPHONE_SIMULATOR
// Go forward. The response will be retrieved from the page cache and will not
// present the error page. Page cache may not always exist on device (which is
// more memory constrained), so this part of the test is simulator-only.
self.serverRespondsWithContent = NO;
[ChromeEarlGrey goForward];
[ChromeEarlGrey waitForWebViewContainingText:"foo"];
// Reload bypasses the cache.
[ChromeEarlGrey reload];
[ChromeEarlGrey waitForStaticHTMLViewContainingText:GetErrorMessage()];
#endif // TARGET_IPHONE_SIMULATOR
}
// Sucessfully loads the page, then loads the URL which fails to load, then
// sucessfully goes back to the first page.
- (void)testGoBackFromErrorPage {
// 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")];
[ChromeEarlGrey waitForStaticHTMLViewContainingText:GetErrorMessage()];
// Going back should sucessfully load the first page.
[ChromeEarlGrey goBack];
[ChromeEarlGrey waitForWebViewContainingText:"Echo"];
}
// Loads the URL which redirects to unresponsive server. // Loads the URL which redirects to unresponsive server.
- (void)testRedirectToFailingURL { - (void)testRedirectToFailingURL {
// No response leads to ERR_INTERNET_DISCONNECTED error. // No response leads to ERR_INTERNET_DISCONNECTED error.
......
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