| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** @fileoverview Suite of tests for settings-checkbox. */ | 5 /** @fileoverview Suite of tests for settings-toggle-button. */ |
| 6 cr.define('settings_checkbox', function() { | 6 cr.define('settings_toggle_button', function() { |
| 7 function registerTests() { | 7 function registerTests() { |
| 8 suite('SettingsCheckbox', function() { | 8 suite('SettingsToggleButton', function() { |
| 9 /** | 9 /** |
| 10 * Checkbox created before each test. | 10 * Toggle button created before each test. |
| 11 * @type {SettingsCheckbox} | 11 * @type {SettingsCheckbox} |
| 12 */ | 12 */ |
| 13 var testElement; | 13 var testElement; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Pref value used in tests, should reflect checkbox 'checked' attribute. | 16 * Pref value used in tests, should reflect the 'checked' attribute. |
| 17 * @type {SettingsCheckbox} | 17 * @type {SettingsCheckbox} |
| 18 */ | 18 */ |
| 19 var pref = { | 19 var pref = { |
| 20 key: 'test', | 20 key: 'test', |
| 21 type: chrome.settingsPrivate.PrefType.BOOLEAN, | 21 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 22 value: true | 22 value: true |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 // Initialize a checked settings-checkbox before each test. | 25 // Initialize a checked control before each test. |
| 26 setup(function() { | 26 setup(function() { |
| 27 PolymerTest.clearBody(); | 27 PolymerTest.clearBody(); |
| 28 testElement = document.createElement('settings-checkbox'); | 28 testElement = document.createElement('settings-toggle-button'); |
| 29 testElement.set('pref', pref); | 29 testElement.set('pref', pref); |
| 30 document.body.appendChild(testElement); | 30 document.body.appendChild(testElement); |
| 31 }); | 31 }); |
| 32 | 32 |
| 33 test('responds to checked attribute', function() { | 33 test('responds to checked attribute', function() { |
| 34 assertTrue(testElement.checked); | 34 assertTrue(testElement.checked); |
| 35 | 35 |
| 36 testElement.removeAttribute('checked'); | 36 testElement.removeAttribute('checked'); |
| 37 assertFalse(testElement.checked); | 37 assertFalse(testElement.checked); |
| 38 assertFalse(pref.value); | 38 assertFalse(pref.value); |
| 39 | 39 |
| 40 testElement.setAttribute('checked', ''); | 40 testElement.setAttribute('checked', ''); |
| 41 assertTrue(testElement.checked); | 41 assertTrue(testElement.checked); |
| 42 assertTrue(pref.value); | 42 assertTrue(pref.value); |
| 43 }); | 43 }); |
| 44 | 44 |
| 45 test('fires a change event', function(done) { | 45 test('fires a change event', function(done) { |
| 46 testElement.addEventListener('change', function() { | 46 testElement.addEventListener('change', function() { |
| 47 assertFalse(testElement.checked); | 47 assertFalse(testElement.checked); |
| 48 done(); | 48 done(); |
| 49 }); | 49 }); |
| 50 MockInteractions.tap(testElement.$.checkbox); | 50 MockInteractions.tap(testElement.$.control); |
| 51 }); | 51 }); |
| 52 | 52 |
| 53 test('does not change when disabled', function() { | 53 test('does not change when disabled', function() { |
| 54 testElement.checked = false; | 54 testElement.checked = false; |
| 55 testElement.setAttribute('disabled', ''); | 55 testElement.setAttribute('disabled', ''); |
| 56 assertTrue(testElement.disabled); | 56 assertTrue(testElement.disabled); |
| 57 assertTrue(testElement.$.checkbox.disabled); | 57 assertTrue(testElement.$.control.disabled); |
| 58 | 58 |
| 59 MockInteractions.tap(testElement.$.checkbox); | 59 MockInteractions.tap(testElement.$.control); |
| 60 assertFalse(testElement.checked); | 60 assertFalse(testElement.checked); |
| 61 assertFalse(testElement.$.checkbox.checked); | 61 assertFalse(testElement.$.control.checked); |
| 62 }); | 62 }); |
| 63 | 63 |
| 64 test('numerical pref', function() { | 64 test('numerical pref', function() { |
| 65 var prefNum = { | 65 var prefNum = { |
| 66 key: 'test', | 66 key: 'test', |
| 67 type: chrome.settingsPrivate.PrefType.NUMBER, | 67 type: chrome.settingsPrivate.PrefType.NUMBER, |
| 68 value: 1 | 68 value: 1 |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 testElement.set('pref', prefNum); | 71 testElement.set('pref', prefNum); |
| 72 assertTrue(testElement.checked); | 72 assertTrue(testElement.checked); |
| 73 | 73 |
| 74 testElement.removeAttribute('checked'); | 74 testElement.removeAttribute('checked'); |
| 75 assertFalse(testElement.checked); | 75 assertFalse(testElement.checked); |
| 76 assertEquals(0, prefNum.value); | 76 assertEquals(0, prefNum.value); |
| 77 | 77 |
| 78 testElement.setAttribute('checked', ''); | 78 testElement.setAttribute('checked', ''); |
| 79 assertTrue(testElement.checked); | 79 assertTrue(testElement.checked); |
| 80 assertEquals(1, prefNum.value); | 80 assertEquals(1, prefNum.value); |
| 81 }); | 81 }); |
| 82 }); | 82 }); |
| 83 } | 83 } |
| 84 | 84 |
| 85 return { | 85 return { |
| 86 registerTests: registerTests, | 86 registerTests: registerTests, |
| 87 }; | 87 }; |
| 88 }); | 88 }); |
| OLD | NEW |