| 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-checkbox. */ |
| 6 cr.define('settings_checkbox', function() { | 6 cr.define('settings_checkbox', function() { |
| 7 function registerTests() { | 7 function registerTests() { |
| 8 suite('SettingsCheckbox', function() { | 8 suite('SettingsCheckbox', function() { |
| 9 /** | 9 /** |
| 10 * Checkbox created before each test. | 10 * Checkbox created before each test. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 // Initialize a checked settings-checkbox before each test. | 25 // Initialize a checked settings-checkbox 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-checkbox'); |
| 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('value changes on tap', function() { |
| 34 assertTrue(testElement.checked); | 34 assertTrue(testElement.checked); |
| 35 | 35 |
| 36 testElement.removeAttribute('checked'); | 36 MockInteractions.tap(testElement.$.checkbox); |
| 37 assertFalse(testElement.checked); | 37 assertFalse(testElement.checked); |
| 38 assertFalse(pref.value); | 38 assertFalse(pref.value); |
| 39 | 39 |
| 40 testElement.setAttribute('checked', ''); | 40 MockInteractions.tap(testElement.$.checkbox); |
| 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.$.checkbox); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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 MockInteractions.tap(testElement.$.checkbox); |
| 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 MockInteractions.tap(testElement.$.checkbox); |
| 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 |