Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: device/gamepad/gamepad_test_helpers.h

Issue 2563483006: Move gamepad_service out of content/ and into device/ (Closed)
Patch Set: addressed Blundell's review comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/gamepad/gamepad_shared_buffer.cc ('k') | device/gamepad/gamepad_test_helpers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_ 5 #ifndef DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_
6 #define DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_ 6 #define DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "device/gamepad/gamepad_data_fetcher.h" 14 #include "device/gamepad/gamepad_data_fetcher.h"
15 #include "device/gamepad/gamepad_service.h"
15 #include "device/gamepad/gamepad_shared_buffer.h" 16 #include "device/gamepad/gamepad_shared_buffer.h"
16 #include "third_party/WebKit/public/platform/WebGamepads.h" 17 #include "third_party/WebKit/public/platform/WebGamepads.h"
17 18
18 namespace device { 19 namespace device {
19 20
20 // Data fetcher that returns canned data for the gamepad provider. 21 // Data fetcher that returns canned data for the gamepad provider.
21 class MockGamepadDataFetcher : public GamepadDataFetcher { 22 class MockGamepadDataFetcher : public GamepadDataFetcher {
22 public: 23 public:
23 // Initializes the fetcher with the given gamepad data, which will be 24 // Initializes the fetcher with the given gamepad data, which will be
24 // returned when the provider queries us. 25 // returned when the provider queries us.
(...skipping 19 matching lines...) Expand all
44 void SetTestData(const blink::WebGamepads& new_data); 45 void SetTestData(const blink::WebGamepads& new_data);
45 46
46 private: 47 private:
47 base::Lock lock_; 48 base::Lock lock_;
48 blink::WebGamepads test_data_; 49 blink::WebGamepads test_data_;
49 base::WaitableEvent read_data_; 50 base::WaitableEvent read_data_;
50 51
51 DISALLOW_COPY_AND_ASSIGN(MockGamepadDataFetcher); 52 DISALLOW_COPY_AND_ASSIGN(MockGamepadDataFetcher);
52 }; 53 };
53 54
54 class MockGamepadSharedBuffer : public GamepadSharedBuffer {
55 public:
56 MockGamepadSharedBuffer();
57
58 base::SharedMemory* shared_memory() override;
59 blink::WebGamepads* buffer() override;
60
61 void WriteBegin() override;
62 void WriteEnd() override;
63
64 private:
65 base::SharedMemory shared_memory_;
66
67 DISALLOW_COPY_AND_ASSIGN(MockGamepadSharedBuffer);
68 };
69
70 // Base class for the other test helpers. This just sets up the system monitor. 55 // Base class for the other test helpers. This just sets up the system monitor.
71 class GamepadTestHelper { 56 class GamepadTestHelper {
72 public: 57 public:
73 GamepadTestHelper(); 58 GamepadTestHelper();
74 virtual ~GamepadTestHelper(); 59 virtual ~GamepadTestHelper();
75 60
76 base::MessageLoop& message_loop() { return message_loop_; } 61 base::MessageLoop& message_loop() { return message_loop_; }
77 62
78 private: 63 private:
79 // This must be constructed before the system monitor. 64 // This must be constructed before the system monitor.
80 base::MessageLoop message_loop_; 65 base::MessageLoop message_loop_;
81 66
82 DISALLOW_COPY_AND_ASSIGN(GamepadTestHelper); 67 DISALLOW_COPY_AND_ASSIGN(GamepadTestHelper);
83 }; 68 };
84 69
70 // Constructs a GamepadService with a mock data source. This bypasses the
71 // global singleton for the gamepad service.
72 class GamepadServiceTestConstructor : public GamepadTestHelper {
73 public:
74 explicit GamepadServiceTestConstructor(const blink::WebGamepads& test_data);
75 ~GamepadServiceTestConstructor() override;
76
77 GamepadService* gamepad_service() { return gamepad_service_; }
78 MockGamepadDataFetcher* data_fetcher() { return data_fetcher_; }
79
80 private:
81 // Owning pointer (can't be a scoped_ptr due to private destructor).
82 GamepadService* gamepad_service_;
83
84 // Pointer owned by the provider (which is owned by the gamepad service).
85 MockGamepadDataFetcher* data_fetcher_;
86
87 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTestConstructor);
88 };
89
85 } // namespace device 90 } // namespace device
86 91
87 #endif // DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_ 92 #endif // DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_
OLDNEW
« no previous file with comments | « device/gamepad/gamepad_shared_buffer.cc ('k') | device/gamepad/gamepad_test_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698