| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "device/gamepad/gamepad_service.h" | 5 #include "device/gamepad/gamepad_service.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/test/scoped_task_environment.h" | 13 #include "base/test/scoped_task_environment.h" |
| 14 #include "device/gamepad/gamepad_consumer.h" | 14 #include "device/gamepad/gamepad_consumer.h" |
| 15 #include "device/gamepad/gamepad_test_helpers.h" | 15 #include "device/gamepad/gamepad_test_helpers.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace device { | 18 namespace device { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 static const int kNumberOfGamepads = blink::WebGamepads::kItemsLengthCap; | 21 static const int kNumberOfGamepads = Gamepads::kItemsLengthCap; |
| 22 } | 22 } |
| 23 | 23 |
| 24 using blink::WebGamepads; | |
| 25 | |
| 26 class ConnectionListener : public device::GamepadConsumer { | 24 class ConnectionListener : public device::GamepadConsumer { |
| 27 public: | 25 public: |
| 28 ConnectionListener() { ClearCounters(); } | 26 ConnectionListener() { ClearCounters(); } |
| 29 | 27 |
| 30 void OnGamepadConnected(unsigned index, | 28 void OnGamepadConnected(unsigned index, const Gamepad& gamepad) override { |
| 31 const blink::WebGamepad& gamepad) override { | |
| 32 connected_counter_++; | 29 connected_counter_++; |
| 33 } | 30 } |
| 34 void OnGamepadDisconnected(unsigned index, | 31 void OnGamepadDisconnected(unsigned index, const Gamepad& gamepad) override { |
| 35 const blink::WebGamepad& gamepad) override { | |
| 36 disconnected_counter_++; | 32 disconnected_counter_++; |
| 37 } | 33 } |
| 38 | 34 |
| 39 void ClearCounters() { | 35 void ClearCounters() { |
| 40 connected_counter_ = 0; | 36 connected_counter_ = 0; |
| 41 disconnected_counter_ = 0; | 37 disconnected_counter_ = 0; |
| 42 } | 38 } |
| 43 | 39 |
| 44 int connected_counter() const { return connected_counter_; } | 40 int connected_counter() const { return connected_counter_; } |
| 45 int disconnected_counter() const { return disconnected_counter_; } | 41 int disconnected_counter() const { return disconnected_counter_; } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 64 return connection_listener_->disconnected_counter(); | 60 return connection_listener_->disconnected_counter(); |
| 65 } | 61 } |
| 66 | 62 |
| 67 void SetUp() override; | 63 void SetUp() override; |
| 68 | 64 |
| 69 private: | 65 private: |
| 70 base::test::ScopedTaskEnvironment scoped_task_environment_; | 66 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 71 device::MockGamepadDataFetcher* fetcher_; | 67 device::MockGamepadDataFetcher* fetcher_; |
| 72 GamepadService* service_; | 68 GamepadService* service_; |
| 73 std::unique_ptr<ConnectionListener> connection_listener_; | 69 std::unique_ptr<ConnectionListener> connection_listener_; |
| 74 WebGamepads test_data_; | 70 Gamepads test_data_; |
| 75 | 71 |
| 76 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTest); | 72 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTest); |
| 77 }; | 73 }; |
| 78 | 74 |
| 79 GamepadServiceTest::GamepadServiceTest() { | 75 GamepadServiceTest::GamepadServiceTest() { |
| 80 memset(&test_data_, 0, sizeof(test_data_)); | 76 memset(&test_data_, 0, sizeof(test_data_)); |
| 81 | 77 |
| 82 // Set it so that we have user gesture. | 78 // Set it so that we have user gesture. |
| 83 test_data_.items[0].buttons_length = 1; | 79 test_data_.items[0].buttons_length = 1; |
| 84 test_data_.items[0].buttons[0].value = 1.f; | 80 test_data_.items[0].buttons[0].value = 1.f; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 WaitForData(); | 121 WaitForData(); |
| 126 EXPECT_EQ(0, GetConnectedCounter()); | 122 EXPECT_EQ(0, GetConnectedCounter()); |
| 127 EXPECT_EQ(kNumberOfGamepads, GetDisconnectedCounter()); | 123 EXPECT_EQ(kNumberOfGamepads, GetDisconnectedCounter()); |
| 128 | 124 |
| 129 WaitForData(); | 125 WaitForData(); |
| 130 EXPECT_EQ(0, GetConnectedCounter()); | 126 EXPECT_EQ(0, GetConnectedCounter()); |
| 131 EXPECT_EQ(0, GetDisconnectedCounter()); | 127 EXPECT_EQ(0, GetDisconnectedCounter()); |
| 132 } | 128 } |
| 133 | 129 |
| 134 } // namespace device | 130 } // namespace device |
| OLD | NEW |