blob: fe32cb3bab5fd41880f15762624a10d6498fdf83 [file] [log] [blame]
jochen@chromium.orgcf786002014-02-11 02:05:541// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
jochen73e711c2015-06-03 10:01:465#ifndef COMPONENTS_TEST_RUNNER_GAMEPAD_CONTROLLER_H_
6#define COMPONENTS_TEST_RUNNER_GAMEPAD_CONTROLLER_H_
jochen@chromium.orgcf786002014-02-11 02:05:547
b.kelemen@samsung.com078780b2014-06-20 16:57:068#include <map>
9
jochen@chromium.orgcf786002014-02-11 02:05:5410#include "base/memory/weak_ptr.h"
jochen746754c52015-06-05 16:40:4111#include "components/test_runner/test_runner_export.h"
jochen@chromium.orgcf786002014-02-11 02:05:5412#include "third_party/WebKit/public/platform/WebGamepads.h"
13
14namespace blink {
15class WebFrame;
b.kelemen@samsung.com078780b2014-06-20 16:57:0616class WebGamepadListener;
jochen@chromium.orgcf786002014-02-11 02:05:5417}
18
jochenf5f31752015-06-03 12:06:3419namespace test_runner {
jochen@chromium.orgcf786002014-02-11 02:05:5420
tfarina@chromium.org79ecada2014-05-04 05:16:1621class WebTestDelegate;
22
jochen746754c52015-06-05 16:40:4123class TEST_RUNNER_EXPORT GamepadController
24 : public base::SupportsWeakPtr<GamepadController> {
jochen@chromium.orgcf786002014-02-11 02:05:5425 public:
mlamouri@chromium.org9c41b462014-08-19 15:51:3426 static base::WeakPtr<GamepadController> Create(WebTestDelegate* delegate);
jochenc8337812015-05-14 01:11:5827 ~GamepadController();
jochen@chromium.orgcf786002014-02-11 02:05:5428
29 void Reset();
30 void Install(blink::WebFrame* frame);
jochen@chromium.orgcf786002014-02-11 02:05:5431
jochenc8337812015-05-14 01:11:5832 void SampleGamepads(blink::WebGamepads& gamepads);
33 void SetListener(blink::WebGamepadListener* listener);
b.kelemen@samsung.com078780b2014-06-20 16:57:0634
jochen@chromium.orgcf786002014-02-11 02:05:5435 private:
36 friend class GamepadControllerBindings;
mlamouri@chromium.org9c41b462014-08-19 15:51:3437 GamepadController();
jochen@chromium.orgcf786002014-02-11 02:05:5438
b.kelemen@samsung.com85603cbb2014-03-25 02:20:0139 // TODO(b.kelemen): for historical reasons Connect just initializes the
40 // object. The 'gamepadconnected' event will be dispatched via
41 // DispatchConnected. Tests for connected events need to first connect(),
42 // then set the gamepad data and finally call dispatchConnected().
43 // We should consider renaming Connect to Init and DispatchConnected to
44 // Connect and at the same time updating all the gamepad tests.
jochen@chromium.orgcf786002014-02-11 02:05:5445 void Connect(int index);
b.kelemen@samsung.com85603cbb2014-03-25 02:20:0146 void DispatchConnected(int index);
47
jochen@chromium.orgcf786002014-02-11 02:05:5448 void Disconnect(int index);
49 void SetId(int index, const std::string& src);
50 void SetButtonCount(int index, int buttons);
51 void SetButtonData(int index, int button, double data);
52 void SetAxisCount(int index, int axes);
53 void SetAxisData(int index, int axis, double data);
54
jochenc8337812015-05-14 01:11:5855 blink::WebGamepadListener* listener_;
56
jochen@chromium.orgcf786002014-02-11 02:05:5457 blink::WebGamepads gamepads_;
58
b.kelemen@samsung.com078780b2014-06-20 16:57:0659 // Mapping from gamepad index to connection state.
60 std::map<int, bool> pending_changes_;
jochen@chromium.orgcf786002014-02-11 02:05:5461
62 base::WeakPtrFactory<GamepadController> weak_factory_;
63
64 DISALLOW_COPY_AND_ASSIGN(GamepadController);
65};
66
jochenf5f31752015-06-03 12:06:3467} // namespace test_runner
jochen@chromium.orgcf786002014-02-11 02:05:5468
jochen73e711c2015-06-03 10:01:4669#endif // COMPONENTS_TEST_RUNNER_GAMEPAD_CONTROLLER_H_