Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="UTF-8">
5 <title>Test for DOMWindowUtils</title>
6 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
8 </head>
9 <body>
10 <div id="content" style="display: none"></div>
11 <pre id="test">
12 <script type="application/javascript">
13 SimpleTest.waitForExplicitFinish();
15 var utils = SpecialPowers.getDOMWindowUtils(window);
16 function test_sendMouseEventDefaults() {
17 var x = 1, y = 2, button = 1, clickCount = 2,
18 modifiers = SpecialPowers.Ci.nsIDOMNSEvent.SHIFT_MASK;
20 window.addEventListener("mousedown", function listener(evt) {
21 window.removeEventListener("mousedown", listener);
22 // Mandatory args
23 is(evt.clientX, x, "check x");
24 is(evt.clientY, y, "check y");
25 is(evt.button, button, "check button");
26 is(evt.detail, clickCount, "check click count");
27 is(evt.getModifierState("Shift"), true, "check modifiers");
29 // Default value for optionals
30 is(evt.mozPressure, 0, "check pressure");
31 is(evt.mozInputSource, SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_MOUSE, "check input source");
32 is(evt.isSynthesized, undefined, "check isSynthesized is undefined in content");
33 is(SpecialPowers.wrap(evt).isSynthesized, true, "check isSynthesized is true from chrome");
34 next();
35 });
37 // Only pass mandatory arguments and check default values
38 utils.sendMouseEvent("mousedown", x, y, button, clickCount, modifiers);
39 }
41 function test_sendMouseEventOptionals() {
42 var x = 1, y = 2, button = 1, clickCount = 3,
43 modifiers = SpecialPowers.Ci.nsIDOMNSEvent.SHIFT_MASK,
44 pressure = 0.5,
45 source = SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_KEYBOARD;
47 window.addEventListener("mouseup", function listener(evt) {
48 window.removeEventListener("mouseup", listener);
49 is(evt.mozInputSource, source, "explicit input source is valid");
50 is(SpecialPowers.wrap(evt).isSynthesized, false, "we can dispatch event that don't look synthesized");
51 next();
52 });
54 // Check explicit value for optional args
55 utils.sendMouseEvent("mouseup", x, y, button, clickCount, modifiers,
56 false, pressure, source, false);
57 }
59 var tests = [
60 test_sendMouseEventDefaults,
61 test_sendMouseEventOptionals
62 ];
64 function next() {
65 if (!tests.length) {
66 SimpleTest.finish();
67 return;
68 }
70 var test = tests.shift();
71 test();
72 }
74 function start() {
75 SimpleTest.waitForExplicitFinish();
76 SimpleTest.executeSoon(next);
77 }
79 window.addEventListener("load", start);
81 </script>
82 </pre>
83 </body>
84 </html>