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 "base/memory/scoped_ptr.h" |
7 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
8 #include "net/base/request_priority.h" | 9 #include "net/base/request_priority.h" |
9 #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" |
10 #include "net/url_request/url_request_test_util.h" | 12 #include "net/url_request/url_request_test_util.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 namespace net { | 15 namespace net { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 // This is a header that signals the end of the data. | 19 // This is a header that signals the end of the data. |
18 const char kGzipData[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"; | 20 const char kGzipData[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"; |
19 const char kGzipDataWithName[] = | 21 const char kGzipDataWithName[] = |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 }; | 73 }; |
72 | 74 |
73 } // namespace | 75 } // namespace |
74 | 76 |
75 TEST(URLRequestJob, TransactionNotifiedWhenDone) { | 77 TEST(URLRequestJob, TransactionNotifiedWhenDone) { |
76 MockNetworkLayer network_layer; | 78 MockNetworkLayer network_layer; |
77 TestURLRequestContext context; | 79 TestURLRequestContext context; |
78 context.set_http_transaction_factory(&network_layer); | 80 context.set_http_transaction_factory(&network_layer); |
79 | 81 |
80 TestDelegate d; | 82 TestDelegate d; |
81 TestURLRequest req( | 83 scoped_ptr<URLRequest> req(context.CreateRequest( |
82 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context); | 84 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, NULL)); |
83 AddMockTransaction(&kGZip_Transaction); | 85 AddMockTransaction(&kGZip_Transaction); |
84 | 86 |
85 req.set_method("GET"); | 87 req->set_method("GET"); |
86 req.Start(); | 88 req->Start(); |
87 | 89 |
88 base::MessageLoop::current()->Run(); | 90 base::MessageLoop::current()->Run(); |
89 | 91 |
90 EXPECT_TRUE(network_layer.done_reading_called()); | 92 EXPECT_TRUE(network_layer.done_reading_called()); |
91 | 93 |
92 RemoveMockTransaction(&kGZip_Transaction); | 94 RemoveMockTransaction(&kGZip_Transaction); |
93 } | 95 } |
94 | 96 |
95 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { | 97 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { |
96 MockNetworkLayer network_layer; | 98 MockNetworkLayer network_layer; |
97 TestURLRequestContext context; | 99 TestURLRequestContext context; |
98 context.set_http_transaction_factory(&network_layer); | 100 context.set_http_transaction_factory(&network_layer); |
99 | 101 |
100 TestDelegate d; | 102 TestDelegate d; |
101 TestURLRequest req( | 103 scoped_ptr<URLRequest> req(context.CreateRequest( |
102 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context); | 104 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, NULL)); |
103 MockTransaction transaction(kGZip_Transaction); | 105 MockTransaction transaction(kGZip_Transaction); |
104 transaction.test_mode = TEST_MODE_SYNC_ALL; | 106 transaction.test_mode = TEST_MODE_SYNC_ALL; |
105 AddMockTransaction(&transaction); | 107 AddMockTransaction(&transaction); |
106 | 108 |
107 req.set_method("GET"); | 109 req->set_method("GET"); |
108 req.Start(); | 110 req->Start(); |
109 | 111 |
110 base::RunLoop().Run(); | 112 base::RunLoop().Run(); |
111 | 113 |
112 EXPECT_TRUE(network_layer.done_reading_called()); | 114 EXPECT_TRUE(network_layer.done_reading_called()); |
113 | 115 |
114 RemoveMockTransaction(&transaction); | 116 RemoveMockTransaction(&transaction); |
115 } | 117 } |
116 | 118 |
117 // Tests processing a large gzip header one byte at a time. | 119 // Tests processing a large gzip header one byte at a time. |
118 TEST(URLRequestJob, SyncSlowTransaction) { | 120 TEST(URLRequestJob, SyncSlowTransaction) { |
119 MockNetworkLayer network_layer; | 121 MockNetworkLayer network_layer; |
120 TestURLRequestContext context; | 122 TestURLRequestContext context; |
121 context.set_http_transaction_factory(&network_layer); | 123 context.set_http_transaction_factory(&network_layer); |
122 | 124 |
123 TestDelegate d; | 125 TestDelegate d; |
124 TestURLRequest req( | 126 scoped_ptr<URLRequest> req(context.CreateRequest( |
125 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, &context); | 127 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, NULL)); |
126 MockTransaction transaction(kGZip_Transaction); | 128 MockTransaction transaction(kGZip_Transaction); |
127 transaction.test_mode = TEST_MODE_SYNC_ALL | TEST_MODE_SLOW_READ; | 129 transaction.test_mode = TEST_MODE_SYNC_ALL | TEST_MODE_SLOW_READ; |
128 transaction.handler = &BigGZipServer; | 130 transaction.handler = &BigGZipServer; |
129 AddMockTransaction(&transaction); | 131 AddMockTransaction(&transaction); |
130 | 132 |
131 req.set_method("GET"); | 133 req->set_method("GET"); |
132 req.Start(); | 134 req->Start(); |
133 | 135 |
134 base::RunLoop().Run(); | 136 base::RunLoop().Run(); |
135 | 137 |
136 EXPECT_TRUE(network_layer.done_reading_called()); | 138 EXPECT_TRUE(network_layer.done_reading_called()); |
137 | 139 |
138 RemoveMockTransaction(&transaction); | 140 RemoveMockTransaction(&transaction); |
139 } | 141 } |
140 | 142 |
141 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) { | 143 TEST(URLRequestJob, RedirectTransactionNotifiedWhenDone) { |
142 MockNetworkLayer network_layer; | 144 MockNetworkLayer network_layer; |
143 TestURLRequestContext context; | 145 TestURLRequestContext context; |
144 context.set_http_transaction_factory(&network_layer); | 146 context.set_http_transaction_factory(&network_layer); |
145 | 147 |
146 TestDelegate d; | 148 TestDelegate d; |
147 TestURLRequest req( | 149 scoped_ptr<URLRequest> req(context.CreateRequest( |
148 GURL(kRedirect_Transaction.url), DEFAULT_PRIORITY, &d, &context); | 150 GURL(kRedirect_Transaction.url), DEFAULT_PRIORITY, &d, NULL)); |
149 AddMockTransaction(&kRedirect_Transaction); | 151 AddMockTransaction(&kRedirect_Transaction); |
150 | 152 |
151 req.set_method("GET"); | 153 req->set_method("GET"); |
152 req.Start(); | 154 req->Start(); |
153 | 155 |
154 base::RunLoop().Run(); | 156 base::RunLoop().Run(); |
155 | 157 |
156 EXPECT_TRUE(network_layer.done_reading_called()); | 158 EXPECT_TRUE(network_layer.done_reading_called()); |
157 | 159 |
158 RemoveMockTransaction(&kRedirect_Transaction); | 160 RemoveMockTransaction(&kRedirect_Transaction); |
159 } | 161 } |
160 | 162 |
161 TEST(URLRequestJob, TransactionNotCachedWhenNetworkDelegateRedirects) { | 163 TEST(URLRequestJob, TransactionNotCachedWhenNetworkDelegateRedirects) { |
162 MockNetworkLayer network_layer; | 164 MockNetworkLayer network_layer; |
163 TestNetworkDelegate network_delegate; | 165 TestNetworkDelegate network_delegate; |
164 network_delegate.set_redirect_on_headers_received_url(GURL("http://foo")); | 166 network_delegate.set_redirect_on_headers_received_url(GURL("http://foo")); |
165 TestURLRequestContext context; | 167 TestURLRequestContext context; |
166 context.set_http_transaction_factory(&network_layer); | 168 context.set_http_transaction_factory(&network_layer); |
167 context.set_network_delegate(&network_delegate); | 169 context.set_network_delegate(&network_delegate); |
168 | 170 |
169 TestDelegate d; | 171 TestDelegate d; |
170 TestURLRequest req(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, | 172 scoped_ptr<URLRequest> req(context.CreateRequest( |
171 &context); | 173 GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d, NULL)); |
172 AddMockTransaction(&kGZip_Transaction); | 174 AddMockTransaction(&kGZip_Transaction); |
173 | 175 |
174 req.set_method("GET"); | 176 req->set_method("GET"); |
175 req.Start(); | 177 req->Start(); |
176 | 178 |
177 base::RunLoop().Run(); | 179 base::RunLoop().Run(); |
178 | 180 |
179 EXPECT_TRUE(network_layer.stop_caching_called()); | 181 EXPECT_TRUE(network_layer.stop_caching_called()); |
180 | 182 |
181 RemoveMockTransaction(&kGZip_Transaction); | 183 RemoveMockTransaction(&kGZip_Transaction); |
182 } | 184 } |
183 | 185 |
184 } // namespace net | 186 } // namespace net |
OLD | NEW |