[NTP] Add ability to toggle between Most Visited and custom links
Implement toggleMostVisitedOrCustomLinks for the EmbbededSearchApi.
This will allow users to toggle between Most Visited tiles and custom
links.
Bug: 953822
Change-Id: Ide2d1a62456649a5b6f9ff45d16548ac1212e0b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1572233
Reviewed-by: Kyle Milka <[email protected]>
Reviewed-by: Marc Treib <[email protected]>
Reviewed-by: Greg Kerr <[email protected]>
Commit-Queue: Kristi Park <[email protected]>
Cr-Commit-Position: refs/heads/master@{#652298}
diff --git a/chrome/browser/search/instant_service_unittest.cc b/chrome/browser/search/instant_service_unittest.cc
index 441588a0..e7001e7e 100644
--- a/chrome/browser/search/instant_service_unittest.cc
+++ b/chrome/browser/search/instant_service_unittest.cc
@@ -106,6 +106,26 @@
EXPECT_FALSE(base::PathExists(database_dir));
}
+TEST_F(InstantServiceTest, DoesToggleMostVisitedOrCustomLinks) {
+ sync_preferences::TestingPrefServiceSyncable* pref_service =
+ profile()->GetTestingPrefService();
+ SetUserSelectedDefaultSearchProvider("{google:baseURL}");
+ ASSERT_FALSE(pref_service->GetBoolean(prefs::kNtpUseMostVisitedTiles));
+
+ // Enable most visited tiles.
+ EXPECT_TRUE(instant_service_->ToggleMostVisitedOrCustomLinks());
+ EXPECT_TRUE(pref_service->GetBoolean(prefs::kNtpUseMostVisitedTiles));
+
+ // Disable most visited tiles.
+ EXPECT_TRUE(instant_service_->ToggleMostVisitedOrCustomLinks());
+ EXPECT_FALSE(pref_service->GetBoolean(prefs::kNtpUseMostVisitedTiles));
+
+ // Should do nothing if this is a non-Google NTP.
+ SetUserSelectedDefaultSearchProvider("https://www.search.com");
+ EXPECT_FALSE(instant_service_->ToggleMostVisitedOrCustomLinks());
+ EXPECT_FALSE(pref_service->GetBoolean(prefs::kNtpUseMostVisitedTiles));
+}
+
TEST_F(InstantServiceTest,
DisableUndoCustomLinkActionForNonGoogleSearchProvider) {
SetUserSelectedDefaultSearchProvider("{google:baseURL}");
@@ -123,6 +143,25 @@
EXPECT_FALSE(instant_service_->ResetCustomLinks());
}
+TEST_F(InstantServiceTest, IsCustomLinksEnabled) {
+ sync_preferences::TestingPrefServiceSyncable* pref_service =
+ profile()->GetTestingPrefService();
+
+ // Test that custom links are only enabled when Most Visited is toggled off
+ // and this is a Google NTP.
+ pref_service->SetBoolean(prefs::kNtpUseMostVisitedTiles, false);
+ SetUserSelectedDefaultSearchProvider("{google:baseURL}");
+ EXPECT_TRUE(instant_service_->IsCustomLinksEnabled());
+
+ // All other cases should return false.
+ SetUserSelectedDefaultSearchProvider("https://www.search.com");
+ EXPECT_FALSE(instant_service_->IsCustomLinksEnabled());
+ pref_service->SetBoolean(prefs::kNtpUseMostVisitedTiles, true);
+ EXPECT_FALSE(instant_service_->IsCustomLinksEnabled());
+ SetUserSelectedDefaultSearchProvider("{google:baseURL}");
+ EXPECT_FALSE(instant_service_->IsCustomLinksEnabled());
+}
+
TEST_F(InstantServiceTest, SetCustomBackgroundURL) {
ASSERT_FALSE(instant_service_->IsCustomBackgroundSet());
const GURL kUrl("https://www.foo.com");