Commit 31322898 authored by David Roger's avatar David Roger Committed by Commit Bot

[Settings] UserEvents depends on history and passphrase

This is a reland of:
https://chromium-review.googlesource.com/1170202

which was reverted because of missing svg icon.

The user events UI toggle should be grayed out and turned off
when there is a passphrase or when history sync is disabled.
Note that this is purely a UI change: the internal sync datatype
is not really turned off in that case, and we assume that the Sync
engines will correctly stop syncing user events in these cases,
even if the preference is still ON.

Bug: 865522, 865537
Change-Id: I745f048b3ca301231f57c04b82d0d9d82a6f3b90
Reviewed-on: https://chromium-review.googlesource.com/1170825Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Commit-Queue: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582433}
parent 5823b44a
......@@ -97,6 +97,9 @@ settings.StatusAction = {
* typedUrlsEnforced: boolean,
* typedUrlsRegistered: boolean,
* typedUrlsSynced: boolean,
* userEventsEnforced: boolean,
* userEventsRegistered: boolean,
* userEventsSynced: boolean,
* }}
*/
settings.SyncPrefs;
......
......@@ -14,6 +14,7 @@
<link rel="import" href="chrome://resources/polymer/v1_0/paper-icon-button/paper-icon-button-light.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-radio-group/paper-radio-group.html">
<link rel="import" href="sync_browser_proxy.html">
<link rel="import" href="../icons.html">
<link rel="import" href="../privacy_page/personalization_options.html">
<link rel="import" href="../route.html">
<link rel="import" href="../settings_shared_css.html">
......@@ -27,7 +28,8 @@
<template>
<style include="settings-shared iron-flex">
#create-password-box,
#reset-sync-message-box {
#reset-sync-message-box-encryption,
#reset-sync-message-box-user-events {
/* In order to line up with the encryption radio box text. */
margin-inline-start: var(--settings-indent-width);
}
......@@ -263,8 +265,11 @@
<div id="historyCheckboxLabel" class="flex">
$i18n{historyCheckboxLabel}
</div>
<cr-toggle checked="{{syncPrefs.typedUrlsSynced}}"
on-change="onSingleSyncDataTypeChanged_"
<!-- 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">
......@@ -344,6 +349,8 @@
</cr-toggle>
</div>
<!-- User events is disabled and unchecked if data is encrypted or
typed urls are disabled. -->
<template is="dom-if" if="[[unifiedConsentEnabled]]">
<div class="layout horizontal list-item"
hidden="[[!syncPrefs.userEventsRegistered]]">
......@@ -352,12 +359,20 @@
<div class="secondary">
$i18n{userEventsCheckboxText}
</div>
<div id="reset-sync-message-box-user-events" class="list-item"
hidden="[[!syncPrefs.encryptAllData]]">
<span>
<iron-icon icon="settings:info-outline"></iron-icon>
$i18nRaw{passphraseResetHint}
</span>
</div>
<cr-toggle checked="{{syncPrefs.userEventsSynced}}"
on-change="onSingleSyncDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes,
syncPrefs.userEventsEnforced)]]"
</div>
<cr-toggle id="userEventsToggle"
checked="{{userEventsToggleValue}}"
on-change="onUserEventsSyncDataTypeChanged_"
disabled="[[shouldUserEventsCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.typedUrlsSynced,
syncPrefs.userEventsEnforced, syncPrefs.encryptAllData)]]"
aria-labelledby="userEventsCheckboxLabel">
</cr-toggle>
</div>
......@@ -431,10 +446,16 @@
</template>
</cr-radio-button>
</paper-radio-group>
<div id="reset-sync-message-box" class="list-item"
<!-- duplicated from above -->
<div id="reset-sync-message-box-encryption" class="list-item"
hidden="[[!syncPrefs.encryptAllData]]">
<span>$i18nRaw{passphraseResetHint}</span>
<span>
<iron-icon icon="settings:info-outline"></iron-icon>
$i18nRaw{passphraseResetHint}
</span>
</div>
</div>
<template is="dom-if" if="[[creatingNewPassphrase_]]">
......
......@@ -158,6 +158,11 @@ Polymer({
}
},
// The toggle for user events is not reflected directly on
// syncPrefs.userEventsSynced, because this sync preference must only be
// updated if there is no passphrase and typedUrls are synced as well.
userEventsToggleValue: Boolean,
// <if expr="not chromeos">
diceEnabled: Boolean,
// </if>
......@@ -304,6 +309,11 @@ Polymer({
if (!this.syncPrefs.autofillRegistered || !this.syncPrefs.autofillSynced)
this.set('syncPrefs.paymentsIntegrationEnabled', false);
this.set(
'userEventsToggleValue',
this.syncPrefs.userEventsSynced && this.syncPrefs.typedUrlsSynced &&
!this.syncPrefs.encryptAllData);
// Hide the new passphrase box if the sync data has been encrypted.
if (this.syncPrefs.encryptAllData)
this.creatingNewPassphrase_ = false;
......@@ -373,6 +383,33 @@ Polymer({
this.onSingleSyncDataTypeChanged_();
},
/**
* Handler for when the autofill data type checkbox is changed.
* @private
*/
onTypedUrlsDataTypeChanged_: function() {
// Enabling typed URLs also resets the user events to ON. |encryptAllData|
// is not expected to change on the fly, and if it changed the user sync
// settings would be reset anyway.
if (!this.syncPrefs.encryptAllData && this.syncPrefs.typedUrlsSynced)
this.set('syncPrefs.userEventsSynced', true);
this.onSingleSyncDataTypeChanged_();
},
/**
* Handler for when the user events data type checkbox is changed.
* @private
*/
onUserEventsSyncDataTypeChanged_: function() {
// Only update the sync preference when there is no passphrase and typed
// URLs are synced.
assert(!this.syncPrefs.encryptAllData && this.syncPrefs.typedUrlsSynced);
this.set('syncPrefs.userEventsSynced', this.userEventsToggleValue);
this.onSingleSyncDataTypeChanged_();
},
/**
* @param {string} passphrase The passphrase input field value
* @param {string} confirmation The passphrase confirmation input field value.
......@@ -506,6 +543,19 @@ Polymer({
return syncAllDataTypes || !autofillSynced;
},
/**
* @param {boolean} syncAllDataTypes
* @param {boolean} typedUrlsSynced
* @param {boolean} userEventsEnforced
* @param {boolean} encryptAllData
* @return {boolean} Whether the sync checkbox should be disabled.
*/
shouldUserEventsCheckboxBeDisabled_: function(
syncAllDataTypes, typedUrlsSynced, userEventsEnforced, encryptAllData) {
return syncAllDataTypes || !typedUrlsSynced || userEventsEnforced ||
encryptAllData;
},
/**
* 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.
......
......@@ -54,9 +54,26 @@ cr.define('settings_people_page_sync_page', function() {
typedUrlsEnforced: false,
typedUrlsRegistered: true,
typedUrlsSynced: true,
userEventsEnforced: false,
userEventsRegistered: true,
userEventsSynced: true,
};
}
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;
......@@ -457,6 +474,66 @@ cr.define('settings_people_page_sync_page', function() {
assertTrue(syncPage.$.encryptionRadioGroupContainer.hidden);
});
test('UserEvents_UnifiedConsent_Encrypted', function() {
const prefs = getSyncAllPrefs();
prefs.encryptAllData = true;
openDatatypeConfigurationWithUnifiedConsent(prefs);
assertTrue(prefs.userEventsSynced);
// History.
historyToggle = syncPage.$$('#historyToggle');
assertFalse(historyToggle.disabled);
assertTrue(historyToggle.checked);
// User events.
userEventsToggle = syncPage.$$('#userEventsToggle');
assertTrue(userEventsToggle.disabled);
assertFalse(userEventsToggle.checked);
resetSyncMessageBox = syncPage.$$('#reset-sync-message-box-user-events');
assertFalse(resetSyncMessageBox.hidden);
});
test('UserEvents_UnifiedConsent_NotEncrypted', function() {
const prefs = getSyncAllPrefs();
openDatatypeConfigurationWithUnifiedConsent(prefs);
assertTrue(prefs.userEventsSynced);
// Check history toggle.
historyToggle = syncPage.$$('#historyToggle');
assertFalse(historyToggle.disabled);
assertTrue(historyToggle.checked);
// Check user events toggle.
userEventsToggle = syncPage.$$('#userEventsToggle');
assertFalse(userEventsToggle.disabled);
assertTrue(userEventsToggle.checked);
resetSyncMessageBox = syncPage.$$('#reset-sync-message-box-user-events');
assertTrue(resetSyncMessageBox.hidden);
// Toggling history also toggles user events.
// Turn history off.
historyToggle.click();
cr.webUIListenerCallback('sync-prefs-changed', prefs);
assertFalse(historyToggle.checked);
assertTrue(userEventsToggle.disabled);
assertFalse(userEventsToggle.checked);
assertTrue(resetSyncMessageBox.hidden);
assertTrue(prefs.userEventsSynced);
// Turn history on.
historyToggle.click();
cr.webUIListenerCallback('sync-prefs-changed', prefs);
assertTrue(historyToggle.checked);
assertFalse(userEventsToggle.disabled);
assertTrue(userEventsToggle.checked);
assertTrue(prefs.userEventsSynced);
// Toggling user events also toggles the sync preference.
userEventsToggle.click();
cr.webUIListenerCallback('sync-prefs-changed', prefs);
assertFalse(userEventsToggle.disabled);
assertFalse(userEventsToggle.checked);
assertFalse(prefs.userEventsSynced);
assertTrue(resetSyncMessageBox.hidden);
});
test(
'ExistingPassphraseSubmitButtonDisabledWhenExistingPassphraseEmpty',
function() {
......
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