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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1759 host_.CancelRequestsForProcess(filter_->child_id()); | 1759 host_.CancelRequestsForProcess(filter_->child_id()); |
1760 host_.CancelRequestsForProcess(second_filter->child_id()); | 1760 host_.CancelRequestsForProcess(second_filter->child_id()); |
1761 | 1761 |
1762 // Flush all the pending requests. | 1762 // Flush all the pending requests. |
1763 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1763 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1764 } | 1764 } |
1765 | 1765 |
1766 // Test the private helper method "CalculateApproximateMemoryCost()". | 1766 // Test the private helper method "CalculateApproximateMemoryCost()". |
1767 TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) { | 1767 TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) { |
1768 net::URLRequestContext context; | 1768 net::URLRequestContext context; |
1769 net::URLRequest req( | 1769 scoped_ptr<net::URLRequest> req(context.CreateRequest( |
1770 GURL("http://www.google.com"), net::DEFAULT_PRIORITY, NULL, &context); | 1770 GURL("http://www.google.com"), net::DEFAULT_PRIORITY, NULL, NULL)); |
1771 EXPECT_EQ(4427, | 1771 EXPECT_EQ( |
1772 ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(&req)); | 1772 4427, |
| 1773 ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(req.get())); |
1773 | 1774 |
1774 // Add 9 bytes of referrer. | 1775 // Add 9 bytes of referrer. |
1775 req.SetReferrer("123456789"); | 1776 req->SetReferrer("123456789"); |
1776 EXPECT_EQ(4436, | 1777 EXPECT_EQ( |
1777 ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(&req)); | 1778 4436, |
| 1779 ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(req.get())); |
1778 | 1780 |
1779 // Add 33 bytes of upload content. | 1781 // Add 33 bytes of upload content. |
1780 std::string upload_content; | 1782 std::string upload_content; |
1781 upload_content.resize(33); | 1783 upload_content.resize(33); |
1782 std::fill(upload_content.begin(), upload_content.end(), 'x'); | 1784 std::fill(upload_content.begin(), upload_content.end(), 'x'); |
1783 scoped_ptr<net::UploadElementReader> reader(new net::UploadBytesElementReader( | 1785 scoped_ptr<net::UploadElementReader> reader(new net::UploadBytesElementReader( |
1784 upload_content.data(), upload_content.size())); | 1786 upload_content.data(), upload_content.size())); |
1785 req.set_upload(make_scoped_ptr( | 1787 req->set_upload(make_scoped_ptr( |
1786 net::UploadDataStream::CreateWithReader(reader.Pass(), 0))); | 1788 net::UploadDataStream::CreateWithReader(reader.Pass(), 0))); |
1787 | 1789 |
1788 // Since the upload throttling is disabled, this has no effect on the cost. | 1790 // Since the upload throttling is disabled, this has no effect on the cost. |
1789 EXPECT_EQ(4436, | 1791 EXPECT_EQ( |
1790 ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(&req)); | 1792 4436, |
| 1793 ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(req.get())); |
1791 } | 1794 } |
1792 | 1795 |
1793 // Test that too much memory for outstanding requests for a particular | 1796 // Test that too much memory for outstanding requests for a particular |
1794 // render_process_host_id causes requests to fail. | 1797 // render_process_host_id causes requests to fail. |
1795 TEST_F(ResourceDispatcherHostTest, TooMuchOutstandingRequestsMemory) { | 1798 TEST_F(ResourceDispatcherHostTest, TooMuchOutstandingRequestsMemory) { |
1796 // Expected cost of each request as measured by | 1799 // Expected cost of each request as measured by |
1797 // ResourceDispatcherHost::CalculateApproximateMemoryCost(). | 1800 // ResourceDispatcherHost::CalculateApproximateMemoryCost(). |
1798 int kMemoryCostOfTest2Req = | 1801 int kMemoryCostOfTest2Req = |
1799 ResourceDispatcherHostImpl::kAvgBytesPerOutstandingRequest + | 1802 ResourceDispatcherHostImpl::kAvgBytesPerOutstandingRequest + |
1800 std::string("GET").size() + | 1803 std::string("GET").size() + |
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2921 } else { | 2924 } else { |
2922 return new net::URLRequestTestJob( | 2925 return new net::URLRequestTestJob( |
2923 request, network_delegate, | 2926 request, network_delegate, |
2924 test_fixture_->response_headers_, test_fixture_->response_data_, | 2927 test_fixture_->response_headers_, test_fixture_->response_data_, |
2925 false); | 2928 false); |
2926 } | 2929 } |
2927 } | 2930 } |
2928 } | 2931 } |
2929 | 2932 |
2930 } // namespace content | 2933 } // namespace content |
OLD | NEW |