browser_touch_pointerevents.js (2091B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that simulating touch only dispatches pointer events from a touch event. 7 8 const TEST_URL = 9 "data:text/html;charset=utf-8," + 10 '<div style="width:100px;height:100px;background-color:red"></div>' + 11 "</body>"; 12 13 addRDMTask(TEST_URL, async function ({ ui }) { 14 info("Toggling on touch simulation."); 15 reloadOnTouchChange(true); 16 await toggleTouchSimulation(ui); 17 18 await testPointerEvents(ui); 19 20 info("Toggling off touch simulation."); 21 await toggleTouchSimulation(ui); 22 reloadOnTouchChange(false); 23 }); 24 25 async function testPointerEvents(ui) { 26 info("Test that pointer events are from touch events"); 27 await SpecialPowers.spawn(ui.getViewportBrowser(), [], async function () { 28 const div = content.document.querySelector("div"); 29 30 div.addEventListener("pointermove", () => { 31 div.style["background-color"] = "green"; //rgb(0,128,0) 32 }); 33 div.addEventListener("pointerdown", e => { 34 Assert.strictEqual( 35 e.pointerType, 36 "touch", 37 "Got pointer event from a touch event." 38 ); 39 }); 40 41 info("Check that the pointerdown event is from a touch event."); 42 const pointerDownPromise = ContentTaskUtils.waitForEvent( 43 div, 44 "pointerdown" 45 ); 46 47 await EventUtils.synthesizeMouseAtCenter( 48 div, 49 { type: "mousedown", isSynthesized: false }, 50 content 51 ); 52 await pointerDownPromise; 53 await EventUtils.synthesizeMouseAtCenter( 54 div, 55 { type: "mouseup", isSynthesized: false }, 56 content 57 ); 58 59 info( 60 "Check that a pointermove event was never dispatched from the mousemove event" 61 ); 62 await EventUtils.synthesizeMouseAtCenter( 63 div, 64 { type: "mousemove", isSynthesized: false }, 65 content 66 ); 67 68 const bg = content 69 .getComputedStyle(div) 70 .getPropertyValue("background-color"); 71 72 is( 73 bg, 74 "rgb(255, 0, 0)", 75 `div's background color should still be red: rgb(255, 0, 0): got ${bg}` 76 ); 77 }); 78 }