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

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

Issue 2517753002: [MD settings] settings toggle control browser test addtion (Closed)
Patch Set: type change Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-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.
11 * @type {SettingsCheckbox} 11 * @type {SettingsCheckbox}
12 */ 12 */
13 var testElement; 13 var testElement;
14 14
15 /**
16 * Pref value used in tests, should reflect the 'checked' attribute.
17 * @type {SettingsCheckbox}
18 */
19 var pref = {
20 key: 'test',
21 type: chrome.settingsPrivate.PrefType.BOOLEAN,
22 value: true
23 };
24
25 // Initialize a checked control before each test. 15 // Initialize a checked control before each test.
26 setup(function() { 16 setup(function() {
17 /**
18 * Pref value used in tests, should reflect the 'checked' attribute.
19 * Create a new pref for each test() to prevent order (state)
20 * dependencies between tests.
21 * @type {chrome.settingsPrivate.PrefObject}
22 */
23 var pref = {
24 key: 'test',
25 type: chrome.settingsPrivate.PrefType.BOOLEAN,
26 value: true
27 };
27 PolymerTest.clearBody(); 28 PolymerTest.clearBody();
28 testElement = document.createElement('settings-toggle-button'); 29 testElement = document.createElement('settings-toggle-button');
29 testElement.set('pref', pref); 30 testElement.set('pref', pref);
30 document.body.appendChild(testElement); 31 document.body.appendChild(testElement);
31 }); 32 });
32 33
33 test('responds to checked attribute', function() { 34 test('responds to checked attribute', function() {
34 assertTrue(testElement.checked); 35 assertTrue(testElement.checked);
35 36
36 testElement.removeAttribute('checked'); 37 testElement.removeAttribute('checked');
37 assertFalse(testElement.checked); 38 assertFalse(testElement.checked);
38 assertFalse(pref.value); 39 assertFalse(testElement.pref.value);
39 40
40 testElement.setAttribute('checked', ''); 41 testElement.setAttribute('checked', '');
41 assertTrue(testElement.checked); 42 assertTrue(testElement.checked);
42 assertTrue(pref.value); 43 assertTrue(testElement.pref.value);
44 });
45
46 test('value changes on tap', function() {
47 assertTrue(testElement.checked);
48 assertTrue(testElement.pref.value);
49
50 MockInteractions.tap(testElement.$.control);
51 assertFalse(testElement.checked);
52 assertFalse(testElement.pref.value);
53
54 MockInteractions.tap(testElement.$.control);
55 assertTrue(testElement.checked);
56 assertTrue(testElement.pref.value);
43 }); 57 });
44 58
45 test('fires a change event', function(done) { 59 test('fires a change event', function(done) {
46 testElement.addEventListener('change', function() { 60 testElement.addEventListener('change', function() {
47 assertFalse(testElement.checked); 61 assertFalse(testElement.checked);
48 done(); 62 done();
49 }); 63 });
64 assertTrue(testElement.checked);
50 MockInteractions.tap(testElement.$.control); 65 MockInteractions.tap(testElement.$.control);
51 }); 66 });
52 67
53 test('does not change when disabled', function() { 68 test('does not change when disabled', function() {
54 testElement.checked = false; 69 testElement.checked = false;
55 testElement.setAttribute('disabled', ''); 70 testElement.setAttribute('disabled', '');
56 assertTrue(testElement.disabled); 71 assertTrue(testElement.disabled);
57 assertTrue(testElement.$.control.disabled); 72 assertTrue(testElement.$.control.disabled);
58 73
59 MockInteractions.tap(testElement.$.control); 74 MockInteractions.tap(testElement.$.control);
(...skipping 19 matching lines...) Expand all
79 assertTrue(testElement.checked); 94 assertTrue(testElement.checked);
80 assertEquals(1, prefNum.value); 95 assertEquals(1, prefNum.value);
81 }); 96 });
82 }); 97 });
83 } 98 }
84 99
85 return { 100 return {
86 registerTests: registerTests, 101 registerTests: registerTests,
87 }; 102 };
88 }); 103 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698