Chromium Code Reviews| 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-toggle-button. */ | 5 /** @fileoverview Suite of tests for settings-toggle-button. */ |
| 6 cr.define('settings_toggle_button', function() { | 6 cr.define('settings_toggle_button', function() { |
| 7 function registerTests() { | 7 function registerTests() { |
| 8 suite('SettingsToggleButton', function() { | 8 suite('SettingsToggleButton', function() { |
| 9 /** | 9 /** |
| 10 * Toggle button created before each test. | 10 * Toggle button created before each test. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 key: 'test', | 24 key: 'test', |
| 25 type: chrome.settingsPrivate.PrefType.BOOLEAN, | 25 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 26 value: true | 26 value: true |
| 27 }; | 27 }; |
| 28 PolymerTest.clearBody(); | 28 PolymerTest.clearBody(); |
| 29 testElement = document.createElement('settings-toggle-button'); | 29 testElement = document.createElement('settings-toggle-button'); |
| 30 testElement.set('pref', pref); | 30 testElement.set('pref', pref); |
| 31 document.body.appendChild(testElement); | 31 document.body.appendChild(testElement); |
| 32 }); | 32 }); |
| 33 | 33 |
| 34 test('responds to checked attribute', function() { | |
| 35 assertTrue(testElement.checked); | |
| 36 | |
| 37 testElement.removeAttribute('checked'); | |
| 38 assertFalse(testElement.checked); | |
| 39 assertFalse(testElement.pref.value); | |
| 40 | |
| 41 testElement.setAttribute('checked', ''); | |
| 42 assertTrue(testElement.checked); | |
| 43 assertTrue(testElement.pref.value); | |
| 44 }); | |
| 45 | |
| 46 test('value changes on tap', function() { | 34 test('value changes on tap', function() { |
| 47 assertTrue(testElement.checked); | 35 assertTrue(testElement.checked); |
| 48 assertTrue(testElement.pref.value); | 36 assertTrue(testElement.pref.value); |
| 49 | 37 |
| 50 MockInteractions.tap(testElement.$.control); | 38 MockInteractions.tap(testElement.$.control); |
| 51 assertFalse(testElement.checked); | 39 assertFalse(testElement.checked); |
| 52 assertFalse(testElement.pref.value); | 40 assertFalse(testElement.pref.value); |
| 53 | 41 |
| 54 MockInteractions.tap(testElement.$.control); | 42 MockInteractions.tap(testElement.$.control); |
| 55 assertTrue(testElement.checked); | 43 assertTrue(testElement.checked); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 79 test('numerical pref', function() { | 67 test('numerical pref', function() { |
| 80 var prefNum = { | 68 var prefNum = { |
| 81 key: 'test', | 69 key: 'test', |
| 82 type: chrome.settingsPrivate.PrefType.NUMBER, | 70 type: chrome.settingsPrivate.PrefType.NUMBER, |
| 83 value: 1 | 71 value: 1 |
| 84 }; | 72 }; |
| 85 | 73 |
| 86 testElement.set('pref', prefNum); | 74 testElement.set('pref', prefNum); |
| 87 assertTrue(testElement.checked); | 75 assertTrue(testElement.checked); |
| 88 | 76 |
| 89 testElement.removeAttribute('checked'); | 77 MockInteractions.tap(testElement.$.control); |
| 90 assertFalse(testElement.checked); | 78 assertFalse(testElement.checked); |
| 91 assertEquals(0, prefNum.value); | 79 assertEquals(0, prefNum.value); |
| 92 | 80 |
| 93 testElement.setAttribute('checked', ''); | 81 MockInteractions.tap(testElement.$.control); |
| 94 assertTrue(testElement.checked); | 82 assertTrue(testElement.checked); |
| 95 assertEquals(1, prefNum.value); | 83 assertEquals(1, prefNum.value); |
| 96 }); | 84 }); |
| 85 | |
| 86 test('numerical pref with custom values', function() { | |
| 87 var prefNum = { | |
| 88 key: 'test', | |
| 89 type: chrome.settingsPrivate.PrefType.NUMBER, | |
| 90 value: 5 | |
| 91 }; | |
| 92 | |
| 93 testElement.numericUncheckedValue = 5; | |
| 94 | |
| 95 testElement.set('pref', prefNum); | |
| 96 assertFalse(testElement.checked); | |
| 97 | |
| 98 MockInteractions.tap(testElement.$.control); | |
| 99 assertTrue(testElement.checked); | |
| 100 assertEquals(1, prefNum.value); | |
| 101 | |
| 102 MockInteractions.tap(testElement.$.control); | |
| 103 assertFalse(testElement.checked); | |
| 104 assertEquals(5, prefNum.value); | |
| 105 }); | |
| 106 | |
| 107 test('numerical pref with unknown inital value', function() { | |
| 108 prefNum = { | |
| 109 key: 'test', | |
| 110 type: chrome.settingsPrivate.PrefType.NUMBER, | |
| 111 value: 3 | |
| 112 }; | |
| 113 | |
| 114 testElement.numericUncheckedValue = 5; | |
|
Dan Beam
2017/02/15 23:25:53
you might need to change this
tommycli
2017/02/15 23:36:52
Done.
| |
| 115 | |
| 116 testElement.set('pref', prefNum); | |
| 117 | |
| 118 // Unknown value should still count as checked. | |
| 119 assertTrue(testElement.checked); | |
| 120 | |
| 121 // The control should not clobber an existing unknown value. | |
| 122 assertEquals(3, prefNum.value); | |
| 123 | |
| 124 // Unchecking should still send the unchecked value to prefs. | |
| 125 MockInteractions.tap(testElement.$.control); | |
| 126 assertFalse(testElement.checked); | |
| 127 assertEquals(5, prefNum.value); | |
| 128 | |
| 129 // Checking should still send the normal checked value to prefs. | |
| 130 MockInteractions.tap(testElement.$.control); | |
| 131 assertTrue(testElement.checked); | |
| 132 assertEquals(1, prefNum.value); | |
| 133 }); | |
| 97 }); | 134 }); |
| 98 } | 135 } |
| 99 | 136 |
| 100 return { | 137 return { |
| 101 registerTests: registerTests, | 138 registerTests: registerTests, |
| 102 }; | 139 }; |
| 103 }); | 140 }); |
| OLD | NEW |