<!-- Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ --><!DOCTYPE HTML><html><head><title>Test gamepad</title><linkrel="stylesheet"type="text/css"href="/tests/SimpleTest/test.css"/></head><body><scripttype="text/javascript"src="mock_gamepad.js"></script><scriptclass="testbody"type="text/javascript">letok=window.parent.ok;letis=window.parent.is;letSimpleTest=window.parent.SimpleTest;letSpecialPowers=window.parent.SpecialPowers;lettests=[touchAdd,touchcheck1,touchAdd,touchcheck2];letgamepad_index;lettestNum=0;lettouchData1=[{touchId:0,surfaceId:0,pos:newFloat32Array([-0.5,0.5]),surf:newFloat32Array([100,100])},{touchId:1,surfaceId:0,pos:newFloat32Array([-0.1,1.0]),surf:newFloat32Array([100,100])}];lettouchData2=[{touchId:2,surfaceId:0,pos:newFloat32Array([-0.2,0.3]),surf:newFloat32Array([120,200])},{touchId:3,surfaceId:0,pos:newFloat32Array([-0.4,0.7]),surf:newFloat32Array([120,200])}];letdata=[touchData1,touchData2];letdataNum=0;window.addEventListener("gamepadconnected",connecthandler);window.addEventListener("gamepadbuttondown",function(){// Wait to ensure that all frames received the button press as well.ok(true,"gamepadbuttondown");SpecialPowers.executeSoon(tests[testNum++]);});asyncfunctionpressButton(){awaitGamepadService.newButtonEvent(gamepad_index,0,true,true);awaitGamepadService.newButtonEvent(gamepad_index,0,false,false);}letframes_loaded=0;asyncfunctionstartTest(){frames_loaded++;letpromise=SpecialPowers.pushPrefEnv({"set":[["dom.gamepad.extensions.enabled",true],["dom.gamepad.extensions.lightindicator",true],["dom.gamepad.extensions.multitouch",true]]});if(frames_loaded==2){awaitpromise;// Add a gamepadgamepad_index=awaitGamepadService.addGamepad("test gamepad",// idGamepadService.standardMapping,GamepadService.leftHand,4,2,1,1,2)awaitgamepad_loaded();}}letf1,f2;asyncfunctiongamepad_loaded(){f1=document.getElementById('f1');f2=document.getElementById('f2');awaitGamepadService.newButtonEvent(gamepad_index,0,true,true);}functionconnecthandler(e){ok(e.gamepad.timestamp<=performance.now(),"gamepad.timestamp should less than or equal to performance.now()");is(e.gamepad.index,0,"correct gamepad index");is(e.gamepad.id,"test gamepad","correct gamepad name");is(e.gamepad.mapping,"standard","standard mapping");is(e.gamepad.hand,"left","left hand");is(e.gamepad.buttons.length,4,"correct number of buttons");is(e.gamepad.axes.length,2,"correct number of axes");is(e.gamepad.hapticActuators.length,1,"correct number of haptics");is(e.gamepad.lightIndicators.length,1,"correct number of light indicators");is(e.gamepad.touchEvents.length,2,"correct number of touches");}functioncheckValueInFloat32Array(array1,array2){if(array1.length!=array2.length){returnfalse;}letindex=0;while(index<array2.length){if(array1[index]!=array2[index]){returnfalse;}++index;}returntrue;}asyncfunctiontouchAdd(){for(letcount=0;count<data[dataNum].length;count++){consttouch=data[dataNum][count];awaitGamepadService.newTouch(gamepad_index,count,touch.touchId,touch.surfaceId,touch.pos,touch.surf);}++dataNum;awaitpressButton();}asyncfunctiontouchcheck1(){lettouches=f1.contentWindow.gamepad.touchEvents;is(touches.length,data[0].length,"f1 number of touches");letcount=0;touches.forEach(function(touch){is(touch.touchId,data[0][count].touchId,"correct GamepadTouch touchId");is(touch.surfaceId,data[0][count].surfaceId,"correct GamepadTouch surfaceId");is(checkValueInFloat32Array(touch.position,data[0][count].pos),true,"correct touch position");is(checkValueInFloat32Array(touch.surfaceDimensions,data[0][count].surf),true,"correct touch surfaceDimensions");++count;});touches=f2.contentWindow.gamepad.touchEvents;is(touches.length,data[0].length,"f2 number of touches");count=0;touches.forEach(function(touch){is(touch.touchId,data[0][count].touchId,"correct GamepadTouch touchId");is(touch.surfaceId,data[0][count].surfaceId,"correct GamepadTouch surfaceId");is(checkValueInFloat32Array(touch.position,data[0][count].pos),true,"correct touch position");is(checkValueInFloat32Array(touch.surfaceDimensions,data[0][count].surf),true,"correct touch surfaceDimensions");++count;});pressButton();}asyncfunctiontouchcheck2(){lettouches=f1.contentWindow.gamepad.touchEvents;is(touches.length,data[1].length,"f1 number of touches");letcount=0;touches.forEach(function(touch){is(touch.touchId,data[1][count].touchId,"correct GamepadTouch touchId");is(touch.surfaceId,data[1][count].surfaceId,"correct GamepadTouch surfaceId");is(checkValueInFloat32Array(touch.position,data[1][count].pos),true,"correct touch position");is(checkValueInFloat32Array(touch.surfaceDimensions,data[1][count].surf),true,"correct touch surfaceDimensions");++count;});touches=f2.contentWindow.gamepad.touchEvents;is(touches.length,data[1].length,"f2 number of touches");count=0;touches.forEach(function(touch){is(touch.touchId,data[1][count].touchId,"correct GamepadTouch touchId");is(touch.surfaceId,data[1][count].surfaceId,"correct GamepadTouch surfaceId");is(checkValueInFloat32Array(touch.position,data[1][count].pos),true,"correct touch position");is(checkValueInFloat32Array(touch.surfaceDimensions,data[1][count].surf),true,"correct touch surfaceDimensions");++count;});SpecialPowers.executeSoon(cleanup);}functioncleanup(){SpecialPowers.executeSoon(asyncfunction(){awaitGamepadService.removeGamepad(gamepad_index);SimpleTest.finish();});}</script><iframeid="f1"src="gamepad_frame_state.html"onload="runGamepadTest(startTest)"></iframe><iframeid="f2"src="gamepad_frame_state.html"onload="runGamepadTest(startTest)"></iframe></body></html>