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

Side by Side Diff: content/browser/loader/resource_loader_unittest.cc

Issue 2526983002: Refactor ResourceHandler API. (Closed)
Patch Set: Fix merge again (?) Created 4 years 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/browser/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 redirect_ ? std::string(kRedirectHeaders, arraysize(kRedirectHeaders)) 259 redirect_ ? std::string(kRedirectHeaders, arraysize(kRedirectHeaders))
260 : net::URLRequestTestJob::test_headers(); 260 : net::URLRequestTestJob::test_headers();
261 return new MockHTTPSURLRequestJob(request, network_delegate, headers, 261 return new MockHTTPSURLRequestJob(request, network_delegate, headers,
262 "dummy response", true); 262 "dummy response", true);
263 } 263 }
264 264
265 private: 265 private:
266 bool redirect_; 266 bool redirect_;
267 }; 267 };
268 268
269 // Arbitrary read buffer size.
270 // Test browser client that captures calls to SelectClientCertificates and 269 // Test browser client that captures calls to SelectClientCertificates and
271 // records the arguments of the most recent call for later inspection. 270 // records the arguments of the most recent call for later inspection.
272 class SelectCertificateBrowserClient : public TestContentBrowserClient { 271 class SelectCertificateBrowserClient : public TestContentBrowserClient {
273 public: 272 public:
274 SelectCertificateBrowserClient() : call_count_(0) {} 273 SelectCertificateBrowserClient() : call_count_(0) {}
275 274
276 // Waits until the first call to SelectClientCertificate. 275 // Waits until the first call to SelectClientCertificate.
277 void WaitForSelectCertificate() { 276 void WaitForSelectCertificate() {
278 select_certificate_run_loop_.Run(); 277 select_certificate_run_loop_.Run();
279 // Process any pending messages - just so tests can check if 278 // Process any pending messages - just so tests can check if
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase( 1267 net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase(
1269 net::URLRequestFailedJob::START, net::ERR_IO_PENDING)); 1268 net::URLRequestFailedJob::START, net::ERR_IO_PENDING));
1270 1269
1271 loader_->StartRequest(); 1270 loader_->StartRequest();
1272 base::RunLoop().RunUntilIdle(); 1271 base::RunLoop().RunUntilIdle();
1273 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called()); 1272 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called());
1274 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called()); 1273 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called());
1275 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_started_called()); 1274 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_started_called());
1276 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_completed_called()); 1275 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_completed_called());
1277 1276
1278 raw_ptr_resource_handler_->CancelWithError(net::ERR_FAILED); 1277 // Can't cancel through the ResourceHandler, since that depends on
1278 // ResourceDispatachHost, which these tests don't use.
1279 loader_->CancelRequest(false);
1279 raw_ptr_resource_handler_->WaitUntilResponseComplete(); 1280 raw_ptr_resource_handler_->WaitUntilResponseComplete();
1280 1281
1281 EXPECT_EQ(0, did_received_redirect_); 1282 EXPECT_EQ(0, did_received_redirect_);
1282 EXPECT_EQ(0, did_receive_response_); 1283 EXPECT_EQ(0, did_receive_response_);
1283 EXPECT_EQ(1, did_finish_loading_); 1284 EXPECT_EQ(1, did_finish_loading_);
1284 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called()); 1285 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called());
1285 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called()); 1286 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called());
1286 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_started_called()); 1287 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_started_called());
1287 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called()); 1288 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called());
1288 EXPECT_EQ(net::ERR_FAILED, raw_ptr_resource_handler_->final_status().error()); 1289 EXPECT_EQ(net::ERR_ABORTED,
1290 raw_ptr_resource_handler_->final_status().error());
1289 EXPECT_EQ("", raw_ptr_resource_handler_->body()); 1291 EXPECT_EQ("", raw_ptr_resource_handler_->body());
1290 } 1292 }
1291 1293
1292 TEST_F(ResourceLoaderTest, OutOfBandCancelDuringRead) { 1294 TEST_F(ResourceLoaderTest, OutOfBandCancelDuringRead) {
1293 SetUpResourceLoaderForUrl( 1295 SetUpResourceLoaderForUrl(
1294 net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase( 1296 net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase(
1295 net::URLRequestFailedJob::READ_SYNC, net::ERR_IO_PENDING)); 1297 net::URLRequestFailedJob::READ_SYNC, net::ERR_IO_PENDING));
1296 1298
1297 loader_->StartRequest(); 1299 loader_->StartRequest();
1298 base::RunLoop().RunUntilIdle(); 1300 base::RunLoop().RunUntilIdle();
1299 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called()); 1301 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called());
1300 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called()); 1302 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called());
1301 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_started_called()); 1303 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_started_called());
1302 EXPECT_EQ(0, raw_ptr_resource_handler_->on_read_completed_called()); 1304 EXPECT_EQ(0, raw_ptr_resource_handler_->on_read_completed_called());
1303 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_completed_called()); 1305 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_completed_called());
1304 1306
1305 raw_ptr_resource_handler_->CancelWithError(net::ERR_FAILED); 1307 // Can't cancel through the ResourceHandler, since that depends on
1308 // ResourceDispatachHost, which these tests don't use.
1309 loader_->CancelRequest(false);
1306 raw_ptr_resource_handler_->WaitUntilResponseComplete(); 1310 raw_ptr_resource_handler_->WaitUntilResponseComplete();
1307 EXPECT_EQ(0, did_received_redirect_); 1311 EXPECT_EQ(0, did_received_redirect_);
1308 EXPECT_EQ(1, did_receive_response_); 1312 EXPECT_EQ(1, did_receive_response_);
1309 EXPECT_EQ(1, did_finish_loading_); 1313 EXPECT_EQ(1, did_finish_loading_);
1310 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called()); 1314 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called());
1311 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called()); 1315 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called());
1312 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_started_called()); 1316 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_started_called());
1313 EXPECT_EQ(0, raw_ptr_resource_handler_->on_read_completed_called()); 1317 EXPECT_EQ(0, raw_ptr_resource_handler_->on_read_completed_called());
1314 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called()); 1318 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called());
1315 EXPECT_EQ(net::ERR_FAILED, raw_ptr_resource_handler_->final_status().error()); 1319 EXPECT_EQ(net::ERR_ABORTED,
1320 raw_ptr_resource_handler_->final_status().error());
1316 EXPECT_EQ("", raw_ptr_resource_handler_->body()); 1321 EXPECT_EQ("", raw_ptr_resource_handler_->body());
1317 } 1322 }
1318 1323
1319 TEST_F(ResourceLoaderTest, ResumeCanceledRequest) { 1324 TEST_F(ResourceLoaderTest, ResumeCanceledRequest) {
1320 raw_ptr_resource_handler_->set_defer_on_will_start(true); 1325 raw_ptr_resource_handler_->set_defer_on_will_start(true);
1321 1326
1322 loader_->StartRequest(); 1327 loader_->StartRequest();
1328 raw_ptr_resource_handler_->WaitUntilDeferred();
1323 loader_->CancelRequest(true); 1329 loader_->CancelRequest(true);
1324 static_cast<ResourceController*>(loader_.get())->Resume(); 1330 raw_ptr_resource_handler_->Resume();
1325 } 1331 }
1326 1332
1327 class ResourceLoaderRedirectToFileTest : public ResourceLoaderTest { 1333 class ResourceLoaderRedirectToFileTest : public ResourceLoaderTest {
1328 public: 1334 public:
1329 ResourceLoaderRedirectToFileTest() 1335 ResourceLoaderRedirectToFileTest()
1330 : file_stream_(NULL), 1336 : file_stream_(NULL),
1331 redirect_to_file_resource_handler_(NULL) { 1337 redirect_to_file_resource_handler_(NULL) {
1332 } 1338 }
1333 1339
1334 ~ResourceLoaderRedirectToFileTest() override { 1340 ~ResourceLoaderRedirectToFileTest() override {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 1608
1603 // Tests that the effective connection type is not set on non-main frame 1609 // Tests that the effective connection type is not set on non-main frame
1604 // requests. 1610 // requests.
1605 TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) { 1611 TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) {
1606 VerifyEffectiveConnectionType(RESOURCE_TYPE_OBJECT, false, 1612 VerifyEffectiveConnectionType(RESOURCE_TYPE_OBJECT, false,
1607 net::EFFECTIVE_CONNECTION_TYPE_3G, 1613 net::EFFECTIVE_CONNECTION_TYPE_3G,
1608 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN); 1614 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
1609 } 1615 }
1610 1616
1611 } // namespace content 1617 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698