Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: net/url_request/url_request_job_unittest.cc

Issue 1662763002: [ON HOLD] Implement pull-based design for content decoding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/url_request/url_request_job.h" 5 #include "net/url_request/url_request_job.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "net/base/request_priority.h" 10 #include "net/base/request_priority.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 response_data->insert(10, 64 * 1024, 'a'); 54 response_data->insert(10, 64 * 1024, 'a');
55 } 55 }
56 56
57 void BrotliHelloServer(const HttpRequestInfo* request, 57 void BrotliHelloServer(const HttpRequestInfo* request,
58 std::string* response_status, 58 std::string* response_status,
59 std::string* response_headers, 59 std::string* response_headers,
60 std::string* response_data) { 60 std::string* response_data) {
61 response_data->assign(kBrotliHelloData, sizeof(kBrotliHelloData) - 1); 61 response_data->assign(kBrotliHelloData, sizeof(kBrotliHelloData) - 1);
62 } 62 }
63 63
64 const MockTransaction kNoFilter_Transaction = {
65 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL,
66 "HTTP/1.1 200 OK",
67 "Cache-Control: max-age=10000\n"
68 "Content-Length: 30\n", // Intentionally wrong.
69 base::Time(),
70 "hello", TEST_MODE_NORMAL, nullptr, nullptr, 0, 0, OK,
71 };
72
64 const MockTransaction kGZip_Transaction = { 73 const MockTransaction kGZip_Transaction = {
65 "http://www.google.com/gzyp", 74 "http://www.google.com/gzyp",
66 "GET", 75 "GET",
67 base::Time(), 76 base::Time(),
68 "", 77 "",
69 LOAD_NORMAL, 78 LOAD_NORMAL,
70 "HTTP/1.1 200 OK", 79 "HTTP/1.1 200 OK",
71 "Cache-Control: max-age=10000\n" 80 "Cache-Control: max-age=10000\n"
72 "Content-Encoding: gzip\n" 81 "Content-Encoding: gzip\n"
73 "Content-Length: 30\n", // Intentionally wrong. 82 "Content-Length: 30\n", // Intentionally wrong.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 "http://www.google.com/brotli", "GET", base::Time(), "", LOAD_NORMAL, 149 "http://www.google.com/brotli", "GET", base::Time(), "", LOAD_NORMAL,
141 "HTTP/1.1 200 OK", 150 "HTTP/1.1 200 OK",
142 "Cache-Control: max-age=10000\n" 151 "Cache-Control: max-age=10000\n"
143 "Content-Encoding: br\n", 152 "Content-Encoding: br\n",
144 base::Time(), "", TEST_MODE_SLOW_READ, &BrotliHelloServer, nullptr, 0, 0, 153 base::Time(), "", TEST_MODE_SLOW_READ, &BrotliHelloServer, nullptr, 0, 0,
145 OK, 154 OK,
146 }; 155 };
147 156
148 } // namespace 157 } // namespace
149 158
159 TEST(URLRequestJob, TransactionNoFilter) {
160 MockNetworkLayer network_layer;
161 TestURLRequestContext context;
162 context.set_http_transaction_factory(&network_layer);
163
164 TestDelegate d;
165 std::unique_ptr<URLRequest> req(context.CreateRequest(
166 GURL(kNoFilter_Transaction.url), DEFAULT_PRIORITY, &d));
167 AddMockTransaction(&kNoFilter_Transaction);
168
169 req->set_method("GET");
170 req->Start();
171
172 base::MessageLoop::current()->Run();
173
174 EXPECT_TRUE(network_layer.done_reading_called());
175
176 RemoveMockTransaction(&kNoFilter_Transaction);
177 }
178
150 TEST(URLRequestJob, TransactionNotifiedWhenDone) { 179 TEST(URLRequestJob, TransactionNotifiedWhenDone) {
151 MockNetworkLayer network_layer; 180 MockNetworkLayer network_layer;
152 TestURLRequestContext context; 181 TestURLRequestContext context;
153 context.set_http_transaction_factory(&network_layer); 182 context.set_http_transaction_factory(&network_layer);
154 183
155 TestDelegate d; 184 TestDelegate d;
156 std::unique_ptr<URLRequest> req( 185 std::unique_ptr<URLRequest> req(
157 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); 186 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d));
158 AddMockTransaction(&kGZip_Transaction); 187 AddMockTransaction(&kGZip_Transaction);
159 188
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 380
352 EXPECT_FALSE(d.request_failed()); 381 EXPECT_FALSE(d.request_failed());
353 EXPECT_EQ(200, req->GetResponseCode()); 382 EXPECT_EQ(200, req->GetResponseCode());
354 EXPECT_EQ(kBrotliDecodedHelloData, d.data_received()); 383 EXPECT_EQ(kBrotliDecodedHelloData, d.data_received());
355 EXPECT_TRUE(network_layer.done_reading_called()); 384 EXPECT_TRUE(network_layer.done_reading_called());
356 385
357 RemoveMockTransaction(&kBrotli_Slow_Transaction); 386 RemoveMockTransaction(&kBrotli_Slow_Transaction);
358 } 387 }
359 388
360 } // namespace net 389 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698