Commit 5031367b authored by Daniel Classon's avatar Daniel Classon Committed by Commit Bot

[OsSettingsDeepLinking] Add deep links to the Privacy Page

Adds deep links to the Privacy Page. Splits the Privacy Page tests into
AllBuilds and PrivacyPageTest_OfficialBuild in order to test deep
linking to the collect crash reports setting.

Bug: 1084154
Change-Id: I88cc0444260d951efd2972c5c8e825ef18c4b760
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2386424
Commit-Queue: Daniel Classon <dclasson@google.com>
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarRegan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803365}
parent cda5ba5d
...@@ -11,6 +11,9 @@ js_type_check("closure_compile") { ...@@ -11,6 +11,9 @@ js_type_check("closure_compile") {
js_library("os_privacy_page") { js_library("os_privacy_page") {
deps = [ deps = [
"..:deep_linking_behavior",
"..:os_route",
"../..:router",
"//chrome/browser/resources/settings/controls:settings_toggle_button", "//chrome/browser/resources/settings/controls:settings_toggle_button",
"//ui/webui/resources/js:load_time_data", "//ui/webui/resources/js:load_time_data",
] ]
...@@ -24,6 +27,9 @@ js_type_check("closure_compile_module") { ...@@ -24,6 +27,9 @@ js_type_check("closure_compile_module") {
js_library("os_privacy_page.m") { js_library("os_privacy_page.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_privacy_page/os_privacy_page.m.js" ] sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_privacy_page/os_privacy_page.m.js" ]
deps = [ deps = [
"..:deep_linking_behavior.m",
"..:os_route.m",
"../..:router.m",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled", "//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/js:load_time_data.m", "//ui/webui/resources/js:load_time_data.m",
] ]
......
<link rel="import" href="chrome://resources/html/polymer.html"> <link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/html/load_time_data.html"> <link rel="import" href="chrome://resources/html/load_time_data.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="../../controls/settings_toggle_button.html"> <link rel="import" href="../../controls/settings_toggle_button.html">
<link rel="import" href="../../settings_shared_css.html"> <link rel="import" href="../../settings_shared_css.html">
...@@ -8,10 +11,13 @@ ...@@ -8,10 +11,13 @@
<template> <template>
<style include="settings-shared"></style> <style include="settings-shared"></style>
<if expr="_google_chrome"> <if expr="_google_chrome">
<settings-toggle-button pref="{{prefs.cros.metrics.reportingEnabled}}" <settings-toggle-button
id="enable-logging"
class="hr" class="hr"
pref="{{prefs.cros.metrics.reportingEnabled}}"
label="$i18n{enableLogging}" label="$i18n{enableLogging}"
sub-label="$i18n{enableLoggingDesc}"> sub-label="$i18n{enableLoggingDesc}"
deep-link-focus-id$="[[Setting.kUsageStatsAndCrashReports]]">
</settings-toggle-button> </settings-toggle-button>
</if> </if>
<template is="dom-if" if="[[showSuggestedContentToggle_]]"> <template is="dom-if" if="[[showSuggestedContentToggle_]]">
...@@ -25,9 +31,11 @@ ...@@ -25,9 +31,11 @@
</settings-toggle-button> </settings-toggle-button>
</template> </template>
<settings-toggle-button <settings-toggle-button
id="enable-verified-access"
class="hr" class="hr"
pref="{{prefs.cros.device.attestation_for_content_protection_enabled}}" pref="{{prefs.cros.device.attestation_for_content_protection_enabled}}"
label="$i18n{enableContentProtectionAttestation}"> label="$i18n{enableContentProtectionAttestation}"
deep-link-focus-id$="[[Setting.kVerifiedAccess]]">
</settings-toggle-button> </settings-toggle-button>
</template> </template>
<script src="os_privacy_page.js"></script> <script src="os_privacy_page.js"></script>
......
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
Polymer({ Polymer({
is: 'os-settings-privacy-page', is: 'os-settings-privacy-page',
behaviors: [
DeepLinkingBehavior,
settings.RouteObserverBehavior,
],
properties: { properties: {
/** /**
* Preferences state. * Preferences state.
...@@ -30,6 +35,30 @@ Polymer({ ...@@ -30,6 +35,30 @@ Polymer({
return loadTimeData.getBoolean('suggestedContentToggleEnabled'); return loadTimeData.getBoolean('suggestedContentToggleEnabled');
}, },
}, },
/**
* 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.kVerifiedAccess,
chromeos.settings.mojom.Setting.kUsageStatsAndCrashReports,
]),
},
}, },
/**
* @param {!settings.Route} route
* @param {!settings.Route} oldRoute
*/
currentRouteChanged(route, oldRoute) {
// Does not apply to this page.
if (route !== settings.routes.OS_PRIVACY) {
return;
}
this.attemptDeepLink();
},
}); });
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
// #import {flush} from'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; // #import {flush} from'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
// #import {assertEquals, assertFalse, assertTrue} from '../../chai_assert.js'; // #import {assertEquals, assertFalse, assertTrue} from '../../chai_assert.js';
// #import {assert} from 'chrome://resources/js/assert.m.js'; // #import {assert} from 'chrome://resources/js/assert.m.js';
// #import {getDeepActiveElement} from 'chrome://resources/js/util.m.js';
// #import {Router, routes} from 'chrome://os-settings/chromeos/os_settings.js';
// #import {waitAfterNextRender} from 'chrome://test/test_util.m.js';
// clang-format on // clang-format on
suite('PrivacyPageTests', function() { suite('PrivacyPageTests', function() {
...@@ -17,10 +20,14 @@ suite('PrivacyPageTests', function() { ...@@ -17,10 +20,14 @@ suite('PrivacyPageTests', function() {
setup(function() { setup(function() {
PolymerTest.clearBody(); PolymerTest.clearBody();
privacyPage = document.createElement('os-settings-privacy-page');
document.body.appendChild(privacyPage);
Polymer.dom.flush();
}); });
teardown(function() { teardown(function() {
privacyPage.remove(); privacyPage.remove();
settings.Router.getInstance().resetRouteForTesting();
}); });
test('Suggested content, visibility disabled', async () => { test('Suggested content, visibility disabled', async () => {
...@@ -28,8 +35,7 @@ suite('PrivacyPageTests', function() { ...@@ -28,8 +35,7 @@ suite('PrivacyPageTests', function() {
suggestedContentToggleEnabled: false, suggestedContentToggleEnabled: false,
}); });
privacyPage = document.createElement('os-settings-privacy-page'); Polymer.dom.flush();
document.body.appendChild(privacyPage);
assertEquals(null, privacyPage.$$('#suggested-content')); assertEquals(null, privacyPage.$$('#suggested-content'));
}); });
...@@ -54,8 +60,6 @@ suite('PrivacyPageTests', function() { ...@@ -54,8 +60,6 @@ suite('PrivacyPageTests', function() {
suggestedContentToggleEnabled: true, suggestedContentToggleEnabled: true,
}); });
privacyPage = document.createElement('os-settings-privacy-page');
// Update the backing pref to enabled. // Update the backing pref to enabled.
privacyPage.prefs = { privacyPage.prefs = {
'settings': { 'settings': {
...@@ -64,7 +68,6 @@ suite('PrivacyPageTests', function() { ...@@ -64,7 +68,6 @@ suite('PrivacyPageTests', function() {
} }
} }
}; };
document.body.appendChild(privacyPage);
Polymer.dom.flush(); Polymer.dom.flush();
...@@ -72,4 +75,60 @@ suite('PrivacyPageTests', function() { ...@@ -72,4 +75,60 @@ suite('PrivacyPageTests', function() {
const suggestedContent = assert(privacyPage.$$('#suggested-content')); const suggestedContent = assert(privacyPage.$$('#suggested-content'));
assertTrue(suggestedContent.checked); assertTrue(suggestedContent.checked);
}); });
test('Deep link to verified access', async () => {
loadTimeData.overrideValues({
isDeepLinkingEnabled: true,
});
const params = new URLSearchParams;
params.append('settingId', '1101');
settings.Router.getInstance().navigateTo(
settings.routes.OS_PRIVACY, params);
Polymer.dom.flush();
const deepLinkElement =
privacyPage.$$('#enable-verified-access').$$('cr-toggle');
await test_util.waitAfterNextRender(deepLinkElement);
assertEquals(
deepLinkElement, getDeepActiveElement(),
'Verified access toggle should be focused for settingId=1101.');
});
}); });
suite('PrivacePageTest_OfficialBuild', function() {
/** @type {SettingsPrivacyPageElement} */
let privacyPage = null;
setup(function() {
PolymerTest.clearBody();
privacyPage = document.createElement('os-settings-privacy-page');
document.body.appendChild(privacyPage);
Polymer.dom.flush();
});
teardown(function() {
privacyPage.remove();
settings.Router.getInstance().resetRouteForTesting();
});
test('Deep link to send usage stats', async () => {
loadTimeData.overrideValues({
isDeepLinkingEnabled: true,
});
const params = new URLSearchParams;
params.append('settingId', '1103');
settings.Router.getInstance().navigateTo(
settings.routes.OS_PRIVACY, params);
Polymer.dom.flush();
const deepLinkElement = privacyPage.$$('#enable-logging').$$('cr-toggle');
await test_util.waitAfterNextRender(deepLinkElement);
assertEquals(
deepLinkElement, getDeepActiveElement(),
'Send usage stats toggle should be focused for settingId=1103.');
});
});
\ No newline at end of file
...@@ -1319,14 +1319,23 @@ var OSSettingsPrivacyPageTest = class extends OSSettingsBrowserTest { ...@@ -1319,14 +1319,23 @@ var OSSettingsPrivacyPageTest = class extends OSSettingsBrowserTest {
/** @override */ /** @override */
get extraLibraries() { get extraLibraries() {
return super.extraLibraries.concat(['os_privacy_page_test.js']); return super.extraLibraries.concat([
BROWSER_SETTINGS_PATH + '../test_util.js',
'os_privacy_page_test.js',
]);
} }
}; };
TEST_F('OSSettingsPrivacyPageTest', 'AllJsTests', () => { TEST_F('OSSettingsPrivacyPageTest', 'AllBuilds', () => {
mocha.run(); mocha.grep('/^(?!PrivacePageTest_OfficialBuild).*$/').run();
}); });
GEN('#if BUILDFLAG(GOOGLE_CHROME_BRANDING)');
TEST_F('OSSettingsPrivacyPageTest', 'PrivacePage_OfficialBuild', () => {
mocha.grep('PrivacePageTest_OfficialBuild').run();
});
GEN('#endif');
// Tests for the Files section. // Tests for the Files section.
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
var OSSettingsFilesPageTest = class extends OSSettingsBrowserTest { var OSSettingsFilesPageTest = class extends OSSettingsBrowserTest {
......
...@@ -79,7 +79,7 @@ function registerTest(testName, module, caseName) { ...@@ -79,7 +79,7 @@ function registerTest(testName, module, caseName) {
}; };
// AboutPage has a test suite that can only succeed on official builds where // AboutPage has a test suite that can only succeed on official builds where
// the is_chrome_branded build flag is enabled // the is_chrome_branded build flag is enabled.
if (testName === 'AboutPage') { if (testName === 'AboutPage') {
TEST_F(className, 'AllBuilds' || 'All', () => { TEST_F(className, 'AllBuilds' || 'All', () => {
mocha.grep('/^(?!AboutPageTest_OfficialBuild).*$/').run(); mocha.grep('/^(?!AboutPageTest_OfficialBuild).*$/').run();
...@@ -90,6 +90,18 @@ function registerTest(testName, module, caseName) { ...@@ -90,6 +90,18 @@ function registerTest(testName, module, caseName) {
mocha.grep('AboutPageTest_OfficialBuild').run(); mocha.grep('AboutPageTest_OfficialBuild').run();
}); });
GEN('#endif'); GEN('#endif');
} else if (testName === 'PrivacyPage') {
// PrivacyPage has a test suite that can only succeed on official builds
// where the is_chrome_branded build flag is enabled.
TEST_F(className, 'AllBuilds' || 'All', () => {
mocha.grep('/^(?!PrivacePageTest_OfficialBuild).*$/').run();
});
GEN('#if BUILDFLAG(GOOGLE_CHROME_BRANDING)');
TEST_F(className, 'OfficialBuild' || 'All', () => {
mocha.grep('PrivacePageTest_OfficialBuild').run();
});
GEN('#endif');
} else { } else {
TEST_F(className, caseName || 'All', () => mocha.run()); TEST_F(className, caseName || 'All', () => mocha.run());
} }
......
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