Bug 1375816 - Part 4: VRController displayId attribute testcase; r=kip
☠☠ backed out by c9b485a4cec3 ☠ ☠
authorDaosheng Mu <daoshengmu@gmail.com>
Fri, 14 Jul 2017 17:08:15 +0800
changeset 369297 73619b7ce23dcd8560f9a1b058952afde8752c08
parent 369296 dd09fc501f90117a86b0230e8f5d3fa9c5755893
child 369298 287b244e6087f0dd3ef04dfc028f15110a06d5fb
push id46634
push userdmu@mozilla.com
push dateTue, 18 Jul 2017 01:45:22 +0000
treeherderautoland@73619b7ce23d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskip
bugs1375816
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1375816 - Part 4: VRController displayId attribute testcase; r=kip MozReview-Commit-ID: KkMXsTDRnQO
dom/vr/test/mochitest/VRSimulationDriver.js
dom/vr/test/mochitest/mochitest.ini
dom/vr/test/mochitest/test_vrController_displayId.html
dom/vr/test/mochitest/test_vrDisplay_getFrameData.html
gfx/vr/VRManager.h
gfx/vr/gfxVRPuppet.cpp
gfx/vr/gfxVRPuppet.h
gfx/vr/ipc/VRManagerParent.cpp
--- a/dom/vr/test/mochitest/VRSimulationDriver.js
+++ b/dom/vr/test/mochitest/VRSimulationDriver.js
@@ -36,22 +36,32 @@ var SetEyeParameter = function(eye, offs
 var SetMountState = function(isMounted) {
   vrMockDisplay.setMountState(isMounted);
 }
 
 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,
   SetEyeResolution: SetEyeResolution,
   SetEyeParameter: SetEyeParameter,
   SetMountState: SetMountState,
   UpdateVRDisplay: UpdateVRDisplay,
+  AttachVRController: AttachVRController,
 
   none: false
 };
 
 return API;
 
 }());
\ No newline at end of file
--- a/dom/vr/test/mochitest/mochitest.ini
+++ b/dom/vr/test/mochitest/mochitest.ini
@@ -1,15 +1,18 @@
 [DEFAULT]
 support-files =
   VRSimulationDriver.js
   requestPresent.js
   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]
 skip-if = (os != "win" && release_or_beta) # Enable Linux after Bug 1310655
 [test_vrDisplay_getFrameData.html]
 skip-if = (os != "win" && release_or_beta) # Enable Linux after Bug 1310655
 [test_vrDisplay_onvrdisplaydeactivate_crosscontent.html]
 skip-if = true
new file mode 100644
--- /dev/null
+++ b/dom/vr/test/mochitest/test_vrController_displayId.html
@@ -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>
\ No newline at end of file
--- a/dom/vr/test/mochitest/test_vrDisplay_getFrameData.html
+++ b/dom/vr/test/mochitest/test_vrDisplay_getFrameData.html
@@ -7,23 +7,21 @@
     <script src="/resources/testharnessreport.js"></script>
     <script src="VRSimulationDriver.js"></script>
     <script src="WebVRHelpers.js"></script>
     <script src="requestPresent.js"></script>
     <script src="runVRTest.js"></script>
 </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(() => {
               VRSimulationDriver.SetEyeResolution(1332, 1586);
               VRSimulationDriver.SetEyeParameter("left", -0.029, 0, 0, 41.65, 35.57, 48.00, 43.97);
               VRSimulationDriver.SetEyeParameter("right", 0.029, 0, 0, 41.65, 43.97, 48.00, 35.57);
               var poseOrient = new Float32Array([-0.188, -0.007, 0.045, -0.980]);
               var posePos = new Float32Array([-0.161, 0.076, -0.250]);
--- a/gfx/vr/VRManager.h
+++ b/gfx/vr/VRManager.h
@@ -32,16 +32,17 @@ public:
   static VRManager* Get();
 
   void AddVRManagerParent(VRManagerParent* aVRManagerParent);
   void RemoveVRManagerParent(VRManagerParent* aVRManagerParent);
 
   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);
   RefPtr<gfx::VRDisplayHost> GetDisplay(const uint32_t& aDisplayID);
   void GetVRDisplayInfo(nsTArray<VRDisplayInfo>& aDisplayInfo);
 
   void SubmitFrame(VRLayerParent* aLayer, layers::PTextureParent* aTexture,
                    const gfx::Rect& aLeftEyeRect,
@@ -62,17 +63,16 @@ protected:
 private:
   RefPtr<layers::TextureHost> mLastFrame;
 
   void Init();
   void Destroy();
   void Shutdown();
 
   void DispatchVRDisplayInfoUpdate();
-  void RefreshVRControllers();
 
   typedef nsTHashtable<nsRefPtrHashKey<VRManagerParent>> VRManagerParentSet;
   VRManagerParentSet mVRManagerParents;
 
   typedef nsTArray<RefPtr<VRSystemManager>> VRSystemManagerArray;
   VRSystemManagerArray mManagers;
 
   typedef nsRefPtrHashtable<nsUint32HashKey, gfx::VRDisplayHost> VRDisplayHostHashMap;
--- a/gfx/vr/gfxVRPuppet.cpp
+++ b/gfx/vr/gfxVRPuppet.cpp
@@ -487,24 +487,22 @@ void
 VRDisplayPuppet::NotifyVSync()
 {
   // We update mIsConneced once per frame.
   mDisplayInfo.mIsConnected = true;
 
   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;
 }
 
 VRControllerPuppet::~VRControllerPuppet()
 {
   MOZ_COUNT_DTOR_INHERITED(VRControllerPuppet, VRControllerHost);
@@ -735,27 +733,33 @@ VRSystemManagerPuppet::GetControllers(ns
   for (uint32_t i = 0; i < mPuppetController.Length(); ++i) {
     aControllerResult.AppendElement(mPuppetController[i]);
   }
 }
 
 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;
 
   if (newControllerCount != mControllerCount) {
     RemoveControllers();
 
     // Re-adding controllers to VRControllerManager.
     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.
       AddGamepad(puppetController->GetControllerInfo());
       ++mControllerCount;
     }
   }
 }
--- a/gfx/vr/gfxVRPuppet.h
+++ b/gfx/vr/gfxVRPuppet.h
@@ -66,17 +66,17 @@ private:
 #endif
 
   VRHMDSensorState mSensorState;
 };
 
 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);
   uint64_t GetButtonTouchState();
   void SetAxisMoveState(uint32_t aAxis, double aValue);
   double GetAxisMoveState(uint32_t aAxis);
   void SetPoseMoveState(const dom::GamepadPoseState& aPose);
   const dom::GamepadPoseState& GetPoseMoveState();
--- a/gfx/vr/ipc/VRManagerParent.cpp
+++ b/gfx/vr/ipc/VRManagerParent.cpp
@@ -305,16 +305,18 @@ VRManagerParent::RecvControllerListenerR
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 VRManagerParent::RecvCreateVRTestSystem()
 {
   VRManager* vm = VRManager::Get();
   vm->CreateVRTestSystem();
+  mDisplayTestID = 0;
+  mControllerTestID = 0;
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 VRManagerParent::RecvCreateVRServiceTestDisplay(const nsCString& aID, const uint32_t& aPromiseID)
 {
   nsTArray<VRDisplayInfo> displayInfoArray;
   impl::VRDisplayPuppet* displayPuppet = nullptr;
@@ -348,16 +350,20 @@ VRManagerParent::RecvCreateVRServiceTest
 mozilla::ipc::IPCResult
 VRManagerParent::RecvCreateVRServiceTestController(const nsCString& aID, const uint32_t& aPromiseID)
 {
   uint32_t controllerIdx = 0;
   nsTArray<VRControllerInfo> controllerInfoArray;
   impl::VRControllerPuppet* controllerPuppet = nullptr;
   VRManager* vm = VRManager::Get();
 
+  if (mHaveControllerListener) {
+    vm->RefreshVRControllers();
+  }
+
   // Get VRControllerPuppet from VRManager
   vm->GetVRControllerInfo(controllerInfoArray);
   for (auto& controllerInfo : controllerInfoArray) {
     if (controllerInfo.GetType() == VRDeviceType::Puppet) {
       if (controllerIdx == mControllerTestID) {
         controllerPuppet = static_cast<impl::VRControllerPuppet*>(
                            vm->GetController(controllerInfo.GetControllerID()).get());
         break;
@@ -381,65 +387,65 @@ VRManagerParent::RecvCreateVRServiceTest
   return IPC_FAIL(this, "SendReplyCreateVRServiceTestController fail");
 }
 
 mozilla::ipc::IPCResult
 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);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 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);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 VRManagerParent::RecvNewButtonEventToMockController(const uint32_t& aDeviceID, const long& aButton,
                                                     const bool& aPressed)
 {
   RefPtr<impl::VRControllerPuppet> controllerPuppet;
-  mVRControllerTests.Get(mControllerTestID,
+  mVRControllerTests.Get(aDeviceID,
                          getter_AddRefs(controllerPuppet));
   MOZ_ASSERT(controllerPuppet);
   controllerPuppet->SetButtonPressState(aButton, aPressed);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 VRManagerParent::RecvNewAxisMoveEventToMockController(const uint32_t& aDeviceID, const long& aAxis,
                                                       const double& aValue)
 {
   RefPtr<impl::VRControllerPuppet> controllerPuppet;
-  mVRControllerTests.Get(mControllerTestID,
+  mVRControllerTests.Get(aDeviceID,
                          getter_AddRefs(controllerPuppet));
   MOZ_ASSERT(controllerPuppet);
   controllerPuppet->SetAxisMoveState(aAxis, aValue);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 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);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 VRManagerParent::RecvVibrateHaptic(const uint32_t& aControllerIdx,