dom/base/test/test_domwindowutils.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/base/test/test_domwindowutils.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <meta charset="UTF-8">
     1.8 +  <title>Test for DOMWindowUtils</title>
     1.9 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.11 +</head>
    1.12 +<body>
    1.13 +<div id="content" style="display: none"></div>
    1.14 +<pre id="test">
    1.15 +<script type="application/javascript">
    1.16 +SimpleTest.waitForExplicitFinish();
    1.17 +
    1.18 +var utils = SpecialPowers.getDOMWindowUtils(window);
    1.19 +function test_sendMouseEventDefaults() {
    1.20 +  var x = 1, y = 2, button = 1, clickCount = 2,
    1.21 +      modifiers = SpecialPowers.Ci.nsIDOMNSEvent.SHIFT_MASK;
    1.22 +
    1.23 +  window.addEventListener("mousedown", function listener(evt) {
    1.24 +    window.removeEventListener("mousedown", listener);
    1.25 +    // Mandatory args
    1.26 +    is(evt.clientX, x, "check x");
    1.27 +    is(evt.clientY, y, "check y");
    1.28 +    is(evt.button, button, "check button");
    1.29 +    is(evt.detail, clickCount, "check click count");
    1.30 +    is(evt.getModifierState("Shift"), true, "check modifiers");
    1.31 +
    1.32 +    // Default value for optionals
    1.33 +    is(evt.mozPressure, 0, "check pressure");
    1.34 +    is(evt.mozInputSource, SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_MOUSE, "check input source");
    1.35 +    is(evt.isSynthesized, undefined, "check isSynthesized is undefined in content");
    1.36 +    is(SpecialPowers.wrap(evt).isSynthesized, true, "check isSynthesized is true from chrome");
    1.37 +    next();
    1.38 +  });
    1.39 +
    1.40 +  // Only pass mandatory arguments and check default values
    1.41 +  utils.sendMouseEvent("mousedown", x, y, button, clickCount, modifiers);
    1.42 +}
    1.43 +
    1.44 +function test_sendMouseEventOptionals() {
    1.45 +  var x = 1, y = 2, button = 1, clickCount = 3,
    1.46 +      modifiers = SpecialPowers.Ci.nsIDOMNSEvent.SHIFT_MASK,
    1.47 +      pressure = 0.5,
    1.48 +      source = SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_KEYBOARD;
    1.49 +
    1.50 +  window.addEventListener("mouseup", function listener(evt) {
    1.51 +    window.removeEventListener("mouseup", listener);
    1.52 +    is(evt.mozInputSource, source, "explicit input source is valid");
    1.53 +    is(SpecialPowers.wrap(evt).isSynthesized, false, "we can dispatch event that don't look synthesized");
    1.54 +    next();
    1.55 +  });
    1.56 +
    1.57 +  // Check explicit value for optional args
    1.58 +  utils.sendMouseEvent("mouseup", x, y, button, clickCount, modifiers,
    1.59 +                       false, pressure, source, false);
    1.60 +}
    1.61 +
    1.62 +var tests = [
    1.63 +  test_sendMouseEventDefaults,
    1.64 +  test_sendMouseEventOptionals
    1.65 +];
    1.66 +
    1.67 +function next() {
    1.68 +  if (!tests.length) {
    1.69 +    SimpleTest.finish();
    1.70 +    return;
    1.71 +  }
    1.72 +
    1.73 +  var test = tests.shift();
    1.74 +  test();
    1.75 +}
    1.76 +
    1.77 +function start() {
    1.78 +  SimpleTest.waitForExplicitFinish();
    1.79 +  SimpleTest.executeSoon(next);
    1.80 +}
    1.81 +
    1.82 +window.addEventListener("load", start);
    1.83 +
    1.84 +</script>
    1.85 +</pre>
    1.86 +</body>
    1.87 +</html>

mercurial