Commit 80b7b264 authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Make Variations unittests use ResponseHeader::SetHeader()

We want to get rid of the single argument AddHeader() method as the two
argument AddHeader() and SetHeader() methods are safer and more
flexible.

In this case, switching to SetHeader() to make clear that there's only
one instance of each of the headers being set.

Bug: 1068194
Change-Id: Id17aba78bb54c47d4087324726b1c32920f29233
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2148021Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Commit-Queue: Matt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758999}
parent 0353c700
......@@ -536,12 +536,12 @@ TEST_F(VariationsServiceTest, InstanceManipulations) {
bool seed_stored;
} cases[] = {
{"", false, false, true},
{"IM:gzip", false, true, true},
{"IM:x-bm", true, false, true},
{"IM:x-bm,gzip", true, true, true},
{"IM: x-bm, gzip", true, true, true},
{"IM:gzip,x-bm", false, false, false},
{"IM:deflate,x-bm,gzip", false, false, false},
{"gzip", false, true, true},
{"x-bm", true, false, true},
{"x-bm,gzip", true, true, true},
{" x-bm, gzip", true, true, true},
{"gzip,x-bm", false, false, false},
{"deflate,x-bm,gzip", false, false, false},
};
std::string serialized_seed = SerializeSeed(CreateTestSeed());
......@@ -558,7 +558,7 @@ TEST_F(VariationsServiceTest, InstanceManipulations) {
head->headers = base::MakeRefCounted<net::HttpResponseHeaders>(
net::HttpUtil::AssembleRawHeaders(headers));
if (!cases[i].im.empty())
head->headers->AddHeader(cases[i].im);
head->headers->SetHeader("IM", cases[i].im);
network::URLLoaderCompletionStatus status;
status.decoded_body_length = serialized_seed.size();
service.test_url_loader_factory()->AddResponse(
......@@ -587,7 +587,7 @@ TEST_F(VariationsServiceTest, CountryHeader) {
auto head = network::mojom::URLResponseHead::New();
head->headers = base::MakeRefCounted<net::HttpResponseHeaders>(
net::HttpUtil::AssembleRawHeaders(headers));
head->headers->AddHeader("X-Country: test");
head->headers->SetHeader("X-Country", "test");
network::URLLoaderCompletionStatus status;
status.decoded_body_length = serialized_seed.size();
service.test_url_loader_factory()->AddResponse(
......@@ -888,14 +888,12 @@ TEST_F(VariationsServiceTest, SafeMode_SuccessfulFetchClearsFailureStreaks) {
std::string response;
ASSERT_TRUE(base::Base64Decode(kBase64SeedData, &response));
const std::string seed_signature_header =
std::string("X-Seed-Signature:") + kBase64SeedSignature;
std::string headers("HTTP/1.1 200 OK\n\n");
auto head = network::mojom::URLResponseHead::New();
head->headers = base::MakeRefCounted<net::HttpResponseHeaders>(
net::HttpUtil::AssembleRawHeaders(headers));
head->headers->AddHeader(seed_signature_header);
head->headers->SetHeader("X-Seed-Signature", kBase64SeedSignature);
network::URLLoaderCompletionStatus status;
status.decoded_body_length = response.size();
service.test_url_loader_factory()->AddResponse(
......@@ -1058,8 +1056,6 @@ TEST_F(VariationsServiceTest, NullResponseReceivedWithHTTPOk) {
std::string response;
ASSERT_TRUE(base::Base64Decode(kBase64SeedData, &response));
const std::string seed_signature_header =
std::string("X-Seed-Signature:") + kBase64SeedSignature;
std::string headers("HTTP/1.1 200 OK\n\n");
auto head = network::mojom::URLResponseHead::New();
......@@ -1067,7 +1063,7 @@ TEST_F(VariationsServiceTest, NullResponseReceivedWithHTTPOk) {
net::HttpUtil::AssembleRawHeaders(headers));
head->headers = http_response_headers;
EXPECT_EQ(net::HTTP_OK, http_response_headers->response_code());
http_response_headers->AddHeader(seed_signature_header);
http_response_headers->SetHeader("X-Seed-Signature", kBase64SeedSignature);
// Set ERR_FAILED status code despite the 200 response code.
network::URLLoaderCompletionStatus status(net::ERR_FAILED);
status.decoded_body_length = response.size();
......
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