Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
|
michaelpg
2015/05/05 22:19:50
It may make more sense to locate these tests along
Jeremy Klein
2015/05/06 18:03:36
+1 to keeping tests by their unit under test if po
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** @fileoverview Series of tests for cr-checkbox. */ | |
| 6 var RegisterCrCheckboxTests = (function() { | |
| 7 suite('CrCheckboxTest', function() { | |
| 8 var checkbox; | |
| 9 | |
| 10 // Import cr_checkbox.html before running suite. | |
| 11 suiteSetup(function(done) { | |
| 12 wcTest.importHtml( | |
| 13 'chrome://resources/cr_elements/cr_checkbox/cr_checkbox.html') | |
| 14 .then(done, done); | |
| 15 }); | |
| 16 | |
| 17 // Initialize a checked cr-checkbox before each test. | |
| 18 setup(function(done) { | |
| 19 wcTest.clear(); | |
| 20 checkbox = document.createElement('cr-checkbox'); | |
|
Jeremy Klein
2015/05/06 18:03:36
Think it would be simple to use test-fixture for m
| |
| 21 checkbox.setAttribute('checked', ''); | |
| 22 document.body.appendChild(checkbox); | |
| 23 | |
| 24 // Wait for the checkbox to be created. | |
| 25 wcTest.async().then(done); | |
| 26 }); | |
| 27 | |
| 28 test('toggles', function() { | |
| 29 assertTrue(checkbox.checked); | |
| 30 checkbox.toggle(); | |
| 31 assertFalse(checkbox.checked); | |
| 32 assertFalse(checkbox.hasAttribute('checked')); | |
| 33 checkbox.toggle(); | |
| 34 assertTrue(checkbox.checked); | |
| 35 assertTrue(checkbox.hasAttribute('checked')); | |
| 36 checkbox.toggle(); | |
| 37 assertFalse(checkbox.checked); | |
| 38 assertFalse(checkbox.hasAttribute('checked')); | |
| 39 }); | |
| 40 | |
| 41 test('checked attribute changes property', function() { | |
| 42 assertTrue(checkbox.checked); | |
| 43 checkbox.removeAttribute('checked'); | |
| 44 assertFalse(checkbox.checked); | |
| 45 checkbox.setAttribute('checked', ''); | |
| 46 assertTrue(checkbox.checked); | |
| 47 }); | |
| 48 | |
| 49 test('change event', function(done) { | |
| 50 checkbox.addEventListener('change', function() { | |
| 51 assertFalse(checkbox.checked); | |
| 52 done(); | |
| 53 }); | |
| 54 checkbox.$.checkbox.tap(); | |
|
Jeremy Klein
2015/05/06 18:03:36
note: iron-test-helpers has some useful bits we'll
| |
| 55 }); | |
| 56 | |
| 57 test('disabled', function() { | |
| 58 wcTest.clear(); | |
| 59 var disabledCheckbox = document.createElement('cr-checkbox'); | |
| 60 disabledCheckbox.setAttribute('disabled', ''); | |
| 61 document.body.appendChild(disabledCheckbox); | |
| 62 | |
| 63 assertTrue(disabledCheckbox.disabled); | |
| 64 | |
| 65 disabledCheckbox.$.checkbox.tap(); | |
| 66 assertFalse(disabledCheckbox.checked); | |
| 67 assertFalse(disabledCheckbox.$.checkbox.checked); | |
| 68 }); | |
| 69 }); | |
| 70 }); | |
| OLD | NEW |