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

Side by Side Diff: chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc

Issue 149287: Fix the unit tests that had multiple ResourceDispatcherHost objects instantia... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <vector> 5 #include <vector>
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "chrome/browser/child_process_security_policy.h" 10 #include "chrome/browser/child_process_security_policy.h"
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 ASSERT_EQ(3U, msgs.size()); 247 ASSERT_EQ(3U, msgs.size());
248 248
249 CheckSuccessfulRequest(msgs[0], URLRequestTestJob::test_data_1()); 249 CheckSuccessfulRequest(msgs[0], URLRequestTestJob::test_data_1());
250 CheckSuccessfulRequest(msgs[1], URLRequestTestJob::test_data_2()); 250 CheckSuccessfulRequest(msgs[1], URLRequestTestJob::test_data_2());
251 CheckSuccessfulRequest(msgs[2], URLRequestTestJob::test_data_3()); 251 CheckSuccessfulRequest(msgs[2], URLRequestTestJob::test_data_3());
252 } 252 }
253 253
254 // Tests whether messages get canceled properly. We issue three requests, 254 // Tests whether messages get canceled properly. We issue three requests,
255 // cancel one of them, and make sure that each sent the proper notifications. 255 // cancel one of them, and make sure that each sent the proper notifications.
256 TEST_F(ResourceDispatcherHostTest, Cancel) { 256 TEST_F(ResourceDispatcherHostTest, Cancel) {
257 ResourceDispatcherHost host(NULL);
258
259 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); 257 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0));
260 258
261 MakeTestRequest(0, 0, 1, URLRequestTestJob::test_url_1()); 259 MakeTestRequest(0, 0, 1, URLRequestTestJob::test_url_1());
262 MakeTestRequest(0, 0, 2, URLRequestTestJob::test_url_2()); 260 MakeTestRequest(0, 0, 2, URLRequestTestJob::test_url_2());
263 MakeTestRequest(0, 0, 3, URLRequestTestJob::test_url_3()); 261 MakeTestRequest(0, 0, 3, URLRequestTestJob::test_url_3());
264 MakeCancelRequest(2); 262 MakeCancelRequest(2);
265 263
266 // flush all the pending requests 264 // flush all the pending requests
267 while (URLRequestTestJob::ProcessOnePendingMessage()); 265 while (URLRequestTestJob::ProcessOnePendingMessage());
268 MessageLoop::current()->RunAllPending(); 266 MessageLoop::current()->RunAllPending();
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // Since the upload throttling is disabled, this has no effect on the cost. 533 // Since the upload throttling is disabled, this has no effect on the cost.
536 EXPECT_EQ(4434, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); 534 EXPECT_EQ(4434, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req));
537 535
538 // Add a file upload -- should have no effect. 536 // Add a file upload -- should have no effect.
539 req.AppendFileToUpload(FilePath(FILE_PATH_LITERAL("does-not-exist.png"))); 537 req.AppendFileToUpload(FilePath(FILE_PATH_LITERAL("does-not-exist.png")));
540 EXPECT_EQ(4434, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); 538 EXPECT_EQ(4434, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req));
541 } 539 }
542 540
543 // Test the private helper method "IncrementOutstandingRequestsMemoryCost()". 541 // Test the private helper method "IncrementOutstandingRequestsMemoryCost()".
544 TEST_F(ResourceDispatcherHostTest, IncrementOutstandingRequestsMemoryCost) { 542 TEST_F(ResourceDispatcherHostTest, IncrementOutstandingRequestsMemoryCost) {
545 ResourceDispatcherHost host(NULL);
546
547 // Add some counts for render_process_host=7 543 // Add some counts for render_process_host=7
548 EXPECT_EQ(0, host.GetOutstandingRequestsMemoryCost(7)); 544 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(7));
549 EXPECT_EQ(1, host.IncrementOutstandingRequestsMemoryCost(1, 7)); 545 EXPECT_EQ(1, host_.IncrementOutstandingRequestsMemoryCost(1, 7));
550 EXPECT_EQ(2, host.IncrementOutstandingRequestsMemoryCost(1, 7)); 546 EXPECT_EQ(2, host_.IncrementOutstandingRequestsMemoryCost(1, 7));
551 EXPECT_EQ(3, host.IncrementOutstandingRequestsMemoryCost(1, 7)); 547 EXPECT_EQ(3, host_.IncrementOutstandingRequestsMemoryCost(1, 7));
552 548
553 // Add some counts for render_process_host=3 549 // Add some counts for render_process_host=3
554 EXPECT_EQ(0, host.GetOutstandingRequestsMemoryCost(3)); 550 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(3));
555 EXPECT_EQ(1, host.IncrementOutstandingRequestsMemoryCost(1, 3)); 551 EXPECT_EQ(1, host_.IncrementOutstandingRequestsMemoryCost(1, 3));
556 EXPECT_EQ(2, host.IncrementOutstandingRequestsMemoryCost(1, 3)); 552 EXPECT_EQ(2, host_.IncrementOutstandingRequestsMemoryCost(1, 3));
557 553
558 // Remove all the counts for render_process_host=7 554 // Remove all the counts for render_process_host=7
559 EXPECT_EQ(3, host.GetOutstandingRequestsMemoryCost(7)); 555 EXPECT_EQ(3, host_.GetOutstandingRequestsMemoryCost(7));
560 EXPECT_EQ(2, host.IncrementOutstandingRequestsMemoryCost(-1, 7)); 556 EXPECT_EQ(2, host_.IncrementOutstandingRequestsMemoryCost(-1, 7));
561 EXPECT_EQ(1, host.IncrementOutstandingRequestsMemoryCost(-1, 7)); 557 EXPECT_EQ(1, host_.IncrementOutstandingRequestsMemoryCost(-1, 7));
562 EXPECT_EQ(0, host.IncrementOutstandingRequestsMemoryCost(-1, 7)); 558 EXPECT_EQ(0, host_.IncrementOutstandingRequestsMemoryCost(-1, 7));
563 EXPECT_EQ(0, host.GetOutstandingRequestsMemoryCost(7)); 559 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(7));
564 560
565 // Remove all the counts for render_process_host=3 561 // Remove all the counts for render_process_host=3
566 EXPECT_EQ(2, host.GetOutstandingRequestsMemoryCost(3)); 562 EXPECT_EQ(2, host_.GetOutstandingRequestsMemoryCost(3));
567 EXPECT_EQ(1, host.IncrementOutstandingRequestsMemoryCost(-1, 3)); 563 EXPECT_EQ(1, host_.IncrementOutstandingRequestsMemoryCost(-1, 3));
568 EXPECT_EQ(0, host.IncrementOutstandingRequestsMemoryCost(-1, 3)); 564 EXPECT_EQ(0, host_.IncrementOutstandingRequestsMemoryCost(-1, 3));
569 EXPECT_EQ(0, host.GetOutstandingRequestsMemoryCost(3)); 565 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(3));
570 566
571 // When an entry reaches 0, it should be deleted. 567 // When an entry reaches 0, it should be deleted.
572 EXPECT_TRUE(host.outstanding_requests_memory_cost_map_.end() == 568 EXPECT_TRUE(host_.outstanding_requests_memory_cost_map_.end() ==
573 host.outstanding_requests_memory_cost_map_.find(7)); 569 host_.outstanding_requests_memory_cost_map_.find(7));
574 EXPECT_TRUE(host.outstanding_requests_memory_cost_map_.end() == 570 EXPECT_TRUE(host_.outstanding_requests_memory_cost_map_.end() ==
575 host.outstanding_requests_memory_cost_map_.find(3)); 571 host_.outstanding_requests_memory_cost_map_.find(3));
576 } 572 }
577 573
578 // Test that when too many requests are outstanding for a particular 574 // Test that when too many requests are outstanding for a particular
579 // render_process_host_id, any subsequent request from it fails. 575 // render_process_host_id, any subsequent request from it fails.
580 TEST_F(ResourceDispatcherHostTest, TooManyOutstandingRequests) { 576 TEST_F(ResourceDispatcherHostTest, TooManyOutstandingRequests) {
581 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); 577 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0));
582 578
583 // Expected cost of each request as measured by 579 // Expected cost of each request as measured by
584 // ResourceDispatcherHost::CalculateApproximateMemoryCost(). 580 // ResourceDispatcherHost::CalculateApproximateMemoryCost().
585 int kMemoryCostOfTest2Req = 581 int kMemoryCostOfTest2Req =
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 EXPECT_EQ(URLRequestStatus::CANCELED, status.status()); 642 EXPECT_EQ(URLRequestStatus::CANCELED, status.status());
647 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, status.os_error()); 643 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, status.os_error());
648 } 644 }
649 645
650 // The final 2 requests should have succeeded. 646 // The final 2 requests should have succeeded.
651 CheckSuccessfulRequest(msgs[kMaxRequests + 2], 647 CheckSuccessfulRequest(msgs[kMaxRequests + 2],
652 URLRequestTestJob::test_data_2()); 648 URLRequestTestJob::test_data_2());
653 CheckSuccessfulRequest(msgs[kMaxRequests + 3], 649 CheckSuccessfulRequest(msgs[kMaxRequests + 3],
654 URLRequestTestJob::test_data_2()); 650 URLRequestTestJob::test_data_2());
655 } 651 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698