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

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

Issue 2526983002: Refactor ResourceHandler API. (Closed)
Patch Set: Response to comments Created 3 years, 10 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) 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 <deque> 10 #include <deque>
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 redirect_ ? std::string(kRedirectHeaders, arraysize(kRedirectHeaders)) 261 redirect_ ? std::string(kRedirectHeaders, arraysize(kRedirectHeaders))
262 : net::URLRequestTestJob::test_headers(); 262 : net::URLRequestTestJob::test_headers();
263 return new MockHTTPSURLRequestJob(request, network_delegate, headers, 263 return new MockHTTPSURLRequestJob(request, network_delegate, headers,
264 "dummy response", true); 264 "dummy response", true);
265 } 265 }
266 266
267 private: 267 private:
268 bool redirect_; 268 bool redirect_;
269 }; 269 };
270 270
271 // Arbitrary read buffer size.
272 // Test browser client that captures calls to SelectClientCertificates and 271 // Test browser client that captures calls to SelectClientCertificates and
273 // records the arguments of the most recent call for later inspection. 272 // records the arguments of the most recent call for later inspection.
274 class SelectCertificateBrowserClient : public TestContentBrowserClient { 273 class SelectCertificateBrowserClient : public TestContentBrowserClient {
275 public: 274 public:
276 SelectCertificateBrowserClient() : call_count_(0) {} 275 SelectCertificateBrowserClient() : call_count_(0) {}
277 276
278 // Waits until the first call to SelectClientCertificate. 277 // Waits until the first call to SelectClientCertificate.
279 void WaitForSelectCertificate() { 278 void WaitForSelectCertificate() {
280 select_certificate_run_loop_.Run(); 279 select_certificate_run_loop_.Run();
281 // Process any pending messages - just so tests can check if 280 // Process any pending messages - just so tests can check if
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 net::URLRequestFailedJob::START, net::ERR_IO_PENDING)); 1381 net::URLRequestFailedJob::START, net::ERR_IO_PENDING));
1383 1382
1384 loader_->StartRequest(); 1383 loader_->StartRequest();
1385 base::RunLoop().RunUntilIdle(); 1384 base::RunLoop().RunUntilIdle();
1386 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called()); 1385 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called());
1387 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called()); 1386 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called());
1388 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_started_called()); 1387 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_started_called());
1389 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_completed_called()); 1388 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_completed_called());
1390 EXPECT_EQ(1, handle_external_protocol_); 1389 EXPECT_EQ(1, handle_external_protocol_);
1391 1390
1392 raw_ptr_resource_handler_->CancelWithError(net::ERR_FAILED); 1391 // Can't cancel through the ResourceHandler, since that depends on
1392 // ResourceDispatachHost, which these tests don't use.
1393 loader_->CancelRequest(false);
1393 raw_ptr_resource_handler_->WaitUntilResponseComplete(); 1394 raw_ptr_resource_handler_->WaitUntilResponseComplete();
1394 1395
1395 EXPECT_EQ(0, did_received_redirect_); 1396 EXPECT_EQ(0, did_received_redirect_);
1396 EXPECT_EQ(0, did_receive_response_); 1397 EXPECT_EQ(0, did_receive_response_);
1397 EXPECT_EQ(1, did_finish_loading_); 1398 EXPECT_EQ(1, did_finish_loading_);
1398 EXPECT_EQ(1, handle_external_protocol_); 1399 EXPECT_EQ(1, handle_external_protocol_);
1399 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called()); 1400 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called());
1400 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called()); 1401 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called());
1401 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_started_called()); 1402 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_started_called());
1402 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called()); 1403 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called());
1403 EXPECT_EQ(net::ERR_FAILED, raw_ptr_resource_handler_->final_status().error()); 1404 EXPECT_EQ(net::ERR_ABORTED,
1405 raw_ptr_resource_handler_->final_status().error());
1404 EXPECT_EQ("", raw_ptr_resource_handler_->body()); 1406 EXPECT_EQ("", raw_ptr_resource_handler_->body());
1405 } 1407 }
1406 1408
1407 TEST_F(ResourceLoaderTest, OutOfBandCancelDuringRead) { 1409 TEST_F(ResourceLoaderTest, OutOfBandCancelDuringRead) {
1408 SetUpResourceLoaderForUrl( 1410 SetUpResourceLoaderForUrl(
1409 net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase( 1411 net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase(
1410 net::URLRequestFailedJob::READ_SYNC, net::ERR_IO_PENDING)); 1412 net::URLRequestFailedJob::READ_SYNC, net::ERR_IO_PENDING));
1411 1413
1412 loader_->StartRequest(); 1414 loader_->StartRequest();
1413 base::RunLoop().RunUntilIdle(); 1415 base::RunLoop().RunUntilIdle();
1414 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called()); 1416 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called());
1415 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called()); 1417 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called());
1416 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_started_called()); 1418 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_started_called());
1417 EXPECT_EQ(0, raw_ptr_resource_handler_->on_read_completed_called()); 1419 EXPECT_EQ(0, raw_ptr_resource_handler_->on_read_completed_called());
1418 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_completed_called()); 1420 EXPECT_EQ(0, raw_ptr_resource_handler_->on_response_completed_called());
1419 EXPECT_EQ(1, handle_external_protocol_); 1421 EXPECT_EQ(1, handle_external_protocol_);
1420 1422
1421 raw_ptr_resource_handler_->CancelWithError(net::ERR_FAILED); 1423 // Can't cancel through the ResourceHandler, since that depends on
1424 // ResourceDispatachHost, which these tests don't use.
1425 loader_->CancelRequest(false);
1422 raw_ptr_resource_handler_->WaitUntilResponseComplete(); 1426 raw_ptr_resource_handler_->WaitUntilResponseComplete();
1423 EXPECT_EQ(0, did_received_redirect_); 1427 EXPECT_EQ(0, did_received_redirect_);
1424 EXPECT_EQ(1, did_receive_response_); 1428 EXPECT_EQ(1, did_receive_response_);
1425 EXPECT_EQ(1, did_finish_loading_); 1429 EXPECT_EQ(1, did_finish_loading_);
1426 EXPECT_EQ(1, handle_external_protocol_); 1430 EXPECT_EQ(1, handle_external_protocol_);
1427 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called()); 1431 EXPECT_EQ(1, raw_ptr_resource_handler_->on_will_start_called());
1428 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called()); 1432 EXPECT_EQ(0, raw_ptr_resource_handler_->on_request_redirected_called());
1429 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_started_called()); 1433 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_started_called());
1430 EXPECT_EQ(0, raw_ptr_resource_handler_->on_read_completed_called()); 1434 EXPECT_EQ(0, raw_ptr_resource_handler_->on_read_completed_called());
1431 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called()); 1435 EXPECT_EQ(1, raw_ptr_resource_handler_->on_response_completed_called());
1432 EXPECT_EQ(net::ERR_FAILED, raw_ptr_resource_handler_->final_status().error()); 1436 EXPECT_EQ(net::ERR_ABORTED,
1437 raw_ptr_resource_handler_->final_status().error());
1433 EXPECT_EQ("", raw_ptr_resource_handler_->body()); 1438 EXPECT_EQ("", raw_ptr_resource_handler_->body());
1434 } 1439 }
1435 1440
1436 TEST_F(ResourceLoaderTest, ResumeCanceledRequest) { 1441 TEST_F(ResourceLoaderTest, ResumeCanceledRequest) {
1437 raw_ptr_resource_handler_->set_defer_on_will_start(true); 1442 raw_ptr_resource_handler_->set_defer_on_will_start(true);
1438 1443
1439 loader_->StartRequest(); 1444 loader_->StartRequest();
1445 raw_ptr_resource_handler_->WaitUntilDeferred();
1440 loader_->CancelRequest(true); 1446 loader_->CancelRequest(true);
1441 static_cast<ResourceController*>(loader_.get())->Resume(); 1447 raw_ptr_resource_handler_->Resume();
1442 } 1448 }
1443 1449
1444 class ResourceLoaderRedirectToFileTest : public ResourceLoaderTest { 1450 class ResourceLoaderRedirectToFileTest : public ResourceLoaderTest {
1445 public: 1451 public:
1446 ResourceLoaderRedirectToFileTest() 1452 ResourceLoaderRedirectToFileTest()
1447 : file_stream_(NULL), 1453 : file_stream_(NULL),
1448 redirect_to_file_resource_handler_(NULL) { 1454 redirect_to_file_resource_handler_(NULL) {
1449 } 1455 }
1450 1456
1451 ~ResourceLoaderRedirectToFileTest() override { 1457 ~ResourceLoaderRedirectToFileTest() override {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 1725
1720 // Tests that the effective connection type is not set on non-main frame 1726 // Tests that the effective connection type is not set on non-main frame
1721 // requests. 1727 // requests.
1722 TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) { 1728 TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) {
1723 VerifyEffectiveConnectionType(RESOURCE_TYPE_OBJECT, false, 1729 VerifyEffectiveConnectionType(RESOURCE_TYPE_OBJECT, false,
1724 net::EFFECTIVE_CONNECTION_TYPE_3G, 1730 net::EFFECTIVE_CONNECTION_TYPE_3G,
1725 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN); 1731 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
1726 } 1732 }
1727 1733
1728 } // namespace content 1734 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698