| OLD | NEW |
| 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/message_loop.h" | 8 #include "base/message_loop.h" |
| 8 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 9 #include "chrome/browser/renderer_host/renderer_security_policy.h" | 10 #include "chrome/browser/renderer_host/renderer_security_policy.h" |
| 10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 11 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 11 #include "chrome/common/chrome_plugin_lib.h" | 12 #include "chrome/common/chrome_plugin_lib.h" |
| 12 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
| 13 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 14 #include "net/url_request/url_request_job.h" | 15 #include "net/url_request/url_request_job.h" |
| 15 #include "net/url_request/url_request_test_job.h" | 16 #include "net/url_request/url_request_test_job.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 // Add 33 bytes of upload content. | 526 // Add 33 bytes of upload content. |
| 526 std::string upload_content; | 527 std::string upload_content; |
| 527 upload_content.resize(33); | 528 upload_content.resize(33); |
| 528 std::fill(upload_content.begin(), upload_content.end(), 'x'); | 529 std::fill(upload_content.begin(), upload_content.end(), 'x'); |
| 529 req.AppendBytesToUpload(upload_content.data(), upload_content.size()); | 530 req.AppendBytesToUpload(upload_content.data(), upload_content.size()); |
| 530 | 531 |
| 531 // Since the upload throttling is disabled, this has no effect on the cost. | 532 // Since the upload throttling is disabled, this has no effect on the cost. |
| 532 EXPECT_EQ(4434, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); | 533 EXPECT_EQ(4434, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); |
| 533 | 534 |
| 534 // Add a file upload -- should have no effect. | 535 // Add a file upload -- should have no effect. |
| 535 req.AppendFileToUpload(L"does-not-exist.png"); | 536 req.AppendFileToUpload(FilePath(FILE_PATH_LITERAL("does-not-exist.png"))); |
| 536 EXPECT_EQ(4434, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); | 537 EXPECT_EQ(4434, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); |
| 537 } | 538 } |
| 538 | 539 |
| 539 // Test the private helper method "IncrementOutstandingRequestsMemoryCost()". | 540 // Test the private helper method "IncrementOutstandingRequestsMemoryCost()". |
| 540 TEST_F(ResourceDispatcherHostTest, IncrementOutstandingRequestsMemoryCost) { | 541 TEST_F(ResourceDispatcherHostTest, IncrementOutstandingRequestsMemoryCost) { |
| 541 ResourceDispatcherHost host(NULL); | 542 ResourceDispatcherHost host(NULL); |
| 542 | 543 |
| 543 // Add some counts for render_process_host=7 | 544 // Add some counts for render_process_host=7 |
| 544 EXPECT_EQ(0, host.GetOutstandingRequestsMemoryCost(7)); | 545 EXPECT_EQ(0, host.GetOutstandingRequestsMemoryCost(7)); |
| 545 EXPECT_EQ(1, host.IncrementOutstandingRequestsMemoryCost(1, 7)); | 546 EXPECT_EQ(1, host.IncrementOutstandingRequestsMemoryCost(1, 7)); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 EXPECT_EQ(URLRequestStatus::CANCELED, status.status()); | 643 EXPECT_EQ(URLRequestStatus::CANCELED, status.status()); |
| 643 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, status.os_error()); | 644 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, status.os_error()); |
| 644 } | 645 } |
| 645 | 646 |
| 646 // The final 2 requests should have succeeded. | 647 // The final 2 requests should have succeeded. |
| 647 CheckSuccessfulRequest(msgs[kMaxRequests + 2], | 648 CheckSuccessfulRequest(msgs[kMaxRequests + 2], |
| 648 URLRequestTestJob::test_data_2()); | 649 URLRequestTestJob::test_data_2()); |
| 649 CheckSuccessfulRequest(msgs[kMaxRequests + 3], | 650 CheckSuccessfulRequest(msgs[kMaxRequests + 3], |
| 650 URLRequestTestJob::test_data_2()); | 651 URLRequestTestJob::test_data_2()); |
| 651 } | 652 } |
| OLD | NEW |