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 "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // respective methods have been called. | 98 // respective methods have been called. |
99 class FakeDataUseAggregator : public data_usage::DataUseAggregator { | 99 class FakeDataUseAggregator : public data_usage::DataUseAggregator { |
100 public: | 100 public: |
101 FakeDataUseAggregator() | 101 FakeDataUseAggregator() |
102 : on_the_record_tx_bytes_(0), | 102 : on_the_record_tx_bytes_(0), |
103 on_the_record_rx_bytes_(0), | 103 on_the_record_rx_bytes_(0), |
104 off_the_record_tx_bytes_(0), | 104 off_the_record_tx_bytes_(0), |
105 off_the_record_rx_bytes_(0) {} | 105 off_the_record_rx_bytes_(0) {} |
106 ~FakeDataUseAggregator() override {} | 106 ~FakeDataUseAggregator() override {} |
107 | 107 |
108 void ReportDataUse(const net::URLRequest& request, | 108 void ReportDataUse(int64_t tx_bytes, |
109 int32_t tab_id, | 109 int64_t rx_bytes, |
110 int64_t tx_bytes, | 110 const GURL& url, |
111 int64_t rx_bytes) override { | 111 const base::TimeTicks& request_time, |
| 112 const GURL& first_party_for_cookies, |
| 113 int32_t tab_id) override { |
112 on_the_record_tx_bytes_ += tx_bytes; | 114 on_the_record_tx_bytes_ += tx_bytes; |
113 on_the_record_rx_bytes_ += rx_bytes; | 115 on_the_record_rx_bytes_ += rx_bytes; |
114 } | 116 } |
115 | 117 |
116 void ReportOffTheRecordDataUse(int64_t tx_bytes, int64_t rx_bytes) override { | 118 void ReportOffTheRecordDataUse(int64_t tx_bytes, int64_t rx_bytes) override { |
117 off_the_record_tx_bytes_ += tx_bytes; | 119 off_the_record_tx_bytes_ += tx_bytes; |
118 off_the_record_rx_bytes_ += rx_bytes; | 120 off_the_record_rx_bytes_ += rx_bytes; |
119 } | 121 } |
120 | 122 |
121 int64_t on_the_record_tx_bytes() const { return on_the_record_tx_bytes_; } | 123 int64_t on_the_record_tx_bytes() const { return on_the_record_tx_bytes_; } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 EXPECT_FALSE(network_delegate()->AreExperimentalCookieFeaturesEnabled()); | 287 EXPECT_FALSE(network_delegate()->AreExperimentalCookieFeaturesEnabled()); |
286 } | 288 } |
287 | 289 |
288 TEST_F(ChromeNetworkDelegateTest, EnableFirstPartyOnlyCookiesIffFlagEnabled) { | 290 TEST_F(ChromeNetworkDelegateTest, EnableFirstPartyOnlyCookiesIffFlagEnabled) { |
289 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 291 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
290 switches::kEnableExperimentalWebPlatformFeatures); | 292 switches::kEnableExperimentalWebPlatformFeatures); |
291 Initialize(); | 293 Initialize(); |
292 EXPECT_TRUE(network_delegate()->AreExperimentalCookieFeaturesEnabled()); | 294 EXPECT_TRUE(network_delegate()->AreExperimentalCookieFeaturesEnabled()); |
293 } | 295 } |
294 | 296 |
295 TEST_F(ChromeNetworkDelegateTest, ReportDataUseToAggregator) { | 297 TEST_F(ChromeNetworkDelegateTest, ReportUserDataUseToAggregator) { |
296 FakeDataUseAggregator fake_aggregator; | 298 FakeDataUseAggregator fake_aggregator; |
297 Initialize(); | 299 Initialize(); |
298 | 300 |
299 chrome_network_delegate()->set_data_use_aggregator( | 301 chrome_network_delegate()->set_data_use_aggregator( |
300 &fake_aggregator, false /* is_data_usage_off_the_record */); | 302 &fake_aggregator, false /* is_data_usage_off_the_record */); |
301 | 303 |
302 scoped_ptr<net::URLRequest> request = | 304 scoped_ptr<net::URLRequest> request = |
303 RequestURL(context(), socket_factory(), true, false); | 305 RequestURL(context(), socket_factory(), true /* from_user */, false); |
304 EXPECT_EQ(request->GetTotalSentBytes(), | 306 EXPECT_EQ(request->GetTotalSentBytes(), |
305 fake_aggregator.on_the_record_tx_bytes()); | 307 fake_aggregator.on_the_record_tx_bytes()); |
306 EXPECT_EQ(request->GetTotalReceivedBytes(), | 308 EXPECT_EQ(request->GetTotalReceivedBytes(), |
| 309 fake_aggregator.on_the_record_rx_bytes()); |
| 310 EXPECT_EQ(0, fake_aggregator.off_the_record_tx_bytes()); |
| 311 EXPECT_EQ(0, fake_aggregator.off_the_record_rx_bytes()); |
| 312 } |
| 313 |
| 314 TEST_F(ChromeNetworkDelegateTest, ReportNonUserDataUseToAggregator) { |
| 315 FakeDataUseAggregator fake_aggregator; |
| 316 Initialize(); |
| 317 |
| 318 chrome_network_delegate()->set_data_use_aggregator( |
| 319 &fake_aggregator, false /* is_data_usage_off_the_record */); |
| 320 |
| 321 scoped_ptr<net::URLRequest> request = |
| 322 RequestURL(context(), socket_factory(), false /* from_user */, false); |
| 323 EXPECT_EQ(request->GetTotalSentBytes(), |
| 324 fake_aggregator.on_the_record_tx_bytes()); |
| 325 EXPECT_EQ(request->GetTotalReceivedBytes(), |
307 fake_aggregator.on_the_record_rx_bytes()); | 326 fake_aggregator.on_the_record_rx_bytes()); |
308 EXPECT_EQ(0, fake_aggregator.off_the_record_tx_bytes()); | 327 EXPECT_EQ(0, fake_aggregator.off_the_record_tx_bytes()); |
309 EXPECT_EQ(0, fake_aggregator.off_the_record_rx_bytes()); | 328 EXPECT_EQ(0, fake_aggregator.off_the_record_rx_bytes()); |
310 } | 329 } |
311 | 330 |
312 TEST_F(ChromeNetworkDelegateTest, ReportOffTheRecordDataUseToAggregator) { | 331 TEST_F(ChromeNetworkDelegateTest, ReportOffTheRecordDataUseToAggregator) { |
313 FakeDataUseAggregator fake_aggregator; | 332 FakeDataUseAggregator fake_aggregator; |
314 Initialize(); | 333 Initialize(); |
315 | 334 |
316 chrome_network_delegate()->set_data_use_aggregator( | 335 chrome_network_delegate()->set_data_use_aggregator( |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 kBlockedFirstPartySite)); | 549 kBlockedFirstPartySite)); |
531 | 550 |
532 cookie_settings_->SetCookieSetting( | 551 cookie_settings_->SetCookieSetting( |
533 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), | 552 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), |
534 ContentSettingsPattern::Wildcard(), | 553 ContentSettingsPattern::Wildcard(), |
535 CONTENT_SETTING_BLOCK); | 554 CONTENT_SETTING_BLOCK); |
536 // Privacy mode is disabled as kAllowedSite is still getting cookies | 555 // Privacy mode is disabled as kAllowedSite is still getting cookies |
537 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 556 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
538 kBlockedFirstPartySite)); | 557 kBlockedFirstPartySite)); |
539 } | 558 } |
OLD | NEW |