Commit ca4b8236 authored by Dan Beam's avatar Dan Beam

Reland "Local NTP: make past search matches change realbox icon to clock"

This is a reland of aaab30e7

CQ_INCLUDE_TRYBOTS=luci.chromium.try:win7-rel

Original change's description:
> Local NTP: make past search matches change realbox icon to clock
>
> R=mahmadi@chromium.org
>
> Fixed: 1043335
> Change-Id: I98b1fbcc0a5b5e0d48334e8eb33a31c66f07a4fe
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2008614
> Auto-Submit: Dan Beam <dbeam@chromium.org>
> Reviewed-by: Moe Ahmadi <mahmadi@chromium.org>
> Commit-Queue: Dan Beam <dbeam@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#733854}

Change-Id: Ia8665be77fb6cac6da6f3f3fbc33697b2b6bc63c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2013813Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735040}
parent 619ad3f1
......@@ -227,6 +227,20 @@ body.hide-fakebox #fakebox {
#realbox-icon {
background-position: center center;
background-repeat: no-repeat;
bottom: 0;
left: 16px;
margin: auto;
position: absolute;
top: 0;
width: 24px;
}
[dir=rtl] #realbox-icon {
left: auto;
right: 16px;
}
#realbox-icon.load-favicon {
background-size: 24px;
}
......@@ -500,8 +514,7 @@ html[dir=rtl] .microphone-icon {
right: auto;
}
#realbox-input-wrapper > :-webkit-any(.google-g-icon, .microphone-icon,
.search-icon) {
#realbox-input-wrapper > :-webkit-any(#realbox-icon, .microphone-icon) {
z-index: 3;
}
......
......@@ -78,7 +78,8 @@
<div id="realbox-container" $i18n{hiddenIfRealboxDisabled}>
<div id="realbox-input-wrapper">
<div id="realbox-icon" class="$i18n{realboxIconClass}"></div>
<div id="realbox-icon" class="$i18n{realboxIconClass}"
data-realbox-icon-class="$i18n{realboxIconClass}"></div>
<input id="realbox" type="search" autocomplete="off" spellcheck="false"
aria-live="polite" autofocus>
<button id="realbox-microphone" class="microphone-icon" hidden></button>
......
......@@ -91,6 +91,7 @@ const CLASSES = {
IMAGE_CONTAINER: 'image-container',
INITED: 'inited', // Reveals the <body> once init() is done.
LEFT_ALIGN_ATTRIBUTION: 'left-align-attribution',
LOAD_FAVICON: 'load-favicon',
// The image next to a realbox match.
MATCH_IMAGE: 'match-image',
// Vertically centers the most visited section for a non-Google provided page.
......@@ -2118,13 +2119,19 @@ function setFakeboxVisibility(show) {
/** @param {!AutocompleteMatch|undefined} match */
function setRealboxIcon(match) {
const showIcon = match && !match.isSearchType;
const loadFavicon = match && !match.isSearchType;
const realboxIcon = $(IDS.REALBOX_ICON);
realboxIcon.style.webkitMask = showIcon ? 'none' : '';
realboxIcon.style.backgroundColor = showIcon ? 'transparent' : '';
realboxIcon.style.webkitMask = loadFavicon ? 'none' : '';
realboxIcon.style.backgroundColor = loadFavicon ? 'transparent' : '';
realboxIcon.style.backgroundImage =
showIcon ? `url(${getIconUrl(match.destinationUrl)})` : '';
loadFavicon ? `url(${getIconUrl(match.destinationUrl)})` : '';
const historical = match && SEARCH_HISTORY_MATCH_TYPES.includes(match.type);
realboxIcon.className = loadFavicon ?
CLASSES.LOAD_FAVICON :
(historical ? CLASSES.CLOCK_ICON :
realboxIcon.dataset['realboxIconClass']);
}
/** @param {boolean} visible */
......
......@@ -4,6 +4,7 @@
#include <string>
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/ui/browser.h"
......@@ -16,6 +17,10 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#endif // defined(OS_WIN)
// A test class that sets up a local HTML file as the NTP URL.
class LocalNTPJavascriptTestBase : public InProcessBrowserTest {
public:
......@@ -47,6 +52,14 @@ class LocalNTPJavascriptTest : public LocalNTPJavascriptTestBase {
public:
LocalNTPJavascriptTest()
: LocalNTPJavascriptTestBase("/local_ntp_browsertest.html") {}
bool ShouldRunRealboxTest() const {
#if defined(OS_WIN)
return base::win::GetVersion() > base::win::Version::WIN7;
#else
return true;
#endif
}
};
// This runs a bunch of pure JS-side tests, i.e. those that don't require any
......@@ -98,27 +111,29 @@ IN_PROC_BROWSER_TEST_F(LocalNTPJavascriptTest, DISABLED_CustomizeMenuTests) {
}
#if !(defined(LEAK_SANITIZER) || defined(ADDRESS_SANITIZER))
IN_PROC_BROWSER_TEST_F(LocalNTPJavascriptTest, Realbox1Tests) {
content::WebContents* active_tab = local_ntp_test_utils::OpenNewTab(
browser(), GURL(chrome::kChromeUINewTabURL));
ASSERT_TRUE(search::IsInstantNTP(active_tab));
bool success = false;
ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
active_tab, "!!runSimpleTests('realbox1')", &success));
EXPECT_TRUE(success);
}
#define REALBOX_SUITE(suite_number) \
IN_PROC_BROWSER_TEST_F(LocalNTPJavascriptTest, \
Realbox##suite_number##Tests) { \
if (!ShouldRunRealboxTest()) \
return; \
content::WebContents* active_tab = local_ntp_test_utils::OpenNewTab( \
browser(), GURL(chrome::kChromeUINewTabURL)); \
ASSERT_TRUE(search::IsInstantNTP(active_tab)); \
\
bool success = false; \
ASSERT_TRUE(instant_test_utils::GetBoolFromJS( \
active_tab, \
base::StringPrintf("!!runSimpleTests('realbox%d')", suite_number), \
&success)); \
EXPECT_TRUE(success); \
}
IN_PROC_BROWSER_TEST_F(LocalNTPJavascriptTest, Realbox2Tests) {
content::WebContents* active_tab = local_ntp_test_utils::OpenNewTab(
browser(), GURL(chrome::kChromeUINewTabURL));
ASSERT_TRUE(search::IsInstantNTP(active_tab));
REALBOX_SUITE(1)
REALBOX_SUITE(2)
REALBOX_SUITE(3)
REALBOX_SUITE(4)
bool success = false;
ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
active_tab, "!!runSimpleTests('realbox2')", &success));
EXPECT_TRUE(success);
}
#undef REALBOX_SUITE
#endif
// A test class that sets up most_visited_browsertest.html as the NTP URL. It's
......
......@@ -70,7 +70,8 @@
<div id="realbox-container">
<div id="realbox-input-wrapper">
<div id="realbox-icon" class="search-icon"></div>
<div id="realbox-icon" class="search-icon"
data-realbox-icon-class="search-icon"></div>
<input id="realbox" type="search" autocomplete="off"
spellcheck="false" autofocus>
<button id="realbox-microphone" class="microphone-icon" hidden>
......
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