Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <meta charset="UTF-8"> |
michael@0 | 5 | <title>Test for DOMWindowUtils</title> |
michael@0 | 6 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <div id="content" style="display: none"></div> |
michael@0 | 11 | <pre id="test"> |
michael@0 | 12 | <script type="application/javascript"> |
michael@0 | 13 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 14 | |
michael@0 | 15 | var utils = SpecialPowers.getDOMWindowUtils(window); |
michael@0 | 16 | function test_sendMouseEventDefaults() { |
michael@0 | 17 | var x = 1, y = 2, button = 1, clickCount = 2, |
michael@0 | 18 | modifiers = SpecialPowers.Ci.nsIDOMNSEvent.SHIFT_MASK; |
michael@0 | 19 | |
michael@0 | 20 | window.addEventListener("mousedown", function listener(evt) { |
michael@0 | 21 | window.removeEventListener("mousedown", listener); |
michael@0 | 22 | // Mandatory args |
michael@0 | 23 | is(evt.clientX, x, "check x"); |
michael@0 | 24 | is(evt.clientY, y, "check y"); |
michael@0 | 25 | is(evt.button, button, "check button"); |
michael@0 | 26 | is(evt.detail, clickCount, "check click count"); |
michael@0 | 27 | is(evt.getModifierState("Shift"), true, "check modifiers"); |
michael@0 | 28 | |
michael@0 | 29 | // Default value for optionals |
michael@0 | 30 | is(evt.mozPressure, 0, "check pressure"); |
michael@0 | 31 | is(evt.mozInputSource, SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_MOUSE, "check input source"); |
michael@0 | 32 | is(evt.isSynthesized, undefined, "check isSynthesized is undefined in content"); |
michael@0 | 33 | is(SpecialPowers.wrap(evt).isSynthesized, true, "check isSynthesized is true from chrome"); |
michael@0 | 34 | next(); |
michael@0 | 35 | }); |
michael@0 | 36 | |
michael@0 | 37 | // Only pass mandatory arguments and check default values |
michael@0 | 38 | utils.sendMouseEvent("mousedown", x, y, button, clickCount, modifiers); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function test_sendMouseEventOptionals() { |
michael@0 | 42 | var x = 1, y = 2, button = 1, clickCount = 3, |
michael@0 | 43 | modifiers = SpecialPowers.Ci.nsIDOMNSEvent.SHIFT_MASK, |
michael@0 | 44 | pressure = 0.5, |
michael@0 | 45 | source = SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_KEYBOARD; |
michael@0 | 46 | |
michael@0 | 47 | window.addEventListener("mouseup", function listener(evt) { |
michael@0 | 48 | window.removeEventListener("mouseup", listener); |
michael@0 | 49 | is(evt.mozInputSource, source, "explicit input source is valid"); |
michael@0 | 50 | is(SpecialPowers.wrap(evt).isSynthesized, false, "we can dispatch event that don't look synthesized"); |
michael@0 | 51 | next(); |
michael@0 | 52 | }); |
michael@0 | 53 | |
michael@0 | 54 | // Check explicit value for optional args |
michael@0 | 55 | utils.sendMouseEvent("mouseup", x, y, button, clickCount, modifiers, |
michael@0 | 56 | false, pressure, source, false); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | var tests = [ |
michael@0 | 60 | test_sendMouseEventDefaults, |
michael@0 | 61 | test_sendMouseEventOptionals |
michael@0 | 62 | ]; |
michael@0 | 63 | |
michael@0 | 64 | function next() { |
michael@0 | 65 | if (!tests.length) { |
michael@0 | 66 | SimpleTest.finish(); |
michael@0 | 67 | return; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | var test = tests.shift(); |
michael@0 | 71 | test(); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | function start() { |
michael@0 | 75 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 76 | SimpleTest.executeSoon(next); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | window.addEventListener("load", start); |
michael@0 | 80 | |
michael@0 | 81 | </script> |
michael@0 | 82 | </pre> |
michael@0 | 83 | </body> |
michael@0 | 84 | </html> |