dom/browser-element/mochitest/browserElement_SendEvent.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 /* Any copyright is dedicated to the public domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // Test that sendMouseEvent dispatch events.
     5 "use strict";
     7 SimpleTest.waitForExplicitFinish();
     8 browserElementTestHelpers.setEnabledPref(true);
     9 browserElementTestHelpers.addPermission();
    11 function runTest() {
    12   var iframe = document.createElement("iframe");
    13   SpecialPowers.wrap(iframe).mozbrowser = true;
    14   document.body.appendChild(iframe);
    16   iframe.addEventListener("mozbrowserloadend", function onloadend(e) {
    17     iframe.sendMouseEvent("mousedown", 10, 10, 0, 1, 0);
    18   });
    20   iframe.addEventListener("mozbrowserlocationchange", function onlocchange(e) {
    21     var a = document.createElement("a");
    22     a.href = e.detail;
    24     switch (a.hash) {
    25       case "#mousedown":
    26         ok(true, "Receive a mousedown event.");
    27         iframe.sendMouseEvent("mousemove", 10, 10, 0, 0, 0);
    28         break;
    29       case "#mousemove":
    30         ok(true, "Receive a mousemove event.");
    31         iframe.sendMouseEvent("mouseup", 10, 10, 0, 1, 0);
    32         break;
    33       case "#mouseup":
    34         ok(true, "Receive a mouseup event.");
    35         break;
    36       case "#click":
    37         ok(true, "Receive a click event.");
    38         if (SpecialPowers.getIntPref("dom.w3c_touch_events.enabled") != 0) {
    39           iframe.sendTouchEvent("touchstart", [1], [10], [10], [2], [2],
    40                                 [20], [0.5], 1, 0);
    41         } else {
    42           iframe.removeEventListener('mozbrowserlocationchange', onlocchange);
    43           SimpleTest.finish();
    44         }
    45         break;
    46       case "#touchstart":
    47         ok(true, "Receive a touchstart event.");
    48         iframe.sendTouchEvent("touchmove", [1], [10], [10], [2], [2],
    49                               [20], [0.5], 1, 0);
    50       case "#touchmove":
    51         ok(true, "Receive a touchmove event.");
    52         iframe.sendTouchEvent("touchend", [1], [10], [10], [2], [2],
    53                               [20], [0.5], 1, 0);
    54         break;
    55       case "#touchend":
    56         ok(true, "Receive a touchend event.");
    57         iframe.sendTouchEvent("touchcancel", [1], [10], [10], [2], [2],
    58                               [20], [0.5], 1, 0);
    59         iframe.removeEventListener('mozbrowserlocationchange', onlocchange);
    60         SimpleTest.finish();
    61         break;
    62     }
    63   });
    65   iframe.src = "data:text/html,<html><body>" +
    66                "<button>send[Mouse|Touch]Event</button>" +
    67                "</body><script>" +
    68                "function changeHash(e) {" +
    69                "  document.location.hash = e.type;" +
    70                "};" +
    71                "window.addEventListener('mousedown', changeHash);" +
    72                "window.addEventListener('mousemove', changeHash);" +
    73                "window.addEventListener('mouseup', changeHash);" +
    74                "window.addEventListener('click', changeHash, true);" +
    75                "window.addEventListener('touchstart', changeHash);" +
    76                "window.addEventListener('touchmove', changeHash);" +
    77                "window.addEventListener('touchend', changeHash);" +
    78                "window.addEventListener('touchcancel', changeHash);" +
    79                "</script></html>";
    81 }
    83 addEventListener('testready', runTest);

mercurial