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

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc

Issue 1546143002: Switch to standard integer types in components/, part 1 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw ork_delegate.h" 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw ork_delegate.h"
6 6
7 #include <stddef.h>
7 #include <stdint.h> 8 #include <stdint.h>
8 9
9 #include <string> 10 #include <string>
10 11
11 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/macros.h"
12 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
13 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
14 #include "base/test/histogram_tester.h" 16 #include "base/test/histogram_tester.h"
15 #include "base/test/mock_entropy_provider.h" 17 #include "base/test/mock_entropy_provider.h"
16 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "build/build_config.h"
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa ss_stats.h" 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa ss_stats.h"
18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h" 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h"
19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metr ics.h" 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metr ics.h"
20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h" 23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h"
21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h" 24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h"
22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs_test_utils.h" 25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs_test_utils.h"
23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h" 26 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h"
24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 27 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" 28 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h"
26 #include "components/data_reduction_proxy/core/common/lofi_decider.h" 29 #include "components/data_reduction_proxy/core/common/lofi_decider.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 EXPECT_EQ(expected_lofi_used, 158 EXPECT_EQ(expected_lofi_used,
156 header_value.find("q=low") != std::string::npos); 159 header_value.find("q=low") != std::string::npos);
157 } 160 }
158 161
159 void VerifyWasLoFiModeActiveOnMainFrame(bool expected_value) { 162 void VerifyWasLoFiModeActiveOnMainFrame(bool expected_value) {
160 test_context_->RunUntilIdle(); 163 test_context_->RunUntilIdle();
161 EXPECT_EQ(expected_value, 164 EXPECT_EQ(expected_value,
162 test_context_->settings()->WasLoFiModeActiveOnMainFrame()); 165 test_context_->settings()->WasLoFiModeActiveOnMainFrame());
163 } 166 }
164 167
165 int64 total_received_bytes() { 168 int64_t total_received_bytes() {
166 return data_reduction_proxy_network_delegate_->total_received_bytes_; 169 return data_reduction_proxy_network_delegate_->total_received_bytes_;
167 } 170 }
168 171
169 int64 total_original_received_bytes() { 172 int64_t total_original_received_bytes() {
170 return data_reduction_proxy_network_delegate_ 173 return data_reduction_proxy_network_delegate_
171 ->total_original_received_bytes_; 174 ->total_original_received_bytes_;
172 } 175 }
173 176
174 net::MockClientSocketFactory* mock_socket_factory() { 177 net::MockClientSocketFactory* mock_socket_factory() {
175 return &mock_socket_factory_; 178 return &mock_socket_factory_;
176 } 179 }
177 180
178 protected: 181 protected:
179 // Each line in |response_headers| should end with "\r\n" and not '\0', and 182 // Each line in |response_headers| should end with "\r\n" and not '\0', and
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 const std::string kOriginalHistogramName = "Net.HttpOriginalContentLength"; 408 const std::string kOriginalHistogramName = "Net.HttpOriginalContentLength";
406 const std::string kDifferenceHistogramName = 409 const std::string kDifferenceHistogramName =
407 "Net.HttpContentLengthDifference"; 410 "Net.HttpContentLengthDifference";
408 const std::string kFreshnessLifetimeHistogramName = 411 const std::string kFreshnessLifetimeHistogramName =
409 "Net.HttpContentFreshnessLifetime"; 412 "Net.HttpContentFreshnessLifetime";
410 const std::string kCacheableHistogramName = "Net.HttpContentLengthCacheable"; 413 const std::string kCacheableHistogramName = "Net.HttpContentLengthCacheable";
411 const std::string kCacheable4HoursHistogramName = 414 const std::string kCacheable4HoursHistogramName =
412 "Net.HttpContentLengthCacheable4Hours"; 415 "Net.HttpContentLengthCacheable4Hours";
413 const std::string kCacheable24HoursHistogramName = 416 const std::string kCacheable24HoursHistogramName =
414 "Net.HttpContentLengthCacheable24Hours"; 417 "Net.HttpContentLengthCacheable24Hours";
415 const int64 kResponseContentLength = 100; 418 const int64_t kResponseContentLength = 100;
416 const int64 kOriginalContentLength = 200; 419 const int64_t kOriginalContentLength = 200;
417 420
418 base::HistogramTester histogram_tester; 421 base::HistogramTester histogram_tester;
419 422
420 set_network_delegate(data_reduction_proxy_network_delegate_.get()); 423 set_network_delegate(data_reduction_proxy_network_delegate_.get());
421 424
422 std::string response_headers = 425 std::string response_headers =
423 "HTTP/1.1 200 OK\r\n" 426 "HTTP/1.1 200 OK\r\n"
424 "Date: Wed, 28 Nov 2007 09:40:09 GMT\r\n" 427 "Date: Wed, 28 Nov 2007 09:40:09 GMT\r\n"
425 "Expires: Mon, 24 Nov 2014 12:45:26 GMT\r\n" 428 "Expires: Mon, 24 Nov 2014 12:45:26 GMT\r\n"
426 "Via: 1.1 Chrome-Compression-Proxy\r\n" 429 "Via: 1.1 Chrome-Compression-Proxy\r\n"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 .ToString() + 644 .ToString() +
642 "; DIRECT"); 645 "; DIRECT");
643 EXPECT_FALSE(data_reduction_proxy_info.is_empty()); 646 EXPECT_FALSE(data_reduction_proxy_info.is_empty());
644 647
645 data_reduction_proxy_network_delegate_->NotifyBeforeSendProxyHeaders( 648 data_reduction_proxy_network_delegate_->NotifyBeforeSendProxyHeaders(
646 nullptr, data_reduction_proxy_info, &headers); 649 nullptr, data_reduction_proxy_info, &headers);
647 EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader)); 650 EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader));
648 } 651 }
649 652
650 TEST_F(DataReductionProxyNetworkDelegateTest, OnCompletedInternal) { 653 TEST_F(DataReductionProxyNetworkDelegateTest, OnCompletedInternal) {
651 const int64 kResponseContentLength = 140; 654 const int64_t kResponseContentLength = 140;
652 const int64 kOriginalContentLength = 200; 655 const int64_t kOriginalContentLength = 200;
653 656
654 set_network_delegate(data_reduction_proxy_network_delegate_.get()); 657 set_network_delegate(data_reduction_proxy_network_delegate_.get());
655 658
656 std::string raw_headers = 659 std::string raw_headers =
657 "HTTP/1.1 200 OK\n" 660 "HTTP/1.1 200 OK\n"
658 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" 661 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n"
659 "Expires: Mon, 24 Nov 2014 12:45:26 GMT\n" 662 "Expires: Mon, 24 Nov 2014 12:45:26 GMT\n"
660 "Via: 1.1 Chrome-Compression-Proxy\n" 663 "Via: 1.1 Chrome-Compression-Proxy\n"
661 "x-original-content-length: " + 664 "x-original-content-length: " +
662 base::Int64ToString(kOriginalContentLength) + "\n"; 665 base::Int64ToString(kOriginalContentLength) + "\n";
663 666
664 HeadersToRaw(&raw_headers); 667 HeadersToRaw(&raw_headers);
665 std::string response_headers = 668 std::string response_headers =
666 net::HttpUtil::ConvertHeadersBackToHTTPResponse(raw_headers); 669 net::HttpUtil::ConvertHeadersBackToHTTPResponse(raw_headers);
667 670
668 FetchURLRequest(GURL("http://www.google.com/"), response_headers, 671 FetchURLRequest(GURL("http://www.google.com/"), response_headers,
669 kResponseContentLength); 672 kResponseContentLength);
670 673
671 EXPECT_EQ( 674 EXPECT_EQ(
672 kResponseContentLength + static_cast<int64_t>(response_headers.size()), 675 kResponseContentLength + static_cast<int64_t>(response_headers.size()),
673 total_received_bytes()); 676 total_received_bytes());
674 // Original size computation does not currently take into account that "\r\n" 677 // Original size computation does not currently take into account that "\r\n"
675 // is removed from each header line. 678 // is removed from each header line.
676 EXPECT_EQ(kOriginalContentLength + static_cast<int64_t>(raw_headers.size()), 679 EXPECT_EQ(kOriginalContentLength + static_cast<int64_t>(raw_headers.size()),
677 total_original_received_bytes()); 680 total_original_received_bytes());
678 } 681 }
679 682
680 } // namespace data_reduction_proxy 683 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698