Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / events / simulated-key-state.html
1 <p>This tests that modifier keys are propagated to the fake mouse event created when you press return and a link has focus.</p>
2 <p>If the test succeeds, you should see six "PASS" messages below.</p>
3 <p>This is the <a id="link" href="#" onclick="checkKeyState(event)" onmousedown="checkKeyState(event)" onmouseuup="checkKeyState(event)">link</a> used for testing.</p>
4 <pre id="console">
5 </pre>
6 <script>
7
8 if (window.testRunner)
9     testRunner.dumpAsText();
10
11 var link = document.getElementById("link");
12 link.focus();
13
14 var expectedCtrl;
15 var expectedAlt;
16 var expectedShift;
17 var expectedMeta;
18
19 function test(ctrlKey, altKey, shiftKey, metaKey)
20 {
21     expectedCtrl = ctrlKey;
22     expectedAlt = altKey;
23     expectedShift = shiftKey;
24     expectedMeta = metaKey;
25     var event = document.createEvent("KeyboardEvents");
26     event.initKeyboardEvent("keypress", true, true, document.defaultView, "Enter", 0, ctrlKey, altKey, shiftKey, metaKey, false);
27     link.dispatchEvent(event);
28 }
29
30 function checkKeyState(event)
31 {
32     if (event.ctrlKey == expectedCtrl && event.altKey == expectedAlt && event.shiftKey == expectedShift && event.metaKey == expectedMeta)
33         document.getElementById("console").innerHTML += "PASS: " + event.type + " event had all the right key state.\n";
34     else
35         document.getElementById("console").innerHTML += "FAIL: " + event.type + " event did not have the right key state.\n";
36 }
37
38 test(false, false, false, false);
39 test(true, false, false, false);
40 test(false, true, false, false);
41 test(false, false, true, false);
42 test(false, false, false, true);
43 test(true, true, true, true);
44
45 link.blur();
46
47 </script>