| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "content/browser/gamepad/gamepad_consumer.h" | 7 #include "content/browser/gamepad/gamepad_consumer.h" |
| 8 #include "content/browser/gamepad/gamepad_service.h" | 8 #include "content/browser/gamepad/gamepad_service.h" |
| 9 #include "content/browser/gamepad/gamepad_test_helpers.h" | 9 #include "content/browser/gamepad/gamepad_test_helpers.h" |
| 10 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 static const int kNumberOfGamepads = blink::WebGamepads::itemsLengthCap; | 16 static const int kNumberOfGamepads = blink::WebGamepads::itemsLengthCap; |
| 17 } | 17 } |
| 18 | 18 |
| 19 using blink::WebGamepads; | 19 using blink::WebGamepads; |
| 20 | 20 |
| 21 class ConnectionListener : public GamepadConsumer { | 21 class ConnectionListener : public GamepadConsumer { |
| 22 public: | 22 public: |
| 23 ConnectionListener() { | 23 ConnectionListener() { |
| 24 ClearCounters(); | 24 ClearCounters(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 virtual void OnGamepadConnected( | 27 virtual void OnGamepadConnected( |
| 28 unsigned index, | 28 unsigned index, |
| 29 const blink::WebGamepad& gamepad) OVERRIDE { | 29 const blink::WebGamepad& gamepad) override { |
| 30 connected_counter_++; | 30 connected_counter_++; |
| 31 } | 31 } |
| 32 virtual void OnGamepadDisconnected( | 32 virtual void OnGamepadDisconnected( |
| 33 unsigned index, | 33 unsigned index, |
| 34 const blink::WebGamepad& gamepad) OVERRIDE { | 34 const blink::WebGamepad& gamepad) override { |
| 35 disconnected_counter_++; | 35 disconnected_counter_++; |
| 36 } | 36 } |
| 37 | 37 |
| 38 void ClearCounters() { | 38 void ClearCounters() { |
| 39 connected_counter_ = 0; | 39 connected_counter_ = 0; |
| 40 disconnected_counter_ = 0; | 40 disconnected_counter_ = 0; |
| 41 } | 41 } |
| 42 | 42 |
| 43 int connected_counter() const { return connected_counter_; } | 43 int connected_counter() const { return connected_counter_; } |
| 44 int disconnected_counter() const { return disconnected_counter_; } | 44 int disconnected_counter() const { return disconnected_counter_; } |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 int connected_counter_; | 47 int connected_counter_; |
| 48 int disconnected_counter_; | 48 int disconnected_counter_; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 class GamepadServiceTest : public testing::Test { | 51 class GamepadServiceTest : public testing::Test { |
| 52 protected: | 52 protected: |
| 53 GamepadServiceTest(); | 53 GamepadServiceTest(); |
| 54 virtual ~GamepadServiceTest() OVERRIDE; | 54 virtual ~GamepadServiceTest() override; |
| 55 | 55 |
| 56 void SetPadsConnected(bool connected); | 56 void SetPadsConnected(bool connected); |
| 57 void WaitForData(); | 57 void WaitForData(); |
| 58 | 58 |
| 59 int GetConnectedCounter() const { | 59 int GetConnectedCounter() const { |
| 60 return connection_listener_->connected_counter(); | 60 return connection_listener_->connected_counter(); |
| 61 } | 61 } |
| 62 int GetDisconnectedCounter() const { | 62 int GetDisconnectedCounter() const { |
| 63 return connection_listener_->disconnected_counter(); | 63 return connection_listener_->disconnected_counter(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual void SetUp() OVERRIDE; | 66 virtual void SetUp() override; |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 MockGamepadDataFetcher* fetcher_; | 69 MockGamepadDataFetcher* fetcher_; |
| 70 GamepadService* service_; | 70 GamepadService* service_; |
| 71 scoped_ptr<ConnectionListener> connection_listener_; | 71 scoped_ptr<ConnectionListener> connection_listener_; |
| 72 TestBrowserThreadBundle browser_thread_; | 72 TestBrowserThreadBundle browser_thread_; |
| 73 WebGamepads test_data_; | 73 WebGamepads test_data_; |
| 74 | 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTest); | 75 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTest); |
| 76 }; | 76 }; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 WaitForData(); | 123 WaitForData(); |
| 124 EXPECT_EQ(0, GetConnectedCounter()); | 124 EXPECT_EQ(0, GetConnectedCounter()); |
| 125 EXPECT_EQ(kNumberOfGamepads, GetDisconnectedCounter()); | 125 EXPECT_EQ(kNumberOfGamepads, GetDisconnectedCounter()); |
| 126 | 126 |
| 127 WaitForData(); | 127 WaitForData(); |
| 128 EXPECT_EQ(0, GetConnectedCounter()); | 128 EXPECT_EQ(0, GetConnectedCounter()); |
| 129 EXPECT_EQ(0, GetDisconnectedCounter()); | 129 EXPECT_EQ(0, GetDisconnectedCounter()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 } // namespace content | 132 } // namespace content |
| OLD | NEW |