OLD | NEW |
---|---|
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 "net/base/request_priority.h" | |
7 #include "net/http/http_transaction_unittest.h" | 8 #include "net/http/http_transaction_unittest.h" |
8 #include "net/url_request/url_request_test_util.h" | 9 #include "net/url_request/url_request_test_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
12 namespace net { | |
13 | |
11 namespace { | 14 namespace { |
12 | 15 |
13 // This is a header that signals the end of the data. | 16 // This is a header that signals the end of the data. |
14 const char kGzipGata[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"; | 17 const char kGzipGata[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"; |
15 | 18 |
16 void GZipServer(const net::HttpRequestInfo* request, | 19 void GZipServer(const HttpRequestInfo* request, |
17 std::string* response_status, std::string* response_headers, | 20 std::string* response_status, |
21 std::string* response_headers, | |
18 std::string* response_data) { | 22 std::string* response_data) { |
19 response_data->assign(kGzipGata, sizeof(kGzipGata)); | 23 response_data->assign(kGzipGata, sizeof(kGzipGata)); |
20 } | 24 } |
21 | 25 |
22 const MockTransaction kGZip_Transaction = { | 26 const MockTransaction kGZip_Transaction = { |
23 "http://www.google.com/gzyp", | 27 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL, |
24 "GET", | 28 "HTTP/1.1 200 OK", |
25 base::Time(), | 29 "Cache-Control: max-age=10000\n" |
26 "", | 30 "Content-Encoding: gzip\n" |
27 net::LOAD_NORMAL, | 31 "Content-Length: 30\n", // Intentionally wrong. |
28 "HTTP/1.1 200 OK", | 32 base::Time(), |
29 "Cache-Control: max-age=10000\n" | 33 "", TEST_MODE_NORMAL, &GZipServer, 0, OK}; |
mmenke
2013/10/31 15:23:43
Probably best to keep the old format here and belo
akalin
2013/10/31 20:02:02
Done.
| |
30 "Content-Encoding: gzip\n" | |
31 "Content-Length: 30\n", // Intentionally wrong. | |
32 base::Time(), | |
33 "", | |
34 TEST_MODE_NORMAL, | |
35 &GZipServer, | |
36 0, | |
37 net::OK | |
38 }; | |
39 | 34 |
40 const MockTransaction kRedirect_Transaction = { | 35 const MockTransaction kRedirect_Transaction = { |
41 "http://www.google.com/redirect", | 36 "http://www.google.com/redirect", "GET", base::Time(), "", LOAD_NORMAL, |
42 "GET", | 37 "HTTP/1.1 302 Found", |
43 base::Time(), | 38 "Cache-Control: max-age=10000\n" |
44 "", | 39 "Location: http://www.google.com/destination\n" |
45 net::LOAD_NORMAL, | 40 "Content-Length: 5\n", |
46 "HTTP/1.1 302 Found", | 41 base::Time(), "hello", TEST_MODE_NORMAL, NULL, 0, OK}; |
47 "Cache-Control: max-age=10000\n" | |
48 "Location: http://www.google.com/destination\n" | |
49 "Content-Length: 5\n", | |
50 base::Time(), | |
51 "hello", | |
52 TEST_MODE_NORMAL, | |
53 NULL, | |
54 0, | |
55 net::OK | |
56 }; | |
57 | 42 |
58 } // namespace | 43 } // namespace |
59 | 44 |
60 TEST(URLRequestJob, TransactionNotifiedWhenDone) { | 45 TEST(URLRequestJob, TransactionNotifiedWhenDone) { |
61 MockNetworkLayer network_layer; | 46 MockNetworkLayer network_layer; |
62 net::TestURLRequestContext context; | 47 TestURLRequestContext context; |
63 context.set_http_transaction_factory(&network_layer); | 48 context.set_http_transaction_factory(&network_layer); |
64 | 49 |
65 net::TestDelegate d; | 50 TestDelegate d; |
66 net::TestURLRequest req(GURL(kGZip_Transaction.url), &d, &context, NULL); | 51 TestURLRequest req( |
52 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context); | |
67 AddMockTransaction(&kGZip_Transaction); | 53 AddMockTransaction(&kGZip_Transaction); |
68 | 54 |
69 req.set_method("GET"); | 55 req.set_method("GET"); |
70 req.Start(); | 56 req.Start(); |
71 | 57 |
72 base::MessageLoop::current()->Run(); | 58 base::MessageLoop::current()->Run(); |
73 | 59 |
74 EXPECT_TRUE(network_layer.done_reading_called()); | 60 EXPECT_TRUE(network_layer.done_reading_called()); |
75 | 61 |
76 RemoveMockTransaction(&kGZip_Transaction); | 62 RemoveMockTransaction(&kGZip_Transaction); |
77 } | 63 } |
78 | 64 |
79 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { | 65 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { |
80 MockNetworkLayer network_layer; | 66 MockNetworkLayer network_layer; |
81 net::TestURLRequestContext context; | 67 TestURLRequestContext context; |
82 context.set_http_transaction_factory(&network_layer); | 68 context.set_http_transaction_factory(&network_layer); |
83 | 69 |
84 net::TestDelegate d; | 70 TestDelegate d; |
85 net::TestURLRequest req(GURL(kGZip_Transaction.url), &d, &context, NULL); | 71 TestURLRequest req( |
72 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context); | |
86 MockTransaction transaction(kGZip_Transaction); | 73 MockTransaction transaction(kGZip_Transaction); |
87 transaction.test_mode = TEST_MODE_SYNC_ALL; | 74 transaction.test_mode = TEST_MODE_SYNC_ALL; |
88 AddMockTransaction(&transaction); | 75 AddMockTransaction(&transaction); |
89 | 76 |
90 req.set_method("GET"); | 77 req.set_method("GET"); |
91 req.Start(); | 78 req.Start(); |
92 | 79 |
93 base::MessageLoop::current()->Run(); | 80 base::MessageLoop::current()->Run(); |
94 | 81 |
95 EXPECT_TRUE(network_layer.done_reading_called()); | 82 EXPECT_TRUE(network_layer.done_reading_called()); |
96 | 83 |
97 RemoveMockTransaction(&transaction); | 84 RemoveMockTransaction(&transaction); |
98 } | 85 } |
99 | 86 |
100 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) { | 87 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) { |
101 MockNetworkLayer network_layer; | 88 MockNetworkLayer network_layer; |
102 net::TestURLRequestContext context; | 89 TestURLRequestContext context; |
103 context.set_http_transaction_factory(&network_layer); | 90 context.set_http_transaction_factory(&network_layer); |
104 | 91 |
105 net::TestDelegate d; | 92 TestDelegate d; |
106 net::TestURLRequest req(GURL(kRedirect_Transaction.url), &d, &context, NULL); | 93 TestURLRequest req( |
94 GURL(kRedirect_Transaction.url), DEFAULT_PRIORITY, &d, &context); | |
107 AddMockTransaction(&kRedirect_Transaction); | 95 AddMockTransaction(&kRedirect_Transaction); |
108 | 96 |
109 req.set_method("GET"); | 97 req.set_method("GET"); |
110 req.Start(); | 98 req.Start(); |
111 | 99 |
112 base::MessageLoop::current()->Run(); | 100 base::MessageLoop::current()->Run(); |
113 | 101 |
114 EXPECT_TRUE(network_layer.done_reading_called()); | 102 EXPECT_TRUE(network_layer.done_reading_called()); |
115 | 103 |
116 RemoveMockTransaction(&kRedirect_Transaction); | 104 RemoveMockTransaction(&kRedirect_Transaction); |
117 } | 105 } |
106 | |
107 } // namespace net | |
OLD | NEW |