| 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 cr-settings-checkbox. */ | 5 /** @fileoverview Suite of tests for settings-checkbox. */ |
| 6 cr.define('cr_settings_checkbox', function() { | 6 cr.define('settings_checkbox', function() { |
| 7 function registerTests() { | 7 function registerTests() { |
| 8 suite('CrSettingsCheckbox', function() { | 8 suite('SettingsCheckbox', function() { |
| 9 /** | 9 /** |
| 10 * Checkbox created before each test. | 10 * Checkbox created before each test. |
| 11 * @type {CrSettingsCheckbox} | 11 * @type {SettingsCheckbox} |
| 12 */ | 12 */ |
| 13 var checkbox; | 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 checkbox 'checked' attribute. |
| 17 * @type {CrSettingsCheckbox} | 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 // Import cr_settings_checkbox.html before running suite. | 25 // Import settings_checkbox.html before running suite. |
| 26 suiteSetup(function() { | 26 suiteSetup(function() { |
| 27 return PolymerTest.importHtml( | 27 return PolymerTest.importHtml( |
| 28 'chrome://md-settings/checkbox/checkbox.html'); | 28 'chrome://md-settings/controls/settings_checkbox.html'); |
| 29 }); | 29 }); |
| 30 | 30 |
| 31 // Initialize a checked cr-settings-checkbox before each test. | 31 // Initialize a checked settings-checkbox before each test. |
| 32 setup(function() { | 32 setup(function() { |
| 33 PolymerTest.clearBody(); | 33 PolymerTest.clearBody(); |
| 34 checkbox = document.createElement('cr-settings-checkbox'); | 34 testElement = document.createElement('settings-checkbox'); |
| 35 checkbox.set('pref', pref); | 35 testElement.set('pref', pref); |
| 36 document.body.appendChild(checkbox); | 36 document.body.appendChild(testElement); |
| 37 }); | 37 }); |
| 38 | 38 |
| 39 test('responds to checked attribute', function() { | 39 test('responds to checked attribute', function() { |
| 40 assertTrue(checkbox.checked); | 40 assertTrue(testElement.checked); |
| 41 | 41 |
| 42 checkbox.removeAttribute('checked'); | 42 testElement.removeAttribute('checked'); |
| 43 assertFalse(checkbox.checked); | 43 assertFalse(testElement.checked); |
| 44 assertFalse(pref.value); | 44 assertFalse(pref.value); |
| 45 | 45 |
| 46 checkbox.setAttribute('checked', ''); | 46 testElement.setAttribute('checked', ''); |
| 47 assertTrue(checkbox.checked); | 47 assertTrue(testElement.checked); |
| 48 assertTrue(pref.value); | 48 assertTrue(pref.value); |
| 49 }); | 49 }); |
| 50 | 50 |
| 51 test('fires a change event', function(done) { | 51 test('fires a change event', function(done) { |
| 52 checkbox.addEventListener('change', function() { | 52 testElement.addEventListener('change', function() { |
| 53 assertFalse(checkbox.checked); | 53 assertFalse(testElement.checked); |
| 54 done(); | 54 done(); |
| 55 }); | 55 }); |
| 56 MockInteractions.tap(checkbox.$.checkbox); | 56 MockInteractions.tap(testElement.$.checkbox); |
| 57 }); | 57 }); |
| 58 | 58 |
| 59 test('does not change when disabled', function() { | 59 test('does not change when disabled', function() { |
| 60 checkbox.checked = false; | 60 testElement.checked = false; |
| 61 checkbox.setAttribute('disabled', ''); | 61 testElement.setAttribute('disabled', ''); |
| 62 assertTrue(checkbox.disabled); | 62 assertTrue(testElement.disabled); |
| 63 assertTrue(checkbox.$.checkbox.disabled); | 63 assertTrue(testElement.$.checkbox.disabled); |
| 64 | 64 |
| 65 MockInteractions.tap(checkbox.$.checkbox); | 65 MockInteractions.tap(testElement.$.checkbox); |
| 66 assertFalse(checkbox.checked); | 66 assertFalse(testElement.checked); |
| 67 assertFalse(checkbox.$.checkbox.checked); | 67 assertFalse(testElement.$.checkbox.checked); |
| 68 }); | 68 }); |
| 69 }); | 69 }); |
| 70 } | 70 } |
| 71 | 71 |
| 72 return { | 72 return { |
| 73 registerTests: registerTests, | 73 registerTests: registerTests, |
| 74 }; | 74 }; |
| 75 }); | 75 }); |
| OLD | NEW |