Commit 68947d74 authored by David Roger's avatar David Roger Committed by Commit Bot

Reland "[Settings] UserEvents depends on history and passphrase"

This is a reland of 13143b64ae10001dd25dcb8b2d8e707b9e439382

Original change's description:
> [Settings] UserEvents depends on history and passphrase
>
> 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: I04844e2ab9c631300e88f02bbedd712f7618bc32
> Reviewed-on: https://chromium-review.googlesource.com/1160658
> Reviewed-by: Scott Chen <scottchen@chromium.org>

TBR=droger

Bug: 865522, 865537
Change-Id: Ifae79eaf00a42c3b536bc54fa5d23cbcbcabd18a
Reviewed-on: https://chromium-review.googlesource.com/1170202
Commit-Queue: David Roger <droger@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582078}
parent 5091f4ca
...@@ -97,6 +97,9 @@ settings.StatusAction = { ...@@ -97,6 +97,9 @@ settings.StatusAction = {
* typedUrlsEnforced: boolean, * typedUrlsEnforced: boolean,
* typedUrlsRegistered: boolean, * typedUrlsRegistered: boolean,
* typedUrlsSynced: boolean, * typedUrlsSynced: boolean,
* userEventsEnforced: boolean,
* userEventsRegistered: boolean,
* userEventsSynced: boolean,
* }} * }}
*/ */
settings.SyncPrefs; settings.SyncPrefs;
......
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
<template> <template>
<style include="settings-shared iron-flex"> <style include="settings-shared iron-flex">
#create-password-box, #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. */ /* In order to line up with the encryption radio box text. */
margin-inline-start: var(--settings-indent-width); margin-inline-start: var(--settings-indent-width);
} }
...@@ -263,8 +264,11 @@ ...@@ -263,8 +264,11 @@
<div id="historyCheckboxLabel" class="flex"> <div id="historyCheckboxLabel" class="flex">
$i18n{historyCheckboxLabel} $i18n{historyCheckboxLabel}
</div> </div>
<cr-toggle checked="{{syncPrefs.typedUrlsSynced}}" <!-- TypedUrls has a special on-change handler to deal with user
on-change="onSingleSyncDataTypeChanged_" events. -->
<cr-toggle id="historyToggle"
checked="{{syncPrefs.typedUrlsSynced}}"
on-change="onTypedUrlsDataTypeChanged_"
disabled="[[shouldSyncCheckboxBeDisabled_( disabled="[[shouldSyncCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.typedUrlsEnforced)]]" syncPrefs.syncAllDataTypes, syncPrefs.typedUrlsEnforced)]]"
aria-labelledby="historyCheckboxLabel"> aria-labelledby="historyCheckboxLabel">
...@@ -344,6 +348,8 @@ ...@@ -344,6 +348,8 @@
</cr-toggle> </cr-toggle>
</div> </div>
<!-- User events is disabled and unchecked if data is encrypted or
typed urls are disabled. -->
<template is="dom-if" if="[[unifiedConsentEnabled]]"> <template is="dom-if" if="[[unifiedConsentEnabled]]">
<div class="layout horizontal list-item" <div class="layout horizontal list-item"
hidden="[[!syncPrefs.userEventsRegistered]]"> hidden="[[!syncPrefs.userEventsRegistered]]">
...@@ -352,12 +358,20 @@ ...@@ -352,12 +358,20 @@
<div class="secondary"> <div class="secondary">
$i18n{userEventsCheckboxText} $i18n{userEventsCheckboxText}
</div> </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> </div>
<cr-toggle checked="{{syncPrefs.userEventsSynced}}" </div>
on-change="onSingleSyncDataTypeChanged_" <cr-toggle id="userEventsToggle"
disabled="[[shouldSyncCheckboxBeDisabled_( checked="{{userEventsToggleValue}}"
syncPrefs.syncAllDataTypes, on-change="onUserEventsSyncDataTypeChanged_"
syncPrefs.userEventsEnforced)]]" disabled="[[shouldUserEventsCheckboxBeDisabled_(
syncPrefs.syncAllDataTypes, syncPrefs.typedUrlsSynced,
syncPrefs.userEventsEnforced, syncPrefs.encryptAllData)]]"
aria-labelledby="userEventsCheckboxLabel"> aria-labelledby="userEventsCheckboxLabel">
</cr-toggle> </cr-toggle>
</div> </div>
...@@ -431,10 +445,16 @@ ...@@ -431,10 +445,16 @@
</template> </template>
</cr-radio-button> </cr-radio-button>
</paper-radio-group> </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]]"> hidden="[[!syncPrefs.encryptAllData]]">
<span>$i18nRaw{passphraseResetHint}</span> <span>
<iron-icon icon="settings:info-outline"></iron-icon>
$i18nRaw{passphraseResetHint}
</span>
</div> </div>
</div> </div>
<template is="dom-if" if="[[creatingNewPassphrase_]]"> <template is="dom-if" if="[[creatingNewPassphrase_]]">
......
...@@ -158,6 +158,11 @@ Polymer({ ...@@ -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"> // <if expr="not chromeos">
diceEnabled: Boolean, diceEnabled: Boolean,
// </if> // </if>
...@@ -304,6 +309,11 @@ Polymer({ ...@@ -304,6 +309,11 @@ Polymer({
if (!this.syncPrefs.autofillRegistered || !this.syncPrefs.autofillSynced) if (!this.syncPrefs.autofillRegistered || !this.syncPrefs.autofillSynced)
this.set('syncPrefs.paymentsIntegrationEnabled', false); 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. // Hide the new passphrase box if the sync data has been encrypted.
if (this.syncPrefs.encryptAllData) if (this.syncPrefs.encryptAllData)
this.creatingNewPassphrase_ = false; this.creatingNewPassphrase_ = false;
...@@ -373,6 +383,33 @@ Polymer({ ...@@ -373,6 +383,33 @@ Polymer({
this.onSingleSyncDataTypeChanged_(); 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} passphrase The passphrase input field value
* @param {string} confirmation The passphrase confirmation input field value. * @param {string} confirmation The passphrase confirmation input field value.
...@@ -506,6 +543,19 @@ Polymer({ ...@@ -506,6 +543,19 @@ Polymer({
return syncAllDataTypes || !autofillSynced; 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 * 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. * they match each other. Additionally, displays error UI if they are invalid.
......
...@@ -54,9 +54,26 @@ cr.define('settings_people_page_sync_page', function() { ...@@ -54,9 +54,26 @@ cr.define('settings_people_page_sync_page', function() {
typedUrlsEnforced: false, typedUrlsEnforced: false,
typedUrlsRegistered: true, typedUrlsRegistered: true,
typedUrlsSynced: 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() { setup(function() {
browserProxy = new TestSyncBrowserProxy(); browserProxy = new TestSyncBrowserProxy();
settings.SyncBrowserProxyImpl.instance_ = browserProxy; settings.SyncBrowserProxyImpl.instance_ = browserProxy;
...@@ -457,6 +474,66 @@ cr.define('settings_people_page_sync_page', function() { ...@@ -457,6 +474,66 @@ cr.define('settings_people_page_sync_page', function() {
assertTrue(syncPage.$.encryptionRadioGroupContainer.hidden); 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( test(
'ExistingPassphraseSubmitButtonDisabledWhenExistingPassphraseEmpty', 'ExistingPassphraseSubmitButtonDisabledWhenExistingPassphraseEmpty',
function() { 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