Commit 848864f6 authored by Kyle Milka's avatar Kyle Milka Committed by Commit Bot

[NTP] Clear background pref if feature is disabled.

Clear the pref if the feature is disabled.

Update the unit tests to explicitly turn on the feature.
Add a new test that the background url is not set when
the feature is turned off.

Bug: 864013
Change-Id: I472f690d870a930f5b9ce35c19117cb69ceb2001
Reviewed-on: https://chromium-review.googlesource.com/1161008Reviewed-by: default avatarMathieu Perreault <mathp@chromium.org>
Commit-Queue: Kyle Milka <kmilka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580341}
parent 659682ad
...@@ -504,6 +504,12 @@ void InstantService::BuildThemeInfo() { ...@@ -504,6 +504,12 @@ void InstantService::BuildThemeInfo() {
// TODO(crbug.com/863942): Should switching default search provider retain the // TODO(crbug.com/863942): Should switching default search provider retain the
// copy of user uploaded photos? // copy of user uploaded photos?
void InstantService::ApplyOrResetCustomBackgroundThemeInfo() { void InstantService::ApplyOrResetCustomBackgroundThemeInfo() {
// Reset the pref if the feature is disabled.
if (!features::IsCustomBackgroundsEnabled()) {
ResetCustomBackgroundThemeInfo();
return;
}
// Custom backgrounds for non-Google search providers are not supported. // Custom backgrounds for non-Google search providers are not supported.
if (!search::DefaultSearchProviderIsGoogle(profile_)) { if (!search::DefaultSearchProviderIsGoogle(profile_)) {
ResetCustomBackgroundThemeInfo(); ResetCustomBackgroundThemeInfo();
......
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/search/instant_unittest_base.h" #include "chrome/browser/search/instant_unittest_base.h"
#include "chrome/browser/search/ntp_features.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/search/instant_types.h" #include "chrome/common/search/instant_types.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
...@@ -19,6 +21,19 @@ ...@@ -19,6 +21,19 @@
using InstantServiceTest = InstantUnitTestBase; using InstantServiceTest = InstantUnitTestBase;
class InstantServiceTestCustomBackgroundsEnabled : public InstantServiceTest {
public:
InstantServiceTestCustomBackgroundsEnabled() {
scoped_feature_list_.InitAndEnableFeature(features::kNtpBackgrounds);
}
~InstantServiceTestCustomBackgroundsEnabled() override {}
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(InstantServiceTestCustomBackgroundsEnabled);
};
TEST_F(InstantServiceTest, GetNTPTileSuggestion) { TEST_F(InstantServiceTest, GetNTPTileSuggestion) {
ntp_tiles::NTPTile some_tile; ntp_tiles::NTPTile some_tile;
some_tile.source = ntp_tiles::TileSource::TOP_SITES; some_tile.source = ntp_tiles::TileSource::TOP_SITES;
...@@ -36,7 +51,7 @@ TEST_F(InstantServiceTest, GetNTPTileSuggestion) { ...@@ -36,7 +51,7 @@ TEST_F(InstantServiceTest, GetNTPTileSuggestion) {
EXPECT_EQ(ntp_tiles::TileTitleSource::TITLE_TAG, items[0].title_source); EXPECT_EQ(ntp_tiles::TileTitleSource::TITLE_TAG, items[0].title_source);
} }
TEST_F(InstantServiceTest, SetCustomBackgroundURL) { TEST_F(InstantServiceTestCustomBackgroundsEnabled, SetCustomBackgroundURL) {
const GURL kUrl("https://www.foo.com"); const GURL kUrl("https://www.foo.com");
instant_service_->SetCustomBackgroundURL(kUrl); instant_service_->SetCustomBackgroundURL(kUrl);
...@@ -44,7 +59,16 @@ TEST_F(InstantServiceTest, SetCustomBackgroundURL) { ...@@ -44,7 +59,16 @@ TEST_F(InstantServiceTest, SetCustomBackgroundURL) {
EXPECT_EQ(kUrl, theme_info->custom_background_url); EXPECT_EQ(kUrl, theme_info->custom_background_url);
} }
TEST_F(InstantServiceTest, SetCustomBackgroundURLInvalidURL) { TEST_F(InstantServiceTest, SetCustomBackgroundURL) {
const GURL kUrl("https://www.foo.com");
instant_service_->SetCustomBackgroundURL(kUrl);
ThemeBackgroundInfo* theme_info = instant_service_->GetThemeInfoForTesting();
EXPECT_EQ(GURL(), theme_info->custom_background_url);
}
TEST_F(InstantServiceTestCustomBackgroundsEnabled,
SetCustomBackgroundURLInvalidURL) {
const GURL kUrl("foo"); const GURL kUrl("foo");
instant_service_->SetCustomBackgroundURL(kUrl); instant_service_->SetCustomBackgroundURL(kUrl);
...@@ -52,7 +76,8 @@ TEST_F(InstantServiceTest, SetCustomBackgroundURLInvalidURL) { ...@@ -52,7 +76,8 @@ TEST_F(InstantServiceTest, SetCustomBackgroundURLInvalidURL) {
EXPECT_EQ(std::string(), theme_info->custom_background_url.spec()); EXPECT_EQ(std::string(), theme_info->custom_background_url.spec());
} }
TEST_F(InstantServiceTest, SetCustomBackgroundURLWithAttributions) { TEST_F(InstantServiceTestCustomBackgroundsEnabled,
SetCustomBackgroundURLWithAttributions) {
const GURL kUrl("https://www.foo.com"); const GURL kUrl("https://www.foo.com");
const std::string kAttributionLine1 = "foo"; const std::string kAttributionLine1 = "foo";
const std::string kAttributionLine2 = "bar"; const std::string kAttributionLine2 = "bar";
...@@ -69,7 +94,8 @@ TEST_F(InstantServiceTest, SetCustomBackgroundURLWithAttributions) { ...@@ -69,7 +94,8 @@ TEST_F(InstantServiceTest, SetCustomBackgroundURLWithAttributions) {
EXPECT_EQ(kActionUrl, theme_info->custom_background_attribution_action_url); EXPECT_EQ(kActionUrl, theme_info->custom_background_attribution_action_url);
} }
TEST_F(InstantServiceTest, ChangingSearchProviderClearsThemeInfoAndPref) { TEST_F(InstantServiceTestCustomBackgroundsEnabled,
ChangingSearchProviderClearsThemeInfoAndPref) {
const GURL kUrl("https://www.foo.com"); const GURL kUrl("https://www.foo.com");
const std::string kAttributionLine1 = "foo"; const std::string kAttributionLine1 = "foo";
const std::string kAttributionLine2 = "bar"; const std::string kAttributionLine2 = "bar";
...@@ -106,7 +132,7 @@ TEST_F(InstantServiceTest, ChangingSearchProviderClearsThemeInfoAndPref) { ...@@ -106,7 +132,7 @@ TEST_F(InstantServiceTest, ChangingSearchProviderClearsThemeInfoAndPref) {
EXPECT_EQ(GURL(), theme_info->custom_background_attribution_action_url); EXPECT_EQ(GURL(), theme_info->custom_background_attribution_action_url);
} }
TEST_F(InstantServiceTest, TEST_F(InstantServiceTestCustomBackgroundsEnabled,
ChangingSearchProviderRemovesLocalBackgroundImageCopy) { ChangingSearchProviderRemovesLocalBackgroundImageCopy) {
base::FilePath user_data_dir; base::FilePath user_data_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
...@@ -125,7 +151,8 @@ TEST_F(InstantServiceTest, ...@@ -125,7 +151,8 @@ TEST_F(InstantServiceTest,
EXPECT_EQ(false, file_exists); EXPECT_EQ(false, file_exists);
} }
TEST_F(InstantServiceTest, CustomBackgroundAttributionActionUrlReset) { TEST_F(InstantServiceTestCustomBackgroundsEnabled,
CustomBackgroundAttributionActionUrlReset) {
const GURL kUrl("https://www.foo.com"); const GURL kUrl("https://www.foo.com");
const std::string kAttributionLine1 = "foo"; const std::string kAttributionLine1 = "foo";
const std::string kAttributionLine2 = "bar"; const std::string kAttributionLine2 = "bar";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment