2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-04-23 22:05:29 +00:00
|
|
|
/* 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_
|
|
|
|
|
2016-06-27 22:26:00 +00:00
|
|
|
#include "nsIIPCBackgroundChildCreateCallback.h"
|
2015-04-23 22:05:29 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2016-06-27 22:26:00 +00:00
|
|
|
class GamepadChangeEvent;
|
2016-06-27 22:25:00 +00:00
|
|
|
class GamepadManager;
|
2016-06-27 22:26:00 +00:00
|
|
|
class GamepadTestChannelChild;
|
|
|
|
class Promise;
|
2015-04-23 22:05:29 +00:00
|
|
|
|
|
|
|
// Service for testing purposes
|
2016-06-27 22:26:00 +00:00
|
|
|
class GamepadServiceTest final : public DOMEventTargetHelper,
|
|
|
|
public nsIIPCBackgroundChildCreateCallback
|
2015-04-23 22:05:29 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-06-27 22:26:00 +00:00
|
|
|
NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GamepadServiceTest,
|
|
|
|
DOMEventTargetHelper)
|
2015-04-23 22:05:29 +00:00
|
|
|
|
2016-06-27 22:26:00 +00:00
|
|
|
uint32_t NoMapping() const { return 0; }
|
|
|
|
uint32_t StandardMapping() const { return 1; }
|
2015-04-23 22:05:29 +00:00
|
|
|
|
2016-06-27 22:26:00 +00:00
|
|
|
already_AddRefed<Promise> AddGamepad(const nsAString& aID,
|
|
|
|
uint32_t aMapping,
|
|
|
|
uint32_t aNumButtons,
|
|
|
|
uint32_t aNumAxes,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
void RemoveGamepad(uint32_t aIndex);
|
|
|
|
void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed);
|
|
|
|
void NewButtonValueEvent(uint32_t aIndex, uint32_t aButton, bool aPressed, double aValue);
|
|
|
|
void NewAxisMoveEvent(uint32_t aIndex, uint32_t aAxis, double aValue);
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
static already_AddRefed<GamepadServiceTest> CreateTestService(nsPIDOMWindowInner* aWindow);
|
|
|
|
nsPIDOMWindowInner* GetParentObject() const { return mWindow; }
|
|
|
|
JSObject* WrapObject(JSContext* aCx, JS::HandleObject aGivenProto) override;
|
2015-04-23 22:05:29 +00:00
|
|
|
|
|
|
|
private:
|
2016-06-27 22:26:00 +00:00
|
|
|
|
|
|
|
// We need to asynchronously create IPDL channel, it is possible that
|
|
|
|
// we send commands before the channel is created, so we have to buffer
|
|
|
|
// them until the channel is created in that case.
|
|
|
|
struct PendingOperation {
|
|
|
|
explicit PendingOperation(const uint32_t& aID,
|
|
|
|
const GamepadChangeEvent& aEvent,
|
|
|
|
Promise* aPromise = nullptr)
|
|
|
|
: mID(aID), mEvent(aEvent), mPromise(aPromise) {}
|
|
|
|
uint32_t mID;
|
|
|
|
const GamepadChangeEvent& mEvent;
|
|
|
|
RefPtr<Promise> mPromise;
|
|
|
|
};
|
|
|
|
|
2015-04-23 22:05:29 +00:00
|
|
|
// Hold a reference to the gamepad service so we don't have to worry about
|
|
|
|
// execution order in tests.
|
2016-06-27 22:25:00 +00:00
|
|
|
RefPtr<GamepadManager> mService;
|
2016-06-27 22:26:00 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
|
|
|
nsTArray<PendingOperation> mPendingOperations;
|
|
|
|
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
|
|
|
|
GamepadTestChannelChild* MOZ_NON_OWNING_REF mChild;
|
|
|
|
|
|
|
|
explicit GamepadServiceTest(nsPIDOMWindowInner* aWindow);
|
|
|
|
~GamepadServiceTest();
|
|
|
|
void InitPBackgroundActor();
|
|
|
|
void DestroyPBackgroundActor();
|
|
|
|
void FlushPendingOperations();
|
|
|
|
|
2015-04-23 22:05:29 +00:00
|
|
|
};
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2015-04-23 22:05:29 +00:00
|
|
|
|
|
|
|
#endif
|