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

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

Issue 2503713004: Avoid string copies when determining approximate memory usage in RDHI (Closed)
Patch Set: rdsmith review and fix unit tests Created 4 years, 1 month 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
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.cc ('k') | 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) 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 2187
2188 // Flush all the pending requests. 2188 // Flush all the pending requests.
2189 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2189 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2190 } 2190 }
2191 2191
2192 // Test the private helper method "CalculateApproximateMemoryCost()". 2192 // Test the private helper method "CalculateApproximateMemoryCost()".
2193 TEST_P(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) { 2193 TEST_P(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) {
2194 net::URLRequestContext context; 2194 net::URLRequestContext context;
2195 std::unique_ptr<net::URLRequest> req(context.CreateRequest( 2195 std::unique_ptr<net::URLRequest> req(context.CreateRequest(
2196 GURL("http://www.google.com"), net::DEFAULT_PRIORITY, NULL)); 2196 GURL("http://www.google.com"), net::DEFAULT_PRIORITY, NULL));
2197 EXPECT_EQ( 2197 EXPECT_EQ(4425, ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(
2198 4427, 2198 req.get()));
2199 ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(req.get()));
2200 2199
2201 // Add 9 bytes of referrer. 2200 // Add 9 bytes of referrer.
2202 req->SetReferrer("123456789"); 2201 req->SetReferrer("123456789");
2203 EXPECT_EQ( 2202 EXPECT_EQ(4434, ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(
2204 4436, 2203 req.get()));
2205 ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(req.get()));
2206 2204
2207 // Add 33 bytes of upload content. 2205 // Add 33 bytes of upload content.
2208 std::string upload_content; 2206 std::string upload_content;
2209 upload_content.resize(33); 2207 upload_content.resize(33);
2210 std::fill(upload_content.begin(), upload_content.end(), 'x'); 2208 std::fill(upload_content.begin(), upload_content.end(), 'x');
2211 std::unique_ptr<net::UploadElementReader> reader( 2209 std::unique_ptr<net::UploadElementReader> reader(
2212 new net::UploadBytesElementReader(upload_content.data(), 2210 new net::UploadBytesElementReader(upload_content.data(),
2213 upload_content.size())); 2211 upload_content.size()));
2214 req->set_upload( 2212 req->set_upload(
2215 net::ElementsUploadDataStream::CreateWithReader(std::move(reader), 0)); 2213 net::ElementsUploadDataStream::CreateWithReader(std::move(reader), 0));
2216 2214
2217 // Since the upload throttling is disabled, this has no effect on the cost. 2215 // Since the upload throttling is disabled, this has no effect on the cost.
2218 EXPECT_EQ( 2216 EXPECT_EQ(4434, ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(
2219 4436, 2217 req.get()));
2220 ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(req.get()));
2221 } 2218 }
2222 2219
2223 // Test that too much memory for outstanding requests for a particular 2220 // Test that too much memory for outstanding requests for a particular
2224 // render_process_host_id causes requests to fail. 2221 // render_process_host_id causes requests to fail.
2225 TEST_P(ResourceDispatcherHostTest, TooMuchOutstandingRequestsMemory) { 2222 TEST_P(ResourceDispatcherHostTest, TooMuchOutstandingRequestsMemory) {
2226 // Expected cost of each request as measured by 2223 // Expected cost of each request as measured by
2227 // ResourceDispatcherHost::CalculateApproximateMemoryCost(). 2224 // ResourceDispatcherHost::CalculateApproximateMemoryCost().
2228 int kMemoryCostOfTest2Req = 2225 int kMemoryCostOfTest2Req =
2229 ResourceDispatcherHostImpl::kAvgBytesPerOutstandingRequest + 2226 ResourceDispatcherHostImpl::kAvgBytesPerOutstandingRequest +
2230 net::URLRequestTestJob::test_url_2().spec().size() + sizeof("GET") - 1; 2227 net::URLRequestTestJob::test_url_2().spec().size() + sizeof("GET") - 1;
(...skipping 1612 matching lines...) Expand 10 before | Expand all | Expand 10 after
3843 return nullptr; 3840 return nullptr;
3844 } 3841 }
3845 3842
3846 INSTANTIATE_TEST_CASE_P( 3843 INSTANTIATE_TEST_CASE_P(
3847 ResourceDispatcherHostTests, 3844 ResourceDispatcherHostTests,
3848 ResourceDispatcherHostTest, 3845 ResourceDispatcherHostTest,
3849 testing::Values(TestConfig::kDefault, 3846 testing::Values(TestConfig::kDefault,
3850 TestConfig::kOptimizeIPCForSmallResourceEnabled)); 3847 TestConfig::kOptimizeIPCForSmallResourceEnabled));
3851 3848
3852 } // namespace content 3849 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698