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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // query which is similar to a query of a service, so it should affect | 215 // query which is similar to a query of a service, so it should affect |
216 // DataUse.TrafficSize.System.Dimensions and DataUse.MessageSize.ServiceName | 216 // DataUse.TrafficSize.System.Dimensions and DataUse.MessageSize.ServiceName |
217 // histograms. AppState and ConnectionType dimensions are always Foreground and | 217 // histograms. AppState and ConnectionType dimensions are always Foreground and |
218 // NotCellular respectively. | 218 // NotCellular respectively. |
219 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementServiceTest) { | 219 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementServiceTest) { |
220 Initialize(); | 220 Initialize(); |
221 base::HistogramTester histogram_tester; | 221 base::HistogramTester histogram_tester; |
222 | 222 |
223 // A query from a service without redirection. | 223 // A query from a service without redirection. |
224 RequestURL(context(), socket_factory(), false, false); | 224 RequestURL(context(), socket_factory(), false, false); |
225 histogram_tester.ExpectTotalCount( | 225 EXPECT_FALSE( |
226 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 1); | 226 histogram_tester |
| 227 .GetTotalCountsForPrefix( |
| 228 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular") |
| 229 .empty()); |
227 histogram_tester.ExpectTotalCount( | 230 histogram_tester.ExpectTotalCount( |
228 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 1); | 231 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 1); |
229 // One upload and one download message, so totalCount should be 2. | 232 EXPECT_FALSE(histogram_tester |
230 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 2); | 233 .GetTotalCountsForPrefix("DataUse.MessageSize.Suggestions") |
| 234 .empty()); |
231 histogram_tester.ExpectTotalCount( | 235 histogram_tester.ExpectTotalCount( |
232 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 0); | 236 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 0); |
233 histogram_tester.ExpectTotalCount( | 237 histogram_tester.ExpectTotalCount( |
234 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 0); | 238 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 0); |
235 } | 239 } |
236 | 240 |
237 // This function tests data use measurement for requests by user.The query from | 241 // This function tests data use measurement for requests by user.The query from |
238 // a user should affect DataUse.TrafficSize.User.Dimensions histogram. AppState | 242 // a user should affect DataUse.TrafficSize.User.Dimensions histogram. AppState |
239 // and ConnectionType dimensions are always Foreground and NotCellular | 243 // and ConnectionType dimensions are always Foreground and NotCellular |
240 // respectively. | 244 // respectively. |
241 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementUserTest) { | 245 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementUserTest) { |
242 Initialize(); | 246 Initialize(); |
243 base::HistogramTester histogram_tester; | 247 base::HistogramTester histogram_tester; |
244 | 248 |
245 // A query from user without redirection. | 249 // A query from user without redirection. |
246 RequestURL(context(), socket_factory(), true, false); | 250 RequestURL(context(), socket_factory(), true, false); |
247 histogram_tester.ExpectTotalCount( | 251 EXPECT_FALSE( |
248 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 1); | 252 histogram_tester |
| 253 .GetTotalCountsForPrefix( |
| 254 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular") |
| 255 .empty()); |
249 histogram_tester.ExpectTotalCount( | 256 histogram_tester.ExpectTotalCount( |
250 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 1); | 257 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 1); |
251 histogram_tester.ExpectTotalCount( | 258 histogram_tester.ExpectTotalCount( |
252 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 0); | 259 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 0); |
253 histogram_tester.ExpectTotalCount( | 260 histogram_tester.ExpectTotalCount( |
254 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 0); | 261 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 0); |
255 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 0); | 262 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 0); |
256 } | 263 } |
257 | 264 |
258 // This function tests data use measurement for requests by services in case the | 265 // This function tests data use measurement for requests by services in case the |
259 // request is redirected once. it makes a query which is similar to a query of a | 266 // request is redirected once. it makes a query which is similar to a query of a |
260 // service, so it should affect DataUse.TrafficSize.System.Dimensions and | 267 // service, so it should affect DataUse.TrafficSize.System.Dimensions and |
261 // DataUse.MessageSize.ServiceName histograms. AppState and ConnectionType | 268 // DataUse.MessageSize.ServiceName histograms. AppState and ConnectionType |
262 // dimensions are always Foreground and NotCellular respectively. | 269 // dimensions are always Foreground and NotCellular respectively. |
263 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementServiceTestWithRedirect) { | 270 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementServiceTestWithRedirect) { |
264 Initialize(); | 271 Initialize(); |
265 base::HistogramTester histogram_tester; | 272 base::HistogramTester histogram_tester; |
266 | 273 |
267 // A query from user with one redirection. | 274 // A query from user with one redirection. |
268 RequestURL(context(), socket_factory(), false, true); | 275 RequestURL(context(), socket_factory(), false, true); |
269 histogram_tester.ExpectTotalCount( | 276 EXPECT_FALSE( |
270 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 2); | 277 histogram_tester |
| 278 .GetTotalCountsForPrefix( |
| 279 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular") |
| 280 .empty()); |
271 histogram_tester.ExpectTotalCount( | 281 histogram_tester.ExpectTotalCount( |
272 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 2); | 282 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 2); |
273 // Two uploads and two downloads message, so totalCount should be 4. | 283 // Two uploads and two downloads message, so totalCount should be 4. |
274 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 4); | 284 EXPECT_FALSE(histogram_tester |
| 285 .GetTotalCountsForPrefix("DataUse.MessageSize.Suggestions") |
| 286 .empty()); |
275 histogram_tester.ExpectTotalCount( | 287 histogram_tester.ExpectTotalCount( |
276 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 0); | 288 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 0); |
277 histogram_tester.ExpectTotalCount( | 289 histogram_tester.ExpectTotalCount( |
278 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 0); | 290 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 0); |
279 } | 291 } |
280 | 292 |
281 // This function tests data use measurement for requests by user in case the | 293 // This function tests data use measurement for requests by user in case the |
282 // request is redirected once.The query from a user should affect | 294 // request is redirected once.The query from a user should affect |
283 // DataUse.TrafficSize.User.Dimensions histogram. AppState and ConnectionType | 295 // DataUse.TrafficSize.User.Dimensions histogram. AppState and ConnectionType |
284 // dimensions are always Foreground and NotCellular respectively. | 296 // dimensions are always Foreground and NotCellular respectively. |
285 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementUserTestWithRedirect) { | 297 TEST_F(ChromeNetworkDelegateTest, DataUseMeasurementUserTestWithRedirect) { |
286 Initialize(); | 298 Initialize(); |
287 base::HistogramTester histogram_tester; | 299 base::HistogramTester histogram_tester; |
288 | 300 |
289 // A query from user with one redirection. | 301 // A query from user with one redirection. |
290 RequestURL(context(), socket_factory(), true, true); | 302 RequestURL(context(), socket_factory(), true, true); |
291 | 303 |
292 histogram_tester.ExpectTotalCount( | 304 EXPECT_FALSE( |
293 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular", 2); | 305 histogram_tester |
| 306 .GetTotalCountsForPrefix( |
| 307 "DataUse.TrafficSize.User.Downstream.Foreground.NotCellular") |
| 308 .empty()); |
294 histogram_tester.ExpectTotalCount( | 309 histogram_tester.ExpectTotalCount( |
295 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 2); | 310 "DataUse.TrafficSize.User.Upstream.Foreground.NotCellular", 2); |
296 histogram_tester.ExpectTotalCount( | 311 histogram_tester.ExpectTotalCount( |
297 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 0); | 312 "DataUse.TrafficSize.System.Downstream.Foreground.NotCellular", 0); |
298 histogram_tester.ExpectTotalCount( | 313 histogram_tester.ExpectTotalCount( |
299 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 0); | 314 "DataUse.TrafficSize.System.Upstream.Foreground.NotCellular", 0); |
300 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 0); | 315 histogram_tester.ExpectTotalCount("DataUse.MessageSize.Suggestions", 0); |
301 } | 316 } |
302 | 317 |
303 TEST_F(ChromeNetworkDelegateTest, DisableSameSiteCookiesIffFlagDisabled) { | 318 TEST_F(ChromeNetworkDelegateTest, DisableSameSiteCookiesIffFlagDisabled) { |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 | 655 |
641 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 656 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
642 kBlockedFirstPartySite)); | 657 kBlockedFirstPartySite)); |
643 | 658 |
644 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, | 659 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, |
645 CONTENT_SETTING_BLOCK); | 660 CONTENT_SETTING_BLOCK); |
646 // Privacy mode is disabled as kAllowedSite is still getting cookies | 661 // Privacy mode is disabled as kAllowedSite is still getting cookies |
647 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 662 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
648 kBlockedFirstPartySite)); | 663 kBlockedFirstPartySite)); |
649 } | 664 } |
OLD | NEW |