Commit 1f96bac0 authored by Kyle Milka's avatar Kyle Milka Committed by Commit Bot

Add default shortcut to Google Search on the NTP

Add a flag to show a Google Search shortcut on the
NTP by default. Only add the shortcut if this is
a Chrome branded build.

Bug: 962558
Change-Id: I4f5cd18b0dc3182264057f55eb381cb94d6ee49b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1614457Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarRamya Nagarajan <ramyan@chromium.org>
Commit-Queue: Kyle Milka <kmilka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663980}
parent 6a70a16f
...@@ -25,11 +25,14 @@ ...@@ -25,11 +25,14 @@
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/grit/locale_settings.h" #include "chrome/grit/locale_settings.h"
#include "chrome/grit/theme_resources.h" #include "chrome/grit/theme_resources.h"
#include "components/grit/components_scaled_resources.h"
#include "components/history/core/browser/history_constants.h" #include "components/history/core/browser/history_constants.h"
#include "components/history/core/browser/top_sites_impl.h" #include "components/history/core/browser/top_sites_impl.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/ntp_tiles/features.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -53,6 +56,14 @@ struct RawPrepopulatedPage { ...@@ -53,6 +56,14 @@ struct RawPrepopulatedPage {
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
// Android does not use prepopulated pages. // Android does not use prepopulated pages.
const RawPrepopulatedPage kRawPrepopulatedPages[] = { const RawPrepopulatedPage kRawPrepopulatedPages[] = {
#if defined(GOOGLE_CHROME_BUILD)
{
IDS_NTP_DEFAULT_SEARCH_URL,
IDS_NTP_DEFAULT_SEARCH_TITLE,
IDS_ONBOARDING_WELCOME_SEARCH,
SkColorSetRGB(63, 132, 197),
},
#endif
{ {
IDS_WEBSTORE_URL, IDS_WEBSTORE_URL,
IDS_EXTENSION_WEB_STORE_TITLE_SHORT, IDS_EXTENSION_WEB_STORE_TITLE_SHORT,
...@@ -73,6 +84,11 @@ void InitializePrepopulatedPageList( ...@@ -73,6 +84,11 @@ void InitializePrepopulatedPageList(
const RawPrepopulatedPage& page = kRawPrepopulatedPages[i]; const RawPrepopulatedPage& page = kRawPrepopulatedPages[i];
if (hide_web_store_icon && page.url_id == IDS_WEBSTORE_URL) if (hide_web_store_icon && page.url_id == IDS_WEBSTORE_URL)
continue; continue;
if (page.url_id == IDS_NTP_DEFAULT_SEARCH_URL &&
!base::FeatureList::IsEnabled(ntp_tiles::kDefaultSearchShortcut)) {
continue;
}
prepopulated_pages->push_back(history::PrepopulatedPage( prepopulated_pages->push_back(history::PrepopulatedPage(
GURL(l10n_util::GetStringUTF8(page.url_id)), GURL(l10n_util::GetStringUTF8(page.url_id)),
l10n_util::GetStringUTF16(page.title_id), page.favicon_id, page.color)); l10n_util::GetStringUTF16(page.title_id), page.favicon_id, page.color));
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/ntp_tiles/constants.h" #include "components/ntp_tiles/constants.h"
#include "components/ntp_tiles/features.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/interstitial_page.h" #include "content/public/browser/interstitial_page.h"
...@@ -81,6 +82,16 @@ content::RenderFrameHost* GetIframe(content::WebContents* tab, ...@@ -81,6 +82,16 @@ content::RenderFrameHost* GetIframe(content::WebContents* tab,
return nullptr; return nullptr;
} }
bool ContainsDefaultSearchTile(content::RenderFrameHost* iframe) {
int num_search_tiles;
EXPECT_TRUE(
instant_test_utils::GetIntFromJS(iframe,
"document.querySelectorAll(\".md-tile["
"href='https://google.com/']\").length",
&num_search_tiles));
return num_search_tiles == 1;
}
class LocalNTPTest : public InProcessBrowserTest { class LocalNTPTest : public InProcessBrowserTest {
public: public:
LocalNTPTest(const std::vector<base::Feature>& enabled_features, LocalNTPTest(const std::vector<base::Feature>& enabled_features,
...@@ -844,4 +855,41 @@ IN_PROC_BROWSER_TEST_F(LocalNTPTest, InterstitialsAreNotNTPs) { ...@@ -844,4 +855,41 @@ IN_PROC_BROWSER_TEST_F(LocalNTPTest, InterstitialsAreNotNTPs) {
EXPECT_TRUE(search::IsInstantNTP(active_tab)); EXPECT_TRUE(search::IsInstantNTP(active_tab));
} }
class LocalNTPNoSearchShortcutTest : public LocalNTPTest {
public:
LocalNTPNoSearchShortcutTest()
: LocalNTPTest({}, {ntp_tiles::kDefaultSearchShortcut}) {}
};
IN_PROC_BROWSER_TEST_F(LocalNTPNoSearchShortcutTest, SearchShortcutHidden) {
content::WebContents* active_tab =
local_ntp_test_utils::OpenNewTab(browser(), GURL("about:blank"));
local_ntp_test_utils::NavigateToNTPAndWaitUntilLoaded(browser());
ASSERT_TRUE(search::IsInstantNTP(active_tab));
content::RenderFrameHost* iframe = GetIframe(active_tab, "mv-single");
EXPECT_FALSE(ContainsDefaultSearchTile(iframe));
}
#if defined(GOOGLE_CHROME_BUILD)
class LocalNTPSearchShortcutTest : public LocalNTPTest {
public:
LocalNTPSearchShortcutTest()
: LocalNTPTest({ntp_tiles::kDefaultSearchShortcut}, {}) {}
};
IN_PROC_BROWSER_TEST_F(LocalNTPSearchShortcutTest, SearchShortcutShown) {
content::WebContents* active_tab =
local_ntp_test_utils::OpenNewTab(browser(), GURL("about:blank"));
local_ntp_test_utils::NavigateToNTPAndWaitUntilLoaded(browser());
ASSERT_TRUE(search::IsInstantNTP(active_tab));
content::RenderFrameHost* iframe = GetIframe(active_tab, kMostVisitedIframe);
EXPECT_TRUE(ContainsDefaultSearchTile(iframe));
}
#endif
} // namespace } // namespace
...@@ -13,6 +13,7 @@ per-file dom_distiller_strings.grdp=file://components/dom_distiller/OWNERS ...@@ -13,6 +13,7 @@ per-file dom_distiller_strings.grdp=file://components/dom_distiller/OWNERS
per-file error_page_strings.grdp=file://components/error_page/OWNERS per-file error_page_strings.grdp=file://components/error_page/OWNERS
per-file management_strings.grdp=file://docs/privacy/OWNERS per-file management_strings.grdp=file://docs/privacy/OWNERS
per-file ntp_snippets_strings.grdp=file://components/ntp_snippets/OWNERS per-file ntp_snippets_strings.grdp=file://components/ntp_snippets/OWNERS
per-file ntp_tiles_strings.grdp=file://components/ntp_tiles/OWNERS
per-file omnibox_strings.grdp=file://components/omnibox/OWNERS per-file omnibox_strings.grdp=file://components/omnibox/OWNERS
per-file page_info_strings.grdp=file://chrome/browser/ui/page_info/OWNERS per-file page_info_strings.grdp=file://chrome/browser/ui/page_info/OWNERS
per-file password_manager_strings.grdp=file://components/password_manager/OWNERS per-file password_manager_strings.grdp=file://components/password_manager/OWNERS
......
...@@ -208,6 +208,7 @@ ...@@ -208,6 +208,7 @@
<part file="login_dialog_strings.grdp" /> <part file="login_dialog_strings.grdp" />
<part file="new_or_sad_tab_strings.grdp" /> <part file="new_or_sad_tab_strings.grdp" />
<part file="ntp_snippets_strings.grdp" /> <part file="ntp_snippets_strings.grdp" />
<part file="ntp_tiles_strings.grdp" />
<part file="omnibox_strings.grdp" /> <part file="omnibox_strings.grdp" />
<part file="page_info_strings.grdp" /> <part file="page_info_strings.grdp" />
<part file="password_manager_strings.grdp" /> <part file="password_manager_strings.grdp" />
......
...@@ -20,4 +20,7 @@ const base::Feature kNtpMostLikelyFaviconsFromServerFeature{ ...@@ -20,4 +20,7 @@ const base::Feature kNtpMostLikelyFaviconsFromServerFeature{
const base::Feature kUsePopularSitesSuggestions{ const base::Feature kUsePopularSitesSuggestions{
"UsePopularSitesSuggestions", base::FEATURE_ENABLED_BY_DEFAULT}; "UsePopularSitesSuggestions", base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kDefaultSearchShortcut{"DefaultSearchShortcut",
base::FEATURE_DISABLED_BY_DEFAULT};
} // namespace ntp_tiles } // namespace ntp_tiles
...@@ -26,6 +26,9 @@ extern const base::Feature kNtpMostLikelyFaviconsFromServerFeature; ...@@ -26,6 +26,9 @@ extern const base::Feature kNtpMostLikelyFaviconsFromServerFeature;
// If this feature is enabled, we enable popular sites in the suggestions UI. // If this feature is enabled, we enable popular sites in the suggestions UI.
extern const base::Feature kUsePopularSitesSuggestions; extern const base::Feature kUsePopularSitesSuggestions;
// If enabled, show a Google search shortcut on the NTP by default.
extern const base::Feature kDefaultSearchShortcut;
} // namespace ntp_tiles } // namespace ntp_tiles
#endif // COMPONENTS_NTP_TILES_FEATURES_H_ #endif // COMPONENTS_NTP_TILES_FEATURES_H_
<?xml version="1.0" encoding="utf-8"?>
<grit-part>
<if expr="not is_android">
<!-- The title for the Google Search shortcut. -->
<message name="IDS_NTP_DEFAULT_SEARCH_TITLE" translateable="false" desc="The label for the default Search shortcut on the New Tab Page.">
Google
</message>
<!-- The URL for the Google Search shortcut. -->
<message name="IDS_NTP_DEFAULT_SEARCH_URL" translateable="false">
https://www.google.com
</message>
</if>
</grit-part>
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