Commit 881845a9 authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

Convert SettingsTestCase testClearCookies to use self.testServer

web::test::HttpServer usage is suspected of introducing flake into the
bot runs. This test has the last usage of
web::test::SetUpSimpleHttpServerWithSetCookies, so Convert it to use the
new test server in order to reduce test helpers utilizing the old http
server.

Bug: 891834
Change-Id: Ie1161507fd78e5b0095a17c91456218a0b6f05c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2376407
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Auto-Submit: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801567}
parent 0c1bd38b
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "build/branding_buildflags.h" #include "build/branding_buildflags.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
...@@ -21,8 +22,7 @@ ...@@ -21,8 +22,7 @@
#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" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "ios/web/public/test/http_server/http_server_util.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -53,10 +53,6 @@ using chrome_test_util::SettingsMenuPrivacyButton; ...@@ -53,10 +53,6 @@ using chrome_test_util::SettingsMenuPrivacyButton;
namespace { namespace {
const char kUrl[] = "http://foo/browsing";
const char kUrlWithSetCookie[] = "http://foo/set_cookie";
const char kResponse[] = "bar";
const char kResponseWithSetCookie[] = "bar with set cookie";
NSString* const kCookieName = @"name"; NSString* const kCookieName = @"name";
NSString* const kCookieValue = @"value"; NSString* const kCookieValue = @"value";
...@@ -353,33 +349,22 @@ id<GREYMatcher> ClearBrowsingDataCell() { ...@@ -353,33 +349,22 @@ id<GREYMatcher> ClearBrowsingDataCell() {
// local server to navigate to a page that sets then tests a cookie, and then // local server to navigate to a page that sets then tests a cookie, and then
// clears the cookie and tests it is not set. // clears the cookie and tests it is not set.
- (void)testClearCookies { - (void)testClearCookies {
// Creates a map of canned responses and set up the test HTML server. GREYAssertTrue(self.testServer->Start(), @"Server did not start.");
std::map<GURL, std::pair<std::string, std::string>> response;
NSString* cookieForURL =
[NSString stringWithFormat:@"%@=%@", kCookieName, kCookieValue];
response[web::test::HttpServer::MakeUrl(kUrlWithSetCookie)] =
std::pair<std::string, std::string>(base::SysNSStringToUTF8(cookieForURL),
kResponseWithSetCookie);
response[web::test::HttpServer::MakeUrl(kUrl)] =
std::pair<std::string, std::string>("", kResponse);
web::test::SetUpSimpleHttpServerWithSetCookies(response);
// Load |kUrl| and check that cookie is not set. // Load |kUrl| and check that cookie is not set.
[ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; [ChromeEarlGrey loadURL:self.testServer->GetURL("/echo")];
[ChromeEarlGrey waitForWebStateContainingText:kResponse];
NSDictionary* cookies = [ChromeEarlGrey cookies]; NSDictionary* cookies = [ChromeEarlGrey cookies];
GREYAssertEqual(0U, cookies.count, @"No cookie should be found."); GREYAssertEqual(0U, cookies.count, @"No cookie should be found.");
// Visit |kUrlWithSetCookie| to set a cookie and then load |kUrl| to check it // Visit "/set-cookie" to set a cookie and then load another page to check
// is still set. // that it is still set.
[ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrlWithSetCookie)]; std::string setCookiePath = base::StringPrintf(
[ChromeEarlGrey waitForWebStateContainingText:kResponseWithSetCookie]; "/set-cookie?%s=%s", base::SysNSStringToUTF8(kCookieName).c_str(),
[ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; base::SysNSStringToUTF8(kCookieValue).c_str());
[ChromeEarlGrey waitForWebStateContainingText:kResponse]; [ChromeEarlGrey loadURL:self.testServer->GetURL(setCookiePath)];
[ChromeEarlGrey loadURL:self.testServer->GetURL("/echo")];
cookies = [ChromeEarlGrey cookies]; cookies = [ChromeEarlGrey cookies];
GREYAssertEqualObjects(kCookieValue, cookies[kCookieName], GREYAssertEqualObjects(kCookieValue, cookies[kCookieName],
...@@ -396,8 +381,7 @@ id<GREYMatcher> ClearBrowsingDataCell() { ...@@ -396,8 +381,7 @@ id<GREYMatcher> ClearBrowsingDataCell() {
[self clearCookiesAndSiteData]; [self clearCookiesAndSiteData];
// Reload and test that there are no cookies left. // Reload and test that there are no cookies left.
[ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; [ChromeEarlGrey loadURL:self.testServer->GetURL("/echo")];
[ChromeEarlGrey waitForWebStateContainingText:kResponse];
cookies = [ChromeEarlGrey cookies]; cookies = [ChromeEarlGrey cookies];
GREYAssertEqual(0U, cookies.count, @"No cookie should be found."); GREYAssertEqual(0U, cookies.count, @"No cookie should be found.");
......
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