Commit 94612d79 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Ported ErrorPageTestCase to ios_web_inttest.

This CL adds ErrorPageTest ios_web_inttest for error pages. These tests
are faster than EG tests and can test is_post and is_off_the_record
arguments passed to TestWebClient. ErrorPageTestCase exists, because
it's not possible to test old implementation with ios_web_inttest
infrastructure. ErrorPageTestCase will be removed when old error pages
code is no longer supported. Tests for is_post and is_off_the_record
arguments will be added in a separate CL.

Bug: 725241
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ic06e9613c6e69a488ac734922ffc691f124bd24b
Reviewed-on: https://chromium-review.googlesource.com/1047951
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556915}
parent f5d26f25
......@@ -93,6 +93,7 @@ NSString* GetNSErrorMessage() {
// Sucessfully loads the page, goes back, stops the server, goes forward and
// reloads.
// TODO(crbug.com/840489): Remove this test.
- (void)testGoForwardAfterServerIsDownAndReload {
// First page loads sucessfully.
[ChromeEarlGrey loadURL:self.testServer->GetURL("/echo")];
......@@ -127,6 +128,7 @@ NSString* GetNSErrorMessage() {
// Sucessfully loads the page, then loads the URL which fails to load, then
// sucessfully goes back to the first page.
// TODO(crbug.com/840489): Remove this test.
- (void)testGoBackFromErrorPage {
// First page loads sucessfully.
[ChromeEarlGrey loadURL:self.testServer->GetURL("/echo")];
......@@ -146,6 +148,7 @@ NSString* GetNSErrorMessage() {
}
// Loads the URL which redirects to unresponsive server.
// TODO(crbug.com/840489): Remove this test.
- (void)testRedirectToFailingURL {
// No response leads to ERR_INTERNET_DISCONNECTED error.
self.serverRespondsWithContent = NO;
......@@ -160,6 +163,7 @@ NSString* GetNSErrorMessage() {
// Loads the page with iframe, and that iframe fails to load. There should be no
// error page if the main frame has sucessfully loaded.
// TODO(crbug.com/840489): Remove this test.
- (void)testErrorPageInIFrame {
[ChromeEarlGrey loadURL:self.testServer->GetURL("/iframe?echo-query")];
[ChromeEarlGrey
......
......@@ -543,6 +543,7 @@ test("ios_web_inttests") {
deps = [
":web",
"//base/test:test_support",
"//ios/testing:embedded_test_server_support",
"//ios/testing:http_server_bundle_data",
"//ios/testing:ios_test_support",
"//ios/web:resources_grit",
......@@ -570,6 +571,7 @@ test("ios_web_inttests") {
"public/test/http_server_inttest.mm",
"test/run_all_unittests.cc",
"url_loader_inttest.mm",
"web_state/error_page_inttest.mm",
"web_state/favicon_callbacks_inttest.mm",
"web_state/http_auth_inttest.mm",
"web_state/navigation_and_load_callbacks_inttest.mm",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/test/scoped_feature_list.h"
#include "ios/testing/embedded_test_server_handlers.h"
#import "ios/testing/wait_util.h"
#include "ios/web/public/features.h"
#import "ios/web/public/navigation_manager.h"
#include "ios/web/public/reload_type.h"
#import "ios/web/public/test/navigation_test_util.h"
#import "ios/web/public/test/web_test_with_web_state.h"
#import "ios/web/public/test/web_view_content_test_util.h"
#import "ios/web/public/web_client.h"
#import "ios/web/public/web_state/web_state.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using testing::WaitUntilConditionOrTimeout;
namespace web {
namespace {
// Overrides PrepareErrorPage to render all important arguments.
class TestWebClient : public WebClient {
void PrepareErrorPage(NSError* error,
bool is_post,
bool is_off_the_record,
NSString** error_html) override {
*error_html =
[NSString stringWithFormat:@"domain: %@ code: %ld post: %d otr: %d",
error.domain, static_cast<long>(error.code),
is_post, is_off_the_record];
}
};
} // namespace
// Test fixture for error page testing. Error page simply renders the arguments
// passed to WebClient::PrepareErrorPage, so the test also acts as integration
// test for PrepareErrorPage WebClient method.
class ErrorPageTest : public WebTestWithWebState {
protected:
ErrorPageTest() : WebTestWithWebState(std::make_unique<TestWebClient>()) {
RegisterDefaultHandlers(&server_);
server_.RegisterRequestHandler(base::BindRepeating(
&net::test_server::HandlePrefixedRequest, "/echo-query",
base::BindRepeating(&testing::HandleEchoQueryOrCloseSocket,
base::ConstRef(server_responds_with_content_))));
server_.RegisterRequestHandler(
base::BindRepeating(&net::test_server::HandlePrefixedRequest, "/iframe",
base::BindRepeating(&testing::HandleIFrame)));
scoped_feature_list_.InitAndEnableFeature(features::kWebErrorPages);
}
void SetUp() override {
WebTestWithWebState::SetUp();
ASSERT_TRUE(server_.Start());
}
net::EmbeddedTestServer server_;
bool server_responds_with_content_ = false;
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(ErrorPageTest);
};
// Loads the URL which fails to load, then sucessfully reloads the page.
TEST_F(ErrorPageTest, ReloadErrorPage) {
// No response leads to -1005 error code.
server_responds_with_content_ = false;
test::LoadUrl(web_state(), server_.GetURL("/echo-query?foo"));
ASSERT_TRUE(test::WaitForWebViewContainingText(
web_state(), "domain: NSURLErrorDomain code: -1005 post: 0 otr: 1"));
// Reload the page, which should load without errors.
server_responds_with_content_ = true;
web_state()->GetNavigationManager()->Reload(ReloadType::NORMAL,
/*check_for_repost=*/false);
ASSERT_TRUE(test::WaitForWebViewContainingText(web_state(), "foo"));
}
// Sucessfully loads the page, stops the server and reloads the page.
TEST_F(ErrorPageTest, ReloadPageAfterServerIsDown) {
// Sucessfully load the page.
server_responds_with_content_ = true;
test::LoadUrl(web_state(), server_.GetURL("/echo-query?foo"));
ASSERT_TRUE(test::WaitForWebViewContainingText(web_state(), "foo"));
// Reload the page, no response leads to -1005 error code.
server_responds_with_content_ = false;
web_state()->GetNavigationManager()->Reload(ReloadType::NORMAL,
/*check_for_repost=*/false);
ASSERT_TRUE(test::WaitForWebViewContainingText(
web_state(), "domain: NSURLErrorDomain code: -1005 post: 0 otr: 1"));
}
// Sucessfully loads the page, goes back, stops the server, goes forward and
// reloads.
TEST_F(ErrorPageTest, GoForwardAfterServerIsDownAndReload) {
// First page loads sucessfully.
test::LoadUrl(web_state(), server_.GetURL("/echo"));
ASSERT_TRUE(test::WaitForWebViewContainingText(web_state(), "Echo"));
// Second page loads sucessfully.
server_responds_with_content_ = true;
test::LoadUrl(web_state(), server_.GetURL("/echo-query?foo"));
ASSERT_TRUE(test::WaitForWebViewContainingText(web_state(), "foo"));
// Go back to the first page.
web_state()->GetNavigationManager()->GoBack();
ASSERT_TRUE(test::WaitForWebViewContainingText(web_state(), "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.
server_responds_with_content_ = false;
web_state()->GetNavigationManager()->GoForward();
ASSERT_TRUE(test::WaitForWebViewContainingText(web_state(), "foo"));
// Reload bypasses the cache.
web_state()->GetNavigationManager()->Reload(ReloadType::NORMAL,
/*check_for_repost=*/false);
ASSERT_TRUE(test::WaitForWebViewContainingText(
web_state(), "domain: NSURLErrorDomain code: -1005 post: 0 otr: 1"));
#endif // TARGET_IPHONE_SIMULATOR
}
// Sucessfully loads the page, then loads the URL which fails to load, then
// sucessfully goes back to the first page.
TEST_F(ErrorPageTest, GoBackFromErrorPage) {
// 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: 1"));
// Going back should sucessfully load the first page.
web_state()->GetNavigationManager()->GoBack();
ASSERT_TRUE(test::WaitForWebViewContainingText(web_state(), "Echo"));
}
// Loads the URL which redirects to unresponsive server.
TEST_F(ErrorPageTest, RedirectToFailingURL) {
// No response leads to -1005 error code.
server_responds_with_content_ = false;
test::LoadUrl(web_state(), server_.GetURL("/server-redirect?echo-query"));
ASSERT_TRUE(test::WaitForWebViewContainingText(
web_state(), "domain: NSURLErrorDomain code: -1005 post: 0 otr: 1"));
}
// Loads the page with iframe, and that iframe fails to load. There should be no
// error page if the main frame has sucessfully loaded.
TEST_F(ErrorPageTest, ErrorPageInIFrame) {
test::LoadUrl(web_state(), server_.GetURL("/iframe?echo-query"));
EXPECT_TRUE(WaitUntilConditionOrTimeout(testing::kWaitForPageLoadTimeout, ^{
return test::IsWebViewContainingCssSelector(web_state(),
"iframe[src*='echo-query']");
}));
}
} // namespace web
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