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 "content/browser/gamepad/gamepad_service.h" |
| 6 |
5 #include <string.h> | 7 #include <string.h> |
6 | 8 |
| 9 #include <memory> |
| 10 |
7 #include "base/macros.h" | 11 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
10 #include "content/browser/gamepad/gamepad_consumer.h" | 13 #include "content/browser/gamepad/gamepad_consumer.h" |
11 #include "content/browser/gamepad/gamepad_service.h" | |
12 #include "content/browser/gamepad/gamepad_test_helpers.h" | 14 #include "content/browser/gamepad/gamepad_test_helpers.h" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 | 17 |
16 namespace content { | 18 namespace content { |
17 | 19 |
18 namespace { | 20 namespace { |
19 static const int kNumberOfGamepads = blink::WebGamepads::itemsLengthCap; | 21 static const int kNumberOfGamepads = blink::WebGamepads::itemsLengthCap; |
20 } | 22 } |
21 | 23 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 64 } |
63 int GetDisconnectedCounter() const { | 65 int GetDisconnectedCounter() const { |
64 return connection_listener_->disconnected_counter(); | 66 return connection_listener_->disconnected_counter(); |
65 } | 67 } |
66 | 68 |
67 void SetUp() override; | 69 void SetUp() override; |
68 | 70 |
69 private: | 71 private: |
70 MockGamepadDataFetcher* fetcher_; | 72 MockGamepadDataFetcher* fetcher_; |
71 GamepadService* service_; | 73 GamepadService* service_; |
72 scoped_ptr<ConnectionListener> connection_listener_; | 74 std::unique_ptr<ConnectionListener> connection_listener_; |
73 TestBrowserThreadBundle browser_thread_; | 75 TestBrowserThreadBundle browser_thread_; |
74 WebGamepads test_data_; | 76 WebGamepads test_data_; |
75 | 77 |
76 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTest); | 78 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTest); |
77 }; | 79 }; |
78 | 80 |
79 GamepadServiceTest::GamepadServiceTest() | 81 GamepadServiceTest::GamepadServiceTest() |
80 : browser_thread_(TestBrowserThreadBundle::IO_MAINLOOP) { | 82 : browser_thread_(TestBrowserThreadBundle::IO_MAINLOOP) { |
81 memset(&test_data_, 0, sizeof(test_data_)); | 83 memset(&test_data_, 0, sizeof(test_data_)); |
82 | 84 |
83 // Set it so that we have user gesture. | 85 // Set it so that we have user gesture. |
84 test_data_.items[0].buttonsLength = 1; | 86 test_data_.items[0].buttonsLength = 1; |
85 test_data_.items[0].buttons[0].value = 1.f; | 87 test_data_.items[0].buttons[0].value = 1.f; |
86 test_data_.items[0].buttons[0].pressed = true; | 88 test_data_.items[0].buttons[0].pressed = true; |
87 } | 89 } |
88 | 90 |
89 GamepadServiceTest::~GamepadServiceTest() { | 91 GamepadServiceTest::~GamepadServiceTest() { |
90 delete service_; | 92 delete service_; |
91 } | 93 } |
92 | 94 |
93 void GamepadServiceTest::SetUp() { | 95 void GamepadServiceTest::SetUp() { |
94 fetcher_ = new MockGamepadDataFetcher(test_data_); | 96 fetcher_ = new MockGamepadDataFetcher(test_data_); |
95 service_ = new GamepadService(scoped_ptr<GamepadDataFetcher>(fetcher_)); | 97 service_ = new GamepadService(std::unique_ptr<GamepadDataFetcher>(fetcher_)); |
96 connection_listener_.reset((new ConnectionListener)); | 98 connection_listener_.reset((new ConnectionListener)); |
97 service_->ConsumerBecameActive(connection_listener_.get()); | 99 service_->ConsumerBecameActive(connection_listener_.get()); |
98 } | 100 } |
99 | 101 |
100 void GamepadServiceTest::SetPadsConnected(bool connected) { | 102 void GamepadServiceTest::SetPadsConnected(bool connected) { |
101 for (int i = 0; i < kNumberOfGamepads; ++i) { | 103 for (int i = 0; i < kNumberOfGamepads; ++i) { |
102 test_data_.items[i].connected = connected; | 104 test_data_.items[i].connected = connected; |
103 } | 105 } |
104 fetcher_->SetTestData(test_data_); | 106 fetcher_->SetTestData(test_data_); |
105 } | 107 } |
(...skipping 18 matching lines...) Expand all Loading... |
124 WaitForData(); | 126 WaitForData(); |
125 EXPECT_EQ(0, GetConnectedCounter()); | 127 EXPECT_EQ(0, GetConnectedCounter()); |
126 EXPECT_EQ(kNumberOfGamepads, GetDisconnectedCounter()); | 128 EXPECT_EQ(kNumberOfGamepads, GetDisconnectedCounter()); |
127 | 129 |
128 WaitForData(); | 130 WaitForData(); |
129 EXPECT_EQ(0, GetConnectedCounter()); | 131 EXPECT_EQ(0, GetConnectedCounter()); |
130 EXPECT_EQ(0, GetDisconnectedCounter()); | 132 EXPECT_EQ(0, GetDisconnectedCounter()); |
131 } | 133 } |
132 | 134 |
133 } // namespace content | 135 } // namespace content |
OLD | NEW |