dom/browser-element/mochitest/browserElement_SendEvent.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial