| Index: components/previews/core/previews_io_data_unittest.cc
|
| diff --git a/components/previews/core/previews_io_data_unittest.cc b/components/previews/core/previews_io_data_unittest.cc
|
| index 604cb1aa0603f64b1be6a683c7c5605a9bd583b9..533bc9920eb900251c7e55c3e082f7397a74fb13 100644
|
| --- a/components/previews/core/previews_io_data_unittest.cc
|
| +++ b/components/previews/core/previews_io_data_unittest.cc
|
| @@ -40,13 +40,15 @@ namespace previews {
|
|
|
| namespace {
|
|
|
| -// TODO(sclittle): Tests should be testing the actual prod code that checks if
|
| -// the appropriate field trial is enabled for the preview, instead of testing
|
| -// this function here. Consider moving that code out of
|
| -// chrome/browser/previews/previews_service.cc and into the previews/ component.
|
| +// This method simulates the actual behavior of the passed in callback, which is
|
| +// validated in other tests. For simplicity, offline, lite page, and server LoFi
|
| +// use the offline previews check. Client LoFi uses a seperate check to verify
|
| +// that types are treated differently.
|
| bool IsPreviewFieldTrialEnabled(PreviewsType type) {
|
| switch (type) {
|
| case PreviewsType::OFFLINE:
|
| + case PreviewsType::LITE_PAGE:
|
| + case PreviewsType::SERVER_LOFI:
|
| return params::IsOfflinePreviewsEnabled();
|
| case PreviewsType::CLIENT_LOFI:
|
| return params::IsClientLoFiEnabled();
|
| @@ -273,6 +275,29 @@ TEST_F(PreviewsIODataTest, TestDisallowOfflineWhenNetworkQualityUnavailable) {
|
| 1);
|
| }
|
|
|
| +TEST_F(PreviewsIODataTest, TestAllowLoFiLitePageWhenNetworkQualityFast) {
|
| + // LoFi and LitePage check NQE on their own.
|
| + InitializeUIService();
|
| + CreateFieldTrialWithParams("ClientSidePreviews", "Enabled",
|
| + {{"show_offline_pages", "true"},
|
| + {"max_allowed_effective_connection_type", "2G"}});
|
| +
|
| + network_quality_estimator()->set_effective_connection_type(
|
| + net::EFFECTIVE_CONNECTION_TYPE_3G);
|
| +
|
| + base::HistogramTester histogram_tester;
|
| + EXPECT_TRUE(io_data()->ShouldAllowPreview(*CreateRequest(),
|
| + PreviewsType::SERVER_LOFI));
|
| + EXPECT_TRUE(
|
| + io_data()->ShouldAllowPreview(*CreateRequest(), PreviewsType::LITE_PAGE));
|
| + histogram_tester.ExpectUniqueSample(
|
| + "Previews.EligibilityReason.LoFi",
|
| + static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1);
|
| + histogram_tester.ExpectUniqueSample(
|
| + "Previews.EligibilityReason.LitePage",
|
| + static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1);
|
| +}
|
| +
|
| TEST_F(PreviewsIODataTest, TestDisallowOfflineWhenNetworkQualityFast) {
|
| InitializeUIService();
|
| CreateFieldTrialWithParams("ClientSidePreviews", "Enabled",
|
| @@ -306,9 +331,7 @@ TEST_F(PreviewsIODataTest, TestDisallowOfflineOnReload) {
|
| EXPECT_FALSE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE));
|
| histogram_tester.ExpectUniqueSample(
|
| "Previews.EligibilityReason.Offline",
|
| - static_cast<int>(
|
| - PreviewsEligibilityReason::RELOAD_DISALLOWED_FOR_OFFLINE),
|
| - 1);
|
| + static_cast<int>(PreviewsEligibilityReason::RELOAD_DISALLOWED), 1);
|
| }
|
|
|
| TEST_F(PreviewsIODataTest, TestAllowOffline) {
|
|
|