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

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

Issue 1431723002: Add brotli content-encoding filter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Exclude brotli_filter_unittest on ios - needs to read input data files Created 4 years, 11 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 "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "net/base/request_priority.h" 9 #include "net/base/request_priority.h"
10 #include "net/http/http_transaction_test_util.h" 10 #include "net/http/http_transaction_test_util.h"
11 #include "net/url_request/url_request.h" 11 #include "net/url_request/url_request.h"
12 #include "net/url_request/url_request_test_util.h" 12 #include "net/url_request/url_request_test_util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace net { 15 namespace net {
16 16
17 namespace { 17 namespace {
18 18
19 // Data encoded in kBrotliHelloData.
20 const char kBrotliDecodedHelloData[] = "hello, world!\n";
21 // kBrotliDecodedHelloData encoded with brotli.
22 const char kBrotliHelloData[] =
23 "\033\015\0\0\244\024\102\152\020\111\152\072\235\126\034";
24
19 // This is a header that signals the end of the data. 25 // This is a header that signals the end of the data.
20 const char kGzipData[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"; 26 const char kGzipData[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0";
21 const char kGzipDataWithName[] = 27 const char kGzipDataWithName[] =
22 "\x1f\x08b\x08\x08\0\0\0\0\0\0name\0\3\0\0\0\0\0\0\0\0"; 28 "\x1f\x08b\x08\x08\0\0\0\0\0\0name\0\3\0\0\0\0\0\0\0\0";
23 // Gzip data that contains the word hello with a newline character. 29 // Gzip data that contains the word hello with a newline character.
24 const char kGzipHelloData[] = 30 const char kGzipHelloData[] =
25 "\x1f\x8b\x08\x08\x46\x7d\x4e\x56\x00\x03\x67\x7a\x69\x70\x2e\x74\x78\x74" 31 "\x1f\x8b\x08\x08\x46\x7d\x4e\x56\x00\x03\x67\x7a\x69\x70\x2e\x74\x78\x74"
26 "\x00\xcb\x48\xcd\xc9\xc9\xe7\x02\x00\x20\x30\x3a\x36\x06\x00\x00\x00"; 32 "\x00\xcb\x48\xcd\xc9\xc9\xe7\x02\x00\x20\x30\x3a\x36\x06\x00\x00\x00";
27 33
28 void GZipServer(const HttpRequestInfo* request, 34 void GZipServer(const HttpRequestInfo* request,
(...skipping 11 matching lines...) Expand all
40 } 46 }
41 47
42 void BigGZipServer(const HttpRequestInfo* request, 48 void BigGZipServer(const HttpRequestInfo* request,
43 std::string* response_status, 49 std::string* response_status,
44 std::string* response_headers, 50 std::string* response_headers,
45 std::string* response_data) { 51 std::string* response_data) {
46 response_data->assign(kGzipDataWithName, sizeof(kGzipDataWithName)); 52 response_data->assign(kGzipDataWithName, sizeof(kGzipDataWithName));
47 response_data->insert(10, 64 * 1024, 'a'); 53 response_data->insert(10, 64 * 1024, 'a');
48 } 54 }
49 55
56 void BrotliHelloServer(const HttpRequestInfo* request,
57 std::string* response_status,
58 std::string* response_headers,
59 std::string* response_data) {
60 response_data->assign(kBrotliHelloData, sizeof(kBrotliHelloData) - 1);
61 }
62
50 const MockTransaction kGZip_Transaction = { 63 const MockTransaction kGZip_Transaction = {
51 "http://www.google.com/gzyp", 64 "http://www.google.com/gzyp",
52 "GET", 65 "GET",
53 base::Time(), 66 base::Time(),
54 "", 67 "",
55 LOAD_NORMAL, 68 LOAD_NORMAL,
56 "HTTP/1.1 200 OK", 69 "HTTP/1.1 200 OK",
57 "Cache-Control: max-age=10000\n" 70 "Cache-Control: max-age=10000\n"
58 "Content-Encoding: gzip\n" 71 "Content-Encoding: gzip\n"
59 "Content-Length: 30\n", // Intentionally wrong. 72 "Content-Length: 30\n", // Intentionally wrong.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 base::Time(), 119 base::Time(),
107 "", 120 "",
108 TEST_MODE_NORMAL, 121 TEST_MODE_NORMAL,
109 nullptr, 122 nullptr,
110 nullptr, 123 nullptr,
111 0, 124 0,
112 0, 125 0,
113 OK, 126 OK,
114 }; 127 };
115 128
129 const MockTransaction kBrotli_Slow_Transaction = {
130 "http://www.google.com/brotli", "GET", base::Time(), "", LOAD_NORMAL,
131 "HTTP/1.1 200 OK",
132 "Cache-Control: max-age=10000\n"
133 "Content-Encoding: br\n",
134 base::Time(), "", TEST_MODE_SLOW_READ, &BrotliHelloServer, nullptr, 0, 0,
135 OK,
136 };
137
116 } // namespace 138 } // namespace
117 139
118 TEST(URLRequestJob, TransactionNotifiedWhenDone) { 140 TEST(URLRequestJob, TransactionNotifiedWhenDone) {
119 MockNetworkLayer network_layer; 141 MockNetworkLayer network_layer;
120 TestURLRequestContext context; 142 TestURLRequestContext context;
121 context.set_http_transaction_factory(&network_layer); 143 context.set_http_transaction_factory(&network_layer);
122 144
123 TestDelegate d; 145 TestDelegate d;
124 scoped_ptr<URLRequest> req( 146 scoped_ptr<URLRequest> req(
125 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); 147 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d));
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 base::MessageLoop::current()->Run(); 289 base::MessageLoop::current()->Run();
268 290
269 EXPECT_FALSE(d.request_failed()); 291 EXPECT_FALSE(d.request_failed());
270 EXPECT_EQ(200, req->GetResponseCode()); 292 EXPECT_EQ(200, req->GetResponseCode());
271 EXPECT_EQ("hello\n", d.data_received()); 293 EXPECT_EQ("hello\n", d.data_received());
272 EXPECT_TRUE(network_layer.done_reading_called()); 294 EXPECT_TRUE(network_layer.done_reading_called());
273 295
274 RemoveMockTransaction(&kGzip_Slow_Transaction); 296 RemoveMockTransaction(&kGzip_Slow_Transaction);
275 } 297 }
276 298
299 TEST(URLRequestJob, SlowBrotliRead) {
300 MockNetworkLayer network_layer;
301 TestURLRequestContext context;
302 context.set_http_transaction_factory(&network_layer);
303
304 TestDelegate d;
305 scoped_ptr<URLRequest> req(context.CreateRequest(
306 GURL(kBrotli_Slow_Transaction.url), DEFAULT_PRIORITY, &d));
307 AddMockTransaction(&kBrotli_Slow_Transaction);
308
309 req->set_method("GET");
310 req->Start();
311
312 base::RunLoop().RunUntilIdle();
313
314 EXPECT_FALSE(d.request_failed());
315 EXPECT_EQ(200, req->GetResponseCode());
316 EXPECT_EQ(kBrotliDecodedHelloData, d.data_received());
317 EXPECT_TRUE(network_layer.done_reading_called());
318
319 RemoveMockTransaction(&kBrotli_Slow_Transaction);
320 }
321
277 } // namespace net 322 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job_unittest.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698