1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_GamepadServiceTest_h_
8 #define mozilla_dom_GamepadServiceTest_h_
10 #include "mozilla/DOMEventTargetHelper.h"
11 #include "mozilla/dom/GamepadBinding.h"
12 #include "mozilla/dom/GamepadHandle.h"
13 #include "mozilla/dom/TypedArray.h"
14 #include "mozilla/WeakPtr.h"
16 namespace mozilla::dom
{
18 class GamepadChangeEvent
;
20 class GamepadTestChannelChild
;
23 // Service for testing purposes
24 class GamepadServiceTest final
: public DOMEventTargetHelper
,
25 public SupportsWeakPtr
{
27 NS_DECL_ISUPPORTS_INHERITED
28 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GamepadServiceTest
,
31 GamepadMappingType
NoMapping() const { return GamepadMappingType::_empty
; }
32 GamepadMappingType
StandardMapping() const {
33 return GamepadMappingType::Standard
;
35 GamepadHand
NoHand() const { return GamepadHand::_empty
; }
36 GamepadHand
LeftHand() const { return GamepadHand::Left
; }
37 GamepadHand
RightHand() const { return GamepadHand::Right
; }
40 void ReplyGamepadHandle(uint32_t aPromiseId
, const GamepadHandle
& aHandle
);
42 // Methods from GamepadServiceTest.webidl
43 already_AddRefed
<Promise
> AddGamepad(
44 const nsAString
& aID
, GamepadMappingType aMapping
, GamepadHand aHand
,
45 uint32_t aNumButtons
, uint32_t aNumAxes
, uint32_t aNumHaptics
,
46 uint32_t aNumLightIndicator
, uint32_t aNumTouchEvents
, ErrorResult
& aRv
);
48 already_AddRefed
<Promise
> RemoveGamepad(uint32_t aHandleSlot
,
51 already_AddRefed
<Promise
> NewButtonEvent(uint32_t aHandleSlot
,
52 uint32_t aButton
, bool aPressed
,
53 bool aTouched
, ErrorResult
& aRv
);
55 already_AddRefed
<Promise
> NewButtonValueEvent(uint32_t aHandleSlot
,
56 uint32_t aButton
, bool aPressed
,
57 bool aTouched
, double aValue
,
60 already_AddRefed
<Promise
> NewAxisMoveEvent(uint32_t aHandleSlot
,
61 uint32_t aAxis
, double aValue
,
64 already_AddRefed
<Promise
> NewPoseMove(
65 uint32_t aHandleSlot
, const Nullable
<Float32Array
>& aOrient
,
66 const Nullable
<Float32Array
>& aPos
,
67 const Nullable
<Float32Array
>& aAngVelocity
,
68 const Nullable
<Float32Array
>& aAngAcceleration
,
69 const Nullable
<Float32Array
>& aLinVelocity
,
70 const Nullable
<Float32Array
>& aLinAcceleration
, ErrorResult
& aRv
);
72 already_AddRefed
<Promise
> NewTouch(uint32_t aHandleSlot
,
73 uint32_t aTouchArrayIndex
,
74 uint32_t aTouchId
, uint8_t aSurfaceId
,
75 const Float32Array
& aPos
,
76 const Nullable
<Float32Array
>& aSurfDim
,
81 static already_AddRefed
<GamepadServiceTest
> CreateTestService(
82 nsPIDOMWindowInner
* aWindow
);
83 nsPIDOMWindowInner
* GetParentObject() const { return mWindow
; }
84 JSObject
* WrapObject(JSContext
* aCx
,
85 JS::Handle
<JSObject
*> aGivenProto
) override
;
88 // Hold a reference to the gamepad service so we don't have to worry about
89 // execution order in tests.
90 RefPtr
<GamepadManager
> mService
;
91 nsCOMPtr
<nsPIDOMWindowInner
> mWindow
;
92 uint32_t mEventNumber
;
95 // IPDL Channel for us to send test events to GamepadPlatformService, it
96 // will only be used in this singleton class and deleted during the IPDL
98 RefPtr
<GamepadTestChannelChild
> mChild
;
99 nsTArray
<GamepadHandle
> mGamepadHandles
;
101 nsRefPtrHashtable
<nsUint32HashKey
, dom::Promise
> mPromiseList
;
103 explicit GamepadServiceTest(nsPIDOMWindowInner
* aWindow
);
104 ~GamepadServiceTest();
105 void InitPBackgroundActor();
106 void DestroyPBackgroundActor();
108 uint32_t AddGamepadHandle(GamepadHandle aHandle
);
109 void RemoveGamepadHandle(uint32_t aHandleSlot
);
110 GamepadHandle
GetHandleInSlot(uint32_t aHandleSlot
) const;
113 } // namespace mozilla::dom