Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Unified Diff: components/previews/core/previews_io_data_unittest.cc

Issue 2749693003: Reland of Moving previews code from components/ to chrome/ (Closed)
Patch Set: fixed vector copy Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/previews/core/previews_io_data.cc ('k') | components/previews/core/previews_opt_out_store_sql.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 39a8925e618e6667060a5207f816ae47e89a35be..23b1bac9a3a2007ad4e929db67761845c9aa64fa 100644
--- a/components/previews/core/previews_io_data_unittest.cc
+++ b/components/previews/core/previews_io_data_unittest.cc
@@ -37,6 +37,10 @@ namespace previews {
namespace {
+bool CheckOfflineFieldTrial(PreviewsType type) {
+ return previews::params::IsOfflinePreviewsEnabled();
+}
+
class TestPreviewsIOData : public PreviewsIOData {
public:
TestPreviewsIOData(
@@ -125,7 +129,7 @@ TEST_F(PreviewsIODataTest, TestInitialization) {
set_io_data(base::MakeUnique<TestPreviewsIOData>(loop_.task_runner(),
loop_.task_runner()));
set_ui_service(base::MakeUnique<PreviewsUIService>(
- io_data(), loop_.task_runner(), nullptr));
+ io_data(), loop_.task_runner(), nullptr, PreviewsIsEnabledCallback()));
base::RunLoop().RunUntilIdle();
// After the outstanding posted tasks have run, |io_data_| should be fully
// initialized.
@@ -144,29 +148,38 @@ TEST_F(PreviewsIODataTest, TestShouldAllowPreview) {
loop_.task_runner()));
base::HistogramTester histogram_tester;
+ // The blacklist is not created yet.
+ EXPECT_FALSE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE));
+ histogram_tester.ExpectUniqueSample(
+ "Previews.EligibilityReason.Offline",
+ static_cast<int>(PreviewsEligibilityReason::BLACKLIST_UNAVAILABLE), 1);
+
+ set_ui_service(base::MakeUnique<PreviewsUIService>(
+ io_data(), loop_.task_runner(),
+ base::MakeUnique<TestPreviewsOptOutStore>(),
+ base::Bind(&CheckOfflineFieldTrial)));
+
+ // The blacklist is not created yet.
+ EXPECT_FALSE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE));
+ histogram_tester.ExpectBucketCount(
+ "Previews.EligibilityReason.Offline",
+ static_cast<int>(PreviewsEligibilityReason::BLACKLIST_UNAVAILABLE), 2);
+
+ base::RunLoop().RunUntilIdle();
+
+ histogram_tester.ExpectTotalCount("Previews.EligibilityReason.Offline", 2);
// If not in the field trial, don't log anything, and return false.
EXPECT_FALSE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE));
- histogram_tester.ExpectTotalCount("Previews.EligibilityReason.Offline", 0);
+ histogram_tester.ExpectTotalCount("Previews.EligibilityReason.Offline", 2);
// Enable Offline previews field trial.
base::FieldTrialList field_trial_list(nullptr);
std::map<std::string, std::string> params;
params["show_offline_pages"] = "true";
+
variations::AssociateVariationParams("ClientSidePreviews", "Enabled", params);
base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled");
- // The blacklist is not created yet.
- EXPECT_FALSE(io_data()->ShouldAllowPreview(*request, PreviewsType::OFFLINE));
- histogram_tester.ExpectUniqueSample(
- "Previews.EligibilityReason.Offline",
- static_cast<int>(PreviewsEligibilityReason::BLACKLIST_UNAVAILABLE), 1);
-
- set_ui_service(base::WrapUnique(
- new PreviewsUIService(io_data(), loop_.task_runner(),
- base::MakeUnique<TestPreviewsOptOutStore>())));
-
- base::RunLoop().RunUntilIdle();
-
// Return one of the failing statuses from the blacklist; cause the blacklist
// to not be loaded by clearing the blacklist.
base::Time now = base::Time::Now();
@@ -227,7 +240,7 @@ TEST_F(PreviewsIODataTest, TestShouldAllowPreview) {
"Previews.EligibilityReason.Offline",
static_cast<int>(PreviewsEligibilityReason::ALLOWED), 1);
- histogram_tester.ExpectTotalCount("Previews.EligibilityReason.Offline", 7);
+ histogram_tester.ExpectTotalCount("Previews.EligibilityReason.Offline", 8);
variations::testing::ClearAllVariationParams();
}
« no previous file with comments | « components/previews/core/previews_io_data.cc ('k') | components/previews/core/previews_opt_out_store_sql.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698