widget/tests/test_assign_event_data.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/tests/test_assign_event_data.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,731 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Testing ns*Event::Assign*EventData()</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.10 +  <script type="text/javascript" src="/tests/SimpleTest/NativeKeyCodes.js"></script>
    1.11 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
    1.12 +  <style>
    1.13 +    #a {
    1.14 +      background-color: transparent;
    1.15 +      transition: background-color 0.1s linear;
    1.16 +    }
    1.17 +    #a:focus {
    1.18 +      background-color: red;
    1.19 +    }
    1.20 +    .slidin {
    1.21 +      border: green 1px solid;
    1.22 +      width: 10px;
    1.23 +      height: 10px;
    1.24 +      animation-name: slidein;
    1.25 +      animation-duration: 1s;
    1.26 +    }
    1.27 +    @keyframes slidein {
    1.28 +      from {
    1.29 +        margin-left: 100%;
    1.30 +      }
    1.31 +      to {
    1.32 +        margin-left: 0;
    1.33 +      }
    1.34 +    }
    1.35 +  </style>
    1.36 +</head>
    1.37 +<body>
    1.38 +<div id="display">
    1.39 +  <input id="input-text">
    1.40 +  <button id="button">button</button>
    1.41 +  <a id="a" href="about:blank">hyper link</a>
    1.42 +  <div id="scrollable-div" style="overflow: auto; width: 30px; height: 30px;"><div id="scrolled-div" style="width: 10px; height: 10px;"></div></div>
    1.43 +  <form id="form"></form>
    1.44 +  <div id="animated-div"></div>
    1.45 +</div>
    1.46 +<div id="content" style="display: none">
    1.47 +</div>
    1.48 +<pre id="test">
    1.49 +</pre>
    1.50 +
    1.51 +<script class="testbody" type="application/javascript">
    1.52 +
    1.53 +SimpleTest.waitForExplicitFinish();
    1.54 +SimpleTest.expectAssertions(0, 32);
    1.55 +
    1.56 +const kIsMac = (navigator.platform.indexOf("Mac") == 0);
    1.57 +const kIsWin = (navigator.platform.indexOf("Win") == 0);
    1.58 +
    1.59 +var gEvent = null;
    1.60 +var gCopiedEvent = [];
    1.61 +var gCallback = null;
    1.62 +var gCallPreventDefault = false;
    1.63 +
    1.64 +function onEvent(aEvent)
    1.65 +{
    1.66 +  if (gCallPreventDefault) {
    1.67 +    aEvent.preventDefault();
    1.68 +  }
    1.69 +  gEvent = aEvent;
    1.70 +  for (var attr in aEvent) {
    1.71 +    if (!attr.match(/^[A-Z0-9_]+$/) && // ignore const attributes
    1.72 +        attr != "multipleActionsPrevented" && // multipleActionsPrevented isn't defined in any DOM event specs.
    1.73 +        typeof(aEvent[attr]) != "function") {
    1.74 +      gCopiedEvent.push({ name: attr, value: aEvent[attr]});
    1.75 +    }
    1.76 +  }
    1.77 +  setTimeout(gCallback, 0);
    1.78 +}
    1.79 +
    1.80 +const kTests = [
    1.81 +  { description: "InternalScrollPortEvent (overflow, vertical)",
    1.82 +    targetID: "scrollable-div", eventType: "overflow",
    1.83 +    dispatchEvent: function () {
    1.84 +      document.getElementById("scrolled-div").style.height = "500px";
    1.85 +    },
    1.86 +    canRun: function () {
    1.87 +      return true;
    1.88 +    },
    1.89 +    todoMismatch: [],
    1.90 +  },
    1.91 +  { description: "InternalScrollPortEvent (overflow, horizontal)",
    1.92 +    targetID: "scrollable-div", eventType: "overflow",
    1.93 +    dispatchEvent: function () {
    1.94 +      document.getElementById("scrolled-div").style.width = "500px";
    1.95 +    },
    1.96 +    canRun: function () {
    1.97 +      return true;
    1.98 +    },
    1.99 +    todoMismatch: [],
   1.100 +  },
   1.101 +  { description: "InternalScrollAreaEvent (MozScrolledAreaChanged, spreading)",
   1.102 +    target: function () { return document; }, eventType: "MozScrolledAreaChanged",
   1.103 +    dispatchEvent: function () {
   1.104 +      document.getElementById("scrollable-div").style.width = "50000px";
   1.105 +      document.getElementById("scrollable-div").style.height = "50000px";
   1.106 +    },
   1.107 +    canRun: function () {
   1.108 +      return true;
   1.109 +    },
   1.110 +    todoMismatch: [],
   1.111 +  },
   1.112 +  { description: "InternalScrollAreaEvent (MozScrolledAreaChanged, shrinking)",
   1.113 +    target: function () { return document; }, eventType: "MozScrolledAreaChanged",
   1.114 +    dispatchEvent: function () {
   1.115 +      document.getElementById("scrollable-div").style.width = "30px";
   1.116 +      document.getElementById("scrollable-div").style.height = "30px";
   1.117 +    },
   1.118 +    canRun: function () {
   1.119 +      return true;
   1.120 +    },
   1.121 +    todoMismatch: [],
   1.122 +  },
   1.123 +  { description: "WidgetKeyboardEvent (keydown of 'a' key without modifiers)",
   1.124 +    targetID: "input-text", eventType: "keydown",
   1.125 +    dispatchEvent: function () {
   1.126 +      document.getElementById(this.targetID).value = "";
   1.127 +      document.getElementById(this.targetID).focus();
   1.128 +      synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_A : MAC_VK_ANSI_A,
   1.129 +                          {}, "a", "a");
   1.130 +    },
   1.131 +    canRun: function () {
   1.132 +      return (kIsMac || kIsWin);
   1.133 +    },
   1.134 +    todoMismatch: [],
   1.135 +  },
   1.136 +  { description: "WidgetKeyboardEvent (keyup of 'a' key without modifiers)",
   1.137 +    targetID: "input-text", eventType: "keydown",
   1.138 +    dispatchEvent: function () {
   1.139 +      document.getElementById(this.targetID).value = "";
   1.140 +      document.getElementById(this.targetID).focus();
   1.141 +      synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_A : MAC_VK_ANSI_A,
   1.142 +                          {}, "a", "a");
   1.143 +    },
   1.144 +    canRun: function () {
   1.145 +      return (kIsMac || kIsWin);
   1.146 +    },
   1.147 +    todoMismatch: [],
   1.148 +  },
   1.149 +  { description: "WidgetKeyboardEvent (keypress of 'b' key with Shift)",
   1.150 +    targetID: "input-text", eventType: "keypress",
   1.151 +    dispatchEvent: function () {
   1.152 +      document.getElementById(this.targetID).value = "";
   1.153 +      document.getElementById(this.targetID).focus();
   1.154 +      synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_B : MAC_VK_ANSI_B,
   1.155 +                          { shiftKey: true }, "B", "B");
   1.156 +    },
   1.157 +    canRun: function () {
   1.158 +      return (kIsMac || kIsWin);
   1.159 +    },
   1.160 +    todoMismatch: [],
   1.161 +  },
   1.162 +  { description: "WidgetKeyboardEvent (keypress of 'c' key with Accel)",
   1.163 +    targetID: "input-text", eventType: "keypress",
   1.164 +    dispatchEvent: function () {
   1.165 +      document.getElementById(this.targetID).value = "";
   1.166 +      document.getElementById(this.targetID).focus();
   1.167 +      synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_C : MAC_VK_ANSI_C,
   1.168 +                          { accelKey: true }, kIsWin ? "\u0003" : "c", "c");
   1.169 +    },
   1.170 +    canRun: function () {
   1.171 +      return (kIsMac || kIsWin);
   1.172 +    },
   1.173 +    todoMismatch: [],
   1.174 +  },
   1.175 +  { description: "WidgetKeyboardEvent (keyup during composition)",
   1.176 +    targetID: "input-text", eventType: "keyup",
   1.177 +    dispatchEvent: function () {
   1.178 +      document.getElementById(this.targetID).value = "";
   1.179 +      document.getElementById(this.targetID).focus();
   1.180 +      synthesizeKey("a", { type: "keydown" });
   1.181 +      synthesizeComposition({ type: "compositionstart" });
   1.182 +      synthesizeComposition({ type: "compositionupdate", data: "\u306D" });
   1.183 +      synthesizeText({ "composition":
   1.184 +        { "string": "\u306D",
   1.185 +          "clauses":
   1.186 +          [
   1.187 +            { "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
   1.188 +          ]
   1.189 +        },
   1.190 +        "caret": { "start": 1, "length": 0 }
   1.191 +      });
   1.192 +      synthesizeKey("a", { type: "keyup" });
   1.193 +      synthesizeComposition({ type: "compositionupdate", data: "\u306D" });
   1.194 +      synthesizeText({ "composition":
   1.195 +        { "string": "\u306D",
   1.196 +          "clauses":
   1.197 +          [
   1.198 +            { "length": 0, "attr": 0 }
   1.199 +          ]
   1.200 +        },
   1.201 +        "caret": { "start": 1, "length": 0 }
   1.202 +      });
   1.203 +      synthesizeComposition({ type: "compositionend", data: "\u732B" });
   1.204 +    },
   1.205 +    canRun: function () {
   1.206 +      return true;
   1.207 +    },
   1.208 +    todoMismatch: [ ],
   1.209 +  },
   1.210 +  { description: "WidgetKeyboardEvent (keydown during composition)",
   1.211 +    targetID: "input-text", eventType: "keydown",
   1.212 +    dispatchEvent: function () {
   1.213 +      document.getElementById(this.targetID).value = "";
   1.214 +      document.getElementById(this.targetID).focus();
   1.215 +      synthesizeComposition({ type: "compositionstart" });
   1.216 +      synthesizeComposition({ type: "compositionupdate", data: "\u306D" });
   1.217 +      synthesizeText({ "composition":
   1.218 +        { "string": "\u306D",
   1.219 +          "clauses":
   1.220 +          [
   1.221 +            { "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
   1.222 +          ]
   1.223 +        },
   1.224 +        "caret": { "start": 1, "length": 0 }
   1.225 +      });
   1.226 +      synthesizeKey("VK_RETURN", { type: "keydown" });
   1.227 +      synthesizeComposition({ type: "compositionupdate", data: "\u306D" });
   1.228 +      synthesizeText({ "composition":
   1.229 +        { "string": "\u306D",
   1.230 +          "clauses":
   1.231 +          [
   1.232 +            { "length": 0, "attr": 0 }
   1.233 +          ]
   1.234 +        },
   1.235 +        "caret": { "start": 1, "length": 0 }
   1.236 +      });
   1.237 +      synthesizeComposition({ type: "compositionend", data: "\u732B" });
   1.238 +      synthesizeKey("VK_RETURN", { type: "keyup" });
   1.239 +    },
   1.240 +    canRun: function () {
   1.241 +      return true;
   1.242 +    },
   1.243 +    todoMismatch: [ ],
   1.244 +  },
   1.245 +  { description: "WidgetMouseEvent (mousedown of left button without modifier)",
   1.246 +    targetID: "button", eventType: "mousedown",
   1.247 +    dispatchEvent: function () {
   1.248 +      synthesizeMouseAtCenter(document.getElementById(this.targetID),
   1.249 +                              { button: 0 });
   1.250 +    },
   1.251 +    canRun: function () {
   1.252 +      return true;
   1.253 +    },
   1.254 +    todoMismatch: [],
   1.255 +  },
   1.256 +  { description: "WidgetMouseEvent (click of middle button with Shift)",
   1.257 +    // XXX I'm not sure why middle click event isn't fired on button element.
   1.258 +    targetID: "input-text", eventType: "click",
   1.259 +    dispatchEvent: function () {
   1.260 +      document.getElementById(this.targetID).value = "";
   1.261 +      synthesizeMouseAtCenter(document.getElementById(this.targetID),
   1.262 +                              { button: 1, shiftKey: true, pressure: 0.5 });
   1.263 +    },
   1.264 +    canRun: function () {
   1.265 +      return true;
   1.266 +    },
   1.267 +    todoMismatch: [],
   1.268 +  },
   1.269 +  { description: "WidgetMouseEvent (mouseup of right button with Alt)",
   1.270 +    targetID: "button", eventType: "mouseup",
   1.271 +    dispatchEvent: function () {
   1.272 +      document.getElementById(this.targetID).value = "";
   1.273 +      synthesizeMouseAtCenter(document.getElementById(this.targetID),
   1.274 +                              { button: 2, altKey: true });
   1.275 +    },
   1.276 +    canRun: function () {
   1.277 +      return true;
   1.278 +    },
   1.279 +    todoMismatch: [],
   1.280 +  },
   1.281 +  { description: "WidgetDragEvent",
   1.282 +    targetID: "input-text", eventType: "dragstart",
   1.283 +    dispatchEvent: function () {
   1.284 +      return;
   1.285 +    },
   1.286 +    canRun: function () {
   1.287 +      todo(false, "WidgetDragEvent isn't tested");
   1.288 +      return false;
   1.289 +    },
   1.290 +    todoMismatch: [],
   1.291 +  },
   1.292 +  { description: "WidgetTextEvent (text)",
   1.293 +    targetID: "input-text", eventType: "text",
   1.294 +    dispatchEvent: function () {
   1.295 +      document.getElementById(this.targetID).value = "";
   1.296 +      document.getElementById(this.targetID).focus();
   1.297 +      synthesizeComposition({ type: "compositionstart" });
   1.298 +      synthesizeComposition({ type: "compositionupdate", data: "\u306D" });
   1.299 +      synthesizeText({ "composition":
   1.300 +        { "string": "\u306D",
   1.301 +          "clauses":
   1.302 +          [
   1.303 +            { "length": 0, "attr": 0 }
   1.304 +          ]
   1.305 +        },
   1.306 +        "caret": { "start": 1, "length": 0 }
   1.307 +      });
   1.308 +      synthesizeComposition({ type: "compositionend", data: "\u732B" });
   1.309 +    },
   1.310 +    canRun: function () {
   1.311 +      return true;
   1.312 +    },
   1.313 +    todoMismatch: [ ],
   1.314 +  },
   1.315 +  { description: "WidgetCompositionEvent (compositionupdate)",
   1.316 +    targetID: "input-text", eventType: "compositionupdate",
   1.317 +    dispatchEvent: function () {
   1.318 +      document.getElementById(this.targetID).value = "";
   1.319 +      document.getElementById(this.targetID).focus();
   1.320 +      synthesizeComposition({ type: "compositionstart" });
   1.321 +      synthesizeComposition({ type: "compositionupdate", data: "\u30E9\u30FC\u30E1\u30F3" });
   1.322 +      synthesizeText({ "composition":
   1.323 +        { "string": "\u30E9\u30FC\u30E1\u30F3",
   1.324 +          "clauses":
   1.325 +          [
   1.326 +            { "length": 0, "attr": 0 }
   1.327 +          ]
   1.328 +        },
   1.329 +        "caret": { "start": 4, "length": 0 }
   1.330 +      });
   1.331 +      synthesizeComposition({ type: "compositionend", data: "\u30E9\u30FC\u30E1\u30F3" });
   1.332 +    },
   1.333 +    canRun: function () {
   1.334 +      return true;
   1.335 +    },
   1.336 +    todoMismatch: [ ],
   1.337 +  },
   1.338 +  { description: "InternalEditorInputEvent (input at key input)",
   1.339 +    targetID: "input-text", eventType: "input",
   1.340 +    dispatchEvent: function () {
   1.341 +      document.getElementById(this.targetID).value = "";
   1.342 +      document.getElementById(this.targetID).focus();
   1.343 +      synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_B : MAC_VK_ANSI_B,
   1.344 +                          { shiftKey: true }, "B", "B");
   1.345 +    },
   1.346 +    canRun: function () {
   1.347 +      return (kIsMac || kIsWin);
   1.348 +    },
   1.349 +    todoMismatch: [],
   1.350 +  },
   1.351 +  { description: "InternalEditorInputEvent (input at composing)",
   1.352 +    targetID: "input-text", eventType: "input",
   1.353 +    dispatchEvent: function () {
   1.354 +      document.getElementById(this.targetID).value = "";
   1.355 +      document.getElementById(this.targetID).focus();
   1.356 +      synthesizeComposition({ type: "compositionstart" });
   1.357 +      synthesizeComposition({ type: "compositionupdate", data: "\u30E9\u30FC\u30E1\u30F3" });
   1.358 +      synthesizeText({ "composition":
   1.359 +        { "string": "\u30E9\u30FC\u30E1\u30F3",
   1.360 +          "clauses":
   1.361 +          [
   1.362 +            { "length": 4, "attr": COMPOSITION_ATTR_RAWINPUT }
   1.363 +          ]
   1.364 +        },
   1.365 +        "caret": { "start": 4, "length": 0 }
   1.366 +      });
   1.367 +    },
   1.368 +    canRun: function () {
   1.369 +      return true;
   1.370 +    },
   1.371 +    todoMismatch: [ ],
   1.372 +  },
   1.373 +  { description: "InternalEditorInputEvent (input at committing)",
   1.374 +    targetID: "input-text", eventType: "input",
   1.375 +    dispatchEvent: function () {
   1.376 +      synthesizeText({ "composition":
   1.377 +        { "string": "\u30E9\u30FC\u30E1\u30F3",
   1.378 +          "clauses":
   1.379 +          [
   1.380 +            { "length": 0, "attr": 0 }
   1.381 +          ]
   1.382 +        },
   1.383 +        "caret": { "start": 4, "length": 0 }
   1.384 +      });
   1.385 +      synthesizeComposition({ type: "compositionend", data: "\u30E9\u30FC\u30E1\u30F3" });
   1.386 +    },
   1.387 +    canRun: function () {
   1.388 +      return true;
   1.389 +    },
   1.390 +    todoMismatch: [ ],
   1.391 +  },
   1.392 +  { description: "WidgetMouseScrollEvent (DOMMouseScroll, vertical)",
   1.393 +    targetID: "input-text", eventType: "DOMMouseScroll",
   1.394 +    dispatchEvent: function () {
   1.395 +      document.getElementById(this.targetID).value = "";
   1.396 +      synthesizeWheel(document.getElementById(this.targetID), 3, 4,
   1.397 +                      { deltaY: 30, lineOrPageDeltaY: 2 });
   1.398 +    },
   1.399 +    canRun: function () {
   1.400 +      return true;
   1.401 +    },
   1.402 +    todoMismatch: [ ],
   1.403 +  },
   1.404 +  { description: "WidgetMouseScrollEvent (DOMMouseScroll, horizontal)",
   1.405 +    targetID: "input-text", eventType: "DOMMouseScroll",
   1.406 +    dispatchEvent: function () {
   1.407 +      document.getElementById(this.targetID).value = "";
   1.408 +      synthesizeWheel(document.getElementById(this.targetID), 4, 5,
   1.409 +                      { deltaX: 30, lineOrPageDeltaX: 2, shiftKey: true });
   1.410 +    },
   1.411 +    canRun: function () {
   1.412 +      return true;
   1.413 +    },
   1.414 +    todoMismatch: [ ],
   1.415 +  },
   1.416 +  { description: "WidgetMouseScrollEvent (MozMousePixelScroll, vertical)",
   1.417 +    targetID: "input-text", eventType: "MozMousePixelScroll",
   1.418 +    dispatchEvent: function () {
   1.419 +      document.getElementById(this.targetID).value = "";
   1.420 +      synthesizeWheel(document.getElementById(this.targetID), 3, 4,
   1.421 +                      { deltaY: 20, lineOrPageDeltaY: 1, altKey: true });
   1.422 +    },
   1.423 +    canRun: function () {
   1.424 +      return true;
   1.425 +    },
   1.426 +    todoMismatch: [ ],
   1.427 +  },
   1.428 +  { description: "WidgetMouseScrollEvent (MozMousePixelScroll, horizontal)",
   1.429 +    targetID: "input-text", eventType: "MozMousePixelScroll",
   1.430 +    dispatchEvent: function () {
   1.431 +      document.getElementById(this.targetID).value = "";
   1.432 +      synthesizeWheel(document.getElementById(this.targetID), 4, 5,
   1.433 +                      { deltaX: 20, lineOrPageDeltaX: 1, ctrlKey: true });
   1.434 +    },
   1.435 +    canRun: function () {
   1.436 +      return true;
   1.437 +    },
   1.438 +    todoMismatch: [ ],
   1.439 +  },
   1.440 +  { description: "WidgetWheelEvent (wheel, vertical)",
   1.441 +    targetID: "input-text", eventType: "wheel",
   1.442 +    dispatchEvent: function () {
   1.443 +      document.getElementById(this.targetID).value = "";
   1.444 +      synthesizeWheel(document.getElementById(this.targetID), 3, 4,
   1.445 +                      { deltaY: 20, lineOrPageDeltaY: 1, altKey: true });
   1.446 +    },
   1.447 +    canRun: function () {
   1.448 +      return true;
   1.449 +    },
   1.450 +    todoMismatch: [ ],
   1.451 +  },
   1.452 +  { description: "WidgetWheelEvent (wheel, horizontal)",
   1.453 +    targetID: "input-text", eventType: "wheel",
   1.454 +    dispatchEvent: function () {
   1.455 +      document.getElementById(this.targetID).value = "";
   1.456 +      synthesizeWheel(document.getElementById(this.targetID), 4, 5,
   1.457 +                      { deltaX: 20, lineOrPageDeltaX: 1, ctrlKey: true });
   1.458 +    },
   1.459 +    canRun: function () {
   1.460 +      return true;
   1.461 +    },
   1.462 +    todoMismatch: [ ],
   1.463 +  },
   1.464 +  { description: "WidgetWheelEvent (wheel, both)",
   1.465 +    targetID: "input-text", eventType: "wheel",
   1.466 +    dispatchEvent: function () {
   1.467 +      document.getElementById(this.targetID).value = "";
   1.468 +      synthesizeWheel(document.getElementById(this.targetID), 4, 5,
   1.469 +                      { deltaX: 20, deltaY: 10,
   1.470 +                        lineOrPageDeltaX: 1, lineOrPageDeltaY: 1 });
   1.471 +    },
   1.472 +    canRun: function () {
   1.473 +      return true;
   1.474 +    },
   1.475 +    todoMismatch: [ ],
   1.476 +  },
   1.477 +  { description: "WidgetTouchEvent (touchstart)",
   1.478 +    target: function () { return document; }, eventType: "touchstart",
   1.479 +    dispatchEvent: function () {
   1.480 +      synthesizeTouchAtPoint(1, 2, { id: 10, rx: 4, ry: 3, angle: 0, force: 1, shiftKey: true});
   1.481 +    },
   1.482 +    canRun: function () {
   1.483 +      return true;
   1.484 +    },
   1.485 +    todoMismatch: [ ],
   1.486 +  },
   1.487 +  { description: "WidgetTouchEvent (touchend)",
   1.488 +    target: function () { return document; }, eventType: "touchend",
   1.489 +    dispatchEvent: function () {
   1.490 +      synthesizeTouchAtPoint(4, 6, { id: 5, rx: 1, ry: 2, angle: 0.5, force: 0.8, ctrlKey: true});
   1.491 +    },
   1.492 +    canRun: function () {
   1.493 +      return true;
   1.494 +    },
   1.495 +    todoMismatch: [ ],
   1.496 +  },
   1.497 +  { description: "InternalFormEvent (reset)",
   1.498 +    targetID: "form", eventType: "reset",
   1.499 +    dispatchEvent: function () {
   1.500 +      document.getElementById("form").reset();
   1.501 +    },
   1.502 +    canRun: function () {
   1.503 +      return true;
   1.504 +    },
   1.505 +    todoMismatch: [ ],
   1.506 +  },
   1.507 +  { description: "WidgetCommandEvent",
   1.508 +    targetID: "input-text", eventType: "",
   1.509 +    dispatchEvent: function () {
   1.510 +      return;
   1.511 +    },
   1.512 +    canRun: function () {
   1.513 +      todo(false, "WidgetCommandEvent isn't tested");
   1.514 +      return false;
   1.515 +    },
   1.516 +    todoMismatch: [],
   1.517 +  },
   1.518 +  { description: "InternalClipboardEvent (copy)",
   1.519 +    targetID: "input-text", eventType: "copy",
   1.520 +    dispatchEvent: function () {
   1.521 +      document.getElementById("input-text").value = "go to clipboard!";
   1.522 +      document.getElementById("input-text").focus();
   1.523 +      document.getElementById("input-text").select();
   1.524 +      synthesizeKey("c", { accelKey: true });
   1.525 +    },
   1.526 +    canRun: function () {
   1.527 +      return true;
   1.528 +    },
   1.529 +    todoMismatch: [ ],
   1.530 +  },
   1.531 +  { description: "InternalUIEvent (DOMActivate)",
   1.532 +    targetID: "button", eventType: "DOMActivate",
   1.533 +    dispatchEvent: function () {
   1.534 +      synthesizeMouseAtCenter(document.getElementById(this.targetID),
   1.535 +                              { button: 0, shiftKey: true });
   1.536 +    },
   1.537 +    canRun: function () {
   1.538 +      return true;
   1.539 +    },
   1.540 +    todoMismatch: [],
   1.541 +  },
   1.542 +  { description: "InternalFocusEvent (focus)",
   1.543 +    targetID: "input-text", eventType: "focus",
   1.544 +    dispatchEvent: function () {
   1.545 +      document.getElementById(this.targetID).focus();
   1.546 +    },
   1.547 +    canRun: function () {
   1.548 +      return true;
   1.549 +    },
   1.550 +    todoMismatch: [],
   1.551 +  },
   1.552 +  { description: "InternalFocusEvent (blur)",
   1.553 +    targetID: "input-text", eventType: "blur",
   1.554 +    dispatchEvent: function () {
   1.555 +      document.getElementById(this.targetID).blur();
   1.556 +    },
   1.557 +    canRun: function () {
   1.558 +      return true;
   1.559 +    },
   1.560 +    todoMismatch: [],
   1.561 +  },
   1.562 +  { description: "WidgetSimpleGestureEvent",
   1.563 +    targetID: "", eventType: "",
   1.564 +    dispatchEvent: function () {
   1.565 +      return;
   1.566 +    },
   1.567 +    canRun: function () {
   1.568 +      // Simple gesture event may be handled before it comes content.
   1.569 +      // So, we cannot test it in this test.
   1.570 +      todo(false, "WidgetSimpleGestureEvent isn't tested");
   1.571 +      return false;
   1.572 +    },
   1.573 +    todoMismatch: [],
   1.574 +  },
   1.575 +  { description: "InternalTransitionEvent (transitionend)",
   1.576 +    targetID: "a", eventType: "transitionend",
   1.577 +    dispatchEvent: function () {
   1.578 +      document.getElementById(this.targetID).focus();
   1.579 +    },
   1.580 +    canRun: function () {
   1.581 +      return true;
   1.582 +    },
   1.583 +    todoMismatch: [],
   1.584 +  },
   1.585 +  { description: "InternalAnimationEvent (animationend)",
   1.586 +    targetID: "animated-div", eventType: "animationend",
   1.587 +    dispatchEvent: function () {
   1.588 +      document.getElementById(this.targetID).className = "slidin";
   1.589 +    },
   1.590 +    canRun: function () {
   1.591 +      return true;
   1.592 +    },
   1.593 +    todoMismatch: [],
   1.594 +  },
   1.595 +  { description: "InternalMutationEvent (DOMAttrModified)",
   1.596 +    targetID: "animated-div", eventType: "DOMAttrModified",
   1.597 +    dispatchEvent: function () {
   1.598 +      document.getElementById(this.targetID).setAttribute("x-data", "foo");
   1.599 +    },
   1.600 +    canRun: function () {
   1.601 +      return true;
   1.602 +    },
   1.603 +    todoMismatch: [],
   1.604 +  },
   1.605 +  { description: "InternalMutationEvent (DOMNodeInserted)",
   1.606 +    targetID: "animated-div", eventType: "DOMNodeInserted",
   1.607 +    dispatchEvent: function () {
   1.608 +      var div = document.createElement("div");
   1.609 +      div.id = "inserted-div";
   1.610 +      document.getElementById("animated-div").appendChild(div);
   1.611 +    },
   1.612 +    canRun: function () {
   1.613 +      return true;
   1.614 +    },
   1.615 +    todoMismatch: [],
   1.616 +  },
   1.617 +  { description: "InternalMutationEvent (DOMNodeRemoved)",
   1.618 +    targetID: "animated-div", eventType: "DOMNodeRemoved",
   1.619 +    dispatchEvent: function () {
   1.620 +      document.getElementById("animated-div").removeChild(document.getElementById("inserted-div"));
   1.621 +    },
   1.622 +    canRun: function () {
   1.623 +      return true;
   1.624 +    },
   1.625 +    todoMismatch: [],
   1.626 +  },
   1.627 +];
   1.628 +
   1.629 +function doTest(aTest)
   1.630 +{
   1.631 +  if (!aTest.canRun()) {
   1.632 +    SimpleTest.executeSoon(runNextTest);
   1.633 +    return;
   1.634 +  }
   1.635 +  gEvent = null;
   1.636 +  gCopiedEvent = [];
   1.637 +  var target = aTest.target ? aTest.target() : document.getElementById(aTest.targetID);
   1.638 +  target.addEventListener(aTest.eventType, onEvent, true);
   1.639 +  gCallback = function () {
   1.640 +    var description = aTest.description + " (gCallPreventDefault=" + gCallPreventDefault + ")";
   1.641 +    target.removeEventListener(aTest.eventType, onEvent, true);
   1.642 +    ok(gEvent !== null, description + ": failed to get duplicated event");
   1.643 +    ok(gCopiedEvent.length > 0, description + ": count of attribute of the event must be larger than 0");
   1.644 +    for (var i = 0; i < gCopiedEvent.length; ++i) {
   1.645 +      var name = gCopiedEvent[i].name;
   1.646 +      if (name == "rangeOffset") {
   1.647 +        todo(false, description + ": " + name + " attribute value is never reset (" + gEvent[name] + ")");
   1.648 +      } else if (name == "eventPhase") {
   1.649 +        is(gEvent[name], 0, description + ": mismatch with fixed value (" + name + ")");
   1.650 +      } else if (name == "rangeParent" || name == "currentTarget") {
   1.651 +        is(gEvent[name], null, description + ": mismatch with fixed value (" + name + ")");
   1.652 +      } else if (aTest.todoMismatch.indexOf(name) >= 0) {
   1.653 +        todo_is(gEvent[name], gCopiedEvent[i].value, description + ": mismatch (" + name + ")");
   1.654 +      } else {
   1.655 +        is(gEvent[name], gCopiedEvent[i].value, description + ": mismatch (" + name + ")");
   1.656 +      }
   1.657 +    }
   1.658 +    runNextTest();
   1.659 +  };
   1.660 +  aTest.dispatchEvent();
   1.661 +}
   1.662 +
   1.663 +var gIndex = -1;
   1.664 +function runNextTest()
   1.665 +{
   1.666 +  if (++gIndex == kTests.length) {
   1.667 +    if (gCallPreventDefault) {
   1.668 +      finish();
   1.669 +      return;
   1.670 +    }
   1.671 +    // Test with a call of preventDefault() of the events.
   1.672 +    gCallPreventDefault = true;
   1.673 +    gIndex = -1;
   1.674 +    // Restoring the initial state of all elements.
   1.675 +    document.getElementById("scrollable-div").style.height = "30px";
   1.676 +    document.getElementById("scrollable-div").style.width = "30px";
   1.677 +    document.getElementById("scrolled-div").style.height = "10px";
   1.678 +    document.getElementById("scrolled-div").style.width = "10px";
   1.679 +    document.getElementById("input-text").value = "";
   1.680 +    document.getElementById("animated-div").className = "";
   1.681 +    document.getElementById("animated-div").removeAttribute("x-data");
   1.682 +    if (document.activeElement) {
   1.683 +      document.activeElement.blur();
   1.684 +    }
   1.685 +    window.requestAnimationFrame(function () {
   1.686 +      setTimeout(runNextTest, 0);
   1.687 +    });
   1.688 +    return;
   1.689 +  }
   1.690 +  doTest(kTests[gIndex]);
   1.691 +}
   1.692 +
   1.693 +function init()
   1.694 +{
   1.695 +  SpecialPowers.setBoolPref("middlemouse.contentLoadURL", false);
   1.696 +  SpecialPowers.setBoolPref("middlemouse.paste", false);
   1.697 +  SpecialPowers.setBoolPref("general.autoScroll", false);
   1.698 +  SpecialPowers.setIntPref("mousewheel.default.action", 0);
   1.699 +  SpecialPowers.setIntPref("mousewheel.default.action.override_x", -1);
   1.700 +  SpecialPowers.setIntPref("mousewheel.with_shift.action", 0);
   1.701 +  SpecialPowers.setIntPref("mousewheel.with_shift.action.override_x", -1);
   1.702 +  SpecialPowers.setIntPref("mousewheel.with_control.action", 0);
   1.703 +  SpecialPowers.setIntPref("mousewheel.with_control.action.override_x", -1);
   1.704 +  SpecialPowers.setIntPref("mousewheel.with_alt.action", 0);
   1.705 +  SpecialPowers.setIntPref("mousewheel.with_alt.action.override_x", -1);
   1.706 +  SpecialPowers.setIntPref("mousewheel.with_meta.action", 0);
   1.707 +  SpecialPowers.setIntPref("mousewheel.with_meta.action.override_x", -1);
   1.708 +
   1.709 +  runNextTest();
   1.710 +}
   1.711 +
   1.712 +function finish()
   1.713 +{
   1.714 +  SpecialPowers.clearUserPref("middlemouse.contentLoadURL");
   1.715 +  SpecialPowers.clearUserPref("middlemouse.paste");
   1.716 +  SpecialPowers.clearUserPref("general.autoScroll");
   1.717 +  SpecialPowers.clearUserPref("mousewheel.default.action");
   1.718 +  SpecialPowers.clearUserPref("mousewheel.default.action.override_x");
   1.719 +  SpecialPowers.clearUserPref("mousewheel.with_shift.action");
   1.720 +  SpecialPowers.clearUserPref("mousewheel.with_shift.action.override_x");
   1.721 +  SpecialPowers.clearUserPref("mousewheel.with_control.action");
   1.722 +  SpecialPowers.clearUserPref("mousewheel.with_control.action.override_x");
   1.723 +  SpecialPowers.clearUserPref("mousewheel.with_alt.action");
   1.724 +  SpecialPowers.clearUserPref("mousewheel.with_alt.action.override_x");
   1.725 +  SpecialPowers.clearUserPref("mousewheel.with_meta.action");
   1.726 +  SpecialPowers.clearUserPref("mousewheel.with_meta.action.override_x");
   1.727 +
   1.728 +  SimpleTest.finish();
   1.729 +}
   1.730 +
   1.731 +SimpleTest.waitForFocus(init);
   1.732 +
   1.733 +</script>
   1.734 +</body>

mercurial