Commit 4367d762 authored by Azeem Arshad's avatar Azeem Arshad Committed by Commit Bot

[Settings Networking] Fix issue with toggle affecting all networks.

This CL fixes issue with Auto connect toggle button toggling for
other networks. This was caused because the updates to fake pref
objects that control this toggle is not propagated down to the
children, thus the toggle maintains same value from last network
detail page. Fixed this by updating the entire pref object instead
of just the value sub-property.

Bug: 957224
Change-Id: Ic95c2b0ed9f77d9547114fe01acfcc18023c38fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1622415
Commit-Queue: Azeem Arshad <azeemarshad@chromium.org>
Reviewed-by: default avatarJeremy Klein <jlklein@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662836}
parent 67bbf841
...@@ -183,6 +183,7 @@ ...@@ -183,6 +183,7 @@
if="[[showAutoConnect_(networkProperties_, globalPolicy, if="[[showAutoConnect_(networkProperties_, globalPolicy,
managedNetworkAvailable)]]"> managedNetworkAvailable)]]">
<settings-toggle-button <settings-toggle-button
id="autoConnectToggle"
pref="{{autoConnect_}}" pref="{{autoConnect_}}"
label="[[getAutoConnectToggleLabel_(networkProperties_)]]"> label="[[getAutoConnectToggleLabel_(networkProperties_)]]">
</settings-toggle-button> </settings-toggle-button>
......
...@@ -88,7 +88,7 @@ Polymer({ ...@@ -88,7 +88,7 @@ Polymer({
globalPolicy: { globalPolicy: {
type: Object, type: Object,
value: null, value: null,
observer: 'updateAutoConnectPref_', observer: 'globalPolicyChanged_',
}, },
/** /**
...@@ -276,6 +276,12 @@ Polymer({ ...@@ -276,6 +276,12 @@ Polymer({
}); });
}, },
/** @param {!chrome.networkingPrivate.GlobalPolicy} globalPolicy */
globalPolicyChanged_: function(globalPolicy) {
this.updateAutoConnectPref_(
!!(this.autoConnect_ && this.autoConnect_.value), globalPolicy);
},
/** @private */ /** @private */
networkPropertiesChanged_: function() { networkPropertiesChanged_: function() {
if (!this.networkProperties_) { if (!this.networkProperties_) {
...@@ -283,13 +289,8 @@ Polymer({ ...@@ -283,13 +289,8 @@ Polymer({
} }
// Update autoConnect if it has changed. Default value is false. // Update autoConnect if it has changed. Default value is false.
const autoConnect = CrOnc.getAutoConnect(this.networkProperties_); this.updateAutoConnectPref_(
if (this.autoConnect_ === undefined) { CrOnc.getAutoConnect(this.networkProperties_), this.globalPolicy);
this.updateAutoConnectPref_();
}
if (autoConnect != this.autoConnect_.value) {
this.autoConnect_.value = autoConnect;
}
// Update preferNetwork if it has changed. Default value is false. // Update preferNetwork if it has changed. Default value is false.
const priority = /** @type {number} */ ( const priority = /** @type {number} */ (
...@@ -338,18 +339,36 @@ Polymer({ ...@@ -338,18 +339,36 @@ Polymer({
this.setNetworkProperties_(onc); this.setNetworkProperties_(onc);
}, },
/** @private */ /**
updateAutoConnectPref_: function() { * Updates auto-connect pref value.
* @param {boolean} value
* @param {!chrome.networkingPrivate.GlobalPolicy|undefined} globalPolicy
* @private
*/
updateAutoConnectPref_: function(value, globalPolicy) {
let enforcement;
let controlledBy;
if (this.isAutoConnectEnforcedByPolicy(
this.networkProperties_, globalPolicy)) {
enforcement = chrome.settingsPrivate.Enforcement.ENFORCED;
controlledBy = chrome.settingsPrivate.ControlledBy.DEVICE_POLICY;
}
if (this.autoConnect_ && this.autoConnect_.value == value &&
enforcement == this.autoConnect_.enforcement &&
controlledBy == this.autoConnect_.controlledBy) {
return;
}
const newPrefValue = { const newPrefValue = {
key: 'fakeAutoConnectPref', key: 'fakeAutoConnectPref',
value: !!this.autoConnect_ && !!this.autoConnect_.value, value: value,
type: chrome.settingsPrivate.PrefType.BOOLEAN, type: chrome.settingsPrivate.PrefType.BOOLEAN,
}; };
if (this.isAutoConnectEnforcedByPolicy( if (enforcement) {
this.networkProperties_, this.globalPolicy)) { newPrefValue.enforcement = enforcement;
newPrefValue.controlledBy = newPrefValue.controlledBy = controlledBy;
chrome.settingsPrivate.ControlledBy.DEVICE_POLICY;
newPrefValue.enforcement = chrome.settingsPrivate.Enforcement.ENFORCED;
} }
this.autoConnect_ = newPrefValue; this.autoConnect_ = newPrefValue;
......
...@@ -256,5 +256,37 @@ suite('InternetDetailPage', function() { ...@@ -256,5 +256,37 @@ suite('InternetDetailPage', function() {
assertTrue(connectButton.hasAttribute('disabled')); assertTrue(connectButton.hasAttribute('disabled'));
}); });
}); });
test.only(
'Auto Connect toggle updates properly after GUID change', function() {
api_.enableNetworkType('WiFi');
setNetworksForTest([
{
GUID: 'wifi1_guid',
Name: 'wifi1',
Type: 'WiFi',
Source: CrOnc.Source.USER,
WiFi: {AutoConnect: true}
},
{
GUID: 'wifi2_guid',
Name: 'wifi1',
Type: 'WiFi',
Source: CrOnc.Source.USER,
WiFi: {AutoConnect: false}
}
]);
internetDetailPage.init('wifi1_guid', 'WiFi', 'wifi_user');
return flushAsync()
.then(() => {
assertTrue(internetDetailPage.$$('#autoConnectToggle').checked);
internetDetailPage.init('wifi2_guid', 'WiFi', 'wifi_user');
return flushAsync();
})
.then(() => {
assertFalse(
internetDetailPage.$$('#autoConnectToggle').checked);
});
});
}); });
}); });
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