| OLD | NEW |
| 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 "ash/shell.h" | 5 #include "ash/shell.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/test/test_simple_task_runner.h" | 8 #include "base/test/test_simple_task_runner.h" |
| 9 #include "components/exo/buffer.h" | 9 #include "components/exo/buffer.h" |
| 10 #include "components/exo/gamepad.h" | 10 #include "components/exo/gamepad.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 polling_task_runner_->RunPendingTasks(); | 55 polling_task_runner_->RunPendingTasks(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void DestroyGamepad(MockGamepadDelegate* delegate) { | 58 void DestroyGamepad(MockGamepadDelegate* delegate) { |
| 59 EXPECT_CALL(*delegate, OnGamepadDestroying(testing::_)).Times(1); | 59 EXPECT_CALL(*delegate, OnGamepadDestroying(testing::_)).Times(1); |
| 60 mock_data_fetcher_ = nullptr; | 60 mock_data_fetcher_ = nullptr; |
| 61 gamepad_.reset(); | 61 gamepad_.reset(); |
| 62 // Process tasks until polling is shut down. | 62 // Process tasks until polling is shut down. |
| 63 polling_task_runner_->RunPendingTasks(); | 63 polling_task_runner_->RunPendingTasks(); |
| 64 polling_task_runner_ = nullptr; | 64 polling_task_runner_ = nullptr; |
| 65 base::RunLoop().RunUntilIdle(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void SetDataAndPostToDelegate(const blink::WebGamepads& new_data) { | 68 void SetDataAndPostToDelegate(const blink::WebGamepads& new_data) { |
| 68 ASSERT_TRUE(mock_data_fetcher_ != nullptr); | 69 ASSERT_TRUE(mock_data_fetcher_ != nullptr); |
| 69 mock_data_fetcher_->SetTestData(new_data); | 70 mock_data_fetcher_->SetTestData(new_data); |
| 70 // Run one polling cycle, which will post a task to the origin task runner. | 71 // Run one polling cycle, which will post a task to the origin task runner. |
| 71 polling_task_runner_->RunPendingTasks(); | 72 polling_task_runner_->RunPendingTasks(); |
| 72 // Run origin task runner to invoke delegate. | 73 // Run origin task runner to invoke delegate. |
| 74 |
| 73 base::RunLoop().RunUntilIdle(); | 75 base::RunLoop().RunUntilIdle(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 protected: | 78 protected: |
| 77 std::unique_ptr<Gamepad> gamepad_; | 79 std::unique_ptr<Gamepad> gamepad_; |
| 78 | 80 |
| 79 // Task runner to simulate the polling thread. | 81 // Task runner to simulate the polling thread. |
| 80 scoped_refptr<base::TestSimpleTaskRunner> polling_task_runner_; | 82 scoped_refptr<base::TestSimpleTaskRunner> polling_task_runner_; |
| 81 | 83 |
| 82 // Weak reference to the mock data fetcher provided by MockDataFetcherFactory. | 84 // Weak reference to the mock data fetcher provided by MockDataFetcherFactory. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 109 gamepad_connected.items[0].connected = true; | 111 gamepad_connected.items[0].connected = true; |
| 110 gamepad_connected.items[0].timestamp = 1; | 112 gamepad_connected.items[0].timestamp = 1; |
| 111 SetDataAndPostToDelegate(gamepad_connected); | 113 SetDataAndPostToDelegate(gamepad_connected); |
| 112 | 114 |
| 113 // Gamepad disconnected. | 115 // Gamepad disconnected. |
| 114 blink::WebGamepads all_disconnected; | 116 blink::WebGamepads all_disconnected; |
| 115 EXPECT_CALL(delegate, OnStateChange(false)).Times(1); | 117 EXPECT_CALL(delegate, OnStateChange(false)).Times(1); |
| 116 SetDataAndPostToDelegate(all_disconnected); | 118 SetDataAndPostToDelegate(all_disconnected); |
| 117 | 119 |
| 118 DestroyGamepad(&delegate); | 120 DestroyGamepad(&delegate); |
| 121 RunAllPendingInMessageLoop(); |
| 119 } | 122 } |
| 120 | 123 |
| 121 TEST_F(GamepadTest, OnAxis) { | 124 TEST_F(GamepadTest, OnAxis) { |
| 122 std::unique_ptr<Surface> surface(new Surface); | 125 std::unique_ptr<Surface> surface(new Surface); |
| 123 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); | 126 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); |
| 124 gfx::Size buffer_size(10, 10); | 127 gfx::Size buffer_size(10, 10); |
| 125 std::unique_ptr<Buffer> buffer( | 128 std::unique_ptr<Buffer> buffer( |
| 126 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); | 129 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); |
| 127 surface->Attach(buffer.get()); | 130 surface->Attach(buffer.get()); |
| 128 surface->Commit(); | 131 surface->Commit(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // scheduled in the next round. | 216 // scheduled in the next round. |
| 214 polling_task_runner_->RunPendingTasks(); | 217 polling_task_runner_->RunPendingTasks(); |
| 215 polling_task_runner_->RunPendingTasks(); | 218 polling_task_runner_->RunPendingTasks(); |
| 216 ASSERT_FALSE(polling_task_runner_->HasPendingTask()); | 219 ASSERT_FALSE(polling_task_runner_->HasPendingTask()); |
| 217 | 220 |
| 218 DestroyGamepad(&delegate); | 221 DestroyGamepad(&delegate); |
| 219 } | 222 } |
| 220 | 223 |
| 221 } // namespace | 224 } // namespace |
| 222 } // namespace exo | 225 } // namespace exo |
| OLD | NEW |