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

Side by Side Diff: chrome/browser/net/chrome_network_delegate_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698