| 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 "chrome/browser/net/chrome_network_delegate.h" | 5 #include "chrome/browser/net/chrome_network_delegate.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/test/histogram_tester.h" | 17 #include "base/test/histogram_tester.h" |
| 17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 20 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 20 #include "chrome/browser/net/safe_search_util.h" | 21 #include "chrome/browser/net/safe_search_util.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 #if defined(ENABLE_EXTENSIONS) | 188 #if defined(ENABLE_EXTENSIONS) |
| 188 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 189 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
| 189 #endif | 190 #endif |
| 190 TestingProfile profile_; | 191 TestingProfile profile_; |
| 191 BooleanPrefMember enable_referrers_; | 192 BooleanPrefMember enable_referrers_; |
| 192 std::unique_ptr<ChromeNetworkDelegate> network_delegate_; | 193 std::unique_ptr<ChromeNetworkDelegate> network_delegate_; |
| 193 net::MockClientSocketFactory socket_factory_; | 194 net::MockClientSocketFactory socket_factory_; |
| 194 std::unique_ptr<net::TestURLRequestContext> context_; | 195 std::unique_ptr<net::TestURLRequestContext> context_; |
| 195 }; | 196 }; |
| 196 | 197 |
| 198 // Test that the total data use consumed by Chrome is recorded correctly. |
| 199 TEST_F(ChromeNetworkDelegateTest, TotalDataUseMeasurementTest) { |
| 200 Initialize(); |
| 201 base::HistogramTester histogram_tester; |
| 202 |
| 203 // A query from a user without redirection. |
| 204 RequestURL(context(), socket_factory(), true, false); |
| 205 std::vector<base::Bucket> buckets = |
| 206 histogram_tester.GetAllSamples("DataUse.BytesSent.Delegate"); |
| 207 EXPECT_FALSE(buckets.empty()); |
| 208 |
| 209 buckets = histogram_tester.GetAllSamples("DataUse.BytesReceived.Delegate"); |
| 210 EXPECT_FALSE(buckets.empty()); |
| 211 } |
| 212 |
| 197 // This function tests data use measurement for requests by services. it makes a | 213 // This function tests data use measurement for requests by services. it makes a |
| 198 // query which is similar to a query of a service, so it should affect | 214 // query which is similar to a query of a service, so it should affect |
| 199 // DataUse.TrafficSize.System.Dimensions and DataUse.MessageSize.ServiceName | 215 // DataUse.TrafficSize.System.Dimensions and DataUse.MessageSize.ServiceName |
| 200 // histograms. AppState and ConnectionType dimensions are always Foreground and | 216 // histograms. AppState and ConnectionType dimensions are always Foreground and |
| 201 // NotCellular respectively. | 217 // NotCellular respectively. |
| 202 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementServiceTest) { | 218 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementServiceTest) { |
| 203 Initialize(); | 219 Initialize(); |
| 204 base::HistogramTester histogram_tester; | 220 base::HistogramTester histogram_tester; |
| 205 | 221 |
| 206 // A query from a service without redirection. | 222 // A query from a service without redirection. |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 | 639 |
| 624 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 640 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
| 625 kBlockedFirstPartySite)); | 641 kBlockedFirstPartySite)); |
| 626 | 642 |
| 627 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, | 643 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, |
| 628 CONTENT_SETTING_BLOCK); | 644 CONTENT_SETTING_BLOCK); |
| 629 // Privacy mode is disabled as kAllowedSite is still getting cookies | 645 // Privacy mode is disabled as kAllowedSite is still getting cookies |
| 630 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 646 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
| 631 kBlockedFirstPartySite)); | 647 kBlockedFirstPartySite)); |
| 632 } | 648 } |
| OLD | NEW |