Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: chrome/test/data/webui/settings/checkbox_tests.js

Issue 1486953003: Support numbers in settings-checkbox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ensure type of boolean pref also Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
34 testElement = document.createElement('settings-checkbox'); 34 testElement = document.createElement('settings-checkbox');
35 testElement.set('pref', pref); 35 testElement.set('pref', pref);
36 document.body.appendChild(testElement); 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(testElement.checked); 40 assertTrue(testElement.checked);
41 41
42 testElement.removeAttribute('checked'); 42 testElement.removeAttribute('checked');
43 assertFalse(testElement.checked); 43 assertFalse(testElement.checked);
44 assertFalse(pref.value); 44 assertEquals(false, pref.value);
45 45
46 testElement.setAttribute('checked', ''); 46 testElement.setAttribute('checked', '');
47 assertTrue(testElement.checked); 47 assertTrue(testElement.checked);
48 assertTrue(pref.value); 48 assertEquals(true, pref.value);
Dan Beam 2015/12/02 21:48:57 why is this better?
stevenjb 2015/12/02 22:07:27 It's not. I made the incorrect assumption that ass
49 }); 49 });
50 50
51 test('fires a change event', function(done) { 51 test('fires a change event', function(done) {
52 testElement.addEventListener('change', function() { 52 testElement.addEventListener('change', function() {
53 assertFalse(testElement.checked); 53 assertFalse(testElement.checked);
54 done(); 54 done();
55 }); 55 });
56 MockInteractions.tap(testElement.$.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 testElement.checked = false; 60 testElement.checked = false;
61 testElement.setAttribute('disabled', ''); 61 testElement.setAttribute('disabled', '');
62 assertTrue(testElement.disabled); 62 assertTrue(testElement.disabled);
63 assertTrue(testElement.$.checkbox.disabled); 63 assertTrue(testElement.$.checkbox.disabled);
64 64
65 MockInteractions.tap(testElement.$.checkbox); 65 MockInteractions.tap(testElement.$.checkbox);
66 assertFalse(testElement.checked); 66 assertFalse(testElement.checked);
67 assertFalse(testElement.$.checkbox.checked); 67 assertFalse(testElement.$.checkbox.checked);
68 }); 68 });
69
70 test('numerical pref', function() {
71 var prefNum = {
72 key: 'test',
73 type: chrome.settingsPrivate.PrefType.NUMBER,
74 value: 1
75 };
76
77 var testElementNum = document.createElement('settings-checkbox');
78 testElementNum.set('pref', prefNum);
Dan Beam 2015/12/02 21:48:57 why can't we just re-use the testElement fixture a
stevenjb 2015/12/02 22:07:27 We can. Done.
79 document.body.appendChild(testElementNum);
Dan Beam 2015/12/02 21:48:57 why does this need to be inserted into the DOM?
stevenjb 2015/12/02 22:07:27 Acknowledged.
80
81 assertTrue(testElementNum.checked);
82
83 testElementNum.removeAttribute('checked');
84 assertFalse(testElementNum.checked);
85 assertEquals(0, prefNum.value);
86
87 testElementNum.setAttribute('checked', '');
88 assertTrue(testElementNum.checked);
89 assertEquals(1, prefNum.value);
90 });
69 }); 91 });
70 } 92 }
71 93
72 return { 94 return {
73 registerTests: registerTests, 95 registerTests: registerTests,
74 }; 96 };
75 }); 97 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698