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

Side by Side Diff: device/gamepad/gamepad_service_unittest.cc

Issue 2563483006: Move gamepad_service out of content/ and into device/ (Closed)
Patch Set: Move gamepad_service out of content/ and into device/ Created 4 years 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 "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 "content/public/test/test_browser_thread_bundle.h"
14 #include "device/gamepad/gamepad_consumer.h" 13 #include "device/gamepad/gamepad_consumer.h"
15 #include "device/gamepad/gamepad_test_helpers.h" 14 #include "device/gamepad/gamepad_test_helpers.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 16
18 namespace content { 17 namespace device {
19 18
20 namespace { 19 namespace {
21 static const int kNumberOfGamepads = blink::WebGamepads::itemsLengthCap; 20 static const int kNumberOfGamepads = blink::WebGamepads::itemsLengthCap;
22 } 21 }
23 22
24 using blink::WebGamepads; 23 using blink::WebGamepads;
25 24
26 class ConnectionListener : public device::GamepadConsumer { 25 class ConnectionListener : public device::GamepadConsumer {
27 public: 26 public:
28 ConnectionListener() { 27 ConnectionListener() { ClearCounters(); }
29 ClearCounters();
30 }
31 28
32 void OnGamepadConnected(unsigned index, 29 void OnGamepadConnected(unsigned index,
33 const blink::WebGamepad& gamepad) override { 30 const blink::WebGamepad& gamepad) override {
34 connected_counter_++; 31 connected_counter_++;
35 } 32 }
36 void OnGamepadDisconnected(unsigned index, 33 void OnGamepadDisconnected(unsigned index,
37 const blink::WebGamepad& gamepad) override { 34 const blink::WebGamepad& gamepad) override {
38 disconnected_counter_++; 35 disconnected_counter_++;
39 } 36 }
40 37
(...skipping 20 matching lines...) Expand all
61 58
62 int GetConnectedCounter() const { 59 int GetConnectedCounter() const {
63 return connection_listener_->connected_counter(); 60 return connection_listener_->connected_counter();
64 } 61 }
65 int GetDisconnectedCounter() const { 62 int GetDisconnectedCounter() const {
66 return connection_listener_->disconnected_counter(); 63 return connection_listener_->disconnected_counter();
67 } 64 }
68 65
69 void SetUp() override; 66 void SetUp() override;
70 67
68 void TearDown() override { base::RunLoop().RunUntilIdle(); }
blundell 2016/12/09 13:35:22 Why is this necessary?
ke.he 2016/12/09 15:15:23 not necessary, removed.
69
71 private: 70 private:
71 base::MessageLoop message_loop_;
72 device::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_;
76 WebGamepads test_data_; 75 WebGamepads test_data_;
77 76
78 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTest); 77 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTest);
79 }; 78 };
80 79
81 GamepadServiceTest::GamepadServiceTest() 80 GamepadServiceTest::GamepadServiceTest() {
82 : browser_thread_(TestBrowserThreadBundle::IO_MAINLOOP) {
83 memset(&test_data_, 0, sizeof(test_data_)); 81 memset(&test_data_, 0, sizeof(test_data_));
84 82
85 // Set it so that we have user gesture. 83 // Set it so that we have user gesture.
86 test_data_.items[0].buttonsLength = 1; 84 test_data_.items[0].buttonsLength = 1;
87 test_data_.items[0].buttons[0].value = 1.f; 85 test_data_.items[0].buttons[0].value = 1.f;
88 test_data_.items[0].buttons[0].pressed = true; 86 test_data_.items[0].buttons[0].pressed = true;
89 } 87 }
90 88
91 GamepadServiceTest::~GamepadServiceTest() { 89 GamepadServiceTest::~GamepadServiceTest() {
92 delete service_; 90 delete service_;
93 } 91 }
94 92
95 void GamepadServiceTest::SetUp() { 93 void GamepadServiceTest::SetUp() {
96 fetcher_ = new device::MockGamepadDataFetcher(test_data_); 94 fetcher_ = new device::MockGamepadDataFetcher(test_data_);
97 service_ = new GamepadService( 95 service_ =
98 std::unique_ptr<device::GamepadDataFetcher>(fetcher_)); 96 new GamepadService(std::unique_ptr<device::GamepadDataFetcher>(fetcher_));
99 connection_listener_.reset((new ConnectionListener)); 97 connection_listener_.reset((new ConnectionListener));
100 service_->SetSanitizationEnabled(false); 98 service_->SetSanitizationEnabled(false);
101 service_->ConsumerBecameActive(connection_listener_.get()); 99 service_->ConsumerBecameActive(connection_listener_.get());
102 } 100 }
103 101
104 void GamepadServiceTest::SetPadsConnected(bool connected) { 102 void GamepadServiceTest::SetPadsConnected(bool connected) {
105 for (int i = 0; i < kNumberOfGamepads; ++i) { 103 for (int i = 0; i < kNumberOfGamepads; ++i) {
106 test_data_.items[i].connected = connected; 104 test_data_.items[i].connected = connected;
107 } 105 }
108 fetcher_->SetTestData(test_data_); 106 fetcher_->SetTestData(test_data_);
(...skipping 18 matching lines...) Expand all
127 SetPadsConnected(false); 125 SetPadsConnected(false);
128 WaitForData(); 126 WaitForData();
129 EXPECT_EQ(0, GetConnectedCounter()); 127 EXPECT_EQ(0, GetConnectedCounter());
130 EXPECT_EQ(kNumberOfGamepads, GetDisconnectedCounter()); 128 EXPECT_EQ(kNumberOfGamepads, GetDisconnectedCounter());
131 129
132 WaitForData(); 130 WaitForData();
133 EXPECT_EQ(0, GetConnectedCounter()); 131 EXPECT_EQ(0, GetConnectedCounter());
134 EXPECT_EQ(0, GetDisconnectedCounter()); 132 EXPECT_EQ(0, GetDisconnectedCounter());
135 } 133 }
136 134
137 } // namespace content 135 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698