OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> |
| 3 <title>input type checkbox</title> |
| 4 <link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org"> |
| 5 <link rel=help href="https://html.spec.whatwg.org/multipage/#checkbox-state-(typ
e=checkbox)"> |
| 6 <script src="../../../../../../resources/testharness.js"></script> |
| 7 <script src="../../../../../../resources/testharnessreport.js"></script> |
| 8 <div id="log"></div> |
| 9 <input type=checkbox id=checkbox1> |
| 10 <input type=checkbox id=checkbox2 disabled> |
| 11 <input type=checkbox id=checkbox3> |
| 12 <input type=checkbox id=checkbox4 checked> |
| 13 <input type=checkbox id=checkbox5> |
| 14 <input type=checkbox id=checkbox6> |
| 15 <script> |
| 16 var checkbox1 = document.getElementById('checkbox1'), |
| 17 checkbox2 = document.getElementById('checkbox2'), |
| 18 checkbox3 = document.getElementById('checkbox3'), |
| 19 checkbox4 = document.getElementById('checkbox4'), |
| 20 checkbox5 = document.getElementById('checkbox5'), |
| 21 checkbox6 = document.getElementById('checkbox6'), |
| 22 c1_input_fired = false, c1_change_fired = false, |
| 23 t1 = async_test("click on mutable checkbox fires the input and change even
ts"), |
| 24 t2 = async_test("click on non-mutable checkbox doesn't fire the input or c
hange event"), |
| 25 t3 = async_test("pre-activation steps on unchecked checkbox"), |
| 26 t4 = async_test("pre-activation steps on checked checkbox"), |
| 27 t5 = async_test("canceled activation steps on unchecked checkbox"), |
| 28 t6 = async_test("canceled activation steps on unchecked checkbox (indeterm
inate=true in onclick)"); |
| 29 |
| 30 checkbox1.oninput= t1.step_func(function(e) { |
| 31 c1_input_fired = true; |
| 32 assert_true(e.bubbles, "event should bubble"); |
| 33 assert_true(e.isTrusted, "event should be trusted"); |
| 34 assert_false(e.cancelable, "event shoud not be cancelable"); |
| 35 assert_true(checkbox1.checked, "checkbox is checked"); |
| 36 assert_false(checkbox1.indeterminate, "checkbox is not indeterminate"); |
| 37 }); |
| 38 |
| 39 checkbox1.onchange = t1.step_func(function(e) { |
| 40 c1_change_fired = true; |
| 41 assert_true(e.bubbles, "event should bubble") |
| 42 assert_true(e.isTrusted, "event should be trusted"); |
| 43 assert_false(e.cancelable, "event shoud not be cancelable"); |
| 44 assert_true(checkbox1.checked, "checkbox is checked"); |
| 45 assert_false(checkbox1.indeterminate, "checkbox is not indeterminate"); |
| 46 }); |
| 47 |
| 48 checkbox2.oninput= t2.step_func(function(e) { |
| 49 assert_unreached("event input fired"); |
| 50 }); |
| 51 |
| 52 checkbox2.onchange = t2.step_func(function(e) { |
| 53 assert_unreached("event change fired"); |
| 54 }); |
| 55 |
| 56 t1.step(function() { |
| 57 checkbox1.click(); |
| 58 assert_true(c1_input_fired); |
| 59 assert_true(c1_change_fired); |
| 60 t1.done(); |
| 61 }); |
| 62 |
| 63 t2.step(function() { |
| 64 checkbox2.click(); |
| 65 t2.done(); |
| 66 }); |
| 67 |
| 68 t3.step(function() { |
| 69 checkbox3.indeterminate = true; |
| 70 checkbox3.click(); |
| 71 assert_true(checkbox3.checked); |
| 72 assert_false(checkbox3.indeterminate); |
| 73 t3.done(); |
| 74 }); |
| 75 |
| 76 t4.step(function() { |
| 77 checkbox4.indeterminate = true; |
| 78 checkbox4.click(); |
| 79 assert_false(checkbox4.checked); |
| 80 assert_false(checkbox4.indeterminate); |
| 81 t4.done(); |
| 82 }); |
| 83 |
| 84 checkbox5.onclick = t5.step_func(function(e) { |
| 85 e.preventDefault(); |
| 86 assert_false(checkbox5.checked); |
| 87 assert_false(checkbox5.indeterminate); |
| 88 t5.done(); |
| 89 }); |
| 90 |
| 91 t5.step(function(){ |
| 92 assert_false(checkbox5.checked); |
| 93 assert_false(checkbox5.indeterminate); |
| 94 checkbox5.click(); |
| 95 }); |
| 96 |
| 97 checkbox6.onclick = t6.step_func(function(e) { |
| 98 checkbox6.indeterminate = true; |
| 99 e.preventDefault(); |
| 100 assert_false(checkbox6.checked); |
| 101 assert_false(checkbox6.indeterminate); |
| 102 t6.done(); |
| 103 }); |
| 104 |
| 105 t6.step(function(){ |
| 106 assert_false(checkbox6.checked); |
| 107 assert_false(checkbox6.indeterminate); |
| 108 checkbox6.click(); |
| 109 }); |
| 110 </script> |
OLD | NEW |