From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/gamepad/GamepadServiceTest.h | 115 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 dom/gamepad/GamepadServiceTest.h (limited to 'dom/gamepad/GamepadServiceTest.h') diff --git a/dom/gamepad/GamepadServiceTest.h b/dom/gamepad/GamepadServiceTest.h new file mode 100644 index 0000000000..3b88ff178a --- /dev/null +++ b/dom/gamepad/GamepadServiceTest.h @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_GamepadServiceTest_h_ +#define mozilla_dom_GamepadServiceTest_h_ + +#include "mozilla/DOMEventTargetHelper.h" +#include "mozilla/dom/GamepadBinding.h" +#include "mozilla/dom/GamepadHandle.h" +#include "mozilla/dom/TypedArray.h" +#include "mozilla/WeakPtr.h" + +namespace mozilla::dom { + +class GamepadChangeEvent; +class GamepadManager; +class GamepadTestChannelChild; +class Promise; + +// Service for testing purposes +class GamepadServiceTest final : public DOMEventTargetHelper, + public SupportsWeakPtr { + public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GamepadServiceTest, + DOMEventTargetHelper) + + GamepadMappingType NoMapping() const { return GamepadMappingType::_empty; } + GamepadMappingType StandardMapping() const { + return GamepadMappingType::Standard; + } + GamepadHand NoHand() const { return GamepadHand::_empty; } + GamepadHand LeftHand() const { return GamepadHand::Left; } + GamepadHand RightHand() const { return GamepadHand::Right; } + + // IPC receiver + void ReplyGamepadHandle(uint32_t aPromiseId, const GamepadHandle& aHandle); + + // Methods from GamepadServiceTest.webidl + already_AddRefed AddGamepad( + const nsAString& aID, GamepadMappingType aMapping, GamepadHand aHand, + uint32_t aNumButtons, uint32_t aNumAxes, uint32_t aNumHaptics, + uint32_t aNumLightIndicator, uint32_t aNumTouchEvents, ErrorResult& aRv); + + already_AddRefed RemoveGamepad(uint32_t aHandleSlot, + ErrorResult& aRv); + + already_AddRefed NewButtonEvent(uint32_t aHandleSlot, + uint32_t aButton, bool aPressed, + bool aTouched, ErrorResult& aRv); + + already_AddRefed NewButtonValueEvent(uint32_t aHandleSlot, + uint32_t aButton, bool aPressed, + bool aTouched, double aValue, + ErrorResult& aRv); + + already_AddRefed NewAxisMoveEvent(uint32_t aHandleSlot, + uint32_t aAxis, double aValue, + ErrorResult& aRv); + + already_AddRefed NewPoseMove( + uint32_t aHandleSlot, const Nullable& aOrient, + const Nullable& aPos, + const Nullable& aAngVelocity, + const Nullable& aAngAcceleration, + const Nullable& aLinVelocity, + const Nullable& aLinAcceleration, ErrorResult& aRv); + + already_AddRefed NewTouch(uint32_t aHandleSlot, + uint32_t aTouchArrayIndex, + uint32_t aTouchId, uint8_t aSurfaceId, + const Float32Array& aPos, + const Nullable& aSurfDim, + ErrorResult& aRv); + + void Shutdown(); + + static already_AddRefed CreateTestService( + nsPIDOMWindowInner* aWindow); + nsPIDOMWindowInner* GetParentObject() const { return mWindow; } + JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + + private: + // Hold a reference to the gamepad service so we don't have to worry about + // execution order in tests. + RefPtr mService; + nsCOMPtr mWindow; + uint32_t mEventNumber; + bool mShuttingDown; + + // IPDL Channel for us to send test events to GamepadPlatformService, it + // will only be used in this singleton class and deleted during the IPDL + // shutdown chain + RefPtr mChild; + nsTArray mGamepadHandles; + + nsRefPtrHashtable mPromiseList; + + explicit GamepadServiceTest(nsPIDOMWindowInner* aWindow); + ~GamepadServiceTest(); + void InitPBackgroundActor(); + void DestroyPBackgroundActor(); + + uint32_t AddGamepadHandle(GamepadHandle aHandle); + void RemoveGamepadHandle(uint32_t aHandleSlot); + GamepadHandle GetHandleInSlot(uint32_t aHandleSlot) const; +}; + +} // namespace mozilla::dom + +#endif -- cgit v1.2.3