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

Unified Diff: components/ntp_tiles/popular_sites_impl_unittest.cc

Issue 2741413008: Introduce flag to disable static popular sites. (Closed)
Patch Set: Use feature instead of params 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/ntp_tiles/popular_sites_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_tiles/popular_sites_impl_unittest.cc
diff --git a/components/ntp_tiles/popular_sites_impl_unittest.cc b/components/ntp_tiles/popular_sites_impl_unittest.cc
index d5502037fde5e76a6121e43e380427a96b29514a..1deff6bd575927161c6b359c202d504d7595a3c4 100644
--- a/components/ntp_tiles/popular_sites_impl_unittest.cc
+++ b/components/ntp_tiles/popular_sites_impl_unittest.cc
@@ -18,9 +18,11 @@
#include "base/memory/ptr_util.h"
#include "base/optional.h"
#include "base/run_loop.h"
+#include "base/test/scoped_feature_list.h"
#include "base/test/sequenced_worker_pool_owner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h"
+#include "components/ntp_tiles/constants.h"
#include "components/ntp_tiles/json_unsafe_parser.h"
#include "components/ntp_tiles/pref_names.h"
#include "components/ntp_tiles/switches.h"
@@ -60,7 +62,7 @@ size_t GetNumberOfDefaultPopularSitesForPlatform() {
#if defined(OS_ANDROID) || defined(OS_IOS)
return 8ul;
#else
- return 0;
+ return 0ul;
#endif
}
@@ -83,18 +85,19 @@ class PopularSitesTest : public ::testing::Test {
{kFaviconUrl, "https://www.chromium.org/favicon.ico"},
},
worker_pool_owner_(2, "PopularSitesTest."),
+ prefs_(new sync_preferences::TestingPrefServiceSyncable()),
url_fetcher_factory_(nullptr) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableNTPPopularSites);
- PopularSitesImpl::RegisterProfilePrefs(prefs_.registry());
+ PopularSitesImpl::RegisterProfilePrefs(prefs_->registry());
CHECK(scoped_cache_dir_.CreateUniqueTempDir());
cache_dir_ = scoped_cache_dir_.GetPath();
}
void SetCountryAndVersion(const std::string& country,
const std::string& version) {
- prefs_.SetString(prefs::kPopularSitesOverrideCountry, country);
- prefs_.SetString(prefs::kPopularSitesOverrideVersion, version);
+ prefs_->SetString(prefs::kPopularSitesOverrideCountry, country);
+ prefs_->SetString(prefs::kPopularSitesOverrideVersion, version);
}
void RespondWithJSON(const std::string& url,
@@ -123,6 +126,11 @@ class PopularSitesTest : public ::testing::Test {
net::URLRequestStatus::SUCCESS);
}
+ void ReregisterProfilePrefs() {
+ prefs_ = base::MakeUnique<sync_preferences::TestingPrefServiceSyncable>();
+ PopularSitesImpl::RegisterProfilePrefs(prefs_->registry());
+ }
+
// Returns an optional bool representing whether the completion callback was
// called at all, and if yes which was the returned bool value.
base::Optional<bool> FetchPopularSites(bool force_download,
@@ -152,7 +160,7 @@ class PopularSitesTest : public ::testing::Test {
std::unique_ptr<PopularSites> CreatePopularSites(
net::URLRequestContextGetter* context) {
return base::MakeUnique<PopularSitesImpl>(
- worker_pool_owner_.pool().get(), &prefs_,
+ worker_pool_owner_.pool().get(), prefs_.get(),
/*template_url_service=*/nullptr,
/*variations_service=*/nullptr, context, cache_dir_,
base::Bind(JsonUnsafeParser::Parse));
@@ -166,7 +174,7 @@ class PopularSitesTest : public ::testing::Test {
base::SequencedWorkerPoolOwner worker_pool_owner_;
base::ScopedTempDir scoped_cache_dir_;
base::FilePath cache_dir_;
- sync_preferences::TestingPrefServiceSyncable prefs_;
+ std::unique_ptr<sync_preferences::TestingPrefServiceSyncable> prefs_;
net::FakeURLFetcherFactory url_fetcher_factory_;
};
@@ -180,7 +188,20 @@ TEST_F(PopularSitesTest, ContainsDefaultTilesRightAfterConstruction) {
Eq(GetNumberOfDefaultPopularSitesForPlatform()));
}
-TEST_F(PopularSitesTest, Zasic) {
+TEST_F(PopularSitesTest, IsEmptyOnConstructionIfDisabledByTrial) {
+ base::test::ScopedFeatureList override_features;
+ override_features.InitAndDisableFeature(kPopularSitesBakedInContentFeature);
+ ReregisterProfilePrefs();
+
+ scoped_refptr<net::TestURLRequestContextGetter> url_request_context(
+ new net::TestURLRequestContextGetter(
+ base::ThreadTaskRunnerHandle::Get()));
+ auto popular_sites = CreatePopularSites(url_request_context.get());
+
+ EXPECT_THAT(popular_sites->sites().size(), Eq(0ul));
+}
+
+TEST_F(PopularSitesTest, ShouldSucceedFetching) {
SetCountryAndVersion("ZZ", "9");
RespondWithJSON(
"https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json",
« no previous file with comments | « components/ntp_tiles/popular_sites_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698