Commit 53ca78bb authored by Tibor Goldschwendt's avatar Tibor Goldschwendt Committed by Commit Bot

[ntp][modules] Add setting to hide modules

Offers a toggle in the customize dialog that hides modules on the NTP.
Screenshot (shown): https://screenshot.googleplex.com/BKvcrirTE6quvdi
Screenshot (hidden): https://screenshot.googleplex.com/AxMQ6DZa3MrHopf

Upon closing the customize dialog the visibility will be applied to the
current NTP and saved to prefs.

Bug: 1135393
Change-Id: I1dde6109ab3b8acccee5a4c57681a42302fbec76
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2454329
Auto-Submit: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarAlex Gough <ajgo@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814816}
parent ac3c3d07
...@@ -241,6 +241,7 @@ ...@@ -241,6 +241,7 @@
#include "chrome/browser/ui/startup/startup_browser_creator.h" #include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/webui/history/foreign_session_handler.h" #include "chrome/browser/ui/webui/history/foreign_session_handler.h"
#include "chrome/browser/ui/webui/history/history_ui.h" #include "chrome/browser/ui/webui/history/history_ui.h"
#include "chrome/browser/ui/webui/new_tab_page/new_tab_page_handler.h"
#include "chrome/browser/ui/webui/settings/settings_ui.h" #include "chrome/browser/ui/webui/settings/settings_ui.h"
#include "chrome/browser/upgrade_detector/upgrade_detector.h" #include "chrome/browser/upgrade_detector/upgrade_detector.h"
#include "components/ntp_tiles/custom_links_manager_impl.h" #include "components/ntp_tiles/custom_links_manager_impl.h"
...@@ -889,6 +890,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry, ...@@ -889,6 +890,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
HistoryUI::RegisterProfilePrefs(registry); HistoryUI::RegisterProfilePrefs(registry);
InstantService::RegisterProfilePrefs(registry); InstantService::RegisterProfilePrefs(registry);
media_router::RegisterProfilePrefs(registry); media_router::RegisterProfilePrefs(registry);
NewTabPageHandler::RegisterProfilePrefs(registry);
NewTabUI::RegisterProfilePrefs(registry); NewTabUI::RegisterProfilePrefs(registry);
ntp_tiles::CustomLinksManagerImpl::RegisterProfilePrefs(registry); ntp_tiles::CustomLinksManagerImpl::RegisterProfilePrefs(registry);
PinnedTabCodec::RegisterProfilePrefs(registry); PinnedTabCodec::RegisterProfilePrefs(registry);
......
...@@ -253,6 +253,7 @@ html_to_js("web_components_local") { ...@@ -253,6 +253,7 @@ html_to_js("web_components_local") {
"realbox.js", "realbox.js",
"iframe.js", "iframe.js",
"voice_search_overlay.js", "voice_search_overlay.js",
"customize_modules.js",
] ]
} }
...@@ -293,6 +294,7 @@ if (optimize_webui) { ...@@ -293,6 +294,7 @@ if (optimize_webui) {
"customize_dialog.js", "customize_dialog.js",
"voice_search_overlay.js", "voice_search_overlay.js",
"customize_backgrounds.js", "customize_backgrounds.js",
"customize_modules.js",
"customize_shortcuts.js", "customize_shortcuts.js",
"iframe.js", "iframe.js",
"mini_page.js", "mini_page.js",
......
...@@ -109,7 +109,8 @@ ...@@ -109,7 +109,8 @@
} }
:host(:not([promo-and-modules-loaded_])) ntp-middle-slot-promo, :host(:not([promo-and-modules-loaded_])) ntp-middle-slot-promo,
:host(:not([promo-and-modules-loaded_])) ntp-module-wrapper { :host(:not([promo-and-modules-loaded_])) ntp-module-wrapper,
:host(:not([modules-visible_])) ntp-module-wrapper {
display: none; display: none;
} }
......
...@@ -199,6 +199,12 @@ class AppElement extends PolymerElement { ...@@ -199,6 +199,12 @@ class AppElement extends PolymerElement {
reflectToAttribute: true, reflectToAttribute: true,
}, },
/** @private */
modulesVisible_: {
type: Boolean,
reflectToAttribute: true,
},
/** @private */ /** @private */
middleSlotPromoLoaded_: Boolean, middleSlotPromoLoaded_: Boolean,
...@@ -216,7 +222,14 @@ class AppElement extends PolymerElement { ...@@ -216,7 +222,14 @@ class AppElement extends PolymerElement {
computed: `computePromoAndModulesLoaded_(middleSlotPromoLoaded_, computed: `computePromoAndModulesLoaded_(middleSlotPromoLoaded_,
modulesLoaded_)`, modulesLoaded_)`,
reflectToAttribute: true, reflectToAttribute: true,
observer: 'onPromoAndModulesLoadedChange_', },
/** @private */
modulesLoadedAndVisible_: {
type: Boolean,
computed: `computeModulesLoadedAndVisible_(promoAndModulesLoaded_,
modulesVisible_)`,
observer: 'onModulesLoadedAndVisibleChange_',
}, },
/** /**
...@@ -259,6 +272,8 @@ class AppElement extends PolymerElement { ...@@ -259,6 +272,8 @@ class AppElement extends PolymerElement {
this.backgroundManager_ = BackgroundManager.getInstance(); this.backgroundManager_ = BackgroundManager.getInstance();
/** @private {?number} */ /** @private {?number} */
this.setThemeListenerId_ = null; this.setThemeListenerId_ = null;
/** @private {?number} */
this.setModulesVisibleListenerId_ = null;
/** @private {!EventTracker} */ /** @private {!EventTracker} */
this.eventTracker_ = new EventTracker(); this.eventTracker_ = new EventTracker();
this.loadOneGoogleBar_(); this.loadOneGoogleBar_();
...@@ -283,6 +298,11 @@ class AppElement extends PolymerElement { ...@@ -283,6 +298,11 @@ class AppElement extends PolymerElement {
performance.measure('theme-set'); performance.measure('theme-set');
this.theme_ = theme; this.theme_ = theme;
}); });
this.setModulesVisibleListenerId_ =
this.callbackRouter_.setModulesVisible.addListener(visible => {
this.modulesVisible_ = visible;
});
this.pageHandler_.updateModulesVisible();
this.eventTracker_.add(window, 'message', (event) => { this.eventTracker_.add(window, 'message', (event) => {
/** @type {!Object} */ /** @type {!Object} */
const data = event.data; const data = event.data;
...@@ -501,6 +521,14 @@ class AppElement extends PolymerElement { ...@@ -501,6 +521,14 @@ class AppElement extends PolymerElement {
(!loadTimeData.getBoolean('modulesEnabled') || this.modulesLoaded_); (!loadTimeData.getBoolean('modulesEnabled') || this.modulesLoaded_);
} }
/**
* @return {boolean}
* @private
*/
computeModulesLoadedAndVisible_() {
return this.promoAndModulesLoaded_ && this.modulesVisible_;
}
/** @private */ /** @private */
async onLazyRendered_() { async onLazyRendered_() {
if (!loadTimeData.getBoolean('modulesEnabled')) { if (!loadTimeData.getBoolean('modulesEnabled')) {
...@@ -593,8 +621,10 @@ class AppElement extends PolymerElement { ...@@ -593,8 +621,10 @@ class AppElement extends PolymerElement {
} }
/** @private */ /** @private */
onPromoAndModulesLoadedChange_() { onModulesLoadedAndVisibleChange_() {
this.pageHandler_.onModulesRendered(BrowserProxy.getInstance().now()); if (this.modulesLoadedAndVisible_) {
this.pageHandler_.onModulesRendered(BrowserProxy.getInstance().now());
}
} }
/** /**
......
...@@ -154,6 +154,10 @@ ...@@ -154,6 +154,10 @@
-webkit-mask-image: url(icons/link.svg); -webkit-mask-image: url(icons/link.svg);
} }
#modulesIcon {
-webkit-mask-image: url(icons/cards.svg);
}
#themesIcon { #themesIcon {
-webkit-mask-image: url(icons/colors.svg); -webkit-mask-image: url(icons/colors.svg);
} }
...@@ -214,6 +218,11 @@ ...@@ -214,6 +218,11 @@
<div id="shortcutsIcon" class="menu-item-icon"></div> <div id="shortcutsIcon" class="menu-item-icon"></div>
$i18n{shortcutsMenuItem} $i18n{shortcutsMenuItem}
</div> </div>
<div class="menu-item" page-name="modules" tabindex="0"
hidden$="[[!modulesEnabled_]]">
<div id="modulesIcon" class="menu-item-icon"></div>
$i18n{modulesMenuItem}
</div>
<div class="menu-item" page-name="themes" tabindex="0"> <div class="menu-item" page-name="themes" tabindex="0">
<div id="themesIcon" class="menu-item-icon"></div> <div id="themesIcon" class="menu-item-icon"></div>
$i18n{themesMenuItem} $i18n{themesMenuItem}
...@@ -231,6 +240,9 @@ ...@@ -231,6 +240,9 @@
</ntp-customize-backgrounds> </ntp-customize-backgrounds>
<ntp-customize-shortcuts page-name="shortcuts"> <ntp-customize-shortcuts page-name="shortcuts">
</ntp-customize-shortcuts> </ntp-customize-shortcuts>
<ntp-customize-modules page-name="modules"
hidden$="[[!modulesEnabled_]]">
</ntp-customize-modules>
<cr-customize-themes id="customizeThemes" page-name="themes"> <cr-customize-themes id="customizeThemes" page-name="themes">
</cr-customize-themes> </cr-customize-themes>
</iron-pages> </iron-pages>
......
...@@ -11,8 +11,10 @@ import 'chrome://resources/polymer/v3_0/iron-selector/iron-selector.js'; ...@@ -11,8 +11,10 @@ import 'chrome://resources/polymer/v3_0/iron-selector/iron-selector.js';
import 'chrome://resources/cr_components/customize_themes/customize_themes.js'; import 'chrome://resources/cr_components/customize_themes/customize_themes.js';
import './customize_backgrounds.js'; import './customize_backgrounds.js';
import './customize_shortcuts.js'; import './customize_shortcuts.js';
import './customize_modules.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert} from 'chrome://resources/js/assert.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {BrowserProxy} from './browser_proxy.js'; import {BrowserProxy} from './browser_proxy.js';
...@@ -91,6 +93,12 @@ class CustomizeDialogElement extends PolymerElement { ...@@ -91,6 +93,12 @@ class CustomizeDialogElement extends PolymerElement {
computed: `computeIsRefreshToggleChecked_(theme, selectedCollection_, computed: `computeIsRefreshToggleChecked_(theme, selectedCollection_,
backgroundSelection)`, backgroundSelection)`,
}, },
/** @private */
modulesEnabled_: {
type: Boolean,
value: () => loadTimeData.getBoolean('modulesEnabled'),
},
}; };
} }
...@@ -153,6 +161,9 @@ class CustomizeDialogElement extends PolymerElement { ...@@ -153,6 +161,9 @@ class CustomizeDialogElement extends PolymerElement {
onDoneClick_() { onDoneClick_() {
this.$.customizeThemes.confirmThemeChanges(); this.$.customizeThemes.confirmThemeChanges();
this.shadowRoot.querySelector('ntp-customize-shortcuts').apply(); this.shadowRoot.querySelector('ntp-customize-shortcuts').apply();
if (this.modulesEnabled_) {
this.shadowRoot.querySelector('ntp-customize-modules').apply();
}
switch (this.backgroundSelection.type) { switch (this.backgroundSelection.type) {
case BackgroundSelectionType.NO_BACKGROUND: case BackgroundSelectionType.NO_BACKGROUND:
this.pageHandler_.setNoBackgroundImage(); this.pageHandler_.setNoBackgroundImage();
......
<style include="cr-icons">
:host {
line-height: 20px;
}
#hide {
align-items: center;
border: 1px solid var(--ntp-border-color);
border-radius: 4px;
box-sizing: border-box;
display: flex;
height: 64px;
max-width: 544px;
width: 100%;
}
:host([hide_]) #hide {
background-color: var(--ntp-selected-background-color);
border-color: var(--ntp-selected-border-color);
color: var(--ntp-selected-border-color);
}
#hideIcon {
margin-inline-end: 20px;
margin-inline-start: 24px;
}
:host([hide_]) #hideIcon {
background-color: var(--ntp-selected-border-color);
}
#hideTitleContainer {
flex-grow: 1;
}
#hideTitle {
font-weight: bold;
}
cr-toggle {
margin-inline-end: 20px;
}
</style>
<div id="hide">
<div id="hideIcon" class="cr-icon icon-visibility-off"></div>
<div id="hideTitleContainer">
<div id="hideTitle">$i18n{hideModules}</div>
$i18n{hideModulesDesc}
</div>
<cr-toggle id="hideToggle" title="$i18n{hideModules}" checked="[[hide_]]"
on-change="onHideChange_"></cr-toggle>
</div>
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import './mini_page.js';
import 'chrome://resources/cr_elements/cr_icons_css.m.js';
import 'chrome://resources/cr_elements/cr_toggle/cr_toggle.m.js';
import 'chrome://resources/cr_elements/cr_button/cr_button.m.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {BrowserProxy} from './browser_proxy.js';
/** Element that lets the user configure modules settings. */
class CustomizeModulesElement extends PolymerElement {
static get is() {
return 'ntp-customize-modules';
}
static get template() {
return html`{__html_template__}`;
}
static get properties() {
return {
/** @private */
hide_: {
type: Boolean,
reflectToAttribute: true,
},
};
}
constructor() {
super();
/** @private {?number} */
this.setModulesVisibleListenerId_ = null;
}
/** @override */
connectedCallback() {
super.connectedCallback();
this.setModulesVisibleListenerId_ =
BrowserProxy.getInstance().callbackRouter.setModulesVisible.addListener(
visible => {
this.hide_ = !visible;
});
BrowserProxy.getInstance().handler.updateModulesVisible();
}
/** @override */
disconnectedCallback() {
super.disconnectedCallback();
BrowserProxy.getInstance().callbackRouter.removeListener(
assert(this.setModulesVisibleListenerId_));
}
apply() {
BrowserProxy.getInstance().handler.setModulesVisible(!this.hide_);
}
/**
* @param {!CustomEvent<boolean>} e
* @private
*/
onHideChange_(e) {
this.hide_ = e.detail;
}
}
customElements.define(CustomizeModulesElement.is, CustomizeModulesElement);
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M16.667 2.5H2.5a.836.836 0 0 0-.833.833v5c0 .459.375.834.833.834h14.167a.836.836 0 0 0 .833-.834v-5a.836.836 0 0 0-.833-.833zm-.834 5V4.167h-12.5V7.5h12.5zm0 8.333V12.5h-12.5v3.333h12.5zm-13.333-5h14.167c.458 0 .833.375.833.834v5a.836.836 0 0 1-.833.833H2.5a.836.836 0 0 1-.833-.833v-5c0-.459.375-.834.833-.834z" fill="#3367D6"/></svg>
\ No newline at end of file
...@@ -36,6 +36,9 @@ ...@@ -36,6 +36,9 @@
<include name="IDR_NEW_TAB_PAGE_CUSTOMIZE_SHORTCUTS_JS" <include name="IDR_NEW_TAB_PAGE_CUSTOMIZE_SHORTCUTS_JS"
file="${root_gen_dir}/chrome/browser/resources/new_tab_page/customize_shortcuts.js" file="${root_gen_dir}/chrome/browser/resources/new_tab_page/customize_shortcuts.js"
use_base_dir="false" type="BINDATA" compress="false" /> use_base_dir="false" type="BINDATA" compress="false" />
<include name="IDR_NEW_TAB_PAGE_CUSTOMIZE_MODULES_JS"
file="${root_gen_dir}/chrome/browser/resources/new_tab_page/customize_modules.js"
use_base_dir="false" type="BINDATA" compress="false" />
<include name="IDR_NEW_TAB_IFRAME_JS" <include name="IDR_NEW_TAB_IFRAME_JS"
file="${root_gen_dir}/chrome/browser/resources/new_tab_page/iframe.js" file="${root_gen_dir}/chrome/browser/resources/new_tab_page/iframe.js"
use_base_dir="false" type="BINDATA" compress="false" /> use_base_dir="false" type="BINDATA" compress="false" />
......
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
type="BINDATA" /> type="BINDATA" />
<include name="IDR_NEW_TAB_PAGE_INFO_SVG" file="icons/info.svg" <include name="IDR_NEW_TAB_PAGE_INFO_SVG" file="icons/info.svg"
type="BINDATA" /> type="BINDATA" />
<include name="IDR_NEW_TAB_PAGE_CARDS_SVG" file="icons/cards.svg"
type="BINDATA" />
<include name="IDR_NEW_TAB_PAGE_NEW_TAB_PAGE_HTML" <include name="IDR_NEW_TAB_PAGE_NEW_TAB_PAGE_HTML"
file="new_tab_page.html" type="BINDATA" /> file="new_tab_page.html" type="BINDATA" />
<include name="IDR_NEW_TAB_PAGE_SHARED_VARS_CSS" <include name="IDR_NEW_TAB_PAGE_SHARED_VARS_CSS"
......
...@@ -341,6 +341,10 @@ interface PageHandler { ...@@ -341,6 +341,10 @@ interface PageHandler {
OnDismissModule(string module_id); OnDismissModule(string module_id);
// Called when a module the given id is restored. // Called when a module the given id is restored.
OnRestoreModule(string module_id); OnRestoreModule(string module_id);
// If |visible| the modules will be shown.
SetModulesVisible(bool visible);
// Triggers a call to |SetModulesVisible| with the current visibility setting.
UpdateModulesVisible();
// ======= METRICS ======= // ======= METRICS =======
// Logs that |tiles| were displayed / updated at |time|. The first instance of // Logs that |tiles| were displayed / updated at |time|. The first instance of
...@@ -437,6 +441,8 @@ interface Page { ...@@ -437,6 +441,8 @@ interface Page {
SetFakeboxFocused(bool focused); SetFakeboxFocused(bool focused);
// If |visible| shows the fakebox. // If |visible| shows the fakebox.
SetFakeboxVisible(bool visible); SetFakeboxVisible(bool visible);
// Updates the module visibility.
SetModulesVisible(bool visible);
// ======= REALBOX ======= // ======= REALBOX =======
// Updates the NTP realbox with the autocomplete results. // Updates the NTP realbox with the autocomplete results.
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "components/omnibox/browser/omnibox_event_global_tracker.h" #include "components/omnibox/browser/omnibox_event_global_tracker.h"
#include "components/omnibox/browser/omnibox_log.h" #include "components/omnibox/browser/omnibox_log.h"
#include "components/omnibox/browser/omnibox_prefs.h" #include "components/omnibox/browser/omnibox_prefs.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/omnibox_focus_type.h" #include "components/search_engines/omnibox_focus_type.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/search_provider_logos/logo_service.h" #include "components/search_provider_logos/logo_service.h"
...@@ -71,6 +72,8 @@ namespace { ...@@ -71,6 +72,8 @@ namespace {
const int64_t kMaxDownloadBytes = 1024 * 1024; const int64_t kMaxDownloadBytes = 1024 * 1024;
constexpr char kModulesVisiblePrefName[] = "NewTabPage.ModulesVisible";
new_tab_page::mojom::ThemePtr MakeTheme(const NtpTheme& ntp_theme) { new_tab_page::mojom::ThemePtr MakeTheme(const NtpTheme& ntp_theme) {
auto theme = new_tab_page::mojom::Theme::New(); auto theme = new_tab_page::mojom::Theme::New();
theme->is_default = ntp_theme.using_default_theme; theme->is_default = ntp_theme.using_default_theme;
...@@ -399,6 +402,11 @@ NewTabPageHandler::~NewTabPageHandler() { ...@@ -399,6 +402,11 @@ NewTabPageHandler::~NewTabPageHandler() {
} }
} }
// static
void NewTabPageHandler::RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(kModulesVisiblePrefName, true);
}
void NewTabPageHandler::AddMostVisitedTile( void NewTabPageHandler::AddMostVisitedTile(
const GURL& url, const GURL& url,
const std::string& title, const std::string& title,
...@@ -665,6 +673,16 @@ void NewTabPageHandler::OnRestoreModule(const std::string& module_id) { ...@@ -665,6 +673,16 @@ void NewTabPageHandler::OnRestoreModule(const std::string& module_id) {
base::UmaHistogramExactLinear(histogram_prefix + "." + module_id, 1, 1); base::UmaHistogramExactLinear(histogram_prefix + "." + module_id, 1, 1);
} }
void NewTabPageHandler::SetModulesVisible(bool visible) {
profile_->GetPrefs()->SetBoolean(kModulesVisiblePrefName, visible);
UpdateModulesVisible();
}
void NewTabPageHandler::UpdateModulesVisible() {
page_->SetModulesVisible(
profile_->GetPrefs()->GetBoolean(kModulesVisiblePrefName));
}
void NewTabPageHandler::OnPromoDataUpdated() { void NewTabPageHandler::OnPromoDataUpdated() {
if (promo_load_start_time_.has_value()) { if (promo_load_start_time_.has_value()) {
base::TimeDelta duration = base::TimeTicks::Now() - *promo_load_start_time_; base::TimeDelta duration = base::TimeTicks::Now() - *promo_load_start_time_;
......
...@@ -71,6 +71,8 @@ class NewTabPageHandler : public new_tab_page::mojom::PageHandler, ...@@ -71,6 +71,8 @@ class NewTabPageHandler : public new_tab_page::mojom::PageHandler,
static const char kModuleDismissedHistogram[]; static const char kModuleDismissedHistogram[];
static const char kModuleRestoredHistogram[]; static const char kModuleRestoredHistogram[];
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
// new_tab_page::mojom::PageHandler: // new_tab_page::mojom::PageHandler:
void AddMostVisitedTile(const GURL& url, void AddMostVisitedTile(const GURL& url,
const std::string& title, const std::string& title,
...@@ -105,6 +107,8 @@ class NewTabPageHandler : public new_tab_page::mojom::PageHandler, ...@@ -105,6 +107,8 @@ class NewTabPageHandler : public new_tab_page::mojom::PageHandler,
void GetPromo(GetPromoCallback callback) override; void GetPromo(GetPromoCallback callback) override;
void OnDismissModule(const std::string& module_id) override; void OnDismissModule(const std::string& module_id) override;
void OnRestoreModule(const std::string& module_id) override; void OnRestoreModule(const std::string& module_id) override;
void SetModulesVisible(bool visible) override;
void UpdateModulesVisible() override;
void OnMostVisitedTilesRendered( void OnMostVisitedTilesRendered(
std::vector<new_tab_page::mojom::MostVisitedTilePtr> tiles, std::vector<new_tab_page::mojom::MostVisitedTilePtr> tiles,
double time) override; double time) override;
......
...@@ -50,6 +50,7 @@ class MockPage : public new_tab_page::mojom::Page { ...@@ -50,6 +50,7 @@ class MockPage : public new_tab_page::mojom::Page {
MOCK_METHOD1(SetTheme, void(new_tab_page::mojom::ThemePtr)); MOCK_METHOD1(SetTheme, void(new_tab_page::mojom::ThemePtr));
MOCK_METHOD1(SetFakeboxFocused, void(bool)); MOCK_METHOD1(SetFakeboxFocused, void(bool));
MOCK_METHOD1(SetFakeboxVisible, void(bool)); MOCK_METHOD1(SetFakeboxVisible, void(bool));
MOCK_METHOD1(SetModulesVisible, void(bool));
MOCK_METHOD1(AutocompleteResultChanged, MOCK_METHOD1(AutocompleteResultChanged,
void(search::mojom::AutocompleteResultPtr)); void(search::mojom::AutocompleteResultPtr));
MOCK_METHOD3(AutocompleteMatchImageAvailable, MOCK_METHOD3(AutocompleteMatchImageAvailable,
......
...@@ -127,12 +127,15 @@ content::WebUIDataSource* CreateNewTabPageUiHtmlSource(Profile* profile) { ...@@ -127,12 +127,15 @@ content::WebUIDataSource* CreateNewTabPageUiHtmlSource(Profile* profile) {
{"defaultThemeLabel", IDS_NTP_CUSTOMIZE_DEFAULT_LABEL}, {"defaultThemeLabel", IDS_NTP_CUSTOMIZE_DEFAULT_LABEL},
{"hideShortcuts", IDS_NTP_CUSTOMIZE_HIDE_SHORTCUTS_LABEL}, {"hideShortcuts", IDS_NTP_CUSTOMIZE_HIDE_SHORTCUTS_LABEL},
{"hideShortcutsDesc", IDS_NTP_CUSTOMIZE_HIDE_SHORTCUTS_DESC}, {"hideShortcutsDesc", IDS_NTP_CUSTOMIZE_HIDE_SHORTCUTS_DESC},
{"hideModules", IDS_NTP_CUSTOMIZE_HIDE_MODULES_LABEL},
{"hideModulesDesc", IDS_NTP_CUSTOMIZE_HIDE_MODULES_DESC},
{"mostVisited", IDS_NTP_CUSTOMIZE_MOST_VISITED_LABEL}, {"mostVisited", IDS_NTP_CUSTOMIZE_MOST_VISITED_LABEL},
{"myShortcuts", IDS_NTP_CUSTOMIZE_MY_SHORTCUTS_LABEL}, {"myShortcuts", IDS_NTP_CUSTOMIZE_MY_SHORTCUTS_LABEL},
{"noBackground", IDS_NTP_CUSTOMIZE_NO_BACKGROUND_LABEL}, {"noBackground", IDS_NTP_CUSTOMIZE_NO_BACKGROUND_LABEL},
{"refreshDaily", IDS_NTP_CUSTOM_BG_DAILY_REFRESH}, {"refreshDaily", IDS_NTP_CUSTOM_BG_DAILY_REFRESH},
{"shortcutsCurated", IDS_NTP_CUSTOMIZE_MY_SHORTCUTS_DESC}, {"shortcutsCurated", IDS_NTP_CUSTOMIZE_MY_SHORTCUTS_DESC},
{"shortcutsMenuItem", IDS_NTP_CUSTOMIZE_MENU_SHORTCUTS_LABEL}, {"shortcutsMenuItem", IDS_NTP_CUSTOMIZE_MENU_SHORTCUTS_LABEL},
{"modulesMenuItem", IDS_NTP_CUSTOMIZE_MENU_MODULES_LABEL},
{"shortcutsOption", IDS_NTP_CUSTOMIZE_MENU_SHORTCUTS_LABEL}, {"shortcutsOption", IDS_NTP_CUSTOMIZE_MENU_SHORTCUTS_LABEL},
{"shortcutsSuggested", IDS_NTP_CUSTOMIZE_MOST_VISITED_DESC}, {"shortcutsSuggested", IDS_NTP_CUSTOMIZE_MOST_VISITED_DESC},
{"themesMenuItem", IDS_NTP_CUSTOMIZE_MENU_COLOR_LABEL}, {"themesMenuItem", IDS_NTP_CUSTOMIZE_MENU_COLOR_LABEL},
......
...@@ -439,26 +439,32 @@ suite('NewTabPageAppTest', () => { ...@@ -439,26 +439,32 @@ suite('NewTabPageAppTest', () => {
}); });
}); });
test('modules appended to page', async () => { [true, false].forEach(visible => {
// Act. test(`modules appended to page if visibility ${visible}`, async () => {
moduleResolver.resolve([ // Act.
{ moduleResolver.resolve([
id: 'foo', {
element: document.createElement('div'), id: 'foo',
title: 'Foo Title', element: document.createElement('div'),
}, title: 'Foo Title',
{ },
id: 'bar', {
element: document.createElement('div'), id: 'bar',
title: 'Bar Title', element: document.createElement('div'),
} title: 'Bar Title',
]); }
await flushTasks(); // Wait for module descriptor resolution. ]);
testProxy.callbackRouterRemote.setModulesVisible(visible);
// Assert. await flushTasks(); // Wait for module descriptor resolution.
const modules = app.shadowRoot.querySelectorAll('ntp-module-wrapper');
assertEquals(2, modules.length); // Assert.
assertEquals(1, testProxy.handler.getCallCount('onModulesRendered')); const modules = app.shadowRoot.querySelectorAll('ntp-module-wrapper');
assertEquals(2, modules.length);
assertEquals(
visible ? 1 : 0,
testProxy.handler.getCallCount('onModulesRendered'));
assertEquals(1, testProxy.handler.getCallCount('updateModulesVisible'));
});
}); });
test('modules can be dismissed and restored', async () => { test('modules can be dismissed and restored', async () => {
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {BrowserProxy} from 'chrome://new-tab-page/new_tab_page.js';
import {createTestProxy} from 'chrome://test/new_tab_page/test_support.js';
suite('NewTabPageCustomizeModulesTest', () => {
/** @type {!CustomizeModulesElement} */
let customizeModules;
/**
* @implements {BrowserProxy}
* @extends {TestBrowserProxy}
*/
let testProxy;
setup(() => {
PolymerTest.clearBody();
testProxy = createTestProxy();
BrowserProxy.instance_ = testProxy;
customizeModules = document.createElement('ntp-customize-modules');
document.body.appendChild(customizeModules);
});
[true, false].forEach(visible => {
test('toggle hide calls handler', async () => {
// Arrange.
testProxy.callbackRouterRemote.setModulesVisible(visible);
// Act.
customizeModules.$.hideToggle.click();
customizeModules.apply();
// Assert.
assertEquals(1, testProxy.handler.getCallCount('setModulesVisible'));
});
});
});
...@@ -83,6 +83,18 @@ TEST_F('NewTabPageCustomizeShortcutsTest', 'All', function() { ...@@ -83,6 +83,18 @@ TEST_F('NewTabPageCustomizeShortcutsTest', 'All', function() {
mocha.run(); mocha.run();
}); });
// eslint-disable-next-line no-var
var NewTabPageCustomizeModulesTest = class extends NewTabPageBrowserTest {
/** @override */
get browsePreload() {
return 'chrome://new-tab-page/test_loader.html?module=new_tab_page/customize_modules_test.js';
}
};
TEST_F('NewTabPageCustomizeModulesTest', 'All', function() {
mocha.run();
});
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
var NewTabPageCustomizeBackgroundsTest = class extends NewTabPageBrowserTest { var NewTabPageCustomizeBackgroundsTest = class extends NewTabPageBrowserTest {
/** @override */ /** @override */
......
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