Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1367)

Side by Side Diff: content/browser/gamepad/gamepad_service_unittest.cc

Issue 2081583002: Migrating majority of gamepad from content/browser/ to device/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final tweaks Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 5 #include "content/browser/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 "content/browser/gamepad/gamepad_consumer.h"
14 #include "content/browser/gamepad/gamepad_test_helpers.h"
15 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "device/gamepad/gamepad_consumer.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 content { 18 namespace content {
19 19
20 namespace { 20 namespace {
21 static const int kNumberOfGamepads = blink::WebGamepads::itemsLengthCap; 21 static const int kNumberOfGamepads = blink::WebGamepads::itemsLengthCap;
22 } 22 }
23 23
24 using blink::WebGamepads; 24 using blink::WebGamepads;
25 25
26 class ConnectionListener : public GamepadConsumer { 26 class ConnectionListener : public device::GamepadConsumer {
27 public: 27 public:
28 ConnectionListener() { 28 ConnectionListener() {
29 ClearCounters(); 29 ClearCounters();
30 } 30 }
31 31
32 void OnGamepadConnected(unsigned index, 32 void OnGamepadConnected(unsigned index,
33 const blink::WebGamepad& gamepad) override { 33 const blink::WebGamepad& gamepad) override {
34 connected_counter_++; 34 connected_counter_++;
35 } 35 }
36 void OnGamepadDisconnected(unsigned index, 36 void OnGamepadDisconnected(unsigned index,
(...skipping 25 matching lines...) Expand all
62 int GetConnectedCounter() const { 62 int GetConnectedCounter() const {
63 return connection_listener_->connected_counter(); 63 return connection_listener_->connected_counter();
64 } 64 }
65 int GetDisconnectedCounter() const { 65 int GetDisconnectedCounter() const {
66 return connection_listener_->disconnected_counter(); 66 return connection_listener_->disconnected_counter();
67 } 67 }
68 68
69 void SetUp() override; 69 void SetUp() override;
70 70
71 private: 71 private:
72 MockGamepadDataFetcher* fetcher_; 72 device::MockGamepadDataFetcher* fetcher_;
73 GamepadService* service_; 73 GamepadService* service_;
74 std::unique_ptr<ConnectionListener> connection_listener_; 74 std::unique_ptr<ConnectionListener> connection_listener_;
75 TestBrowserThreadBundle browser_thread_; 75 TestBrowserThreadBundle browser_thread_;
76 WebGamepads test_data_; 76 WebGamepads test_data_;
77 77
78 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTest); 78 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTest);
79 }; 79 };
80 80
81 GamepadServiceTest::GamepadServiceTest() 81 GamepadServiceTest::GamepadServiceTest()
82 : browser_thread_(TestBrowserThreadBundle::IO_MAINLOOP) { 82 : browser_thread_(TestBrowserThreadBundle::IO_MAINLOOP) {
83 memset(&test_data_, 0, sizeof(test_data_)); 83 memset(&test_data_, 0, sizeof(test_data_));
84 84
85 // Set it so that we have user gesture. 85 // Set it so that we have user gesture.
86 test_data_.items[0].buttonsLength = 1; 86 test_data_.items[0].buttonsLength = 1;
87 test_data_.items[0].buttons[0].value = 1.f; 87 test_data_.items[0].buttons[0].value = 1.f;
88 test_data_.items[0].buttons[0].pressed = true; 88 test_data_.items[0].buttons[0].pressed = true;
89 } 89 }
90 90
91 GamepadServiceTest::~GamepadServiceTest() { 91 GamepadServiceTest::~GamepadServiceTest() {
92 delete service_; 92 delete service_;
93 } 93 }
94 94
95 void GamepadServiceTest::SetUp() { 95 void GamepadServiceTest::SetUp() {
96 fetcher_ = new MockGamepadDataFetcher(test_data_); 96 fetcher_ = new device::MockGamepadDataFetcher(test_data_);
97 service_ = new GamepadService(std::unique_ptr<GamepadDataFetcher>(fetcher_)); 97 service_ = new GamepadService(
98 std::unique_ptr<device::GamepadDataFetcher>(fetcher_));
98 connection_listener_.reset((new ConnectionListener)); 99 connection_listener_.reset((new ConnectionListener));
99 service_->ConsumerBecameActive(connection_listener_.get()); 100 service_->ConsumerBecameActive(connection_listener_.get());
100 } 101 }
101 102
102 void GamepadServiceTest::SetPadsConnected(bool connected) { 103 void GamepadServiceTest::SetPadsConnected(bool connected) {
103 for (int i = 0; i < kNumberOfGamepads; ++i) { 104 for (int i = 0; i < kNumberOfGamepads; ++i) {
104 test_data_.items[i].connected = connected; 105 test_data_.items[i].connected = connected;
105 } 106 }
106 fetcher_->SetTestData(test_data_); 107 fetcher_->SetTestData(test_data_);
107 } 108 }
(...skipping 18 matching lines...) Expand all
126 WaitForData(); 127 WaitForData();
127 EXPECT_EQ(0, GetConnectedCounter()); 128 EXPECT_EQ(0, GetConnectedCounter());
128 EXPECT_EQ(kNumberOfGamepads, GetDisconnectedCounter()); 129 EXPECT_EQ(kNumberOfGamepads, GetDisconnectedCounter());
129 130
130 WaitForData(); 131 WaitForData();
131 EXPECT_EQ(0, GetConnectedCounter()); 132 EXPECT_EQ(0, GetConnectedCounter());
132 EXPECT_EQ(0, GetDisconnectedCounter()); 133 EXPECT_EQ(0, GetDisconnectedCounter());
133 } 134 }
134 135
135 } // namespace content 136 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gamepad/gamepad_service_test_helpers.cc ('k') | content/browser/gamepad/gamepad_shared_buffer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698