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-checkbox. */
6 cr.define('cr_checkbox', function() {
7 function registerTests() {
8 suite('CrCheckbox', function() {
10 * Checkbox created before each test.
15 // Import cr_checkbox.html before running suite.
16 suiteSetup(function() {
17 return PolymerTest.importHtml(
18 'chrome://resources/cr_elements/v1_0/cr_checkbox/cr_checkbox.html');
21 // Initialize a checked cr-checkbox before each test.
22 setup(function(done) {
23 PolymerTest.clearBody();
24 checkbox = document.createElement('cr-checkbox');
25 checkbox.setAttribute('checked', '');
26 document.body.appendChild(checkbox);
28 // Allow for the checkbox to be created and attached.
32 test('can toggle', function() {
33 assertTrue(checkbox.checked);
36 assertFalse(checkbox.checked);
37 assertFalse(checkbox.hasAttribute('checked'));
40 assertTrue(checkbox.checked);
41 assertTrue(checkbox.hasAttribute('checked'));
44 test('responds to checked attribute', function() {
45 assertTrue(checkbox.checked);
47 checkbox.removeAttribute('checked');
48 assertFalse(checkbox.checked);
50 checkbox.setAttribute('checked', '');
51 assertTrue(checkbox.checked);
54 test('fires a change event', function(done) {
55 checkbox.addEventListener('change', function() {
56 assertFalse(checkbox.checked);
59 MockInteractions.tap(checkbox.$.checkbox);
62 test('does not change when disabled', function() {
63 checkbox.checked = false;
64 checkbox.setAttribute('disabled', '');
65 assertTrue(checkbox.disabled);
67 MockInteractions.tap(checkbox.$.checkbox);
68 assertFalse(checkbox.checked);
69 assertFalse(checkbox.$.checkbox.checked);
75 registerTests: registerTests,