Commit 6c781857 authored by Thomas Tangl's avatar Thomas Tangl Committed by Commit Bot

[unified-consent] Create settings-sync-controls element

All sync data type toggles are moved into one polymer
element.

Note: There is no structural change in this CL.
In a follow-up CL the toggles are moved to a subpage
which is accessible from the sync page.

Bug: 912598
Change-Id: I7d07a7051d34840d94a1229c7dae92fa2c1e680c
Reviewed-on: https://chromium-review.googlesource.com/c/1367648
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615490}
parent 68c6c04a
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/html/util.html">
<link rel="import" href="chrome://resources/html/web_ui_listener_behavior.html">
<link rel="import" href="chrome://resources/cr_elements/cr_toggle/cr_toggle.html">
<link rel="import" href="chrome://resources/cr_elements/shared_vars_css.html">
<link rel="import" href="sync_browser_proxy.html">
<link rel="import" href="../settings_shared_css.html">
<link rel="import" href="../settings_vars_css.html">
<dom-module id="settings-sync-controls">
<template>
<style include="settings-shared">
#sync-data-types .list-item:not([hidden]) ~ .list-item:not([hidden]) {
border-top: var(--settings-separator-line);
}
.list-item {
display: flex;
}
.list-item > div {
flex: 1;
}
</style>
<div class="settings-box first">
<div id="syncEverythingCheckboxLabel" class="start">
$i18n{syncEverythingCheckboxLabel}
</div>
<cr-toggle id="syncAllDataTypesControl"
checked="{{syncPrefs.syncAllDataTypes}}"
on-change="onSyncAllDataTypesChanged_"
aria-labelledby="syncEverythingCheckboxLabel">
</cr-toggle>
</div>
<div class="list-frame" id="sync-data-types">
<div class="list-item" hidden="[[!syncPrefs.appsRegistered]]">
<div id="appCheckboxLabel">
$i18n{appCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.appsSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.appsEnforced)]]"
aria-labelledby="appCheckboxLabel">
</cr-toggle>
</div>
<div class="list-item" hidden="[[!syncPrefs.bookmarksRegistered]]">
<div id="bookmarksCheckboxLabel">
$i18n{bookmarksCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.bookmarksSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.bookmarksEnforced)]]"
aria-labelledby="bookmarksCheckboxLabel">
</cr-toggle>
</div>
<div class="list-item" hidden="[[!syncPrefs.extensionsRegistered]]">
<div id="extensionsCheckboxLabel">
$i18n{extensionsCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.extensionsSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.extensionsEnforced)]]"
aria-labelledby="extensionsCheckboxLabel">
</cr-toggle>
</div>
<div class="list-item" hidden="[[!syncPrefs.typedUrlsRegistered]]">
<div id="historyCheckboxLabel">
$i18n{historyCheckboxLabel}
</div>
<!-- TypedUrls has a special on-change handler to deal with user
events. -->
<cr-toggle id="historyToggle"
checked="{{syncPrefs.typedUrlsSynced}}"
on-change="onTypedUrlsDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.typedUrlsEnforced)]]"
aria-labelledby="historyCheckboxLabel">
</cr-toggle>
</div>
<div class="list-item" hidden="[[!syncPrefs.preferencesRegistered]]">
<div id="settingsCheckboxLabel">
$i18n{settingsCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.preferencesSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes,
syncPrefs.preferencesEnforced)]]"
aria-labelledby="settingsCheckboxLabel">
</cr-toggle>
</div>
<div class="list-item" hidden="[[!syncPrefs.themesRegistered]]">
<div id="themesAndWallpapersCheckboxLabel">
$i18n{themesAndWallpapersCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.themesSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.themesEnforced)]]"
aria-labelledby="themesAndWallpapersCheckboxLabel">
</cr-toggle>
</div>
<div class="list-item" hidden="[[!syncPrefs.tabsRegistered]]">
<div id="openTabsCheckboxLabel">
$i18n{openTabsCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.tabsSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.tabsEnforced)]]"
aria-labelledby="openTabsCheckboxLabel">
</cr-toggle>
</div>
<div class="list-item" hidden="[[!syncPrefs.passwordsRegistered]]">
<div id="passwordsCheckboxLabel">
$i18n{passwordsCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.passwordsSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.passwordsEnforced)]]"
aria-labelledby="passwordsCheckboxLabel">
</cr-toggle>
</div>
<div class="list-item" hidden="[[!syncPrefs.autofillRegistered]]">
<div id="autofillCheckboxLabel">
$i18n{autofillCheckboxLabel}
</div>
<!-- Autofill has a special on-change handler to deal with
Payments integration. -->
<cr-toggle checked="{{syncPrefs.autofillSynced}}"
on-change="onAutofillDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.autofillEnforced)]]"
aria-labelledby="autofillCheckboxLabel">
</cr-toggle>
</div>
<div class="list-item" hidden="[[!syncPrefs.autofillRegistered]]">
<!-- The Payments integration checkbox is a special case in many
ways. It's visible only if autofill is registered. It's
disabled and unchecked if autofill is unchecked.-->
<div>
$i18n{enablePaymentsIntegrationCheckboxLabel}
<a href="$i18nRaw{autofillHelpURL}" target="_blank">
$i18n{learnMore}
</a>
</div>
<cr-toggle checked="{{syncPrefs.paymentsIntegrationEnabled}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldPaymentsCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.autofillSynced)]]"
aria-label="$i18n{enablePaymentsIntegrationCheckboxLabel}">
</cr-toggle>
</div>
</div>
</template>
<script src="sync_controls.js"></script>
</dom-module>
// Copyright 2018 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.
(function() {
/**
* Names of the individual data type properties to be cached from
* settings.SyncPrefs when the user checks 'Sync All'.
* @type {!Array<string>}
*/
const SyncPrefsIndividualDataTypes = [
'appsSynced',
'extensionsSynced',
'preferencesSynced',
'autofillSynced',
'typedUrlsSynced',
'themesSynced',
'bookmarksSynced',
'passwordsSynced',
'tabsSynced',
'paymentsIntegrationEnabled',
];
/**
* @fileoverview
* 'settings-sync-controls' contains all sync data type controls.
*/
Polymer({
is: 'settings-sync-controls',
behaviors: [WebUIListenerBehavior],
properties: {
/**
* The current sync preferences, supplied by SyncBrowserProxy.
* @type {settings.SyncPrefs|undefined}
*/
syncPrefs: Object,
},
/** @private {?settings.SyncBrowserProxy} */
browserProxy_: null,
/**
* Caches the individually selected synced data types. This is used to
* be able to restore the selections after checking and unchecking Sync All.
* @private {?Object}
*/
cachedSyncPrefs_: null,
/** @override */
created: function() {
this.browserProxy_ = settings.SyncBrowserProxyImpl.getInstance();
},
/** @override */
attached: function() {
this.addWebUIListener(
'sync-prefs-changed', this.handleSyncPrefsChanged_.bind(this));
},
/**
* Handler for when the sync preferences are updated.
* @private
*/
handleSyncPrefsChanged_: function(syncPrefs) {
this.syncPrefs = syncPrefs;
// If autofill is not registered or synced, force Payments integration off.
if (!this.syncPrefs.autofillRegistered || !this.syncPrefs.autofillSynced)
this.set('syncPrefs.paymentsIntegrationEnabled', false);
},
/**
* Handler for when the sync all data types checkbox is changed.
* @param {!Event} event
* @private
*/
onSyncAllDataTypesChanged_: function(event) {
if (event.target.checked) {
this.set('syncPrefs.syncAllDataTypes', true);
// Cache the previously selected preference before checking every box.
this.cachedSyncPrefs_ = {};
for (const dataType of SyncPrefsIndividualDataTypes) {
// These are all booleans, so this shallow copy is sufficient.
this.cachedSyncPrefs_[dataType] = this.syncPrefs[dataType];
this.set(['syncPrefs', dataType], true);
}
} else if (this.cachedSyncPrefs_) {
// Restore the previously selected preference.
for (const dataType of SyncPrefsIndividualDataTypes) {
this.set(['syncPrefs', dataType], this.cachedSyncPrefs_[dataType]);
}
}
this.onSingleSyncDataTypeChanged_();
},
/**
* Handler for when any sync data type checkbox is changed (except autofill).
* @private
*/
onSingleSyncDataTypeChanged_: function() {
assert(this.syncPrefs);
this.browserProxy_.setSyncDatatypes(this.syncPrefs);
},
/**
* Handler for when the autofill data type checkbox is changed.
* @private
*/
onAutofillDataTypeChanged_: function() {
this.set(
'syncPrefs.paymentsIntegrationEnabled', this.syncPrefs.autofillSynced);
this.onSingleSyncDataTypeChanged_();
},
/**
* Handler for when the autofill data type checkbox is changed.
* @private
*/
onTypedUrlsDataTypeChanged_: function() {
this.onSingleSyncDataTypeChanged_();
},
/**
* @param {boolean} syncAllDataTypes
* @param {boolean} enforced
* @return {boolean} Whether the sync checkbox should be disabled.
*/
shouldSyncCheckboxBeDisabled_: function(syncAllDataTypes, enforced) {
return syncAllDataTypes || enforced;
},
/**
* @param {boolean} syncAllDataTypes
* @param {boolean} autofillSynced
* @return {boolean} Whether the sync checkbox should be disabled.
*/
shouldPaymentsCheckboxBeDisabled_: function(
syncAllDataTypes, autofillSynced) {
return syncAllDataTypes || !autofillSynced;
},
});
})();
......@@ -4,7 +4,6 @@
<link rel="import" href="chrome://resources/html/util.html">
<link rel="import" href="chrome://resources/html/web_ui_listener_behavior.html">
<link rel="import" href="chrome://resources/cr_elements/cr_input/cr_input.html">
<link rel="import" href="chrome://resources/cr_elements/cr_toggle/cr_toggle.html">
<link rel="import" href="chrome://resources/cr_elements/cr_radio_button/cr_radio_button.html">
<link rel="import" href="chrome://resources/cr_elements/cr_radio_group/cr_radio_group.html">
<link rel="import" href="chrome://resources/cr_elements/shared_vars_css.html">
......@@ -12,6 +11,7 @@
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-icon-button/paper-icon-button-light.html">
<link rel="import" href="sync_browser_proxy.html">
<link rel="import" href="sync_controls.html">
<link rel="import" href="../icons.html">
<link rel="import" href="../privacy_page/personalization_options.html">
<link rel="import" href="../route.html">
......@@ -61,10 +61,6 @@
align-items: center;
}
#sync-data-types .list-item:not([hidden]) ~ .list-item:not([hidden]) {
border-top: var(--settings-separator-line);
}
#other-sync-items {
padding-bottom: 8px;
}
......@@ -165,7 +161,7 @@
<div id="[[pages_.CONFIGURE]]"
hidden$="[[!isStatus_(pages_.CONFIGURE, pageStatus_)]]">
<!-- TODO(http://crbug.com/862983) Remove this section once the Unified
Consent feature is launched. -->
Consent feature is launched. -->
<template is="dom-if" if="[[shouldShowExistingPassphraseInSyncSection_(
unifiedConsentEnabled, syncPrefs.passphraseRequired)]]">
<div id="existingPassphrase" class="list-frame">
......@@ -196,161 +192,7 @@
</div>
</template>
<div class="settings-box first">
<div id="syncEverythingCheckboxLabel" class="start">
$i18n{syncEverythingCheckboxLabel}
</div>
<cr-toggle id="syncAllDataTypesControl"
checked="{{syncPrefs.syncAllDataTypes}}"
on-change="onSyncAllDataTypesChanged_"
aria-labelledby="syncEverythingCheckboxLabel">
</cr-toggle>
</div>
<div class="list-frame" id="sync-data-types">
<div class="layout horizontal list-item"
hidden="[[!syncPrefs.appsRegistered]]">
<div id="appCheckboxLabel" class="flex">
$i18n{appCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.appsSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.appsEnforced)]]"
aria-labelledby="appCheckboxLabel">
</cr-toggle>
</div>
<div class="layout horizontal list-item"
hidden="[[!syncPrefs.bookmarksRegistered]]">
<div id="bookmarksCheckboxLabel" class="flex">
$i18n{bookmarksCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.bookmarksSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.bookmarksEnforced)]]"
aria-labelledby="bookmarksCheckboxLabel">
</cr-toggle>
</div>
<div class="layout horizontal list-item"
hidden="[[!syncPrefs.extensionsRegistered]]">
<div id="extensionsCheckboxLabel" class="flex">
$i18n{extensionsCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.extensionsSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.extensionsEnforced)]]"
aria-labelledby="extensionsCheckboxLabel">
</cr-toggle>
</div>
<div class="layout horizontal list-item"
hidden="[[!syncPrefs.typedUrlsRegistered]]">
<div id="historyCheckboxLabel" class="flex">
$i18n{historyCheckboxLabel}
</div>
<!-- TypedUrls has a special on-change handler to deal with user
events. -->
<cr-toggle id="historyToggle"
checked="{{syncPrefs.typedUrlsSynced}}"
on-change="onTypedUrlsDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.typedUrlsEnforced)]]"
aria-labelledby="historyCheckboxLabel">
</cr-toggle>
</div>
<div class="layout horizontal list-item"
hidden="[[!syncPrefs.preferencesRegistered]]">
<div id="settingsCheckboxLabel" class="flex">
$i18n{settingsCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.preferencesSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes,
syncPrefs.preferencesEnforced)]]"
aria-labelledby="settingsCheckboxLabel">
</cr-toggle>
</div>
<div class="layout horizontal list-item"
hidden="[[!syncPrefs.themesRegistered]]">
<div id="themesAndWallpapersCheckboxLabel" class="flex">
$i18n{themesAndWallpapersCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.themesSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.themesEnforced)]]"
aria-labelledby="themesAndWallpapersCheckboxLabel">
</cr-toggle>
</div>
<div class="layout horizontal list-item"
hidden="[[!syncPrefs.tabsRegistered]]">
<div id="openTabsCheckboxLabel" class="flex">
$i18n{openTabsCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.tabsSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.tabsEnforced)]]"
aria-labelledby="openTabsCheckboxLabel">
</cr-toggle>
</div>
<div class="layout horizontal list-item"
hidden="[[!syncPrefs.passwordsRegistered]]">
<div id="passwordsCheckboxLabel" class="flex">
$i18n{passwordsCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.passwordsSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.passwordsEnforced)]]"
aria-labelledby="passwordsCheckboxLabel">
</cr-toggle>
</div>
<div class="layout horizontal list-item"
hidden="[[!syncPrefs.autofillRegistered]]">
<div id="autofillCheckboxLabel" class="flex">
$i18n{autofillCheckboxLabel}
</div>
<!-- Autofill has a special on-change handler to deal with
Payments integration. -->
<cr-toggle checked="{{syncPrefs.autofillSynced}}"
on-change="onAutofillDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.autofillEnforced)]]"
aria-labelledby="autofillCheckboxLabel">
</cr-toggle>
</div>
<div class="layout horizontal list-item"
hidden="[[!syncPrefs.autofillRegistered]]">
<!-- The Payments integration checkbox is a special case in many
ways. It's visible only if autofill is registered. It's
disabled and unchecked if autofill is unchecked.-->
<div class="flex">
$i18n{enablePaymentsIntegrationCheckboxLabel}
<a href="$i18nRaw{autofillHelpURL}" target="_blank">
$i18n{learnMore}
</a>
</div>
<cr-toggle
checked="{{syncPrefs.paymentsIntegrationEnabled}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldPaymentsCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.autofillSynced)]]"
aria-label="$i18n{enablePaymentsIntegrationCheckboxLabel}">
</cr-toggle>
</div>
</div>
<settings-sync-controls></settings-sync-controls>
<div id="other-sync-items"
class$="[[getListFrameClass_(unifiedConsentEnabled)]]">
......@@ -455,6 +297,7 @@
</div>
</div>
</div>
<template is="dom-if" if="[[unifiedConsentEnabled]]">
<div class="settings-box first">
<h2>$i18n{nonPersonalizedServicesSectionLabel}</h2>
......
......@@ -14,24 +14,6 @@ const RadioButtonNames = {
ENCRYPT_WITH_PASSPHRASE: 'encrypt-with-passphrase',
};
/**
* Names of the individual data type properties to be cached from
* settings.SyncPrefs when the user checks 'Sync All'.
* @type {!Array<string>}
*/
const SyncPrefsIndividualDataTypes = [
'appsSynced',
'extensionsSynced',
'preferencesSynced',
'autofillSynced',
'typedUrlsSynced',
'themesSynced',
'bookmarksSynced',
'passwordsSynced',
'tabsSynced',
'paymentsIntegrationEnabled',
];
/**
* @fileoverview
* 'settings-sync-page' is the settings page containing sync settings.
......@@ -187,13 +169,6 @@ Polymer({
*/
didAbort_: false,
/**
* Caches the individually selected synced data types. This is used to
* be able to restore the selections after checking and unchecking Sync All.
* @private {?Object}
*/
cachedSyncPrefs_: null,
/** @override */
created: function() {
this.browserProxy_ = settings.SyncBrowserProxyImpl.getInstance();
......@@ -300,10 +275,6 @@ Polymer({
this.syncPrefs = syncPrefs;
this.pageStatus_ = settings.PageStatus.CONFIGURE;
// If autofill is not registered or synced, force Payments integration off.
if (!this.syncPrefs.autofillRegistered || !this.syncPrefs.autofillSynced)
this.set('syncPrefs.paymentsIntegrationEnabled', false);
// Hide the new passphrase box if the sync data has been encrypted.
if (this.syncPrefs.encryptAllData)
this.creatingNewPassphrase_ = false;
......@@ -320,67 +291,11 @@ Polymer({
}
},
/**
* Handler for when the sync all data types checkbox is changed.
* @param {!Event} event
* @private
*/
onSyncAllDataTypesChanged_: function(event) {
if (event.target.checked) {
this.set('syncPrefs.syncAllDataTypes', true);
// Cache the previously selected preference before checking every box.
this.cachedSyncPrefs_ = {};
for (const dataType of SyncPrefsIndividualDataTypes) {
// These are all booleans, so this shallow copy is sufficient.
this.cachedSyncPrefs_[dataType] = this.syncPrefs[dataType];
this.set(['syncPrefs', dataType], true);
}
} else if (this.cachedSyncPrefs_) {
// Restore the previously selected preference.
for (const dataType of SyncPrefsIndividualDataTypes) {
this.set(['syncPrefs', dataType], this.cachedSyncPrefs_[dataType]);
}
}
this.onSingleSyncDataTypeChanged_();
},
/**
* Handler for when any sync data type checkbox is changed (except autofill).
* @private
*/
onSingleSyncDataTypeChanged_: function() {
assert(this.syncPrefs);
this.browserProxy_.setSyncDatatypes(this.syncPrefs)
.then(this.handlePageStatusChanged_.bind(this));
},
/** @private */
onActivityControlsTap_: function() {
this.browserProxy_.openActivityControlsUrl();
},
/**
* Handler for when the autofill data type checkbox is changed.
* @private
*/
onAutofillDataTypeChanged_: function() {
this.set(
'syncPrefs.paymentsIntegrationEnabled', this.syncPrefs.autofillSynced);
this.onSingleSyncDataTypeChanged_();
},
/**
* Handler for when the autofill data type checkbox is changed.
* @private
*/
onTypedUrlsDataTypeChanged_: function() {
this.onSingleSyncDataTypeChanged_();
},
/**
* @param {string} passphrase The passphrase input field value
* @param {string} confirmation The passphrase confirmation input field value.
......@@ -496,25 +411,6 @@ Polymer({
return this.syncPrefs.enterGooglePassphraseBody;
},
/**
* @param {boolean} syncAllDataTypes
* @param {boolean} enforced
* @return {boolean} Whether the sync checkbox should be disabled.
*/
shouldSyncCheckboxBeDisabled_: function(syncAllDataTypes, enforced) {
return syncAllDataTypes || enforced;
},
/**
* @param {boolean} syncAllDataTypes
* @param {boolean} autofillSynced
* @return {boolean} Whether the sync checkbox should be disabled.
*/
shouldPaymentsCheckboxBeDisabled_: function(
syncAllDataTypes, autofillSynced) {
return syncAllDataTypes || !autofillSynced;
},
/**
* Checks the supplied passphrases to ensure that they are not empty and that
* they match each other. Additionally, displays error UI if they are invalid.
......
......@@ -1139,7 +1139,16 @@
type="chrome_html"
preprocess="true"
allowexternalscript="true" />
<structure name="IDR_SETTINGS_SYNC_PAGE_JS"
<structure name="IDR_SETTINGS_SYNC_CONTROLS_JS"
file="people_page/sync_controls.js"
type="chrome_html"
preprocess="true" />
<structure name="IDR_SETTINGS_SYNC_CONTROLS_HTML"
file="people_page/sync_controls.html"
type="chrome_html"
preprocess="true"
allowexternalscript="true" />
<structure name="IDR_SETTINGS_SYNC_PAGE_JS"
file="people_page/sync_page.js"
type="chrome_html"
preprocess="true" />
......
......@@ -591,6 +591,33 @@ TEST_F('CrSettingsPeoplePageSyncAccountControlTest', 'All', function() {
GEN('#endif // !defined(OS_CHROMEOS)');
/**
* Test fixture for
* chrome/browser/resources/settings/people_page/sync_controls.html.
* @constructor
* @extends {CrSettingsBrowserTest}
*/
function CrSettingsPeoplePageSyncControlsTest() {}
CrSettingsPeoplePageSyncControlsTest.prototype = {
__proto__: CrSettingsBrowserTest.prototype,
/** @override */
browsePreload: 'chrome://settings/people_page/sync_controls.html',
/** @override */
extraLibraries: CrSettingsBrowserTest.prototype.extraLibraries.concat([
'../test_browser_proxy.js',
'test_sync_browser_proxy.js',
'test_util.js',
'people_page_sync_controls.js',
]),
};
TEST_F('CrSettingsPeoplePageSyncControlsTest', 'All', function() {
mocha.run();
});
/**
* Test fixture for
* chrome/browser/resources/settings/people_page/sync_page.html.
......
// Copyright 2018 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.
cr.define('settings_people_page_sync_controls', function() {
suite('SyncControlsTest', function() {
let syncControls = null;
let browserProxy = null;
/**
* Returns sync prefs with everything synced.
* @return {!settings.SyncPrefs}
*/
function getSyncAllPrefs() {
return {
appsEnforced: false,
appsRegistered: true,
appsSynced: true,
autofillEnforced: false,
autofillRegistered: true,
autofillSynced: true,
bookmarksEnforced: false,
bookmarksRegistered: true,
bookmarksSynced: true,
extensionsEnforced: false,
extensionsRegistered: true,
extensionsSynced: true,
passwordsEnforced: false,
passwordsRegistered: true,
passwordsSynced: true,
paymentsIntegrationEnabled: true,
preferencesEnforced: false,
preferencesRegistered: true,
preferencesSynced: true,
syncAllDataTypes: true,
tabsEnforced: false,
tabsRegistered: true,
tabsSynced: true,
themesEnforced: false,
themesRegistered: true,
themesSynced: true,
typedUrlsEnforced: false,
typedUrlsRegistered: true,
typedUrlsSynced: true,
};
}
setup(function() {
browserProxy = new TestSyncBrowserProxy();
settings.SyncBrowserProxyImpl.instance_ = browserProxy;
PolymerTest.clearBody();
syncControls = document.createElement('settings-sync-controls');
document.body.appendChild(syncControls);
// Start with Sync All.
cr.webUIListenerCallback('sync-prefs-changed', getSyncAllPrefs());
Polymer.dom.flush();
});
teardown(function() {
syncControls.remove();
});
test('SettingIndividualDatatypes', function() {
const syncAllDataTypesControl = syncControls.$.syncAllDataTypesControl;
assertFalse(syncAllDataTypesControl.disabled);
assertTrue(syncAllDataTypesControl.checked);
// Assert that all the individual datatype controls are disabled.
const datatypeControls =
syncControls.shadowRoot.querySelectorAll('.list-item cr-toggle');
for (const control of datatypeControls) {
assertTrue(control.disabled);
assertTrue(control.checked);
}
// Uncheck the Sync All control.
syncAllDataTypesControl.click();
function verifyPrefs(prefs) {
const expected = getSyncAllPrefs();
expected.syncAllDataTypes = false;
assertEquals(JSON.stringify(expected), JSON.stringify(prefs));
cr.webUIListenerCallback('sync-prefs-changed', expected);
// Assert that all the individual datatype controls are enabled.
for (const control of datatypeControls) {
assertFalse(control.disabled);
assertTrue(control.checked);
}
browserProxy.resetResolver('setSyncDatatypes');
// Test an arbitrarily-selected control (extensions synced control).
datatypeControls[2].click();
return browserProxy.whenCalled('setSyncDatatypes')
.then(function(prefs) {
const expected = getSyncAllPrefs();
expected.syncAllDataTypes = false;
expected.extensionsSynced = false;
assertEquals(JSON.stringify(expected), JSON.stringify(prefs));
});
}
return browserProxy.whenCalled('setSyncDatatypes').then(verifyPrefs);
});
});
});
......@@ -3,8 +3,7 @@
// found in the LICENSE file.
cr.define('settings_people_page_sync_page', function() {
suite('AdvancedSyncSettingsTests', function() {
suite('SyncSettingsTests', function() {
let syncPage = null;
let browserProxy = null;
let encryptWithGoogle = null;
......@@ -57,20 +56,6 @@ cr.define('settings_people_page_sync_page', function() {
};
}
function openDatatypeConfigurationWithUnifiedConsent(prefs) {
syncPage.unifiedConsentEnabled = true;
cr.webUIListenerCallback('sync-prefs-changed', prefs);
Polymer.dom.flush();
const syncAllDataTypesControl = syncPage.$.syncAllDataTypesControl;
assertFalse(syncAllDataTypesControl.disabled);
assertTrue(syncAllDataTypesControl.checked);
// Uncheck the Sync All control.
syncAllDataTypesControl.click();
}
setup(function() {
browserProxy = new TestSyncBrowserProxy();
settings.SyncBrowserProxyImpl.instance_ = browserProxy;
......@@ -246,50 +231,6 @@ cr.define('settings_people_page_sync_page', function() {
assertTrue(spinnerPage.hidden);
});
test('SettingIndividualDatatypes', function() {
const syncAllDataTypesControl = syncPage.$.syncAllDataTypesControl;
assertFalse(syncAllDataTypesControl.disabled);
assertTrue(syncAllDataTypesControl.checked);
// Assert that all the individual datatype controls are disabled.
const datatypeControls =
syncPage.$$('#configure').querySelectorAll('.list-item cr-toggle');
for (const control of datatypeControls) {
assertTrue(control.disabled);
assertTrue(control.checked);
}
// Uncheck the Sync All control.
syncAllDataTypesControl.click();
function verifyPrefs(prefs) {
const expected = getSyncAllPrefs();
expected.syncAllDataTypes = false;
assertEquals(JSON.stringify(expected), JSON.stringify(prefs));
cr.webUIListenerCallback('sync-prefs-changed', expected);
// Assert that all the individual datatype controls are enabled.
for (const control of datatypeControls) {
assertFalse(control.disabled);
assertTrue(control.checked);
}
browserProxy.resetResolver('setSyncDatatypes');
// Test an arbitrarily-selected control (extensions synced control).
datatypeControls[2].click();
return browserProxy.whenCalled('setSyncDatatypes')
.then(function(prefs) {
const expected = getSyncAllPrefs();
expected.syncAllDataTypes = false;
expected.extensionsSynced = false;
assertEquals(JSON.stringify(expected), JSON.stringify(prefs));
});
}
return browserProxy.whenCalled('setSyncDatatypes').then(verifyPrefs);
});
test('RadioBoxesEnabledWhenUnencrypted', function() {
// Verify that the encryption radio boxes are enabled.
assertFalse(encryptWithGoogle.disabled);
......
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