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

Side by Side Diff: components/exo/gaming_seat_unittest.cc

Issue 2900773003: Allow gaming_seat to use ozone gamepad as back-end (Closed)
Patch Set: Add gaming_seat_ozone to exo Created 3 years, 6 months 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "components/exo/gaming_seat.h" 5 #include "components/exo/gaming_seat.h"
6 #include "ash/shell.h" 6 #include "ash/shell.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/test/test_simple_task_runner.h" 9 #include "base/test/test_simple_task_runner.h"
10 #include "components/exo/buffer.h" 10 #include "components/exo/buffer.h"
(...skipping 24 matching lines...) Expand all
35 public: 35 public:
36 MockGamepadDelegate() {} 36 MockGamepadDelegate() {}
37 37
38 // Overridden from GamepadDelegate: 38 // Overridden from GamepadDelegate:
39 MOCK_METHOD0(OnRemoved, void()); 39 MOCK_METHOD0(OnRemoved, void());
40 MOCK_METHOD2(OnAxis, void(int, double)); 40 MOCK_METHOD2(OnAxis, void(int, double));
41 MOCK_METHOD3(OnButton, void(int, bool, double)); 41 MOCK_METHOD3(OnButton, void(int, bool, double));
42 MOCK_METHOD0(OnFrame, void()); 42 MOCK_METHOD0(OnFrame, void());
43 }; 43 };
44 44
45 class GamingSeatTest : public test::ExoTestBase { 45 class GamingSeatJoydevTest : public test::ExoTestBase {
46 public: 46 public:
47 GamingSeatTest() {} 47 GamingSeatJoydevTest() {}
48 48
49 std::unique_ptr<device::GamepadDataFetcher> MockDataFetcherFactory() { 49 std::unique_ptr<device::GamepadDataFetcher> MockDataFetcherFactory() {
50 device::Gamepads initial_data; 50 device::Gamepads initial_data;
51 std::unique_ptr<device::MockGamepadDataFetcher> fetcher( 51 std::unique_ptr<device::MockGamepadDataFetcher> fetcher(
52 new device::MockGamepadDataFetcher(initial_data)); 52 new device::MockGamepadDataFetcher(initial_data));
53 mock_data_fetcher_ = fetcher.get(); 53 mock_data_fetcher_ = fetcher.get();
54 return std::move(fetcher); 54 return std::move(fetcher);
55 } 55 }
56 56
57 void InitializeGamingSeat(MockGamingSeatDelegate* delegate) { 57 void InitializeGamingSeat(MockGamingSeatDelegate* delegate) {
58 polling_task_runner_ = new base::TestSimpleTaskRunner(); 58 polling_task_runner_ = new base::TestSimpleTaskRunner();
59 gaming_seat_.reset( 59 gaming_seat_.reset(
60 new GamingSeat(delegate, polling_task_runner_.get(), 60 new GamingSeat(delegate, polling_task_runner_.get(),
61 base::Bind(&GamingSeatTest::MockDataFetcherFactory, 61 base::Bind(&GamingSeatJoydevTest::MockDataFetcherFactory,
62 base::Unretained(this)))); 62 base::Unretained(this))));
63 // Run the polling task runner to have it create the data fetcher. 63 // Run the polling task runner to have it create the data fetcher.
64 polling_task_runner_->RunPendingTasks(); 64 polling_task_runner_->RunPendingTasks();
65 } 65 }
66 66
67 void DestroyGamingSeat(MockGamingSeatDelegate* delegate) { 67 void DestroyGamingSeat(MockGamingSeatDelegate* delegate) {
68 EXPECT_CALL(*delegate, Die()).Times(1); 68 EXPECT_CALL(*delegate, Die()).Times(1);
69 mock_data_fetcher_ = nullptr; 69 mock_data_fetcher_ = nullptr;
70 gaming_seat_.reset(); 70 gaming_seat_.reset();
71 // Process tasks until polling is shut down. 71 // Process tasks until polling is shut down.
(...skipping 14 matching lines...) Expand all
86 std::unique_ptr<GamingSeat> gaming_seat_; 86 std::unique_ptr<GamingSeat> gaming_seat_;
87 87
88 // Task runner to simulate the polling thread. 88 // Task runner to simulate the polling thread.
89 scoped_refptr<base::TestSimpleTaskRunner> polling_task_runner_; 89 scoped_refptr<base::TestSimpleTaskRunner> polling_task_runner_;
90 90
91 // Weak reference to the mock data fetcher provided by MockDataFetcherFactory. 91 // Weak reference to the mock data fetcher provided by MockDataFetcherFactory.
92 // This instance is valid until both gamepad_ and polling_task_runner_ are 92 // This instance is valid until both gamepad_ and polling_task_runner_ are
93 // shut down. 93 // shut down.
94 device::MockGamepadDataFetcher* mock_data_fetcher_; 94 device::MockGamepadDataFetcher* mock_data_fetcher_;
95 95
96 DISALLOW_COPY_AND_ASSIGN(GamingSeatTest); 96 DISALLOW_COPY_AND_ASSIGN(GamingSeatJoydevTest);
97 }; 97 };
98 98
99 TEST_F(GamingSeatTest, ConnectionChange) { 99 TEST_F(GamingSeatJoydevTest, ConnectionChange) {
100 std::unique_ptr<Surface> surface(new Surface); 100 std::unique_ptr<Surface> surface(new Surface);
101 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 101 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
102 gfx::Size buffer_size(10, 10); 102 gfx::Size buffer_size(10, 10);
103 std::unique_ptr<Buffer> buffer( 103 std::unique_ptr<Buffer> buffer(
104 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 104 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
105 surface->Attach(buffer.get()); 105 surface->Attach(buffer.get());
106 surface->Commit(); 106 surface->Commit();
107 107
108 testing::StrictMock<MockGamingSeatDelegate>* gaming_seat_delegate = 108 testing::StrictMock<MockGamingSeatDelegate>* gaming_seat_delegate =
109 new testing::StrictMock<MockGamingSeatDelegate>(); 109 new testing::StrictMock<MockGamingSeatDelegate>();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 SetDataAndPostToDelegate(gamepad_connected); 152 SetDataAndPostToDelegate(gamepad_connected);
153 153
154 // Gamepad disconnected. 154 // Gamepad disconnected.
155 device::Gamepads all_disconnected; 155 device::Gamepads all_disconnected;
156 SetDataAndPostToDelegate(all_disconnected); 156 SetDataAndPostToDelegate(all_disconnected);
157 157
158 DestroyGamingSeat(gaming_seat_delegate); 158 DestroyGamingSeat(gaming_seat_delegate);
159 } 159 }
160 160
161 TEST_F(GamingSeatTest, OnAxis) { 161 TEST_F(GamingSeatJoydevTest, OnAxis) {
162 std::unique_ptr<Surface> surface(new Surface); 162 std::unique_ptr<Surface> surface(new Surface);
163 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 163 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
164 gfx::Size buffer_size(10, 10); 164 gfx::Size buffer_size(10, 10);
165 std::unique_ptr<Buffer> buffer( 165 std::unique_ptr<Buffer> buffer(
166 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 166 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
167 surface->Attach(buffer.get()); 167 surface->Attach(buffer.get());
168 surface->Commit(); 168 surface->Commit();
169 169
170 testing::StrictMock<MockGamingSeatDelegate>* gaming_seat_delegate = 170 testing::StrictMock<MockGamingSeatDelegate>* gaming_seat_delegate =
171 new testing::StrictMock<MockGamingSeatDelegate>(); 171 new testing::StrictMock<MockGamingSeatDelegate>();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 EXPECT_CALL(gamepad_delegate0, OnAxis(0, 2.0)).Times(1); 211 EXPECT_CALL(gamepad_delegate0, OnAxis(0, 2.0)).Times(1);
212 EXPECT_CALL(gamepad_delegate0, OnFrame()).Times(1); 212 EXPECT_CALL(gamepad_delegate0, OnFrame()).Times(1);
213 SetDataAndPostToDelegate(axis_moved); 213 SetDataAndPostToDelegate(axis_moved);
214 214
215 EXPECT_CALL(gamepad_delegate0, OnRemoved()).Times(1); 215 EXPECT_CALL(gamepad_delegate0, OnRemoved()).Times(1);
216 EXPECT_CALL(gamepad_delegate2, OnRemoved()).Times(1); 216 EXPECT_CALL(gamepad_delegate2, OnRemoved()).Times(1);
217 DestroyGamingSeat(gaming_seat_delegate); 217 DestroyGamingSeat(gaming_seat_delegate);
218 } 218 }
219 219
220 TEST_F(GamingSeatTest, OnButton) { 220 TEST_F(GamingSeatJoydevTest, OnButton) {
221 std::unique_ptr<Surface> surface(new Surface); 221 std::unique_ptr<Surface> surface(new Surface);
222 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 222 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
223 gfx::Size buffer_size(10, 10); 223 gfx::Size buffer_size(10, 10);
224 std::unique_ptr<Buffer> buffer( 224 std::unique_ptr<Buffer> buffer(
225 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 225 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
226 surface->Attach(buffer.get()); 226 surface->Attach(buffer.get());
227 surface->Commit(); 227 surface->Commit();
228 228
229 testing::StrictMock<MockGamingSeatDelegate>* gaming_seat_delegate = 229 testing::StrictMock<MockGamingSeatDelegate>* gaming_seat_delegate =
230 new testing::StrictMock<MockGamingSeatDelegate>(); 230 new testing::StrictMock<MockGamingSeatDelegate>();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 EXPECT_CALL(gamepad_delegate0, OnButton(0, true, 2.0)).Times(1); 273 EXPECT_CALL(gamepad_delegate0, OnButton(0, true, 2.0)).Times(1);
274 EXPECT_CALL(gamepad_delegate0, OnFrame()).Times(1); 274 EXPECT_CALL(gamepad_delegate0, OnFrame()).Times(1);
275 SetDataAndPostToDelegate(axis_moved); 275 SetDataAndPostToDelegate(axis_moved);
276 276
277 EXPECT_CALL(gamepad_delegate0, OnRemoved()).Times(1); 277 EXPECT_CALL(gamepad_delegate0, OnRemoved()).Times(1);
278 EXPECT_CALL(gamepad_delegate2, OnRemoved()).Times(1); 278 EXPECT_CALL(gamepad_delegate2, OnRemoved()).Times(1);
279 279
280 DestroyGamingSeat(gaming_seat_delegate); 280 DestroyGamingSeat(gaming_seat_delegate);
281 } 281 }
282 282
283 TEST_F(GamingSeatTest, OnWindowFocused) { 283 TEST_F(GamingSeatJoydevTest, OnWindowFocused) {
284 // Create surface and move focus to it. 284 // Create surface and move focus to it.
285 std::unique_ptr<Surface> surface(new Surface); 285 std::unique_ptr<Surface> surface(new Surface);
286 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 286 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
287 gfx::Size buffer_size(10, 10); 287 gfx::Size buffer_size(10, 10);
288 std::unique_ptr<Buffer> buffer( 288 std::unique_ptr<Buffer> buffer(
289 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 289 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
290 surface->Attach(buffer.get()); 290 surface->Attach(buffer.get());
291 surface->Commit(); 291 surface->Commit();
292 292
293 testing::StrictMock<MockGamingSeatDelegate>* gaming_seat_delegate = 293 testing::StrictMock<MockGamingSeatDelegate>* gaming_seat_delegate =
(...skipping 22 matching lines...) Expand all
316 // scheduled in the next round. 316 // scheduled in the next round.
317 polling_task_runner_->RunPendingTasks(); 317 polling_task_runner_->RunPendingTasks();
318 polling_task_runner_->RunPendingTasks(); 318 polling_task_runner_->RunPendingTasks();
319 ASSERT_FALSE(polling_task_runner_->HasPendingTask()); 319 ASSERT_FALSE(polling_task_runner_->HasPendingTask());
320 320
321 DestroyGamingSeat(gaming_seat_delegate); 321 DestroyGamingSeat(gaming_seat_delegate);
322 } 322 }
323 323
324 } // namespace 324 } // namespace
325 } // namespace exo 325 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698