Commit 4c403bf0 authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

[iOS] Replace web::HttpServer in HistoryUITestCase

Changes being made in crrev.com/c/2353092 are breaking these tests when
using web::HttpServer. So this CL converts them to the now recommended
EmbeddedTestServer.

Bug: 891834
Change-Id: I3a64b9ce3288fe137dc9b6dd01d7352cd72e395b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2362972Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799754}
parent 1b8fda88
...@@ -174,7 +174,6 @@ source_set("eg2_tests") { ...@@ -174,7 +174,6 @@ source_set("eg2_tests") {
"//ios/chrome/test/earl_grey:eg_test_support+eg2", "//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2", "//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib", "//ios/third_party/earl_grey2:test_lib",
"//ios/web/public/test/http_server",
"//net:test_support", "//net:test_support",
] ]
frameworks = [ "UIKit.framework" ] frameworks = [ "UIKit.framework" ]
......
...@@ -23,9 +23,10 @@ ...@@ -23,9 +23,10 @@
#import "ios/chrome/test/earl_grey/chrome_matchers.h" #import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/testing/earl_grey/earl_grey_test.h" #import "ios/testing/earl_grey/earl_grey_test.h"
#import "ios/web/public/test/http_server/http_server.h"
#import "ios/web/public/test/http_server/http_server_util.h"
#import "net/base/mac/url_conversions.h" #import "net/base/mac/url_conversions.h"
#include "net/test/embedded_test_server/embedded_test_server.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) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -39,9 +40,9 @@ using chrome_test_util::OpenLinkInNewTabButton; ...@@ -39,9 +40,9 @@ using chrome_test_util::OpenLinkInNewTabButton;
using chrome_test_util::OpenLinkInNewWindowButton; using chrome_test_util::OpenLinkInNewWindowButton;
namespace { namespace {
char kURL1[] = "http://firstURL"; char kURL1[] = "/firstURL";
char kURL2[] = "http://secondURL"; char kURL2[] = "/secondURL";
char kURL3[] = "http://thirdURL"; char kURL3[] = "/thirdURL";
char kTitle1[] = "Page 1"; char kTitle1[] = "Page 1";
char kTitle2[] = "Page 2"; char kTitle2[] = "Page 2";
char kResponse1[] = "Test Page 1 content"; char kResponse1[] = "Test Page 1 content";
...@@ -82,6 +83,32 @@ id<GREYMatcher> EmptyIllustratedTableViewBackground() { ...@@ -82,6 +83,32 @@ id<GREYMatcher> EmptyIllustratedTableViewBackground() {
return grey_accessibilityID(kTableViewIllustratedEmptyViewID); return grey_accessibilityID(kTableViewIllustratedEmptyViewID);
} }
// Provides responses for URLs.
std::unique_ptr<net::test_server::HttpResponse> StandardResponse(
const net::test_server::HttpRequest& request) {
std::unique_ptr<net::test_server::BasicHttpResponse> http_response =
std::make_unique<net::test_server::BasicHttpResponse>();
http_response->set_code(net::HTTP_OK);
const char kPageFormat[] = "<head><title>%s</title></head><body>%s</body>";
if (request.relative_url == kURL1) {
std::string page_html =
base::StringPrintf(kPageFormat, kTitle1, kResponse1);
http_response->set_content(page_html);
} else if (request.relative_url == kURL2) {
std::string page_html =
base::StringPrintf(kPageFormat, kTitle2, kResponse2);
http_response->set_content(page_html);
} else if (request.relative_url == kURL3) {
http_response->set_content(
base::StringPrintf("<body>%s</body>", kResponse3));
} else {
return nullptr;
}
return std::move(http_response);
}
} // namespace } // namespace
// History UI tests. // History UI tests.
...@@ -100,38 +127,16 @@ id<GREYMatcher> EmptyIllustratedTableViewBackground() { ...@@ -100,38 +127,16 @@ id<GREYMatcher> EmptyIllustratedTableViewBackground() {
@implementation HistoryUITestCase @implementation HistoryUITestCase
#if defined(CHROME_EARL_GREY_2) - (void)setUp {
+ (void)setUpForTestCase {
[super setUpForTestCase];
[self setUpHelper];
}
#elif defined(CHROME_EARL_GREY_1)
// Set up called once for the class.
+ (void)setUp {
[super setUp]; [super setUp];
[self setUpHelper]; self.testServer->RegisterRequestHandler(
} base::BindRepeating(&StandardResponse));
#else GREYAssertTrue(self.testServer->Start(), @"Server did not start.");
#error Not an EarlGrey Test
#endif
+ (void)setUpHelper { _URL1 = self.testServer->GetURL(kURL1);
std::map<GURL, std::string> responses; _URL2 = self.testServer->GetURL(kURL2);
const char kPageFormat[] = "<head><title>%s</title></head><body>%s</body>"; _URL3 = self.testServer->GetURL(kURL3);
responses[web::test::HttpServer::MakeUrl(kURL1)] =
base::StringPrintf(kPageFormat, kTitle1, kResponse1);
responses[web::test::HttpServer::MakeUrl(kURL2)] =
base::StringPrintf(kPageFormat, kTitle2, kResponse2);
// Page 3 does not have <title> tag, so URL will be its title.
responses[web::test::HttpServer::MakeUrl(kURL3)] = kResponse3;
web::test::SetUpSimpleHttpServer(responses);
}
- (void)setUp {
[super setUp];
_URL1 = web::test::HttpServer::MakeUrl(kURL1);
_URL2 = web::test::HttpServer::MakeUrl(kURL2);
_URL3 = web::test::HttpServer::MakeUrl(kURL3);
[ChromeEarlGrey clearBrowsingHistory]; [ChromeEarlGrey clearBrowsingHistory];
// Some tests rely on a clean state for the "Clear Browsing Data" settings // Some tests rely on a clean state for the "Clear Browsing Data" settings
// screen. // screen.
......
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