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