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

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, 4 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 std::string* response_status, 43 std::string* response_status,
44 std::string* response_headers, 44 std::string* response_headers,
45 std::string* response_data) { 45 std::string* response_data) {
46 response_data->assign(kGzipData, sizeof(kGzipData)); 46 response_data->assign(kGzipData, sizeof(kGzipData));
47 } 47 }
48 48
49 void GZipHelloServer(const HttpRequestInfo* request, 49 void GZipHelloServer(const HttpRequestInfo* request,
50 std::string* response_status, 50 std::string* response_status,
51 std::string* response_headers, 51 std::string* response_headers,
52 std::string* response_data) { 52 std::string* response_data) {
53 response_data->assign(kGzipHelloData, sizeof(kGzipHelloData)); 53 response_data->assign(kGzipHelloData, sizeof(kGzipHelloData) - 1);
54 } 54 }
55 55
56 void BigGZipServer(const HttpRequestInfo* request, 56 void BigGZipServer(const HttpRequestInfo* request,
57 std::string* response_status, 57 std::string* response_status,
58 std::string* response_headers, 58 std::string* response_headers,
59 std::string* response_data) { 59 std::string* response_data) {
60 response_data->assign(kGzipDataWithName, sizeof(kGzipDataWithName)); 60 response_data->assign(kGzipDataWithName, sizeof(kGzipDataWithName));
61 response_data->insert(10, 64 * 1024, 'a'); 61 response_data->insert(10, 64 * 1024, 'a');
62 } 62 }
63 63
(...skipping 24 matching lines...) Expand all
88 transaction->cert = 88 transaction->cert =
89 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 89 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
90 } else { 90 } else {
91 transaction->cert = nullptr; 91 transaction->cert = nullptr;
92 } 92 }
93 transaction->cert_status = 0; 93 transaction->cert_status = 0;
94 transaction->ssl_connection_status = 0; 94 transaction->ssl_connection_status = 0;
95 transaction->return_code = OK; 95 transaction->return_code = OK;
96 } 96 }
97 97
98 const MockTransaction kNoFilter_Transaction = {
99 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL,
100 "HTTP/1.1 200 OK",
101 "Cache-Control: max-age=10000\n"
102 "Content-Length: 30\n", // Intentionally wrong.
103 base::Time(),
104 "hello", TEST_MODE_NORMAL, nullptr, nullptr, 0, 0, OK,
105 };
106
98 const MockTransaction kGZip_Transaction = { 107 const MockTransaction kGZip_Transaction = {
99 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, 108 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL,
100 "HTTP/1.1 200 OK", 109 "HTTP/1.1 200 OK",
101 "Cache-Control: max-age=10000\n" 110 "Cache-Control: max-age=10000\n"
102 "Content-Encoding: gzip\n" 111 "Content-Encoding: gzip\n"
103 "Content-Length: 30\n", // Intentionally wrong. 112 "Content-Length: 30\n", // Intentionally wrong.
104 base::Time(), 113 base::Time(),
105 "", TEST_MODE_NORMAL, &GZipServer, nullptr, nullptr, 0, 0, OK, 114 "", TEST_MODE_NORMAL, &GZipServer, nullptr, nullptr, 0, 0, OK,
106 }; 115 };
107 116
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 "http://www.google.com/brotli", "GET", base::Time(), "", LOAD_NORMAL, 165 "http://www.google.com/brotli", "GET", base::Time(), "", LOAD_NORMAL,
157 "HTTP/1.1 200 OK", 166 "HTTP/1.1 200 OK",
158 "Cache-Control: max-age=10000\n" 167 "Cache-Control: max-age=10000\n"
159 "Content-Encoding: br\n", 168 "Content-Encoding: br\n",
160 base::Time(), "", TEST_MODE_SLOW_READ, &BrotliHelloServer, nullptr, nullptr, 169 base::Time(), "", TEST_MODE_SLOW_READ, &BrotliHelloServer, nullptr, nullptr,
161 0, 0, OK, 170 0, 0, OK,
162 }; 171 };
163 172
164 } // namespace 173 } // namespace
165 174
175 TEST(URLRequestJob, TransactionNoFilter) {
176 MockNetworkLayer network_layer;
177 TestURLRequestContext context;
178 context.set_http_transaction_factory(&network_layer);
179
180 TestDelegate d;
181 std::unique_ptr<URLRequest> req(context.CreateRequest(
182 GURL(kNoFilter_Transaction.url), DEFAULT_PRIORITY, &d));
183 AddMockTransaction(&kNoFilter_Transaction);
184
185 req->set_method("GET");
186 req->Start();
187
188 base::RunLoop().Run();
189
190 EXPECT_TRUE(network_layer.done_reading_called());
mmenke 2016/07/28 18:40:14 Should we check the final result of the transactio
xunjieli 2016/08/01 16:46:24 Done.
191
192 RemoveMockTransaction(&kNoFilter_Transaction);
193 }
194
166 TEST(URLRequestJob, TransactionNotifiedWhenDone) { 195 TEST(URLRequestJob, TransactionNotifiedWhenDone) {
167 MockNetworkLayer network_layer; 196 MockNetworkLayer network_layer;
168 TestURLRequestContext context; 197 TestURLRequestContext context;
169 context.set_http_transaction_factory(&network_layer); 198 context.set_http_transaction_factory(&network_layer);
170 199
171 TestDelegate d; 200 TestDelegate d;
172 std::unique_ptr<URLRequest> req( 201 std::unique_ptr<URLRequest> req(
173 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); 202 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d));
174 AddMockTransaction(&kGZip_Transaction); 203 AddMockTransaction(&kGZip_Transaction);
175 204
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 589
561 EXPECT_FALSE(d.request_failed()); 590 EXPECT_FALSE(d.request_failed());
562 EXPECT_EQ(200, req->GetResponseCode()); 591 EXPECT_EQ(200, req->GetResponseCode());
563 EXPECT_EQ(kBrotliDecodedHelloData, d.data_received()); 592 EXPECT_EQ(kBrotliDecodedHelloData, d.data_received());
564 EXPECT_TRUE(network_layer.done_reading_called()); 593 EXPECT_TRUE(network_layer.done_reading_called());
565 594
566 RemoveMockTransaction(&kBrotli_Slow_Transaction); 595 RemoveMockTransaction(&kBrotli_Slow_Transaction);
567 } 596 }
568 597
569 } // namespace net 598 } // namespace net
OLDNEW
« net/url_request/url_request_job.cc ('K') | « net/url_request/url_request_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698