| 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_experiments.h" | 5 #include "components/previews/core/previews_experiments.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/feature_list.h" |
| 11 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 11 #include "base/metrics/field_trial_params.h" | 13 #include "base/metrics/field_trial_params.h" |
| 12 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 13 #include "components/variations/variations_associated_data.h" | 15 #include "components/variations/variations_associated_data.h" |
| 14 | 16 |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 18 |
| 17 namespace previews { | 19 namespace previews { |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 const char kClientSidePreviewsFieldTrial[] = "ClientSidePreviews"; | 23 const char kClientSidePreviewsFieldTrial[] = "ClientSidePreviews"; |
| 22 const char kClientLoFiFieldTrial[] = "PreviewsClientLoFi"; | 24 const char kClientLoFiFieldTrial[] = "PreviewsClientLoFi"; |
| 23 const char kEnabled[] = "Enabled"; | 25 const char kEnabled[] = "Enabled"; |
| 24 | 26 |
| 25 // Verifies that we can enable offline previews via field trial. | 27 // Verifies that we can enable offline previews via field trial. |
| 26 TEST(PreviewsExperimentsTest, TestFieldTrialOfflinePage) { | 28 TEST(PreviewsExperimentsTest, TestFieldTrialOfflinePage) { |
| 27 EXPECT_FALSE(IsIncludedInClientSidePreviewsExperimentsFieldTrial()); | |
| 28 EXPECT_FALSE(params::IsOfflinePreviewsEnabled()); | 29 EXPECT_FALSE(params::IsOfflinePreviewsEnabled()); |
| 29 | 30 |
| 30 base::FieldTrialList field_trial_list(nullptr); | 31 base::FieldTrialList field_trial_list(nullptr); |
| 31 | 32 |
| 32 std::map<std::string, std::string> params; | 33 std::map<std::string, std::string> params; |
| 33 params["show_offline_pages"] = "true"; | 34 params["show_offline_pages"] = "true"; |
| 34 EXPECT_TRUE(base::AssociateFieldTrialParams(kClientSidePreviewsFieldTrial, | 35 EXPECT_TRUE(base::AssociateFieldTrialParams(kClientSidePreviewsFieldTrial, |
| 35 kEnabled, params)); | 36 kEnabled, params)); |
| 36 EXPECT_TRUE(base::FieldTrialList::CreateFieldTrial( | 37 EXPECT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 37 kClientSidePreviewsFieldTrial, kEnabled)); | 38 kClientSidePreviewsFieldTrial, kEnabled)); |
| 38 | 39 |
| 39 EXPECT_TRUE(IsIncludedInClientSidePreviewsExperimentsFieldTrial()); | |
| 40 EXPECT_TRUE(params::IsOfflinePreviewsEnabled()); | 40 EXPECT_TRUE(params::IsOfflinePreviewsEnabled()); |
| 41 variations::testing::ClearAllVariationParams(); | 41 variations::testing::ClearAllVariationParams(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Verifies that we can enable offline previews via comand line. |
| 45 TEST(PreviewsExperimentsTest, TestCommandLineOfflinePage) { |
| 46 EXPECT_FALSE(params::IsOfflinePreviewsEnabled()); |
| 47 |
| 48 std::unique_ptr<base::FeatureList> feature_list = |
| 49 base::MakeUnique<base::FeatureList>(); |
| 50 |
| 51 // The feature is explicitly enabled on the command-line. |
| 52 feature_list->InitializeFromCommandLine("OfflinePreviews", ""); |
| 53 base::FeatureList::ClearInstanceForTesting(); |
| 54 base::FeatureList::SetInstance(std::move(feature_list)); |
| 55 |
| 56 EXPECT_TRUE(params::IsOfflinePreviewsEnabled()); |
| 57 base::FeatureList::ClearInstanceForTesting(); |
| 58 } |
| 59 |
| 44 // Verifies that the default params are correct, and that custom params can be | 60 // Verifies that the default params are correct, and that custom params can be |
| 45 // set, for both the previews blacklist and offline previews. | 61 // set, for both the previews blacklist and offline previews. |
| 46 TEST(PreviewsExperimentsTest, TestParamsForBlackListAndOffline) { | 62 TEST(PreviewsExperimentsTest, TestParamsForBlackListAndOffline) { |
| 47 // Verify that the default params are correct. | 63 // Verify that the default params are correct. |
| 48 EXPECT_EQ(4u, params::MaxStoredHistoryLengthForPerHostBlackList()); | 64 EXPECT_EQ(4u, params::MaxStoredHistoryLengthForPerHostBlackList()); |
| 49 EXPECT_EQ(10u, params::MaxStoredHistoryLengthForHostIndifferentBlackList()); | 65 EXPECT_EQ(10u, params::MaxStoredHistoryLengthForHostIndifferentBlackList()); |
| 50 EXPECT_EQ(100u, params::MaxInMemoryHostsInBlackList()); | 66 EXPECT_EQ(100u, params::MaxInMemoryHostsInBlackList()); |
| 51 EXPECT_EQ(2, params::PerHostBlackListOptOutThreshold()); | 67 EXPECT_EQ(2, params::PerHostBlackListOptOutThreshold()); |
| 52 EXPECT_EQ(4, params::HostIndifferentBlackListOptOutThreshold()); | 68 EXPECT_EQ(4, params::HostIndifferentBlackListOptOutThreshold()); |
| 53 EXPECT_EQ(base::TimeDelta::FromDays(30), params::PerHostBlackListDuration()); | 69 EXPECT_EQ(base::TimeDelta::FromDays(30), params::PerHostBlackListDuration()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 EXPECT_EQ(10, params::ClientLoFiVersion()); | 162 EXPECT_EQ(10, params::ClientLoFiVersion()); |
| 147 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_3G, | 163 EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_3G, |
| 148 params::EffectiveConnectionTypeThresholdForClientLoFi()); | 164 params::EffectiveConnectionTypeThresholdForClientLoFi()); |
| 149 | 165 |
| 150 variations::testing::ClearAllVariationParams(); | 166 variations::testing::ClearAllVariationParams(); |
| 151 } | 167 } |
| 152 | 168 |
| 153 } // namespace | 169 } // namespace |
| 154 | 170 |
| 155 } // namespace previews | 171 } // namespace previews |
| OLD | NEW |