| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/prefs/pref_member.h" | 13 #include "base/prefs/pref_member.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/test/histogram_tester.h" | 15 #include "base/test/histogram_tester.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 17 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 18 #include "chrome/browser/net/safe_search_util.h" | 18 #include "chrome/browser/net/safe_search_util.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/test/base/testing_browser_process.h" | 20 #include "chrome/test/base/testing_browser_process.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 22 #include "chrome/test/base/testing_profile_manager.h" | 22 #include "chrome/test/base/testing_profile_manager.h" |
| 23 #include "components/content_settings/core/browser/cookie_settings.h" | 23 #include "components/content_settings/core/browser/cookie_settings.h" |
| 24 #include "components/content_settings/core/common/pref_names.h" | 24 #include "components/content_settings/core/common/pref_names.h" |
| 25 #include "components/data_usage/core/data_use_aggregator.h" | 25 #include "components/data_usage/core/data_use_aggregator.h" |
| 26 #include "components/data_usage/core/data_use_amortizer.h" |
| 26 #include "components/data_usage/core/data_use_annotator.h" | 27 #include "components/data_usage/core/data_use_annotator.h" |
| 27 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 28 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
| 28 #include "content/public/browser/resource_request_info.h" | 29 #include "content/public/browser/resource_request_info.h" |
| 29 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 30 #include "content/public/common/resource_type.h" | 31 #include "content/public/common/resource_type.h" |
| 31 #include "content/public/test/test_browser_thread_bundle.h" | 32 #include "content/public/test/test_browser_thread_bundle.h" |
| 32 #include "net/base/request_priority.h" | 33 #include "net/base/request_priority.h" |
| 33 #include "net/socket/socket_test_util.h" | 34 #include "net/socket/socket_test_util.h" |
| 34 #include "net/url_request/url_request.h" | 35 #include "net/url_request/url_request.h" |
| 35 #include "net/url_request/url_request_test_util.h" | 36 #include "net/url_request/url_request_test_util.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 base::RunLoop().RunUntilIdle(); | 95 base::RunLoop().RunUntilIdle(); |
| 95 return request.Pass(); | 96 return request.Pass(); |
| 96 } | 97 } |
| 97 | 98 |
| 98 // A fake DataUseAggregator for testing that only counts how many times its | 99 // A fake DataUseAggregator for testing that only counts how many times its |
| 99 // respective methods have been called. | 100 // respective methods have been called. |
| 100 class FakeDataUseAggregator : public data_usage::DataUseAggregator { | 101 class FakeDataUseAggregator : public data_usage::DataUseAggregator { |
| 101 public: | 102 public: |
| 102 FakeDataUseAggregator() | 103 FakeDataUseAggregator() |
| 103 : data_usage::DataUseAggregator( | 104 : data_usage::DataUseAggregator( |
| 104 scoped_ptr<data_usage::DataUseAnnotator>()), | 105 scoped_ptr<data_usage::DataUseAnnotator>(), |
| 106 scoped_ptr<data_usage::DataUseAmortizer>()), |
| 105 on_the_record_tx_bytes_(0), | 107 on_the_record_tx_bytes_(0), |
| 106 on_the_record_rx_bytes_(0), | 108 on_the_record_rx_bytes_(0), |
| 107 off_the_record_tx_bytes_(0), | 109 off_the_record_tx_bytes_(0), |
| 108 off_the_record_rx_bytes_(0) {} | 110 off_the_record_rx_bytes_(0) {} |
| 109 ~FakeDataUseAggregator() override {} | 111 ~FakeDataUseAggregator() override {} |
| 110 | 112 |
| 111 void ReportDataUse(net::URLRequest* request, | 113 void ReportDataUse(net::URLRequest* request, |
| 112 int64_t tx_bytes, | 114 int64_t tx_bytes, |
| 113 int64_t rx_bytes) override { | 115 int64_t rx_bytes) override { |
| 114 on_the_record_tx_bytes_ += tx_bytes; | 116 on_the_record_tx_bytes_ += tx_bytes; |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 kBlockedFirstPartySite)); | 534 kBlockedFirstPartySite)); |
| 533 | 535 |
| 534 cookie_settings_->SetCookieSetting( | 536 cookie_settings_->SetCookieSetting( |
| 535 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), | 537 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), |
| 536 ContentSettingsPattern::Wildcard(), | 538 ContentSettingsPattern::Wildcard(), |
| 537 CONTENT_SETTING_BLOCK); | 539 CONTENT_SETTING_BLOCK); |
| 538 // Privacy mode is disabled as kAllowedSite is still getting cookies | 540 // Privacy mode is disabled as kAllowedSite is still getting cookies |
| 539 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 541 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
| 540 kBlockedFirstPartySite)); | 542 kBlockedFirstPartySite)); |
| 541 } | 543 } |
| OLD | NEW |