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
3 // found in the LICENSE file.
5 /** @fileoverview Suite of tests for cr-settings-checkbox. */
6 cr.define('cr_settings_checkbox', function() {
7 function registerTests() {
8 suite('CrSettingsCheckbox', function() {
10 * Checkbox created before each test.
11 * @type {CrSettingsCheckbox}
16 * Pref value used in tests, should reflect checkbox 'checked' attribute.
17 * @type {CrSettingsCheckbox}
21 type: chrome.settingsPrivate.PrefType.BOOLEAN,
25 // Import cr_settings_checkbox.html before running suite.
26 suiteSetup(function() {
27 return PolymerTest.importHtml(
28 'chrome://md-settings/checkbox/checkbox.html');
31 // Initialize a checked cr-settings-checkbox before each test.
33 PolymerTest.clearBody();
34 checkbox = document.createElement('cr-settings-checkbox');
35 checkbox.set('pref', pref);
36 document.body.appendChild(checkbox);
39 test('responds to checked attribute', function() {
40 assertTrue(checkbox.checked);
42 checkbox.removeAttribute('checked');
43 assertFalse(checkbox.checked);
44 assertFalse(pref.value);
46 checkbox.setAttribute('checked', '');
47 assertTrue(checkbox.checked);
48 assertTrue(pref.value);
51 test('fires a change event', function(done) {
52 checkbox.addEventListener('change', function() {
53 assertFalse(checkbox.checked);
56 MockInteractions.tap(checkbox.$.checkbox);
59 test('does not change when disabled', function() {
60 checkbox.checked = false;
61 checkbox.setAttribute('disabled', '');
62 assertTrue(checkbox.disabled);
63 assertTrue(checkbox.$.checkbox.disabled);
65 MockInteractions.tap(checkbox.$.checkbox);
66 assertFalse(checkbox.checked);
67 assertFalse(checkbox.$.checkbox.checked);
73 registerTests: registerTests,