Bug 1375816 - Part 4: VRController displayId attribute testcase; r=kip

MozReview-Commit-ID: KkMXsTDRnQO

--HG--
extra : rebase_source : d4a91a5e8a33de2f65c4c6ce23dab6ccdab13952
This commit is contained in:
Daosheng Mu 2017-07-14 17:08:15 +08:00
parent 9e15accf51
commit f2d37e1ed5
9 changed files with 89 additions and 18 deletions

View File

@ -41,6 +41,15 @@ var UpdateVRDisplay = function() {
vrMockDisplay.update();
}
var AttachVRController = function() {
var promise = VRServiceTest.attachVRController("VRControllerTest");
promise.then(function (controller) {
assert_true(controller != null, "AttachVRController should success.");
});
return promise;
}
var API = {
AttachWebVRDisplay: AttachWebVRDisplay,
SetVRDisplayPose: SetVRDisplayPose,
@ -48,6 +57,7 @@ var API = {
SetEyeParameter: SetEyeParameter,
SetMountState: SetMountState,
UpdateVRDisplay: UpdateVRDisplay,
AttachVRController: AttachVRController,
none: false
};

View File

@ -5,6 +5,9 @@ support-files =
runVRTest.js
WebVRHelpers.js
[test_vrController_displayId.html]
# Enable Linux after Bug 1310655 # TIMED_OUT for Mac in release nonE10s, and Android.
skip-if = (os != "win" && release_or_beta) || (os == "mac" && !e10s && !debug) || (os == "android")
[test_vrDisplay_canvas2d.html]
skip-if = (os != "win" && release_or_beta) # Enable Linux after Bug 1310655
[test_vrDisplay_exitPresent.html]

View File

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<title>VRController DisplayId</title>
<meta name="timeout" content="long"/>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="VRSimulationDriver.js"></script>
<script src="runVRTest.js"></script>
</head>
<body>
<script>
"use strict";
var vrDisplay;
var controllerCount = 0;
function addController() {
promise_test((test) => {
return VRSimulationDriver.AttachVRController().then((controller) => {
controller.newButtonEvent(0, true);
});
}, "Finish to add VRController.");
}
function listenControllerEvents() {
async_test(function(t) {
window.addEventListener("gamepadconnected", function() {
var gamepads = navigator.getGamepads();
assert_equals(gamepads[controllerCount].displayId, vrDisplay.displayId, "gamepad.displayId should be equal to vrDisplay.");
++controllerCount;
if (controllerCount == 1) {
t.done();
}
});
}, "Finish to verify VRController.displayId.");
}
function startTest() {
promise_test((test) => {
listenControllerEvents();
return navigator.getVRDisplays().then((displays) => {
vrDisplay = displays[0];
assert_equals(displays.length, 1, "displays.length must be one after attach.");
assert_equals(displays[0].displayId, 1, "displayId must be one.");
addController();
});
}, "Finish to add VRDisplay.");
}
runVRTest(startTest);
</script>
</body>
</html>

View File

@ -12,13 +12,11 @@
</head>
<body id="body">
<canvas id="webglCanvas"></canvas>
<div id="testDiv"></div>
<script>
"use strict";
var vrDisplay;
var vrRAF;
var canvas = document.getElementById('webglCanvas');
var div = document.getElementById('testDiv');
function startTest() {
promise_test((test) => {
return attachVRDisplay(test).then(() => {

View File

@ -37,6 +37,7 @@ public:
void NotifyVsync(const TimeStamp& aVsyncTimestamp);
void NotifyVRVsync(const uint32_t& aDisplayID);
void RefreshVRDisplays(bool aMustDispatch = false);
void RefreshVRControllers();
void ScanForControllers();
void RemoveControllers();
template<class T> void NotifyGamepadChange(const T& aInfo);
@ -67,7 +68,6 @@ private:
void Shutdown();
void DispatchVRDisplayInfoUpdate();
void RefreshVRControllers();
typedef nsTHashtable<nsRefPtrHashKey<VRManagerParent>> VRManagerParentSet;
VRManagerParentSet mVRManagerParents;

View File

@ -492,14 +492,12 @@ VRDisplayPuppet::NotifyVSync()
VRDisplayHost::NotifyVSync();
}
VRControllerPuppet::VRControllerPuppet(dom::GamepadHand aHand)
: VRControllerHost(VRDeviceType::Puppet)
VRControllerPuppet::VRControllerPuppet(dom::GamepadHand aHand, uint32_t aDisplayID)
: VRControllerHost(VRDeviceType::Puppet, aHand, aDisplayID)
, mButtonPressState(0)
{
MOZ_COUNT_CTOR_INHERITED(VRControllerPuppet, VRControllerHost);
mControllerInfo.mControllerName.AssignLiteral("Puppet Gamepad");
mControllerInfo.mMappingType = GamepadMappingType::_empty;
mControllerInfo.mHand = aHand;
mControllerInfo.mNumButtons = kNumPuppetButtonMask;
mControllerInfo.mNumAxes = kNumPuppetAxis;
mControllerInfo.mNumHaptics = kNumPuppetHaptcs;
@ -740,6 +738,11 @@ VRSystemManagerPuppet::GetControllers(nsTArray<RefPtr<VRControllerHost>>& aContr
void
VRSystemManagerPuppet::ScanForControllers()
{
// mPuppetHMD is available after VRDisplay is created
// at GetHMDs().
if (!mPuppetHMD) {
return;
}
// We make VRSystemManagerPuppet has two controllers always.
const uint32_t newControllerCount = 2;
@ -750,7 +753,8 @@ VRSystemManagerPuppet::ScanForControllers()
for (uint32_t i = 0; i < newControllerCount; ++i) {
dom::GamepadHand hand = (i % 2) ? dom::GamepadHand::Right :
dom::GamepadHand::Left;
RefPtr<VRControllerPuppet> puppetController = new VRControllerPuppet(hand);
RefPtr<VRControllerPuppet> puppetController = new VRControllerPuppet(hand,
mPuppetHMD->GetDisplayInfo().GetDisplayID());
mPuppetController.AppendElement(puppetController);
// Not already present, add it.

View File

@ -71,7 +71,7 @@ private:
class VRControllerPuppet : public VRControllerHost
{
public:
explicit VRControllerPuppet(dom::GamepadHand aHand);
explicit VRControllerPuppet(dom::GamepadHand aHand, uint32_t aDisplayID);
void SetButtonPressState(uint32_t aButton, bool aPressed);
uint64_t GetButtonPressState();
void SetButtonTouchState(uint32_t aButton, bool aTouched);

View File

@ -310,6 +310,8 @@ VRManagerParent::RecvCreateVRTestSystem()
{
VRManager* vm = VRManager::Get();
vm->CreateVRTestSystem();
mDisplayTestID = 0;
mControllerTestID = 0;
return IPC_OK();
}
@ -353,6 +355,10 @@ VRManagerParent::RecvCreateVRServiceTestController(const nsCString& aID, const u
impl::VRControllerPuppet* controllerPuppet = nullptr;
VRManager* vm = VRManager::Get();
if (mHaveControllerListener) {
vm->RefreshVRControllers();
}
// Get VRControllerPuppet from VRManager
vm->GetVRControllerInfo(controllerInfoArray);
for (auto& controllerInfo : controllerInfoArray) {
@ -386,7 +392,7 @@ VRManagerParent::RecvSetDisplayInfoToMockDisplay(const uint32_t& aDeviceID,
const VRDisplayInfo& aDisplayInfo)
{
RefPtr<impl::VRDisplayPuppet> displayPuppet;
mVRDisplayTests.Get(mDisplayTestID,
mVRDisplayTests.Get(aDeviceID,
getter_AddRefs(displayPuppet));
MOZ_ASSERT(displayPuppet);
displayPuppet->SetDisplayInfo(aDisplayInfo);
@ -398,7 +404,7 @@ VRManagerParent::RecvSetSensorStateToMockDisplay(const uint32_t& aDeviceID,
const VRHMDSensorState& aSensorState)
{
RefPtr<impl::VRDisplayPuppet> displayPuppet;
mVRDisplayTests.Get(mDisplayTestID,
mVRDisplayTests.Get(aDeviceID,
getter_AddRefs(displayPuppet));
MOZ_ASSERT(displayPuppet);
displayPuppet->SetSensorState(aSensorState);
@ -410,7 +416,7 @@ VRManagerParent::RecvNewButtonEventToMockController(const uint32_t& aDeviceID, c
const bool& aPressed)
{
RefPtr<impl::VRControllerPuppet> controllerPuppet;
mVRControllerTests.Get(mControllerTestID,
mVRControllerTests.Get(aDeviceID,
getter_AddRefs(controllerPuppet));
MOZ_ASSERT(controllerPuppet);
controllerPuppet->SetButtonPressState(aButton, aPressed);
@ -422,7 +428,7 @@ VRManagerParent::RecvNewAxisMoveEventToMockController(const uint32_t& aDeviceID,
const double& aValue)
{
RefPtr<impl::VRControllerPuppet> controllerPuppet;
mVRControllerTests.Get(mControllerTestID,
mVRControllerTests.Get(aDeviceID,
getter_AddRefs(controllerPuppet));
MOZ_ASSERT(controllerPuppet);
controllerPuppet->SetAxisMoveState(aAxis, aValue);
@ -434,7 +440,7 @@ VRManagerParent::RecvNewPoseMoveToMockController(const uint32_t& aDeviceID,
const GamepadPoseState& pose)
{
RefPtr<impl::VRControllerPuppet> controllerPuppet;
mVRControllerTests.Get(mControllerTestID,
mVRControllerTests.Get(aDeviceID,
getter_AddRefs(controllerPuppet));
MOZ_ASSERT(controllerPuppet);
controllerPuppet->SetPoseMoveState(pose);

View File

@ -12,7 +12,3 @@
[HTMLIFrameElement interface: attribute allowvr]
expected: FAIL
[Gamepad interface: attribute displayId]
expected: FAIL