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 void OnGamepadConnected(unsigned index, |
28 unsigned index, | 28 const blink::WebGamepad& gamepad) override { |
29 const blink::WebGamepad& gamepad) override { | |
30 connected_counter_++; | 29 connected_counter_++; |
31 } | 30 } |
32 virtual void OnGamepadDisconnected( | 31 void OnGamepadDisconnected(unsigned index, |
33 unsigned index, | 32 const blink::WebGamepad& gamepad) override { |
34 const blink::WebGamepad& gamepad) override { | |
35 disconnected_counter_++; | 33 disconnected_counter_++; |
36 } | 34 } |
37 | 35 |
38 void ClearCounters() { | 36 void ClearCounters() { |
39 connected_counter_ = 0; | 37 connected_counter_ = 0; |
40 disconnected_counter_ = 0; | 38 disconnected_counter_ = 0; |
41 } | 39 } |
42 | 40 |
43 int connected_counter() const { return connected_counter_; } | 41 int connected_counter() const { return connected_counter_; } |
44 int disconnected_counter() const { return disconnected_counter_; } | 42 int disconnected_counter() const { return disconnected_counter_; } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 WaitForData(); | 121 WaitForData(); |
124 EXPECT_EQ(0, GetConnectedCounter()); | 122 EXPECT_EQ(0, GetConnectedCounter()); |
125 EXPECT_EQ(kNumberOfGamepads, GetDisconnectedCounter()); | 123 EXPECT_EQ(kNumberOfGamepads, GetDisconnectedCounter()); |
126 | 124 |
127 WaitForData(); | 125 WaitForData(); |
128 EXPECT_EQ(0, GetConnectedCounter()); | 126 EXPECT_EQ(0, GetConnectedCounter()); |
129 EXPECT_EQ(0, GetDisconnectedCounter()); | 127 EXPECT_EQ(0, GetDisconnectedCounter()); |
130 } | 128 } |
131 | 129 |
132 } // namespace content | 130 } // namespace content |
OLD | NEW |