| Index: content/browser/gamepad/gamepad_provider_unittest.cc
|
| diff --git a/content/browser/gamepad/gamepad_provider_unittest.cc b/content/browser/gamepad/gamepad_provider_unittest.cc
|
| index 00d48c6ad802123fcdea8d41acc5d977bfc11863..b016405e6e7c9c4d54406a126b284f8ab645f33b 100644
|
| --- a/content/browser/gamepad/gamepad_provider_unittest.cc
|
| +++ b/content/browser/gamepad/gamepad_provider_unittest.cc
|
| @@ -10,39 +10,39 @@
|
| #include "content/common/gamepad_messages.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| +namespace content {
|
| +
|
| namespace {
|
|
|
| -class MockDataFetcher : public gamepad::DataFetcher {
|
| +using WebKit::WebGamepads;
|
| +
|
| +class MockDataFetcher : public GamepadDataFetcher {
|
| public:
|
| - MockDataFetcher() : read_data_(false, false) {
|
| - memset(&test_data, 0, sizeof(test_data));
|
| + MockDataFetcher(WebGamepads& test_data) : read_data_(false, false) {
|
| + test_data_ = test_data;
|
| }
|
| - virtual void GetGamepadData(WebKit::WebGamepads* pads,
|
| + virtual void GetGamepadData(WebGamepads* pads,
|
| bool devices_changed_hint) OVERRIDE {
|
| - *pads = test_data;
|
| + *pads = test_data_;
|
| read_data_.Signal();
|
| }
|
|
|
| - void SetData(WebKit::WebGamepads& data) {
|
| - test_data = data;
|
| - }
|
| -
|
| void WaitForDataRead() { return read_data_.Wait(); }
|
|
|
| - WebKit::WebGamepads test_data;
|
| + WebGamepads test_data_;
|
| base::WaitableEvent read_data_;
|
| };
|
|
|
| // Main test fixture
|
| class GamepadProviderTest : public testing::Test {
|
| public:
|
| - gamepad::Provider* CreateProvider() {
|
| + GamepadProvider* CreateProvider(WebGamepads& test_data) {
|
| #if defined(OS_MACOSX)
|
| base::SystemMonitor::AllocateSystemIOPorts();
|
| #endif
|
| system_monitor_.reset(new base::SystemMonitor);
|
| - mock_data_fetcher_ = new MockDataFetcher;
|
| - provider_ = new gamepad::Provider(mock_data_fetcher_);
|
| + mock_data_fetcher_ = new MockDataFetcher(test_data);
|
| + provider_ = new GamepadProvider(mock_data_fetcher_);
|
| return provider_.get();
|
| }
|
|
|
| @@ -53,24 +53,20 @@ class GamepadProviderTest : public testing::Test {
|
| MessageLoop main_message_loop_;
|
| scoped_ptr<base::SystemMonitor> system_monitor_;
|
| MockDataFetcher* mock_data_fetcher_;
|
| - scoped_refptr<gamepad::Provider> provider_;
|
| + scoped_refptr<GamepadProvider> provider_;
|
| };
|
|
|
| TEST_F(GamepadProviderTest, BasicStartStop) {
|
| - gamepad::Provider* provider = CreateProvider();
|
| + WebGamepads test_data;
|
| + memset(&test_data, 0, sizeof(test_data));
|
| + GamepadProvider* provider = CreateProvider(test_data);
|
| provider->Start();
|
| provider->Stop();
|
| // Just ensure that there's no asserts on startup, shutdown, or destroy.
|
| }
|
|
|
| -// http://crbug.com/105348
|
| -TEST_F(GamepadProviderTest, FLAKY_PollingAccess) {
|
| - using namespace gamepad;
|
| -
|
| - Provider* provider = CreateProvider();
|
| - provider->Start();
|
| -
|
| - WebKit::WebGamepads test_data;
|
| +TEST_F(GamepadProviderTest, PollingAccess) {
|
| + WebGamepads test_data;
|
| test_data.length = 1;
|
| test_data.items[0].connected = true;
|
| test_data.items[0].timestamp = 0;
|
| @@ -79,7 +75,9 @@ TEST_F(GamepadProviderTest, FLAKY_PollingAccess) {
|
| test_data.items[0].buttons[0] = 1.f;
|
| test_data.items[0].axes[0] = -1.f;
|
| test_data.items[0].axes[1] = .5f;
|
| - mock_data_fetcher_->SetData(test_data);
|
| +
|
| + GamepadProvider* provider = CreateProvider(test_data);
|
| + provider->Start();
|
|
|
| main_message_loop_.RunAllPending();
|
|
|
| @@ -95,22 +93,14 @@ TEST_F(GamepadProviderTest, FLAKY_PollingAccess) {
|
|
|
| GamepadHardwareBuffer* hwbuf = static_cast<GamepadHardwareBuffer*>(mem);
|
| // See gamepad_hardware_buffer.h for details on the read discipline.
|
| - base::subtle::Atomic32 start, end;
|
| - WebKit::WebGamepads output;
|
| - int contention_count;
|
| -
|
| - // Here we're attempting to test the read discipline during contention. If
|
| - // we fail to read this many times, then the read thread is starving, and we
|
| - // should fail the test.
|
| - for (contention_count = 0; contention_count < 1000; ++contention_count) {
|
| - end = base::subtle::Acquire_Load(&hwbuf->end_marker);
|
| + WebGamepads output;
|
| +
|
| + base::subtle::Atomic32 version;
|
| + do {
|
| + version = hwbuf->sequence.ReadBegin();
|
| memcpy(&output, &hwbuf->buffer, sizeof(output));
|
| - start = base::subtle::Acquire_Load(&hwbuf->start_marker);
|
| - if (start == end)
|
| - break;
|
| - base::PlatformThread::YieldCurrentThread();
|
| - }
|
| - EXPECT_GT(1000, contention_count);
|
| + } while (hwbuf->sequence.ReadRetry(version));
|
| +
|
| EXPECT_EQ(1u, output.length);
|
| EXPECT_EQ(1u, output.items[0].buttonsLength);
|
| EXPECT_EQ(1.f, output.items[0].buttons[0]);
|
| @@ -122,3 +112,5 @@ TEST_F(GamepadProviderTest, FLAKY_PollingAccess) {
|
| }
|
|
|
| } // namespace
|
| +
|
| +} // namespace content
|
|
|