1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/browser-element/mochitest/browserElement_SendEvent.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* Any copyright is dedicated to the public domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Test that sendMouseEvent dispatch events. 1.8 +"use strict"; 1.9 + 1.10 +SimpleTest.waitForExplicitFinish(); 1.11 +browserElementTestHelpers.setEnabledPref(true); 1.12 +browserElementTestHelpers.addPermission(); 1.13 + 1.14 +function runTest() { 1.15 + var iframe = document.createElement("iframe"); 1.16 + SpecialPowers.wrap(iframe).mozbrowser = true; 1.17 + document.body.appendChild(iframe); 1.18 + 1.19 + iframe.addEventListener("mozbrowserloadend", function onloadend(e) { 1.20 + iframe.sendMouseEvent("mousedown", 10, 10, 0, 1, 0); 1.21 + }); 1.22 + 1.23 + iframe.addEventListener("mozbrowserlocationchange", function onlocchange(e) { 1.24 + var a = document.createElement("a"); 1.25 + a.href = e.detail; 1.26 + 1.27 + switch (a.hash) { 1.28 + case "#mousedown": 1.29 + ok(true, "Receive a mousedown event."); 1.30 + iframe.sendMouseEvent("mousemove", 10, 10, 0, 0, 0); 1.31 + break; 1.32 + case "#mousemove": 1.33 + ok(true, "Receive a mousemove event."); 1.34 + iframe.sendMouseEvent("mouseup", 10, 10, 0, 1, 0); 1.35 + break; 1.36 + case "#mouseup": 1.37 + ok(true, "Receive a mouseup event."); 1.38 + break; 1.39 + case "#click": 1.40 + ok(true, "Receive a click event."); 1.41 + if (SpecialPowers.getIntPref("dom.w3c_touch_events.enabled") != 0) { 1.42 + iframe.sendTouchEvent("touchstart", [1], [10], [10], [2], [2], 1.43 + [20], [0.5], 1, 0); 1.44 + } else { 1.45 + iframe.removeEventListener('mozbrowserlocationchange', onlocchange); 1.46 + SimpleTest.finish(); 1.47 + } 1.48 + break; 1.49 + case "#touchstart": 1.50 + ok(true, "Receive a touchstart event."); 1.51 + iframe.sendTouchEvent("touchmove", [1], [10], [10], [2], [2], 1.52 + [20], [0.5], 1, 0); 1.53 + case "#touchmove": 1.54 + ok(true, "Receive a touchmove event."); 1.55 + iframe.sendTouchEvent("touchend", [1], [10], [10], [2], [2], 1.56 + [20], [0.5], 1, 0); 1.57 + break; 1.58 + case "#touchend": 1.59 + ok(true, "Receive a touchend event."); 1.60 + iframe.sendTouchEvent("touchcancel", [1], [10], [10], [2], [2], 1.61 + [20], [0.5], 1, 0); 1.62 + iframe.removeEventListener('mozbrowserlocationchange', onlocchange); 1.63 + SimpleTest.finish(); 1.64 + break; 1.65 + } 1.66 + }); 1.67 + 1.68 + iframe.src = "data:text/html,<html><body>" + 1.69 + "<button>send[Mouse|Touch]Event</button>" + 1.70 + "</body><script>" + 1.71 + "function changeHash(e) {" + 1.72 + " document.location.hash = e.type;" + 1.73 + "};" + 1.74 + "window.addEventListener('mousedown', changeHash);" + 1.75 + "window.addEventListener('mousemove', changeHash);" + 1.76 + "window.addEventListener('mouseup', changeHash);" + 1.77 + "window.addEventListener('click', changeHash, true);" + 1.78 + "window.addEventListener('touchstart', changeHash);" + 1.79 + "window.addEventListener('touchmove', changeHash);" + 1.80 + "window.addEventListener('touchend', changeHash);" + 1.81 + "window.addEventListener('touchcancel', changeHash);" + 1.82 + "</script></html>"; 1.83 + 1.84 +} 1.85 + 1.86 +addEventListener('testready', runTest);