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

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

Issue 2466073002: Movw GamepadService out of content/browser/ and into device/ (Closed)
Patch Set: Fixed everything but one unittest Created 4 years, 1 month 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 class GamepadService; 21 class GamepadService;
21 22
22 // Data fetcher that returns canned data for the gamepad provider. 23 // Data fetcher that returns canned data for the gamepad provider.
23 class MockGamepadDataFetcher : public GamepadDataFetcher { 24 class MockGamepadDataFetcher : public GamepadDataFetcher {
24 public: 25 public:
(...skipping 21 matching lines...) Expand all
46 void SetTestData(const blink::WebGamepads& new_data); 47 void SetTestData(const blink::WebGamepads& new_data);
47 48
48 private: 49 private:
49 base::Lock lock_; 50 base::Lock lock_;
50 blink::WebGamepads test_data_; 51 blink::WebGamepads test_data_;
51 base::WaitableEvent read_data_; 52 base::WaitableEvent read_data_;
52 53
53 DISALLOW_COPY_AND_ASSIGN(MockGamepadDataFetcher); 54 DISALLOW_COPY_AND_ASSIGN(MockGamepadDataFetcher);
54 }; 55 };
55 56
56 class MockGamepadSharedBuffer : public GamepadSharedBuffer {
57 public:
58 MockGamepadSharedBuffer();
59
60 base::SharedMemory* shared_memory() override;
61 blink::WebGamepads* buffer() override;
62
63 void WriteBegin() override;
64 void WriteEnd() override;
65
66 private:
67 base::SharedMemory shared_memory_;
68
69 DISALLOW_COPY_AND_ASSIGN(MockGamepadSharedBuffer);
70 };
71
72 // Base class for the other test helpers. This just sets up the system monitor. 57 // Base class for the other test helpers. This just sets up the system monitor.
73 class GamepadTestHelper { 58 class GamepadTestHelper {
74 public: 59 public:
75 GamepadTestHelper(); 60 GamepadTestHelper();
76 virtual ~GamepadTestHelper(); 61 virtual ~GamepadTestHelper();
77 62
78 base::MessageLoop& message_loop() { return message_loop_; } 63 base::MessageLoop& message_loop() { return message_loop_; }
79 64
80 private: 65 private:
81 // This must be constructed before the system monitor. 66 // This must be constructed before the system monitor.
82 base::MessageLoop message_loop_; 67 base::MessageLoop message_loop_;
83 68
84 DISALLOW_COPY_AND_ASSIGN(GamepadTestHelper); 69 DISALLOW_COPY_AND_ASSIGN(GamepadTestHelper);
85 }; 70 };
86 71
72 // Constructs a GamepadService with a mock data source. This bypasses the
73 // global singleton for the gamepad service.
74 class GamepadServiceTestConstructor : public GamepadTestHelper {
75 public:
76 explicit GamepadServiceTestConstructor(const blink::WebGamepads& test_data);
77 ~GamepadServiceTestConstructor() override;
78
79 GamepadService* gamepad_service() { return gamepad_service_; }
80 MockGamepadDataFetcher* data_fetcher() { return data_fetcher_; }
81
82 private:
83 // Owning pointer (can't be a scoped_ptr due to private destructor).
84 GamepadService* gamepad_service_;
85
86 // Pointer owned by the provider (which is owned by the gamepad service).
87 MockGamepadDataFetcher* data_fetcher_;
88
89 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTestConstructor);
90 };
91
87 } // namespace device 92 } // namespace device
88 93
89 #endif // DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_ 94 #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