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

Replace ExternalURLErrorPageTestCase.testErrorPage with hermetic test.

Old test was loading http://mock/redirect and because this URL did not
exist the load was failing because of DNS resolution error.

New test uses EmbeddedTestServer, which closes the socket to simulate
ERR_INTERNET_DISCONNECTED error.

Bug: 694662
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ib8974954403f868aa8b41df49da8e83a7902a61e
Reviewed-on: https://chromium-review.googlesource.com/1033952Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554805}
parent 31c0204d
...@@ -52,23 +52,6 @@ using web::test::HttpServer; ...@@ -52,23 +52,6 @@ using web::test::HttpServer;
#pragma mark - tests #pragma mark - tests
// Tests whether the error page is displayed for a bad URL.
- (void)testErrorPage {
// 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
std::unique_ptr<web::DataResponseProvider> provider(
new ErrorPageResponseProvider());
web::test::SetUpHttpServer(std::move(provider));
[ChromeEarlGrey loadURL:ErrorPageResponseProvider::GetDnsFailureUrl()];
[ChromeEarlGrey waitForErrorPage];
}
// Tests whether the error page is displayed if it is behind a redirect. // Tests whether the error page is displayed if it is behind a redirect.
- (void)testErrorPageRedirect { - (void)testErrorPageRedirect {
// TODO(crbug.com/694662): This test relies on external URL because of the bug. // TODO(crbug.com/694662): This test relies on external URL because of the bug.
......
...@@ -276,6 +276,7 @@ source_set("eg_tests") { ...@@ -276,6 +276,7 @@ source_set("eg_tests") {
"browsing_prevent_default_egtest.mm", "browsing_prevent_default_egtest.mm",
"cache_egtest.mm", "cache_egtest.mm",
"child_window_open_by_dom_egtest.mm", "child_window_open_by_dom_egtest.mm",
"error_page_egtest.mm",
"forms_egtest.mm", "forms_egtest.mm",
"http_auth_egtest.mm", "http_auth_egtest.mm",
"js_print_egtest.mm", "js_print_egtest.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.
#import <EarlGrey/EarlGrey.h>
#include <string>
#import "base/mac/bind_objc_block.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Returns ERR_INTERNET_DISCONNECTED error message.
NSString* GetErrorMessage() {
return base::SysUTF8ToNSString(
net::ErrorToShortString(net::ERR_INTERNET_DISCONNECTED));
}
} // namespace
// Tests critical user journeys reloated to page load errors.
@interface ErrorPageTestCase : ChromeTestCase
// YES if test server is replying with valid HTML content (URL query). NO if
// test server closes the socket.
@property(atomic) BOOL serverRespondsWithContent;
@end
@implementation ErrorPageTestCase
@synthesize serverRespondsWithContent = _serverRespondsWithContent;
- (void)setUp {
[super setUp];
// Tests handler which replies with URL query if serverRespondsWithContent set
// to YES. Otherwise the handler closes the socket.
using net::test_server::HttpRequest;
using net::test_server::HttpResponse;
auto handler = ^std::unique_ptr<HttpResponse>(const HttpRequest& request) {
if (!self.serverRespondsWithContent) {
return std::make_unique<net::test_server::RawHttpResponse>(
/*headers=*/"", /*contents=*/"");
}
auto response = std::make_unique<net::test_server::BasicHttpResponse>();
response->set_content_type("text/html");
response->set_content(request.GetURL().query());
return std::move(response);
};
self.testServer->RegisterDefaultHandler(base::BindBlockArc(handler));
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
}
// Loads the URL which fails to load, then sucessfully reloads the page.
- (void)testReload {
// No response leads to ERR_INTERNET_DISCONNECTED error.
self.serverRespondsWithContent = NO;
[ChromeEarlGrey loadURL:self.testServer->GetURL("/?foo")];
[ChromeEarlGrey waitForStaticHTMLViewContainingText:GetErrorMessage()];
// Reload the page, which should load without errors.
self.serverRespondsWithContent = YES;
[ChromeEarlGrey reload];
[ChromeEarlGrey waitForWebViewContainingText:"foo"];
}
@end
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