| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/process_util.h" | 6 #include "base/process_util.h" |
| 7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "base/system_monitor/system_monitor.h" | 8 #include "base/system_monitor/system_monitor.h" |
| 9 #include "content/browser/gamepad/data_fetcher.h" |
| 9 #include "content/browser/gamepad/gamepad_provider.h" | 10 #include "content/browser/gamepad/gamepad_provider.h" |
| 11 #include "content/common/gamepad_hardware_buffer.h" |
| 10 #include "content/common/gamepad_messages.h" | 12 #include "content/common/gamepad_messages.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.
h" |
| 12 | 15 |
| 13 namespace content { | 16 namespace content { |
| 14 | 17 |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| 17 using WebKit::WebGamepads; | 20 using WebKit::WebGamepads; |
| 18 | 21 |
| 19 class MockDataFetcher : public GamepadDataFetcher { | 22 class MockDataFetcher : public GamepadDataFetcher { |
| 20 public: | 23 public: |
| 21 MockDataFetcher(WebGamepads& test_data) : read_data_(false, false) { | 24 explicit MockDataFetcher(const WebGamepads& test_data) |
| 22 test_data_ = test_data; | 25 : test_data_(test_data), |
| 26 read_data_(false, false) { |
| 23 } | 27 } |
| 24 virtual void GetGamepadData(WebGamepads* pads, | 28 virtual void GetGamepadData(WebGamepads* pads, |
| 25 bool devices_changed_hint) OVERRIDE { | 29 bool devices_changed_hint) OVERRIDE { |
| 26 *pads = test_data_; | 30 *pads = test_data_; |
| 27 read_data_.Signal(); | 31 read_data_.Signal(); |
| 28 } | 32 } |
| 29 | 33 |
| 30 void WaitForDataRead() { return read_data_.Wait(); } | 34 void WaitForDataRead() { return read_data_.Wait(); } |
| 31 | 35 |
| 32 WebGamepads test_data_; | 36 WebGamepads test_data_; |
| 33 base::WaitableEvent read_data_; | 37 base::WaitableEvent read_data_; |
| 34 }; | 38 }; |
| 35 | 39 |
| 36 // Main test fixture | 40 // Main test fixture |
| 37 class GamepadProviderTest : public testing::Test { | 41 class GamepadProviderTest : public testing::Test { |
| 38 public: | 42 public: |
| 39 GamepadProvider* CreateProvider(WebGamepads& test_data) { | 43 GamepadProvider* CreateProvider(const WebGamepads& test_data) { |
| 40 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
| 41 base::SystemMonitor::AllocateSystemIOPorts(); | 45 base::SystemMonitor::AllocateSystemIOPorts(); |
| 42 #endif | 46 #endif |
| 43 system_monitor_.reset(new base::SystemMonitor); | 47 system_monitor_.reset(new base::SystemMonitor); |
| 44 mock_data_fetcher_ = new MockDataFetcher(test_data); | 48 mock_data_fetcher_ = new MockDataFetcher(test_data); |
| 45 provider_ = new GamepadProvider(mock_data_fetcher_); | 49 provider_ = new GamepadProvider(mock_data_fetcher_); |
| 46 return provider_.get(); | 50 return provider_.get(); |
| 47 } | 51 } |
| 48 | 52 |
| 49 protected: | 53 protected: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 EXPECT_EQ(1u, output.length); | 99 EXPECT_EQ(1u, output.length); |
| 96 EXPECT_EQ(1u, output.items[0].buttonsLength); | 100 EXPECT_EQ(1u, output.items[0].buttonsLength); |
| 97 EXPECT_EQ(1.f, output.items[0].buttons[0]); | 101 EXPECT_EQ(1.f, output.items[0].buttons[0]); |
| 98 EXPECT_EQ(2u, output.items[0].axesLength); | 102 EXPECT_EQ(2u, output.items[0].axesLength); |
| 99 EXPECT_EQ(-1.f, output.items[0].axes[0]); | 103 EXPECT_EQ(-1.f, output.items[0].axes[0]); |
| 100 EXPECT_EQ(0.5f, output.items[0].axes[1]); | 104 EXPECT_EQ(0.5f, output.items[0].axes[1]); |
| 101 } | 105 } |
| 102 | 106 |
| 103 } // namespace | 107 } // namespace |
| 104 | 108 |
| 105 } // namespace content | 109 } // namespace content |
| OLD | NEW |