Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/previews/core/previews_io_data.h" | 5 #include "components/previews/core/previews_io_data.h" |
| 6 | 6 |
| 7 #include <initializer_list> | 7 #include <initializer_list> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 namespace previews { | 39 namespace previews { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // TODO(sclittle): Tests should be testing the actual prod code that checks if | 43 // TODO(sclittle): Tests should be testing the actual prod code that checks if |
| 44 // the appropriate field trial is enabled for the preview, instead of testing | 44 // the appropriate field trial is enabled for the preview, instead of testing |
| 45 // this function here. Consider moving that code out of | 45 // this function here. Consider moving that code out of |
| 46 // chrome/browser/previews/previews_service.cc and into the previews/ component. | 46 // chrome/browser/previews/previews_service.cc and into the previews/ component. |
| 47 bool IsPreviewFieldTrialEnabled(PreviewsType type) { | 47 bool IsPreviewFieldTrialEnabled(PreviewsType type) { |
| 48 switch (type) { | 48 switch (type) { |
| 49 // Use the offline field trial to simulate LoFi and LitePages being enabled. | |
|
tbansal1
2017/05/02 21:49:31
Is it possible to expand on this comment a bit? Th
RyanSturm
2017/05/02 22:57:19
Done. I removed sclittle's comment as it makes lit
| |
| 49 case PreviewsType::OFFLINE: | 50 case PreviewsType::OFFLINE: |
| 51 case PreviewsType::LITE_PAGE: | |
| 52 case PreviewsType::SERVER_LOFI: | |
| 50 return params::IsOfflinePreviewsEnabled(); | 53 return params::IsOfflinePreviewsEnabled(); |
| 51 case PreviewsType::CLIENT_LOFI: | 54 case PreviewsType::CLIENT_LOFI: |
| 52 return params::IsClientLoFiEnabled(); | 55 return params::IsClientLoFiEnabled(); |
| 53 case PreviewsType::NONE: | 56 case PreviewsType::NONE: |
| 54 case PreviewsType::LAST: | 57 case PreviewsType::LAST: |
| 55 break; | 58 break; |
| 56 } | 59 } |
| 57 NOTREACHED(); | 60 NOTREACHED(); |
| 58 return false; | 61 return false; |
| 59 } | 62 } |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 | 269 |
| 267 base::HistogramTester histogram_tester; | 270 base::HistogramTester histogram_tester; |
| 268 EXPECT_FALSE( | 271 EXPECT_FALSE( |
| 269 io_data()->ShouldAllowPreview(*CreateRequest(), PreviewsType::OFFLINE)); | 272 io_data()->ShouldAllowPreview(*CreateRequest(), PreviewsType::OFFLINE)); |
| 270 histogram_tester.ExpectUniqueSample( | 273 histogram_tester.ExpectUniqueSample( |
| 271 "Previews.EligibilityReason.Offline", | 274 "Previews.EligibilityReason.Offline", |
| 272 static_cast<int>(PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE), | 275 static_cast<int>(PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE), |
| 273 1); | 276 1); |
| 274 } | 277 } |
| 275 | 278 |
| 279 TEST_F(PreviewsIODataTest, TestAllowLoFiLitePageWhenNetworkQualityFast) { | |
| 280 // LoFi and LitePage check NQE on their own. | |
| 281 InitializeUIService(); | |
| 282 CreateFieldTrialWithParams("ClientSidePreviews", "Enabled", | |
| 283 {{"show_offline_pages", "true"}, | |
| 284 {"max_allowed_effective_connection_type", "2G"}}); | |
| 285 | |
| 286 network_quality_estimator()->set_effective_connection_type( | |
| 287 net::EFFECTIVE_CONNECTION_TYPE_3G); | |
| 288 | |
| 289 base::HistogramTester histogram_tester; | |
| 290 EXPECT_TRUE(io_data()->ShouldAllowPreview(*CreateRequest(), | |
| 291 PreviewsType::SERVER_LOFI)); | |
| 292 EXPECT_TRUE( | |
| 293 io_data()->ShouldAllowPreview(*CreateRequest(), PreviewsType::LITE_PAGE)); | |
| 294 histogram_tester.ExpectUniqueSample( | |
| 295 "Previews.EligibilityReason.ServerLoFi", | |
| 296 static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1); | |
| 297 histogram_tester.ExpectUniqueSample( | |
| 298 "Previews.EligibilityReason.LitePage", | |
| 299 static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1); | |
| 300 } | |
| 301 | |
| 276 TEST_F(PreviewsIODataTest, TestDisallowOfflineWhenNetworkQualityFast) { | 302 TEST_F(PreviewsIODataTest, TestDisallowOfflineWhenNetworkQualityFast) { |
| 277 InitializeUIService(); | 303 InitializeUIService(); |
| 278 CreateFieldTrialWithParams("ClientSidePreviews", "Enabled", | 304 CreateFieldTrialWithParams("ClientSidePreviews", "Enabled", |
| 279 {{"show_offline_pages", "true"}, | 305 {{"show_offline_pages", "true"}, |
| 280 {"max_allowed_effective_connection_type", "2G"}}); | 306 {"max_allowed_effective_connection_type", "2G"}}); |
| 281 | 307 |
| 282 network_quality_estimator()->set_effective_connection_type( | 308 network_quality_estimator()->set_effective_connection_type( |
| 283 net::EFFECTIVE_CONNECTION_TYPE_3G); | 309 net::EFFECTIVE_CONNECTION_TYPE_3G); |
| 284 | 310 |
| 285 base::HistogramTester histogram_tester; | 311 base::HistogramTester histogram_tester; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 299 network_quality_estimator()->set_effective_connection_type( | 325 network_quality_estimator()->set_effective_connection_type( |
| 300 net::EFFECTIVE_CONNECTION_TYPE_2G); | 326 net::EFFECTIVE_CONNECTION_TYPE_2G); |
| 301 | 327 |
| 302 std::unique_ptr<net::URLRequest> request = CreateRequest(); | 328 std::unique_ptr<net::URLRequest> request = CreateRequest(); |
| 303 request->SetLoadFlags(net::LOAD_BYPASS_CACHE); | 329 request->SetLoadFlags(net::LOAD_BYPASS_CACHE); |
| 304 | 330 |
| 305 base::HistogramTester histogram_tester; | 331 base::HistogramTester histogram_tester; |
| 306 EXPECT_FALSE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE)); | 332 EXPECT_FALSE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE)); |
| 307 histogram_tester.ExpectUniqueSample( | 333 histogram_tester.ExpectUniqueSample( |
| 308 "Previews.EligibilityReason.Offline", | 334 "Previews.EligibilityReason.Offline", |
| 309 static_cast<int>( | 335 static_cast<int>(PreviewsEligibilityReason::RELOAD_DISALLOWED), 1); |
| 310 PreviewsEligibilityReason::RELOAD_DISALLOWED_FOR_OFFLINE), | |
| 311 1); | |
| 312 } | 336 } |
| 313 | 337 |
| 314 TEST_F(PreviewsIODataTest, TestAllowOffline) { | 338 TEST_F(PreviewsIODataTest, TestAllowOffline) { |
| 315 InitializeUIService(); | 339 InitializeUIService(); |
| 316 CreateFieldTrialWithParams("ClientSidePreviews", "Enabled", | 340 CreateFieldTrialWithParams("ClientSidePreviews", "Enabled", |
| 317 {{"show_offline_pages", "true"}, | 341 {{"show_offline_pages", "true"}, |
| 318 {"max_allowed_effective_connection_type", "2G"}}); | 342 {"max_allowed_effective_connection_type", "2G"}}); |
| 319 | 343 |
| 320 network_quality_estimator()->set_effective_connection_type( | 344 network_quality_estimator()->set_effective_connection_type( |
| 321 net::EFFECTIVE_CONNECTION_TYPE_2G); | 345 net::EFFECTIVE_CONNECTION_TYPE_2G); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 EXPECT_TRUE( | 434 EXPECT_TRUE( |
| 411 io_data()->ShouldAllowPreview(*request, PreviewsType::CLIENT_LOFI)); | 435 io_data()->ShouldAllowPreview(*request, PreviewsType::CLIENT_LOFI)); |
| 412 histogram_tester.ExpectUniqueSample( | 436 histogram_tester.ExpectUniqueSample( |
| 413 "Previews.EligibilityReason.ClientLoFi", | 437 "Previews.EligibilityReason.ClientLoFi", |
| 414 static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1); | 438 static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1); |
| 415 } | 439 } |
| 416 | 440 |
| 417 } // namespace | 441 } // namespace |
| 418 | 442 |
| 419 } // namespace previews | 443 } // namespace previews |
| OLD | NEW |