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

Side by Side Diff: net/http/http_cache_unittest.cc

Issue 2889273003: Fix some non-const ref function argument types. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/http/http_server_properties_impl_unittest.cc » ('j') | 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 "net/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 7707 matching lines...) Expand 10 before | Expand all | Expand 10 after
7718 // priority. 7718 // priority.
7719 ReadAndVerifyTransaction(trans.get(), transaction); 7719 ReadAndVerifyTransaction(trans.get(), transaction);
7720 7720
7721 EXPECT_EQ(HIGHEST, cache.network_layer()->last_create_transaction_priority()); 7721 EXPECT_EQ(HIGHEST, cache.network_layer()->last_create_transaction_priority());
7722 7722
7723 RemoveMockTransaction(&kRangeGET_TransactionOK); 7723 RemoveMockTransaction(&kRangeGET_TransactionOK);
7724 } 7724 }
7725 7725
7726 namespace { 7726 namespace {
7727 7727
7728 void RunTransactionAndGetNetworkBytes(MockHttpCache& cache, 7728 void RunTransactionAndGetNetworkBytes(MockHttpCache* cache,
7729 const MockTransaction& trans_info, 7729 const MockTransaction& trans_info,
7730 int64_t* sent_bytes, 7730 int64_t* sent_bytes,
7731 int64_t* received_bytes) { 7731 int64_t* received_bytes) {
7732 RunTransactionTestBase( 7732 RunTransactionTestBase(
7733 cache.http_cache(), trans_info, MockHttpRequest(trans_info), nullptr, 7733 cache->http_cache(), trans_info, MockHttpRequest(trans_info), nullptr,
7734 NetLogWithSource(), nullptr, sent_bytes, received_bytes, nullptr); 7734 NetLogWithSource(), nullptr, sent_bytes, received_bytes, nullptr);
7735 } 7735 }
7736 7736
7737 } // namespace 7737 } // namespace
7738 7738
7739 TEST(HttpCache, NetworkBytesCacheMissAndThenHit) { 7739 TEST(HttpCache, NetworkBytesCacheMissAndThenHit) {
7740 MockHttpCache cache; 7740 MockHttpCache cache;
7741 7741
7742 MockTransaction transaction(kSimpleGET_Transaction); 7742 MockTransaction transaction(kSimpleGET_Transaction);
7743 int64_t sent, received; 7743 int64_t sent, received;
7744 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); 7744 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received);
7745 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent); 7745 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent);
7746 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received); 7746 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received);
7747 7747
7748 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); 7748 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received);
7749 EXPECT_EQ(0, sent); 7749 EXPECT_EQ(0, sent);
7750 EXPECT_EQ(0, received); 7750 EXPECT_EQ(0, received);
7751 } 7751 }
7752 7752
7753 TEST(HttpCache, NetworkBytesConditionalRequest304) { 7753 TEST(HttpCache, NetworkBytesConditionalRequest304) {
7754 MockHttpCache cache; 7754 MockHttpCache cache;
7755 7755
7756 ScopedMockTransaction transaction(kETagGET_Transaction); 7756 ScopedMockTransaction transaction(kETagGET_Transaction);
7757 int64_t sent, received; 7757 int64_t sent, received;
7758 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); 7758 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received);
7759 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent); 7759 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent);
7760 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received); 7760 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received);
7761 7761
7762 transaction.load_flags = LOAD_VALIDATE_CACHE; 7762 transaction.load_flags = LOAD_VALIDATE_CACHE;
7763 transaction.handler = ETagGet_ConditionalRequest_Handler; 7763 transaction.handler = ETagGet_ConditionalRequest_Handler;
7764 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); 7764 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received);
7765 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent); 7765 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent);
7766 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received); 7766 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received);
7767 } 7767 }
7768 7768
7769 TEST(HttpCache, NetworkBytesConditionalRequest200) { 7769 TEST(HttpCache, NetworkBytesConditionalRequest200) {
7770 MockHttpCache cache; 7770 MockHttpCache cache;
7771 7771
7772 MockTransaction transaction(kTypicalGET_Transaction); 7772 MockTransaction transaction(kTypicalGET_Transaction);
7773 transaction.request_headers = "Foo: bar\r\n"; 7773 transaction.request_headers = "Foo: bar\r\n";
7774 transaction.response_headers = 7774 transaction.response_headers =
7775 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" 7775 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n"
7776 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" 7776 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n"
7777 "Etag: \"foopy\"\n" 7777 "Etag: \"foopy\"\n"
7778 "Cache-Control: max-age=0\n" 7778 "Cache-Control: max-age=0\n"
7779 "Vary: Foo\n"; 7779 "Vary: Foo\n";
7780 AddMockTransaction(&transaction); 7780 AddMockTransaction(&transaction);
7781 int64_t sent, received; 7781 int64_t sent, received;
7782 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); 7782 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received);
7783 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent); 7783 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent);
7784 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received); 7784 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received);
7785 7785
7786 RevalidationServer server; 7786 RevalidationServer server;
7787 transaction.handler = server.Handler; 7787 transaction.handler = server.Handler;
7788 transaction.request_headers = "Foo: none\r\n"; 7788 transaction.request_headers = "Foo: none\r\n";
7789 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); 7789 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received);
7790 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent); 7790 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent);
7791 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received); 7791 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received);
7792 7792
7793 RemoveMockTransaction(&transaction); 7793 RemoveMockTransaction(&transaction);
7794 } 7794 }
7795 7795
7796 TEST(HttpCache, NetworkBytesRange) { 7796 TEST(HttpCache, NetworkBytesRange) {
7797 MockHttpCache cache; 7797 MockHttpCache cache;
7798 AddMockTransaction(&kRangeGET_TransactionOK); 7798 AddMockTransaction(&kRangeGET_TransactionOK);
7799 MockTransaction transaction(kRangeGET_TransactionOK); 7799 MockTransaction transaction(kRangeGET_TransactionOK);
7800 7800
7801 // Read bytes 40-49 from the network. 7801 // Read bytes 40-49 from the network.
7802 int64_t sent, received; 7802 int64_t sent, received;
7803 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); 7803 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received);
7804 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent); 7804 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent);
7805 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received); 7805 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received);
7806 7806
7807 // Read bytes 40-49 from the cache. 7807 // Read bytes 40-49 from the cache.
7808 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); 7808 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received);
7809 EXPECT_EQ(0, sent); 7809 EXPECT_EQ(0, sent);
7810 EXPECT_EQ(0, received); 7810 EXPECT_EQ(0, received);
7811 base::RunLoop().RunUntilIdle(); 7811 base::RunLoop().RunUntilIdle();
7812 7812
7813 // Read bytes 30-39 from the network. 7813 // Read bytes 30-39 from the network.
7814 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; 7814 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER;
7815 transaction.data = "rg: 30-39 "; 7815 transaction.data = "rg: 30-39 ";
7816 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); 7816 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received);
7817 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent); 7817 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes, sent);
7818 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received); 7818 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes, received);
7819 base::RunLoop().RunUntilIdle(); 7819 base::RunLoop().RunUntilIdle();
7820 7820
7821 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache. 7821 // Read bytes 20-29 and 50-59 from the network, bytes 30-49 from the cache.
7822 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; 7822 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER;
7823 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; 7823 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 ";
7824 RunTransactionAndGetNetworkBytes(cache, transaction, &sent, &received); 7824 RunTransactionAndGetNetworkBytes(&cache, transaction, &sent, &received);
7825 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes * 2, sent); 7825 EXPECT_EQ(MockNetworkTransaction::kTotalSentBytes * 2, sent);
7826 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes * 2, received); 7826 EXPECT_EQ(MockNetworkTransaction::kTotalReceivedBytes * 2, received);
7827 7827
7828 RemoveMockTransaction(&kRangeGET_TransactionOK); 7828 RemoveMockTransaction(&kRangeGET_TransactionOK);
7829 } 7829 }
7830 7830
7831 class HttpCachePrefetchValidationTest : public ::testing::Test { 7831 class HttpCachePrefetchValidationTest : public ::testing::Test {
7832 protected: 7832 protected:
7833 static const int kNumSecondsPerMinute = 60; 7833 static const int kNumSecondsPerMinute = 60;
7834 static const int kMaxAgeSecs = 100; 7834 static const int kMaxAgeSecs = 100;
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
8255 ASSERT_TRUE(attrs->GetDictionary( 8255 ASSERT_TRUE(attrs->GetDictionary(
8256 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs)); 8256 base::trace_event::MemoryAllocatorDump::kNameSize, &size_attrs));
8257 std::string size; 8257 std::string size;
8258 ASSERT_TRUE(size_attrs->GetString("value", &size)); 8258 ASSERT_TRUE(size_attrs->GetString("value", &size));
8259 int actual_size = 0; 8259 int actual_size = 0;
8260 ASSERT_TRUE(base::HexStringToInt(size, &actual_size)); 8260 ASSERT_TRUE(base::HexStringToInt(size, &actual_size));
8261 ASSERT_LT(0, actual_size); 8261 ASSERT_LT(0, actual_size);
8262 } 8262 }
8263 8263
8264 } // namespace net 8264 } // namespace net
OLDNEW
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/http/http_server_properties_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698