| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 suite('controlled button', function() { | 5 suite('controlled button', function() { |
| 6 /** @type {ControlledButtonElement} */ | 6 /** @type {ControlledButtonElement} */ |
| 7 var button; | 7 var controlledButton; |
| 8 | 8 |
| 9 /** @type {!chrome.settingsPrivate.PrefObject} */ | 9 /** @type {!chrome.settingsPrivate.PrefObject} */ |
| 10 var pref = { | 10 var uncontrolledPref = { |
| 11 key: 'test', | 11 key: 'test', |
| 12 type: chrome.settingsPrivate.PrefType.BOOLEAN, | 12 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 13 value: true | 13 value: true |
| 14 }; | 14 }; |
| 15 | 15 |
| 16 /** @type {!chrome.settingsPrivate.PrefObject} */ |
| 17 var extensionControlledPref = Object.assign({ |
| 18 controlledBy: chrome.settingsPrivate.ControlledBy.EXTENSION, |
| 19 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED, |
| 20 }, uncontrolledPref); |
| 21 |
| 22 /** @type {!chrome.settingsPrivate.PrefObject} */ |
| 23 var policyControlledPref = Object.assign({ |
| 24 controlledBy: chrome.settingsPrivate.ControlledBy.USER_POLICY, |
| 25 enforcement: chrome.settingsPrivate.Enforcement.ENFORCED, |
| 26 }, uncontrolledPref); |
| 27 |
| 16 setup(function() { | 28 setup(function() { |
| 17 PolymerTest.clearBody(); | 29 PolymerTest.clearBody(); |
| 18 button = document.createElement('controlled-button'); | 30 controlledButton = document.createElement('controlled-button'); |
| 19 button.pref = pref; | 31 controlledButton.pref = uncontrolledPref; |
| 20 document.body.appendChild(button); | 32 document.body.appendChild(controlledButton); |
| 33 Polymer.dom.flush(); |
| 21 }); | 34 }); |
| 22 | 35 |
| 23 test('disables when pref is managed', function() { | 36 test('controlled prefs', function() { |
| 24 button.set('pref.enforcement', chrome.settingsPrivate.Enforcement.ENFORCED); | 37 assertFalse(controlledButton.$$('paper-button').disabled); |
| 38 assertFalse(!!controlledButton.$$('cr-policy-pref-indicator')); |
| 39 |
| 40 controlledButton.pref = extensionControlledPref; |
| 25 Polymer.dom.flush(); | 41 Polymer.dom.flush(); |
| 26 assertTrue(button.$$('paper-button').disabled); | 42 assertTrue(controlledButton.$$('paper-button').disabled); |
| 43 assertFalse(!!controlledButton.$$('cr-policy-pref-indicator')); |
| 27 | 44 |
| 28 var indicator = button.$$('cr-policy-pref-indicator'); | 45 controlledButton.pref = policyControlledPref; |
| 46 Polymer.dom.flush(); |
| 47 assertTrue(controlledButton.$$('paper-button').disabled); |
| 48 var indicator = controlledButton.$$('cr-policy-pref-indicator'); |
| 29 assertTrue(!!indicator); | 49 assertTrue(!!indicator); |
| 30 assertGT(indicator.clientHeight, 0); | 50 assertGT(indicator.clientHeight, 0); |
| 31 | 51 |
| 32 button.set('pref.enforcement', undefined); | 52 controlledButton.pref = uncontrolledPref; |
| 33 Polymer.dom.flush(); | 53 Polymer.dom.flush(); |
| 34 assertFalse(button.$$('paper-button').disabled); | 54 assertFalse(controlledButton.$$('paper-button').disabled); |
| 35 assertEquals(0, indicator.clientHeight); | 55 assertFalse(!!controlledButton.$$('cr-policy-pref-indicator')); |
| 36 }); | 56 }); |
| 37 }); | 57 }); |
| OLD | NEW |