| 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> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/net/safe_search_util.h" | 21 #include "chrome/browser/net/safe_search_util.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/test/base/testing_browser_process.h" | 23 #include "chrome/test/base/testing_browser_process.h" |
| 24 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
| 25 #include "chrome/test/base/testing_profile_manager.h" | 25 #include "chrome/test/base/testing_profile_manager.h" |
| 26 #include "components/content_settings/core/browser/cookie_settings.h" | 26 #include "components/content_settings/core/browser/cookie_settings.h" |
| 27 #include "components/content_settings/core/common/pref_names.h" | 27 #include "components/content_settings/core/common/pref_names.h" |
| 28 #include "components/data_usage/core/data_use_aggregator.h" | 28 #include "components/data_usage/core/data_use_aggregator.h" |
| 29 #include "components/data_usage/core/data_use_amortizer.h" | 29 #include "components/data_usage/core/data_use_amortizer.h" |
| 30 #include "components/data_usage/core/data_use_annotator.h" | 30 #include "components/data_usage/core/data_use_annotator.h" |
| 31 #include "components/data_use_measurement/core/data_use_user_data.h" | |
| 32 #include "components/prefs/pref_member.h" | 31 #include "components/prefs/pref_member.h" |
| 33 #include "components/sync_preferences/testing_pref_service_syncable.h" | 32 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 34 #include "content/public/browser/resource_request_info.h" | 33 #include "content/public/browser/resource_request_info.h" |
| 35 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
| 36 #include "content/public/common/resource_type.h" | 35 #include "content/public/common/resource_type.h" |
| 37 #include "content/public/test/test_browser_thread_bundle.h" | 36 #include "content/public/test/test_browser_thread_bundle.h" |
| 38 #include "net/base/request_priority.h" | 37 #include "net/base/request_priority.h" |
| 39 #include "net/http/http_request_headers.h" | 38 #include "net/http/http_request_headers.h" |
| 40 #include "net/socket/socket_test_util.h" | 39 #include "net/socket/socket_test_util.h" |
| 41 #include "net/url_request/url_request.h" | 40 #include "net/url_request/url_request.h" |
| 42 #include "net/url_request/url_request_test_util.h" | 41 #include "net/url_request/url_request_test_util.h" |
| 43 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
| 44 #include "url/gurl.h" | 43 #include "url/gurl.h" |
| 45 | 44 |
| 46 #if defined(ENABLE_EXTENSIONS) | 45 #if defined(ENABLE_EXTENSIONS) |
| 47 #include "chrome/browser/extensions/event_router_forwarder.h" | 46 #include "chrome/browser/extensions/event_router_forwarder.h" |
| 48 #endif | 47 #endif |
| 49 | 48 |
| 50 namespace { | 49 namespace { |
| 51 | 50 |
| 52 // This function requests a URL, and makes it return a known response. If | 51 // This function requests a URL, and makes it return a known response. |
| 53 // |from_user| is true, it attaches a ResourceRequestInfo to the URLRequest, | 52 // ResourceRequestInfo is attached to the URLRequest, to represent this request |
| 54 // because requests from users have this info. If |from_user| is false, the | 53 // as an user initiated. |
| 55 // request is presumed to be from a service, and the service name is set in the | |
| 56 // request's user data. (As an example suggestions service tag is attached). if | |
| 57 // |redirect| is true, it adds necessary socket data to have it follow redirect | |
| 58 // before getting the final response. | |
| 59 std::unique_ptr<net::URLRequest> RequestURL( | 54 std::unique_ptr<net::URLRequest> RequestURL( |
| 60 net::URLRequestContext* context, | 55 net::URLRequestContext* context, |
| 61 net::MockClientSocketFactory* socket_factory, | 56 net::MockClientSocketFactory* socket_factory) { |
| 62 bool from_user, | |
| 63 bool redirect) { | |
| 64 net::MockRead redirect_mock_reads[] = { | 57 net::MockRead redirect_mock_reads[] = { |
| 65 net::MockRead("HTTP/1.1 302 Found\r\n" | 58 net::MockRead("HTTP/1.1 302 Found\r\n" |
| 66 "Location: http://bar.com/\r\n\r\n"), | 59 "Location: http://bar.com/\r\n\r\n"), |
| 67 net::MockRead(net::SYNCHRONOUS, net::OK), | 60 net::MockRead(net::SYNCHRONOUS, net::OK), |
| 68 }; | 61 }; |
| 69 net::StaticSocketDataProvider redirect_socket_data_provider( | 62 net::StaticSocketDataProvider redirect_socket_data_provider( |
| 70 redirect_mock_reads, arraysize(redirect_mock_reads), nullptr, 0); | 63 redirect_mock_reads, arraysize(redirect_mock_reads), nullptr, 0); |
| 71 | 64 |
| 72 if (redirect) | |
| 73 socket_factory->AddSocketDataProvider(&redirect_socket_data_provider); | |
| 74 net::MockRead response_mock_reads[] = { | 65 net::MockRead response_mock_reads[] = { |
| 75 net::MockRead("HTTP/1.1 200 OK\r\n\r\n"), net::MockRead("response body"), | 66 net::MockRead("HTTP/1.1 200 OK\r\n\r\n"), net::MockRead("response body"), |
| 76 net::MockRead(net::SYNCHRONOUS, net::OK), | 67 net::MockRead(net::SYNCHRONOUS, net::OK), |
| 77 }; | 68 }; |
| 78 net::StaticSocketDataProvider response_socket_data_provider( | 69 net::StaticSocketDataProvider response_socket_data_provider( |
| 79 response_mock_reads, arraysize(response_mock_reads), nullptr, 0); | 70 response_mock_reads, arraysize(response_mock_reads), nullptr, 0); |
| 80 socket_factory->AddSocketDataProvider(&response_socket_data_provider); | 71 socket_factory->AddSocketDataProvider(&response_socket_data_provider); |
| 81 net::TestDelegate test_delegate; | 72 net::TestDelegate test_delegate; |
| 82 test_delegate.set_quit_on_complete(true); | 73 test_delegate.set_quit_on_complete(true); |
| 83 std::unique_ptr<net::URLRequest> request(context->CreateRequest( | 74 std::unique_ptr<net::URLRequest> request(context->CreateRequest( |
| 84 GURL("http://example.com"), net::DEFAULT_PRIORITY, &test_delegate)); | 75 GURL("http://example.com"), net::DEFAULT_PRIORITY, &test_delegate)); |
| 85 | 76 |
| 86 if (from_user) { | 77 content::ResourceRequestInfo::AllocateForTesting( |
| 87 content::ResourceRequestInfo::AllocateForTesting( | 78 request.get(), content::RESOURCE_TYPE_MAIN_FRAME, nullptr, -2, -2, -2, |
| 88 request.get(), content::RESOURCE_TYPE_MAIN_FRAME, nullptr, -2, -2, -2, | 79 true, false, true, true, false); |
| 89 true, false, true, true, false); | 80 |
| 90 } else { | |
| 91 request->SetUserData( | |
| 92 data_use_measurement::DataUseUserData::kUserDataKey, | |
| 93 new data_use_measurement::DataUseUserData( | |
| 94 data_use_measurement::DataUseUserData::SUGGESTIONS, | |
| 95 data_use_measurement::DataUseUserData::FOREGROUND)); | |
| 96 } | |
| 97 request->Start(); | 81 request->Start(); |
| 98 base::RunLoop().RunUntilIdle(); | 82 base::RunLoop().RunUntilIdle(); |
| 99 return request; | 83 return request; |
| 100 } | 84 } |
| 101 | 85 |
| 102 // A fake DataUseAggregator for testing that only counts how many times its | 86 // A fake DataUseAggregator for testing that only counts how many times its |
| 103 // respective methods have been called. | 87 // respective methods have been called. |
| 104 class FakeDataUseAggregator : public data_usage::DataUseAggregator { | 88 class FakeDataUseAggregator : public data_usage::DataUseAggregator { |
| 105 public: | 89 public: |
| 106 FakeDataUseAggregator() | 90 FakeDataUseAggregator() |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 137 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 154 &enable_referrers_, nullptr, nullptr, nullptr, nullptr, | 138 &enable_referrers_, nullptr, nullptr, nullptr, nullptr, |
| 155 profile_.GetTestingPrefService()); | 139 profile_.GetTestingPrefService()); |
| 156 profile_manager_.reset( | 140 profile_manager_.reset( |
| 157 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 141 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 158 ASSERT_TRUE(profile_manager_->SetUp()); | 142 ASSERT_TRUE(profile_manager_->SetUp()); |
| 159 } | 143 } |
| 160 | 144 |
| 161 void Initialize() { | 145 void Initialize() { |
| 162 network_delegate_.reset( | 146 network_delegate_.reset( |
| 163 new ChromeNetworkDelegate(forwarder(), &enable_referrers_, | 147 new ChromeNetworkDelegate(forwarder(), &enable_referrers_)); |
| 164 metrics::UpdateUsagePrefCallbackType())); | |
| 165 context_->set_client_socket_factory(&socket_factory_); | 148 context_->set_client_socket_factory(&socket_factory_); |
| 166 context_->set_network_delegate(network_delegate_.get()); | 149 context_->set_network_delegate(network_delegate_.get()); |
| 167 context_->Init(); | 150 context_->Init(); |
| 168 } | 151 } |
| 169 | 152 |
| 170 net::TestURLRequestContext* context() { return context_.get(); } | 153 net::TestURLRequestContext* context() { return context_.get(); } |
| 171 net::NetworkDelegate* network_delegate() { return network_delegate_.get(); } | 154 net::NetworkDelegate* network_delegate() { return network_delegate_.get(); } |
| 172 net::MockClientSocketFactory* socket_factory() { return &socket_factory_; } | 155 net::MockClientSocketFactory* socket_factory() { return &socket_factory_; } |
| 173 | 156 |
| 174 ChromeNetworkDelegate* chrome_network_delegate() { | 157 ChromeNetworkDelegate* chrome_network_delegate() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 189 #if defined(ENABLE_EXTENSIONS) | 172 #if defined(ENABLE_EXTENSIONS) |
| 190 scoped_refptr<extensions::EventRouterForwarder> forwarder_; | 173 scoped_refptr<extensions::EventRouterForwarder> forwarder_; |
| 191 #endif | 174 #endif |
| 192 TestingProfile profile_; | 175 TestingProfile profile_; |
| 193 BooleanPrefMember enable_referrers_; | 176 BooleanPrefMember enable_referrers_; |
| 194 std::unique_ptr<ChromeNetworkDelegate> network_delegate_; | 177 std::unique_ptr<ChromeNetworkDelegate> network_delegate_; |
| 195 net::MockClientSocketFactory socket_factory_; | 178 net::MockClientSocketFactory socket_factory_; |
| 196 std::unique_ptr<net::TestURLRequestContext> context_; | 179 std::unique_ptr<net::TestURLRequestContext> context_; |
| 197 }; | 180 }; |
| 198 | 181 |
| 199 // Test that the total data use consumed by Chrome is recorded correctly. | |
| 200 TEST_F(ChromeNetworkDelegateTest, TotalDataUseMeasurementTest) { | |
| 201 Initialize(); | |
| 202 base::HistogramTester histogram_tester; | |
| 203 | |
| 204 // A query from a user without redirection. | |
| 205 RequestURL(context(), socket_factory(), true, false); | |
| 206 std::vector<base::Bucket> buckets = | |
| 207 histogram_tester.GetAllSamples("DataUse.BytesSent.Delegate"); | |
| 208 EXPECT_FALSE(buckets.empty()); | |
| 209 | |
| 210 buckets = histogram_tester.GetAllSamples("DataUse.BytesReceived.Delegate"); | |
| 211 EXPECT_FALSE(buckets.empty()); | |
| 212 } | |
| 213 | |
| 214 // This function tests data use measurement for requests by services. it makes a | |
| 215 // query which is similar to a query of a service, so it should affect | |
| 216 // DataUse.TrafficSize.System.Dimensions and DataUse.MessageSize.ServiceName | |
| 217 // histograms. AppState and ConnectionType dimensions are always Foreground and | |
| 218 // NotCellular respectively. | |
| 219 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementServiceTest) { | |
| 220 Initialize(); | |
| 221 base::HistogramTester histogram_tester; | |
| 222 | |
| 223 // A query from a service without redirection. | |
| 224 RequestURL(context(), socket_factory(), false, false); | |
| 225 EXPECT_FALSE( | |
| 226 histogram_tester | |
| 227 .GetTotalCountsForPrefix( | |
| 228 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular") | |
| 229 .empty()); | |
| 230 histogram_tester.ExpectTotalCount( | |
| 231 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 1); | |
| 232 EXPECT_FALSE(histogram_tester | |
| 233 .GetTotalCountsForPrefix("DataUse.MessageSize.Suggestions") | |
| 234 .empty()); | |
| 235 histogram_tester.ExpectTotalCount( | |
| 236 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 0); | |
| 237 histogram_tester.ExpectTotalCount( | |
| 238 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 0); | |
| 239 } | |
| 240 | |
| 241 // This function tests data use measurement for requests by user.The query from | |
| 242 // a user should affect DataUse.TrafficSize.User.Dimensions histogram. AppState | |
| 243 // and ConnectionType dimensions are always Foreground and NotCellular | |
| 244 // respectively. | |
| 245 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementUserTest) { | |
| 246 Initialize(); | |
| 247 base::HistogramTester histogram_tester; | |
| 248 | |
| 249 // A query from user without redirection. | |
| 250 RequestURL(context(), socket_factory(), true, false); | |
| 251 EXPECT_FALSE( | |
| 252 histogram_tester | |
| 253 .GetTotalCountsForPrefix( | |
| 254 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular") | |
| 255 .empty()); | |
| 256 histogram_tester.ExpectTotalCount( | |
| 257 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 1); | |
| 258 histogram_tester.ExpectTotalCount( | |
| 259 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 0); | |
| 260 histogram_tester.ExpectTotalCount( | |
| 261 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 0); | |
| 262 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 0); | |
| 263 } | |
| 264 | |
| 265 // This function tests data use measurement for requests by services in case the | |
| 266 // request is redirected once. it makes a query which is similar to a query of a | |
| 267 // service, so it should affect DataUse.TrafficSize.System.Dimensions and | |
| 268 // DataUse.MessageSize.ServiceName histograms. AppState and ConnectionType | |
| 269 // dimensions are always Foreground and NotCellular respectively. | |
| 270 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementServiceTestWithRedirect) { | |
| 271 Initialize(); | |
| 272 base::HistogramTester histogram_tester; | |
| 273 | |
| 274 // A query from user with one redirection. | |
| 275 RequestURL(context(), socket_factory(), false, true); | |
| 276 EXPECT_FALSE( | |
| 277 histogram_tester | |
| 278 .GetTotalCountsForPrefix( | |
| 279 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular") | |
| 280 .empty()); | |
| 281 histogram_tester.ExpectTotalCount( | |
| 282 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 2); | |
| 283 // Two uploads and two downloads message, so totalCount should be 4. | |
| 284 EXPECT_FALSE(histogram_tester | |
| 285 .GetTotalCountsForPrefix("DataUse.MessageSize.Suggestions") | |
| 286 .empty()); | |
| 287 histogram_tester.ExpectTotalCount( | |
| 288 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 0); | |
| 289 histogram_tester.ExpectTotalCount( | |
| 290 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 0); | |
| 291 } | |
| 292 | |
| 293 // This function tests data use measurement for requests by user in case the | |
| 294 // request is redirected once.The query from a user should affect | |
| 295 // DataUse.TrafficSize.User.Dimensions histogram. AppState and ConnectionType | |
| 296 // dimensions are always Foreground and NotCellular respectively. | |
| 297 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementUserTestWithRedirect) { | |
| 298 Initialize(); | |
| 299 base::HistogramTester histogram_tester; | |
| 300 | |
| 301 // A query from user with one redirection. | |
| 302 RequestURL(context(), socket_factory(), true, true); | |
| 303 | |
| 304 EXPECT_FALSE( | |
| 305 histogram_tester | |
| 306 .GetTotalCountsForPrefix( | |
| 307 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular") | |
| 308 .empty()); | |
| 309 histogram_tester.ExpectTotalCount( | |
| 310 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 2); | |
| 311 histogram_tester.ExpectTotalCount( | |
| 312 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 0); | |
| 313 histogram_tester.ExpectTotalCount( | |
| 314 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 0); | |
| 315 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 0); | |
| 316 } | |
| 317 | |
| 318 TEST_F(ChromeNetworkDelegateTest, DisableSameSiteCookiesIffFlagDisabled) { | 182 TEST_F(ChromeNetworkDelegateTest, DisableSameSiteCookiesIffFlagDisabled) { |
| 319 Initialize(); | 183 Initialize(); |
| 320 EXPECT_FALSE(network_delegate()->AreExperimentalCookieFeaturesEnabled()); | 184 EXPECT_FALSE(network_delegate()->AreExperimentalCookieFeaturesEnabled()); |
| 321 } | 185 } |
| 322 | 186 |
| 323 TEST_F(ChromeNetworkDelegateTest, EnableSameSiteCookiesIffFlagEnabled) { | 187 TEST_F(ChromeNetworkDelegateTest, EnableSameSiteCookiesIffFlagEnabled) { |
| 324 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 188 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 325 switches::kEnableExperimentalWebPlatformFeatures); | 189 switches::kEnableExperimentalWebPlatformFeatures); |
| 326 Initialize(); | 190 Initialize(); |
| 327 EXPECT_TRUE(network_delegate()->AreExperimentalCookieFeaturesEnabled()); | 191 EXPECT_TRUE(network_delegate()->AreExperimentalCookieFeaturesEnabled()); |
| 328 } | 192 } |
| 329 | 193 |
| 330 TEST_F(ChromeNetworkDelegateTest, ReportDataUseToAggregator) { | 194 TEST_F(ChromeNetworkDelegateTest, ReportDataUseToAggregator) { |
| 331 FakeDataUseAggregator fake_aggregator; | 195 FakeDataUseAggregator fake_aggregator; |
| 332 Initialize(); | 196 Initialize(); |
| 333 | 197 |
| 334 chrome_network_delegate()->set_data_use_aggregator( | 198 chrome_network_delegate()->set_data_use_aggregator( |
| 335 &fake_aggregator, false /* is_data_usage_off_the_record */); | 199 &fake_aggregator, false /* is_data_usage_off_the_record */); |
| 336 | 200 |
| 337 std::unique_ptr<net::URLRequest> request = | 201 std::unique_ptr<net::URLRequest> request = |
| 338 RequestURL(context(), socket_factory(), true, false); | 202 RequestURL(context(), socket_factory()); |
| 339 EXPECT_EQ(request->GetTotalSentBytes(), | 203 EXPECT_EQ(request->GetTotalSentBytes(), |
| 340 fake_aggregator.on_the_record_tx_bytes()); | 204 fake_aggregator.on_the_record_tx_bytes()); |
| 341 EXPECT_EQ(request->GetTotalReceivedBytes(), | 205 EXPECT_EQ(request->GetTotalReceivedBytes(), |
| 342 fake_aggregator.on_the_record_rx_bytes()); | 206 fake_aggregator.on_the_record_rx_bytes()); |
| 343 EXPECT_EQ(0, fake_aggregator.off_the_record_tx_bytes()); | 207 EXPECT_EQ(0, fake_aggregator.off_the_record_tx_bytes()); |
| 344 EXPECT_EQ(0, fake_aggregator.off_the_record_rx_bytes()); | 208 EXPECT_EQ(0, fake_aggregator.off_the_record_rx_bytes()); |
| 345 } | 209 } |
| 346 | 210 |
| 347 TEST_F(ChromeNetworkDelegateTest, ReportOffTheRecordDataUseToAggregator) { | 211 TEST_F(ChromeNetworkDelegateTest, ReportOffTheRecordDataUseToAggregator) { |
| 348 FakeDataUseAggregator fake_aggregator; | 212 FakeDataUseAggregator fake_aggregator; |
| 349 Initialize(); | 213 Initialize(); |
| 350 | 214 |
| 351 chrome_network_delegate()->set_data_use_aggregator( | 215 chrome_network_delegate()->set_data_use_aggregator( |
| 352 &fake_aggregator, true /* is_data_usage_off_the_record */); | 216 &fake_aggregator, true /* is_data_usage_off_the_record */); |
| 353 std::unique_ptr<net::URLRequest> request = | 217 std::unique_ptr<net::URLRequest> request = |
| 354 RequestURL(context(), socket_factory(), true, false); | 218 RequestURL(context(), socket_factory()); |
| 355 | 219 |
| 356 EXPECT_EQ(0, fake_aggregator.on_the_record_tx_bytes()); | 220 EXPECT_EQ(0, fake_aggregator.on_the_record_tx_bytes()); |
| 357 EXPECT_EQ(0, fake_aggregator.on_the_record_rx_bytes()); | 221 EXPECT_EQ(0, fake_aggregator.on_the_record_rx_bytes()); |
| 358 EXPECT_EQ(request->GetTotalSentBytes(), | 222 EXPECT_EQ(request->GetTotalSentBytes(), |
| 359 fake_aggregator.off_the_record_tx_bytes()); | 223 fake_aggregator.off_the_record_tx_bytes()); |
| 360 EXPECT_EQ(request->GetTotalReceivedBytes(), | 224 EXPECT_EQ(request->GetTotalReceivedBytes(), |
| 361 fake_aggregator.off_the_record_rx_bytes()); | 225 fake_aggregator.off_the_record_rx_bytes()); |
| 362 } | 226 } |
| 363 | 227 |
| 364 class ChromeNetworkDelegatePolicyTest : public testing::Test { | 228 class ChromeNetworkDelegatePolicyTest : public testing::Test { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 nullptr, | 267 nullptr, |
| 404 &force_google_safe_search_, | 268 &force_google_safe_search_, |
| 405 &force_youtube_restrict_, | 269 &force_youtube_restrict_, |
| 406 nullptr, | 270 nullptr, |
| 407 profile_.GetTestingPrefService()); | 271 profile_.GetTestingPrefService()); |
| 408 } | 272 } |
| 409 | 273 |
| 410 protected: | 274 protected: |
| 411 std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate() { | 275 std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate() { |
| 412 std::unique_ptr<ChromeNetworkDelegate> network_delegate( | 276 std::unique_ptr<ChromeNetworkDelegate> network_delegate( |
| 413 new ChromeNetworkDelegate(forwarder(), &enable_referrers_, | 277 new ChromeNetworkDelegate(forwarder(), &enable_referrers_)); |
| 414 metrics::UpdateUsagePrefCallbackType())); | |
| 415 network_delegate->set_force_google_safe_search(&force_google_safe_search_); | 278 network_delegate->set_force_google_safe_search(&force_google_safe_search_); |
| 416 network_delegate->set_force_youtube_restrict(&force_youtube_restrict_); | 279 network_delegate->set_force_youtube_restrict(&force_youtube_restrict_); |
| 417 return std::move(network_delegate); | 280 return std::move(network_delegate); |
| 418 } | 281 } |
| 419 | 282 |
| 420 void SetSafeSearch(bool google_safe_search, int youtube_restrict) { | 283 void SetSafeSearch(bool google_safe_search, int youtube_restrict) { |
| 421 force_google_safe_search_.SetValue(google_safe_search); | 284 force_google_safe_search_.SetValue(google_safe_search); |
| 422 force_youtube_restrict_.SetValue(youtube_restrict); | 285 force_youtube_restrict_.SetValue(youtube_restrict); |
| 423 } | 286 } |
| 424 | 287 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 nullptr, | 338 nullptr, |
| 476 nullptr, | 339 nullptr, |
| 477 nullptr, | 340 nullptr, |
| 478 &allowed_domains_for_apps_, | 341 &allowed_domains_for_apps_, |
| 479 profile_.GetTestingPrefService()); | 342 profile_.GetTestingPrefService()); |
| 480 } | 343 } |
| 481 | 344 |
| 482 protected: | 345 protected: |
| 483 std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate() { | 346 std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate() { |
| 484 std::unique_ptr<ChromeNetworkDelegate> network_delegate( | 347 std::unique_ptr<ChromeNetworkDelegate> network_delegate( |
| 485 new ChromeNetworkDelegate(forwarder(), &enable_referrers_, | 348 new ChromeNetworkDelegate(forwarder(), &enable_referrers_)); |
| 486 metrics::UpdateUsagePrefCallbackType())); | |
| 487 network_delegate->set_allowed_domains_for_apps(&allowed_domains_for_apps_); | 349 network_delegate->set_allowed_domains_for_apps(&allowed_domains_for_apps_); |
| 488 return std::move(network_delegate); | 350 return std::move(network_delegate); |
| 489 } | 351 } |
| 490 | 352 |
| 491 // Will set the AllowedDomainsForApps policy to have the value of |allowed|. | 353 // Will set the AllowedDomainsForApps policy to have the value of |allowed|. |
| 492 // Will make a request to |url| and check the headers in request. | 354 // Will make a request to |url| and check the headers in request. |
| 493 // If |expected| is passed as false, this routine verifies that no | 355 // If |expected| is passed as false, this routine verifies that no |
| 494 // X-GoogApps-Allowed-Domains header is set. If |expected| is passed as true, | 356 // X-GoogApps-Allowed-Domains header is set. If |expected| is passed as true, |
| 495 // this routine verifies that the X-GoogApps-Allowed-Domains header is set and | 357 // this routine verifies that the X-GoogApps-Allowed-Domains header is set and |
| 496 // the value is identical to |allowed|. | 358 // the value is identical to |allowed|. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 | 432 |
| 571 void SetUp() override { | 433 void SetUp() override { |
| 572 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 434 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 573 &enable_referrers_, nullptr, nullptr, nullptr, nullptr, | 435 &enable_referrers_, nullptr, nullptr, nullptr, nullptr, |
| 574 profile_.GetTestingPrefService()); | 436 profile_.GetTestingPrefService()); |
| 575 } | 437 } |
| 576 | 438 |
| 577 protected: | 439 protected: |
| 578 std::unique_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { | 440 std::unique_ptr<ChromeNetworkDelegate> CreateNetworkDelegate() { |
| 579 std::unique_ptr<ChromeNetworkDelegate> network_delegate( | 441 std::unique_ptr<ChromeNetworkDelegate> network_delegate( |
| 580 new ChromeNetworkDelegate(forwarder(), &enable_referrers_, | 442 new ChromeNetworkDelegate(forwarder(), &enable_referrers_)); |
| 581 metrics::UpdateUsagePrefCallbackType())); | |
| 582 network_delegate->set_cookie_settings(cookie_settings_); | 443 network_delegate->set_cookie_settings(cookie_settings_); |
| 583 return network_delegate; | 444 return network_delegate; |
| 584 } | 445 } |
| 585 | 446 |
| 586 void SetDelegate(net::NetworkDelegate* delegate) { | 447 void SetDelegate(net::NetworkDelegate* delegate) { |
| 587 network_delegate_ = delegate; | 448 network_delegate_ = delegate; |
| 588 context_.set_network_delegate(network_delegate_); | 449 context_.set_network_delegate(network_delegate_); |
| 589 } | 450 } |
| 590 | 451 |
| 591 protected: | 452 protected: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 | 519 |
| 659 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 520 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
| 660 kBlockedFirstPartySite)); | 521 kBlockedFirstPartySite)); |
| 661 | 522 |
| 662 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, | 523 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, |
| 663 CONTENT_SETTING_BLOCK); | 524 CONTENT_SETTING_BLOCK); |
| 664 // Privacy mode is disabled as kAllowedSite is still getting cookies | 525 // Privacy mode is disabled as kAllowedSite is still getting cookies |
| 665 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 526 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
| 666 kBlockedFirstPartySite)); | 527 kBlockedFirstPartySite)); |
| 667 } | 528 } |
| OLD | NEW |