Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / radio-checkbox-restore-indeterminate.html
blob33bc7a75f0af4ff2a85d6a3bfc703f6fed6e466b
1 <html>
2 <head>
4 <script>
5 if (window.testRunner)
6 testRunner.dumpAsText();
8 function dispatchEvent(target, eventType, offsetX, offsetY)
10 var targetRect = target.getBoundingClientRect();
11 var ev = document.createEvent("MouseEvent");
12 ev.initMouseEvent(eventType, true, true, window, 1, 1, 1, targetRect.left + offsetX, targetRect.top + offsetY, false, false, false, false, 0, document);
13 target.dispatchEvent(ev);
16 function log(s)
18 document.getElementById('result').innerHTML += s + '<br>';
21 function defaultPreventingHandler(e) {
22 e.preventDefault();
25 function runTests()
27 var radio1 = document.getElementById("radio1");
28 var radio2 = document.getElementById("radio2");
30 var radio3 = document.getElementById("radio3");
31 var radio4 = document.getElementById("radio4");
33 var check1 = document.getElementById("check1");
34 var check2 = document.getElementById("check2");
36 radio1.checked = true;
38 radio3.checked = true;
39 radio3.indeterminate = true;
40 radio4.indeterminate = true;
42 check1.checked = true;
43 check1.indeterminate = true;
45 check2.checked = false;
46 check2.indeterminate = true;
48 radio3.addEventListener('click', defaultPreventingHandler, false);
49 radio4.addEventListener('click', defaultPreventingHandler, false);
50 check1.addEventListener('click', defaultPreventingHandler, false);
51 check2.addEventListener('click', defaultPreventingHandler, false);
53 // Clicking selected radio should not unselect them both
54 dispatchEvent(radio1, "click", 2, 2);
56 // Default-prevented click should not change checked or intermediate state
57 dispatchEvent(radio3, "click", 2, 2);
58 dispatchEvent(radio4, "click", 2, 2);
60 // Default-prevented click should not change checked or intermediate state
61 dispatchEvent(check1, "click", 2, 2);
62 dispatchEvent(check2, "click", 2, 2);
64 if (radio1.checked)
65 log('Click did not unselect all radio buttons: PASS');
66 else
67 log('Click unselected all radio buttons: FAIL');
69 log('<br>Checking whether default-prevented click clobbered indeterminate state:')
70 log('On checked radio button: ' + (radio3.indeterminate ? 'PASS' : 'FAIL'));
71 log('On unchecked radio button: ' + (radio4.indeterminate ? 'PASS' : 'FAIL'));
72 log('On checked checkbox: ' + (check1.indeterminate ? 'PASS' : 'FAIL'));
73 log('On unchecked checkbox: ' + (check2.indeterminate ? 'PASS' : 'FAIL'));
75 log('<br>Checking whether default-prevented click clobbered checked state:')
76 log('On checked radio button: ' + (radio3.checked ? 'PASS' : 'FAIL'));
77 log('On unchecked radio button: ' + (!radio4.checked ? 'PASS' : 'FAIL'));
78 log('On checked checkbox: ' + (check1.checked ? 'PASS' : 'FAIL'));
79 log('On unchecked checkbox: ' + (!check2.checked ? 'PASS' : 'FAIL'));
81 </script>
83 </head>
85 <body onload="runTests()">
87 <form>
88 <input type="radio" name="test" id="radio1" value="a">A
89 <input type="radio" name="test" id="radio2" value="b">B
90 </form>
92 <form>
93 <input type="radio" name="test2" id="radio3" value="a">Intermediate A
94 <input type="radio" name="test2" id="radio4" value="b">Intermediate B
95 </form>
97 <form>
98 <input type="checkbox" name="check1" id="check1" value="a">C
99 <input type="checkbox" name="check2" id="check2" value="b">D
100 </form>
102 <div id="result"></div>
103 </body>
104 </html>