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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/prefs/pref_member.h" | 15 #include "base/prefs/pref_member.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/test/histogram_tester.h" | 17 #include "base/test/histogram_tester.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 20 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 21 #include "chrome/browser/net/expect_ct_monitor.h" |
21 #include "chrome/browser/net/safe_search_util.h" | 22 #include "chrome/browser/net/safe_search_util.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "chrome/test/base/testing_browser_process.h" | 24 #include "chrome/test/base/testing_browser_process.h" |
24 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
25 #include "chrome/test/base/testing_profile_manager.h" | 26 #include "chrome/test/base/testing_profile_manager.h" |
26 #include "components/content_settings/core/browser/cookie_settings.h" | 27 #include "components/content_settings/core/browser/cookie_settings.h" |
27 #include "components/content_settings/core/common/pref_names.h" | 28 #include "components/content_settings/core/common/pref_names.h" |
28 #include "components/data_usage/core/data_use_aggregator.h" | 29 #include "components/data_usage/core/data_use_aggregator.h" |
29 #include "components/data_usage/core/data_use_amortizer.h" | 30 #include "components/data_usage/core/data_use_amortizer.h" |
30 #include "components/data_usage/core/data_use_annotator.h" | 31 #include "components/data_usage/core/data_use_annotator.h" |
(...skipping 20 matching lines...) Expand all Loading... |
51 namespace { | 52 namespace { |
52 | 53 |
53 // This function requests a URL, and makes it return a known response. If | 54 // This function requests a URL, and makes it return a known response. If |
54 // |from_user| is true, it attaches a ResourceRequestInfo to the URLRequest, | 55 // |from_user| is true, it attaches a ResourceRequestInfo to the URLRequest, |
55 // because requests from users have this info. If |from_user| is false, the | 56 // because requests from users have this info. If |from_user| is false, the |
56 // request is presumed to be from a service, and the service name is set in the | 57 // 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 // 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 // |redirect| is true, it adds necessary socket data to have it follow redirect |
59 // before getting the final response. | 60 // before getting the final response. |
60 scoped_ptr<net::URLRequest> RequestURL( | 61 scoped_ptr<net::URLRequest> RequestURL( |
| 62 GURL url, |
61 net::URLRequestContext* context, | 63 net::URLRequestContext* context, |
62 net::MockClientSocketFactory* socket_factory, | 64 net::MockClientSocketFactory* socket_factory, |
63 bool from_user, | 65 bool from_user, |
64 bool redirect) { | 66 bool redirect) { |
65 net::MockRead redirect_mock_reads[] = { | 67 net::MockRead redirect_mock_reads[] = { |
66 net::MockRead("HTTP/1.1 302 Found\r\n" | 68 net::MockRead("HTTP/1.1 302 Found\r\n" |
67 "Location: http://bar.com/\r\n\r\n"), | 69 "Location: http://bar.com/\r\n\r\n"), |
68 net::MockRead(net::SYNCHRONOUS, net::OK), | 70 net::MockRead(net::SYNCHRONOUS, net::OK), |
69 }; | 71 }; |
70 net::StaticSocketDataProvider redirect_socket_data_provider( | 72 net::StaticSocketDataProvider redirect_socket_data_provider( |
71 redirect_mock_reads, arraysize(redirect_mock_reads), nullptr, 0); | 73 redirect_mock_reads, arraysize(redirect_mock_reads), nullptr, 0); |
72 | 74 |
73 if (redirect) | 75 if (redirect) |
74 socket_factory->AddSocketDataProvider(&redirect_socket_data_provider); | 76 socket_factory->AddSocketDataProvider(&redirect_socket_data_provider); |
75 net::MockRead response_mock_reads[] = { | 77 net::MockRead response_mock_reads[] = { |
76 net::MockRead("HTTP/1.1 200 OK\r\n\r\n"), net::MockRead("response body"), | 78 net::MockRead("HTTP/1.1 200 OK\r\n\r\n"), net::MockRead("response body"), |
77 net::MockRead(net::SYNCHRONOUS, net::OK), | 79 net::MockRead(net::SYNCHRONOUS, net::OK), |
78 }; | 80 }; |
79 net::StaticSocketDataProvider response_socket_data_provider( | 81 net::StaticSocketDataProvider response_socket_data_provider( |
80 response_mock_reads, arraysize(response_mock_reads), nullptr, 0); | 82 response_mock_reads, arraysize(response_mock_reads), nullptr, 0); |
81 socket_factory->AddSocketDataProvider(&response_socket_data_provider); | 83 socket_factory->AddSocketDataProvider(&response_socket_data_provider); |
82 net::TestDelegate test_delegate; | 84 net::TestDelegate test_delegate; |
83 test_delegate.set_quit_on_complete(true); | 85 test_delegate.set_quit_on_complete(true); |
84 scoped_ptr<net::URLRequest> request(context->CreateRequest( | 86 scoped_ptr<net::URLRequest> request( |
85 GURL("http://example.com"), net::DEFAULT_PRIORITY, &test_delegate)); | 87 context->CreateRequest(url, net::DEFAULT_PRIORITY, &test_delegate)); |
86 | 88 |
87 if (from_user) { | 89 if (from_user) { |
88 content::ResourceRequestInfo::AllocateForTesting( | 90 content::ResourceRequestInfo::AllocateForTesting( |
89 request.get(), content::RESOURCE_TYPE_MAIN_FRAME, nullptr, -2, -2, -2, | 91 request.get(), content::RESOURCE_TYPE_MAIN_FRAME, nullptr, -2, -2, -2, |
90 true, false, true, true, false); | 92 true, false, true, true, false); |
91 } else { | 93 } else { |
92 request->SetUserData( | 94 request->SetUserData( |
93 data_use_measurement::DataUseUserData::kUserDataKey, | 95 data_use_measurement::DataUseUserData::kUserDataKey, |
94 new data_use_measurement::DataUseUserData( | 96 new data_use_measurement::DataUseUserData( |
95 data_use_measurement::DataUseUserData::SUGGESTIONS)); | 97 data_use_measurement::DataUseUserData::SUGGESTIONS)); |
96 } | 98 } |
97 request->Start(); | 99 request->Start(); |
98 base::RunLoop().RunUntilIdle(); | 100 base::RunLoop().RunUntilIdle(); |
99 return request; | 101 return request; |
100 } | 102 } |
101 | 103 |
| 104 scoped_ptr<net::URLRequest> RequestNonSSLURL( |
| 105 net::URLRequestContext* context, |
| 106 net::MockClientSocketFactory* socket_factory, |
| 107 bool from_user, |
| 108 bool redirect) { |
| 109 return RequestURL(GURL("http://example.test"), context, socket_factory, |
| 110 from_user, redirect); |
| 111 } |
| 112 |
| 113 scoped_ptr<net::URLRequest> RequestSSLURL( |
| 114 net::CertStatus cert_status, |
| 115 net::URLRequestContext* context, |
| 116 net::MockClientSocketFactory* socket_factory, |
| 117 bool from_user, |
| 118 bool redirect) { |
| 119 net::SSLSocketDataProvider ssl_data(net::ASYNC, net::OK); |
| 120 ssl_data.cert_status = cert_status; |
| 121 socket_factory->AddSSLSocketDataProvider(&ssl_data); |
| 122 return RequestURL(GURL("https://example.test"), context, socket_factory, |
| 123 from_user, redirect); |
| 124 } |
| 125 |
102 // A fake DataUseAggregator for testing that only counts how many times its | 126 // A fake DataUseAggregator for testing that only counts how many times its |
103 // respective methods have been called. | 127 // respective methods have been called. |
104 class FakeDataUseAggregator : public data_usage::DataUseAggregator { | 128 class FakeDataUseAggregator : public data_usage::DataUseAggregator { |
105 public: | 129 public: |
106 FakeDataUseAggregator() | 130 FakeDataUseAggregator() |
107 : data_usage::DataUseAggregator( | 131 : data_usage::DataUseAggregator( |
108 scoped_ptr<data_usage::DataUseAnnotator>(), | 132 scoped_ptr<data_usage::DataUseAnnotator>(), |
109 scoped_ptr<data_usage::DataUseAmortizer>()), | 133 scoped_ptr<data_usage::DataUseAmortizer>()), |
110 on_the_record_tx_bytes_(0), | 134 on_the_record_tx_bytes_(0), |
111 on_the_record_rx_bytes_(0), | 135 on_the_record_rx_bytes_(0), |
(...skipping 18 matching lines...) Expand all Loading... |
130 int64_t off_the_record_tx_bytes() const { return off_the_record_tx_bytes_; } | 154 int64_t off_the_record_tx_bytes() const { return off_the_record_tx_bytes_; } |
131 int64_t off_the_record_rx_bytes() const { return off_the_record_rx_bytes_; } | 155 int64_t off_the_record_rx_bytes() const { return off_the_record_rx_bytes_; } |
132 | 156 |
133 private: | 157 private: |
134 int64_t on_the_record_tx_bytes_; | 158 int64_t on_the_record_tx_bytes_; |
135 int64_t on_the_record_rx_bytes_; | 159 int64_t on_the_record_rx_bytes_; |
136 int64_t off_the_record_tx_bytes_; | 160 int64_t off_the_record_tx_bytes_; |
137 int64_t off_the_record_rx_bytes_; | 161 int64_t off_the_record_rx_bytes_; |
138 }; | 162 }; |
139 | 163 |
| 164 class TestExpectCTMonitor : public ExpectCTMonitor { |
| 165 public: |
| 166 TestExpectCTMonitor() : num_ct_compliance_failures_(0) {} |
| 167 ~TestExpectCTMonitor() override {} |
| 168 |
| 169 size_t num_ct_compliance_failures() { return num_ct_compliance_failures_; } |
| 170 |
| 171 // ExpectCTMonitor: |
| 172 void OnCTComplianceFailed(net::URLRequest* request) override { |
| 173 num_ct_compliance_failures_++; |
| 174 } |
| 175 |
| 176 private: |
| 177 size_t num_ct_compliance_failures_; |
| 178 }; |
| 179 |
140 } // namespace | 180 } // namespace |
141 | 181 |
142 class ChromeNetworkDelegateTest : public testing::Test { | 182 class ChromeNetworkDelegateTest : public testing::Test { |
143 public: | 183 public: |
144 ChromeNetworkDelegateTest() | 184 ChromeNetworkDelegateTest() |
145 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 185 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
146 context_(new net::TestURLRequestContext(true)) { | 186 context_(new net::TestURLRequestContext(true)) { |
147 #if defined(ENABLE_EXTENSIONS) | 187 #if defined(ENABLE_EXTENSIONS) |
148 forwarder_ = new extensions::EventRouterForwarder(); | 188 forwarder_ = new extensions::EventRouterForwarder(); |
149 #endif | 189 #endif |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // query which is similar to a query of a service, so it should affect | 239 // query which is similar to a query of a service, so it should affect |
200 // DataUse.TrafficSize.System.Dimensions and DataUse.MessageSize.ServiceName | 240 // DataUse.TrafficSize.System.Dimensions and DataUse.MessageSize.ServiceName |
201 // histograms. AppState and ConnectionType dimensions are always Foreground and | 241 // histograms. AppState and ConnectionType dimensions are always Foreground and |
202 // NotCellular respectively. | 242 // NotCellular respectively. |
203 #if !defined(OS_IOS) | 243 #if !defined(OS_IOS) |
204 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementServiceTest) { | 244 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementServiceTest) { |
205 Initialize(); | 245 Initialize(); |
206 base::HistogramTester histogram_tester; | 246 base::HistogramTester histogram_tester; |
207 | 247 |
208 // A query from a service without redirection. | 248 // A query from a service without redirection. |
209 RequestURL(context(), socket_factory(), false, false); | 249 RequestNonSSLURL(context(), socket_factory(), false, false); |
210 histogram_tester.ExpectTotalCount( | 250 histogram_tester.ExpectTotalCount( |
211 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 1); | 251 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 1); |
212 histogram_tester.ExpectTotalCount( | 252 histogram_tester.ExpectTotalCount( |
213 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 1); | 253 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 1); |
214 // One upload and one download message, so totalCount should be 2. | 254 // One upload and one download message, so totalCount should be 2. |
215 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 2); | 255 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 2); |
216 histogram_tester.ExpectTotalCount( | 256 histogram_tester.ExpectTotalCount( |
217 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 0); | 257 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 0); |
218 histogram_tester.ExpectTotalCount( | 258 histogram_tester.ExpectTotalCount( |
219 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 0); | 259 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 0); |
220 } | 260 } |
221 | 261 |
222 // This function tests data use measurement for requests by user.The query from | 262 // This function tests data use measurement for requests by user.The query from |
223 // a user should affect DataUse.TrafficSize.User.Dimensions histogram. AppState | 263 // a user should affect DataUse.TrafficSize.User.Dimensions histogram. AppState |
224 // and ConnectionType dimensions are always Foreground and NotCellular | 264 // and ConnectionType dimensions are always Foreground and NotCellular |
225 // respectively. | 265 // respectively. |
226 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementUserTest) { | 266 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementUserTest) { |
227 Initialize(); | 267 Initialize(); |
228 base::HistogramTester histogram_tester; | 268 base::HistogramTester histogram_tester; |
229 | 269 |
230 // A query from user without redirection. | 270 // A query from user without redirection. |
231 RequestURL(context(), socket_factory(), true, false); | 271 RequestNonSSLURL(context(), socket_factory(), true, false); |
232 histogram_tester.ExpectTotalCount( | 272 histogram_tester.ExpectTotalCount( |
233 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 1); | 273 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 1); |
234 histogram_tester.ExpectTotalCount( | 274 histogram_tester.ExpectTotalCount( |
235 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 1); | 275 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 1); |
236 histogram_tester.ExpectTotalCount( | 276 histogram_tester.ExpectTotalCount( |
237 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 0); | 277 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 0); |
238 histogram_tester.ExpectTotalCount( | 278 histogram_tester.ExpectTotalCount( |
239 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 0); | 279 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 0); |
240 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 0); | 280 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 0); |
241 } | 281 } |
242 | 282 |
243 // This function tests data use measurement for requests by services in case the | 283 // This function tests data use measurement for requests by services in case the |
244 // request is redirected once. it makes a query which is similar to a query of a | 284 // request is redirected once. it makes a query which is similar to a query of a |
245 // service, so it should affect DataUse.TrafficSize.System.Dimensions and | 285 // service, so it should affect DataUse.TrafficSize.System.Dimensions and |
246 // DataUse.MessageSize.ServiceName histograms. AppState and ConnectionType | 286 // DataUse.MessageSize.ServiceName histograms. AppState and ConnectionType |
247 // dimensions are always Foreground and NotCellular respectively. | 287 // dimensions are always Foreground and NotCellular respectively. |
248 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementServiceTestWithRedirect) { | 288 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementServiceTestWithRedirect) { |
249 Initialize(); | 289 Initialize(); |
250 base::HistogramTester histogram_tester; | 290 base::HistogramTester histogram_tester; |
251 | 291 |
252 // A query from user with one redirection. | 292 // A query from user with one redirection. |
253 RequestURL(context(), socket_factory(), false, true); | 293 RequestNonSSLURL(context(), socket_factory(), false, true); |
254 histogram_tester.ExpectTotalCount( | 294 histogram_tester.ExpectTotalCount( |
255 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 2); | 295 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 2); |
256 histogram_tester.ExpectTotalCount( | 296 histogram_tester.ExpectTotalCount( |
257 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 2); | 297 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 2); |
258 // Two uploads and two downloads message, so totalCount should be 4. | 298 // Two uploads and two downloads message, so totalCount should be 4. |
259 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 4); | 299 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 4); |
260 histogram_tester.ExpectTotalCount( | 300 histogram_tester.ExpectTotalCount( |
261 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 0); | 301 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 0); |
262 histogram_tester.ExpectTotalCount( | 302 histogram_tester.ExpectTotalCount( |
263 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 0); | 303 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 0); |
264 } | 304 } |
265 | 305 |
266 // This function tests data use measurement for requests by user in case the | 306 // This function tests data use measurement for requests by user in case the |
267 // request is redirected once.The query from a user should affect | 307 // request is redirected once.The query from a user should affect |
268 // DataUse.TrafficSize.User.Dimensions histogram. AppState and ConnectionType | 308 // DataUse.TrafficSize.User.Dimensions histogram. AppState and ConnectionType |
269 // dimensions are always Foreground and NotCellular respectively. | 309 // dimensions are always Foreground and NotCellular respectively. |
270 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementUserTestWithRedirect) { | 310 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementUserTestWithRedirect) { |
271 Initialize(); | 311 Initialize(); |
272 base::HistogramTester histogram_tester; | 312 base::HistogramTester histogram_tester; |
273 | 313 |
274 // A query from user with one redirection. | 314 // A query from user with one redirection. |
275 RequestURL(context(), socket_factory(), true, true); | 315 RequestNonSSLURL(context(), socket_factory(), true, true); |
276 | 316 |
277 histogram_tester.ExpectTotalCount( | 317 histogram_tester.ExpectTotalCount( |
278 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 2); | 318 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 2); |
279 histogram_tester.ExpectTotalCount( | 319 histogram_tester.ExpectTotalCount( |
280 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 2); | 320 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 2); |
281 histogram_tester.ExpectTotalCount( | 321 histogram_tester.ExpectTotalCount( |
282 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 0); | 322 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 0); |
283 histogram_tester.ExpectTotalCount( | 323 histogram_tester.ExpectTotalCount( |
284 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 0); | 324 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 0); |
285 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 0); | 325 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 0); |
(...skipping 14 matching lines...) Expand all Loading... |
300 } | 340 } |
301 | 341 |
302 TEST_F(ChromeNetworkDelegateTest, ReportDataUseToAggregator) { | 342 TEST_F(ChromeNetworkDelegateTest, ReportDataUseToAggregator) { |
303 FakeDataUseAggregator fake_aggregator; | 343 FakeDataUseAggregator fake_aggregator; |
304 Initialize(); | 344 Initialize(); |
305 | 345 |
306 chrome_network_delegate()->set_data_use_aggregator( | 346 chrome_network_delegate()->set_data_use_aggregator( |
307 &fake_aggregator, false /* is_data_usage_off_the_record */); | 347 &fake_aggregator, false /* is_data_usage_off_the_record */); |
308 | 348 |
309 scoped_ptr<net::URLRequest> request = | 349 scoped_ptr<net::URLRequest> request = |
310 RequestURL(context(), socket_factory(), true, false); | 350 RequestNonSSLURL(context(), socket_factory(), true, false); |
311 EXPECT_EQ(request->GetTotalSentBytes(), | 351 EXPECT_EQ(request->GetTotalSentBytes(), |
312 fake_aggregator.on_the_record_tx_bytes()); | 352 fake_aggregator.on_the_record_tx_bytes()); |
313 EXPECT_EQ(request->GetTotalReceivedBytes(), | 353 EXPECT_EQ(request->GetTotalReceivedBytes(), |
314 fake_aggregator.on_the_record_rx_bytes()); | 354 fake_aggregator.on_the_record_rx_bytes()); |
315 EXPECT_EQ(0, fake_aggregator.off_the_record_tx_bytes()); | 355 EXPECT_EQ(0, fake_aggregator.off_the_record_tx_bytes()); |
316 EXPECT_EQ(0, fake_aggregator.off_the_record_rx_bytes()); | 356 EXPECT_EQ(0, fake_aggregator.off_the_record_rx_bytes()); |
317 } | 357 } |
318 | 358 |
319 TEST_F(ChromeNetworkDelegateTest, ReportOffTheRecordDataUseToAggregator) { | 359 TEST_F(ChromeNetworkDelegateTest, ReportOffTheRecordDataUseToAggregator) { |
320 FakeDataUseAggregator fake_aggregator; | 360 FakeDataUseAggregator fake_aggregator; |
321 Initialize(); | 361 Initialize(); |
322 | 362 |
323 chrome_network_delegate()->set_data_use_aggregator( | 363 chrome_network_delegate()->set_data_use_aggregator( |
324 &fake_aggregator, true /* is_data_usage_off_the_record */); | 364 &fake_aggregator, true /* is_data_usage_off_the_record */); |
325 scoped_ptr<net::URLRequest> request = | 365 scoped_ptr<net::URLRequest> request = |
326 RequestURL(context(), socket_factory(), true, false); | 366 RequestNonSSLURL(context(), socket_factory(), true, false); |
327 | 367 |
328 EXPECT_EQ(0, fake_aggregator.on_the_record_tx_bytes()); | 368 EXPECT_EQ(0, fake_aggregator.on_the_record_tx_bytes()); |
329 EXPECT_EQ(0, fake_aggregator.on_the_record_rx_bytes()); | 369 EXPECT_EQ(0, fake_aggregator.on_the_record_rx_bytes()); |
330 EXPECT_EQ(request->GetTotalSentBytes(), | 370 EXPECT_EQ(request->GetTotalSentBytes(), |
331 fake_aggregator.off_the_record_tx_bytes()); | 371 fake_aggregator.off_the_record_tx_bytes()); |
332 EXPECT_EQ(request->GetTotalReceivedBytes(), | 372 EXPECT_EQ(request->GetTotalReceivedBytes(), |
333 fake_aggregator.off_the_record_rx_bytes()); | 373 fake_aggregator.off_the_record_rx_bytes()); |
334 } | 374 } |
335 | 375 |
336 class ChromeNetworkDelegateSafeSearchTest : public testing::Test { | 376 class ChromeNetworkDelegateSafeSearchTest : public testing::Test { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 kBlockedFirstPartySite)); | 577 kBlockedFirstPartySite)); |
538 | 578 |
539 cookie_settings_->SetCookieSetting( | 579 cookie_settings_->SetCookieSetting( |
540 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), | 580 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), |
541 ContentSettingsPattern::Wildcard(), | 581 ContentSettingsPattern::Wildcard(), |
542 CONTENT_SETTING_BLOCK); | 582 CONTENT_SETTING_BLOCK); |
543 // Privacy mode is disabled as kAllowedSite is still getting cookies | 583 // Privacy mode is disabled as kAllowedSite is still getting cookies |
544 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 584 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
545 kBlockedFirstPartySite)); | 585 kBlockedFirstPartySite)); |
546 } | 586 } |
| 587 |
| 588 // Tests that the ExpectCTMonitor is invoked when an Expect CT site |
| 589 // violates the Certificate Transparency policy, and not invoked for a |
| 590 // non-HTTPS request or an HTTPS request that doesn't violate the CT |
| 591 // policy. |
| 592 TEST_F(ChromeNetworkDelegateTest, ExpectCTMonitor) { |
| 593 Initialize(); |
| 594 TestExpectCTMonitor monitor; |
| 595 chrome_network_delegate()->set_expect_ct_monitor(&monitor); |
| 596 EXPECT_EQ(0u, monitor.num_ct_compliance_failures()); |
| 597 RequestSSLURL(net::CERT_STATUS_CT_COMPLIANCE_FAILED, context(), |
| 598 socket_factory(), true, false); |
| 599 EXPECT_EQ(1u, monitor.num_ct_compliance_failures()); |
| 600 RequestNonSSLURL(context(), socket_factory(), true, false); |
| 601 EXPECT_EQ(1u, monitor.num_ct_compliance_failures()); |
| 602 RequestSSLURL(0, context(), socket_factory(), true, false); |
| 603 EXPECT_EQ(1u, monitor.num_ct_compliance_failures()); |
| 604 } |
OLD | NEW |