Commit 6c403709 authored by Daniel Classon's avatar Daniel Classon Committed by Commit Bot

[OsSettingsDeepLinking] Add deep links to the Search Page

Adds deep links to the Search and Assistant page, inclusind the Google
assistant subpage.

Bug: 1084154
Change-Id: I151f03ab0160921afaf0037b319d9c8f95dd813b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2378391Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarJimmy Gong <jimmyxgong@chromium.org>
Commit-Queue: Daniel Classon <dclasson@google.com>
Cr-Commit-Position: refs/heads/master@{#801975}
parent c4772ede
......@@ -19,7 +19,9 @@ js_library("google_assistant_browser_proxy") {
js_library("google_assistant_page") {
deps = [
":google_assistant_browser_proxy",
"..:deep_linking_behavior",
"..:metrics_recorder",
"..:os_route",
"../../prefs:prefs_behavior",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:i18n_behavior",
......
......@@ -14,7 +14,10 @@
<link rel="import" href="../../prefs/prefs_behavior.html">
<link rel="import" href="../../settings_shared_css.html">
<link rel="import" href="../../prefs/pref_util.html">
<link rel="import" href="../deep_linking_behavior.html">
<link rel="import" href="../metrics_recorder.html">
<link rel="import" href="../os_route.html">
<link rel="import" href="../../router.html">
<dom-module id="settings-google-assistant-page">
<template>
......@@ -44,7 +47,8 @@
pref="{{prefs.settings.voice_interaction.enabled}}"
label="[[getAssistantOnOffLabel_(
prefs.settings.voice_interaction.enabled.value)]]"
disabled="{{prefs.settings.assistant.disabled_by_policy.value}}">
disabled="{{prefs.settings.assistant.disabled_by_policy.value}}"
deep-link-focus-id$="[[Setting.kAssistantOnOff]]">
</settings-toggle-button>
<template is="dom-if"
if="[[prefs.settings.voice_interaction.enabled.value]]">
......@@ -52,7 +56,8 @@
class="hr"
pref="{{prefs.settings.voice_interaction.context.enabled}}"
label="$i18n{googleAssistantEnableContext}"
sub-label="$i18n{googleAssistantEnableContextDescription}">
sub-label="$i18n{googleAssistantEnableContextDescription}"
deep-link-focus-id$="[[Setting.kAssistantRelatedInfo]]">
</settings-toggle-button>
<template is="dom-if" if="[[quickAnswersAvailable_]]">
<div class="settings-box continuation embedded"
......@@ -61,7 +66,8 @@
id="google-assistant-quick-answers-enable"
pref="{{prefs.settings.voice_interaction.quick_answers.enabled}}"
label="$i18n{googleAssistantEnableQuickAnswers}"
sub-label="$i18n{googleAssistantEnableQuickAnswersDescription}">
sub-label="$i18n{googleAssistantEnableQuickAnswersDescription}"
deep-link-focus-id$="[[Setting.kAssistantQuickAnswers]]">
</settings-toggle-button>
</div>
</template>
......@@ -71,7 +77,8 @@
label="$i18n{googleAssistantEnableHotword}"
sub-label="$i18n{googleAssistantEnableHotwordDescription}"
on-settings-boolean-control-change="onEnableHotwordChange_"
hidden="[[!hotwordDspAvailable_]]">
hidden="[[!hotwordDspAvailable_]]"
deep-link-focus-id$="[[Setting.kAssistantOkGoogle]]">
</settings-toggle-button>
<div class="settings-box" id="dsp-hotword-container"
hidden="[[hotwordDspAvailable_]]">
......@@ -119,7 +126,8 @@
<controlled-button id="retrain-voice-model"
on-click="onRetrainVoiceModelTapped_"
label="$i18n{googleAssistantVoiceSettingsRetrainButton}"
pref="{{prefs.settings.voice_interaction.hotword.enabled}}">
pref="{{prefs.settings.voice_interaction.hotword.enabled}}"
deep-link-focus-id$="[[Setting.kTrainAssistantVoiceModel]]">
</controlled-button>
</div>
</template>
......@@ -127,13 +135,15 @@
class="hr"
pref="{{prefs.settings.voice_interaction.notification.enabled}}"
label="$i18n{googleAssistantEnableNotification}"
sub-label="$i18n{googleAssistantEnableNotificationDescription}">
sub-label="$i18n{googleAssistantEnableNotificationDescription}"
deep-link-focus-id$="[[Setting.kAssistantNotifications]]">
</settings-toggle-button>
<settings-toggle-button id="google-assistant-launch-with-mic-open"
class="hr"
pref="{{prefs.settings.voice_interaction.launch_with_mic_open}}"
label="$i18n{googleAssistantLaunchWithMicOpen}"
sub-label="$i18n{googleAssistantLaunchWithMicOpenDescription}">
sub-label="$i18n{googleAssistantLaunchWithMicOpenDescription}"
deep-link-focus-id$="[[Setting.kAssistantVoiceInput]]">
</settings-toggle-button>
<cr-link-row id="google-assistant-settings" class="hr"
on-click="onGoogleAssistantSettingsTapped_"
......
......@@ -41,7 +41,10 @@ const ConsentStatus = {
Polymer({
is: 'settings-google-assistant-page',
behaviors: [I18nBehavior, PrefsBehavior, WebUIListenerBehavior],
behaviors: [
DeepLinkingBehavior, I18nBehavior, PrefsBehavior,
settings.RouteObserverBehavior, WebUIListenerBehavior
],
properties: {
/** @private */
......@@ -96,6 +99,23 @@ Polymer({
type: Boolean,
value: false,
},
/**
* Used by DeepLinkingBehavior to focus this page's deep links.
* @type {!Set<!chromeos.settings.mojom.Setting>}
*/
supportedSettingIds: {
type: Object,
value: () => new Set([
chromeos.settings.mojom.Setting.kAssistantOnOff,
chromeos.settings.mojom.Setting.kAssistantRelatedInfo,
chromeos.settings.mojom.Setting.kAssistantQuickAnswers,
chromeos.settings.mojom.Setting.kAssistantOkGoogle,
chromeos.settings.mojom.Setting.kAssistantNotifications,
chromeos.settings.mojom.Setting.kAssistantVoiceInput,
chromeos.settings.mojom.Setting.kTrainAssistantVoiceModel,
]),
},
},
observers: [
......@@ -125,6 +145,19 @@ Polymer({
chrome.send('initializeGoogleAssistantPage');
},
/**
* @param {!settings.Route} route
* @param {!settings.Route} oldRoute
*/
currentRouteChanged(route, oldRoute) {
// Does not apply to this page.
if (route !== settings.routes.GOOGLE_ASSISTANT) {
return;
}
this.attemptDeepLink();
},
/**
* @param {boolean} toggleValue
* @return {string}
......
......@@ -10,6 +10,7 @@ js_type_check("closure_compile") {
js_library("os_search_page") {
deps = [
"..:deep_linking_behavior",
"..:os_route",
"../..:router",
"../../prefs",
......
......@@ -13,6 +13,7 @@
<link rel="import" href="../../controls/extension_controlled_indicator.html">
<link rel="import" href="../google_assistant_page/google_assistant_page.html">
<link rel="import" href="../../i18n_setup.html">
<link rel="import" href="../deep_linking_behavior.html">
<link rel="import" href="../os_route.html">
<link rel="import" href="../../router.html">
<link rel="import" href="../../search_engines_page/search_engines_browser_proxy.html">
......@@ -68,7 +69,8 @@
<select class="md-select" on-change="onChange_"
aria-labelledby="searchExplanation"
disabled$="[[isDefaultSearchEngineEnforced_(
prefs.default_search_provider_data.template_url_data)]]">
prefs.default_search_provider_data.template_url_data)]]"
deep-link-focus-id$="[[Setting.kPreferredSearchEngine]]">
<template is="dom-repeat" items="[[searchEngines_]]">
<option selected="[[item.default]]">[[item.name]]</option>
</template>
......
......@@ -9,7 +9,11 @@
Polymer({
is: 'os-settings-search-page',
behaviors: [I18nBehavior],
behaviors: [
DeepLinkingBehavior,
I18nBehavior,
settings.RouteObserverBehavior,
],
properties: {
prefs: Object,
......@@ -38,6 +42,16 @@ Polymer({
return loadTimeData.getBoolean('isAssistantAllowed');
},
},
/**
* Used by DeepLinkingBehavior to focus this page's deep links.
* @type {!Set<!chromeos.settings.mojom.Setting>}
*/
supportedSettingIds: {
type: Object,
value: () =>
new Set([chromeos.settings.mojom.Setting.kPreferredSearchEngine]),
},
},
/** @private {?settings.SearchEnginesBrowserProxy} */
......@@ -63,6 +77,19 @@ Polymer({
}
},
/**
* @param {!settings.Route} route
* @param {!settings.Route} oldRoute
*/
currentRouteChanged(route, oldRoute) {
// Does not apply to this page.
if (route !== settings.routes.OS_SEARCH) {
return;
}
this.attemptDeepLink();
},
/** @private */
onChange_() {
const select = /** @type {!HTMLSelectElement} */ (this.$$('select'));
......
......@@ -241,6 +241,29 @@ suite('GoogleAssistantHandler', function() {
assertTrue(!!button);
});
test('Deep link to retrain voice model', async () => {
loadTimeData.overrideValues({isDeepLinkingEnabled: true});
assertTrue(loadTimeData.getBoolean('isDeepLinkingEnabled'));
page.setPrefValue('settings.voice_interaction.enabled', true);
page.setPrefValue('settings.voice_interaction.hotword.enabled', true);
page.setPrefValue(
'settings.voice_interaction.activity_control.consent_status',
ConsentStatus.kActivityControlAccepted);
Polymer.dom.flush();
const params = new URLSearchParams;
params.append('settingId', '607');
settings.Router.getInstance().navigateTo(
settings.routes.GOOGLE_ASSISTANT, params);
const deepLinkElement = page.$$('#retrain-voice-model').$$('cr-button');
await test_util.waitAfterNextRender(deepLinkElement);
assertEquals(
deepLinkElement, getDeepActiveElement(),
'Retrain model button should be focused for settingId=607.');
});
test('toggleAssistantNotification', function() {
let button = page.$$('#google-assistant-notification-enable');
assertFalse(!!button);
......
......@@ -43,6 +43,7 @@ cr.define('os_settings_search_page', function() {
teardown(function() {
page.remove();
settings.Router.getInstance().resetRouteForTesting();
});
// Tests that the page is querying and displaying search engine info on
......@@ -118,5 +119,21 @@ cr.define('os_settings_search_page', function() {
assertFalse(!!page.$$('extension-controlled-indicator'));
assertTrue(!!page.$$('cr-policy-pref-indicator'));
});
test('Deep link to preferred search engine', async () => {
loadTimeData.overrideValues({isDeepLinkingEnabled: true});
assertTrue(loadTimeData.getBoolean('isDeepLinkingEnabled'));
const params = new URLSearchParams;
params.append('settingId', '600');
settings.Router.getInstance().navigateTo(
settings.routes.OS_SEARCH, params);
const deepLinkElement = page.$$('select');
await test_util.waitAfterNextRender(deepLinkElement);
assertEquals(
deepLinkElement, getDeepActiveElement(),
'Preferred search dropdown should be focused for settingId=600.');
});
});
});
......@@ -703,6 +703,7 @@ var OSSettingsGoogleAssistantPageTest = class extends OSSettingsBrowserTest {
return super.extraLibraries.concat([
'//ui/webui/resources/js/promise_resolver.js',
BROWSER_SETTINGS_PATH + '../test_browser_proxy.js',
BROWSER_SETTINGS_PATH + '../test_util.js',
'google_assistant_page_test.js',
]);
}
......@@ -1635,6 +1636,7 @@ var OSSettingsSearchPageTest = class extends OSSettingsBrowserTest {
get extraLibraries() {
return super.extraLibraries.concat([
BROWSER_SETTINGS_PATH + '../test_browser_proxy.js',
BROWSER_SETTINGS_PATH + '../test_util.js',
BROWSER_SETTINGS_PATH + 'test_search_engines_browser_proxy.js',
'os_search_page_test.js',
]);
......
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