| OLD | NEW |
| 1 // Copyright (c) 2012 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/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
| 7 #include "content/browser/gamepad/gamepad_data_fetcher.h" | 7 #include "content/browser/gamepad/gamepad_data_fetcher.h" |
| 8 #include "content/browser/gamepad/gamepad_provider.h" | 8 #include "content/browser/gamepad/gamepad_provider.h" |
| 9 #include "content/browser/gamepad/gamepad_test_helpers.h" | 9 #include "content/browser/gamepad/gamepad_test_helpers.h" |
| 10 #include "content/common/gamepad_hardware_buffer.h" | 10 #include "content/common/gamepad_hardware_buffer.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // Crashes. http://crbug.com/106163 | 66 // Crashes. http://crbug.com/106163 |
| 67 TEST_F(GamepadProviderTest, PollingAccess) { | 67 TEST_F(GamepadProviderTest, PollingAccess) { |
| 68 WebGamepads test_data; | 68 WebGamepads test_data; |
| 69 test_data.length = 1; | 69 test_data.length = 1; |
| 70 test_data.items[0].connected = true; | 70 test_data.items[0].connected = true; |
| 71 test_data.items[0].timestamp = 0; | 71 test_data.items[0].timestamp = 0; |
| 72 test_data.items[0].buttonsLength = 1; | 72 test_data.items[0].buttonsLength = 1; |
| 73 test_data.items[0].axesLength = 2; | 73 test_data.items[0].axesLength = 2; |
| 74 test_data.items[0].buttons[0] = 1.f; | 74 test_data.items[0].buttons[0].value = 1.f; |
| 75 test_data.items[0].buttons[0].pressed = true; |
| 75 test_data.items[0].axes[0] = -1.f; | 76 test_data.items[0].axes[0] = -1.f; |
| 76 test_data.items[0].axes[1] = .5f; | 77 test_data.items[0].axes[1] = .5f; |
| 77 | 78 |
| 78 GamepadProvider* provider = CreateProvider(test_data); | 79 GamepadProvider* provider = CreateProvider(test_data); |
| 79 provider->Resume(); | 80 provider->Resume(); |
| 80 | 81 |
| 81 message_loop().RunUntilIdle(); | 82 message_loop().RunUntilIdle(); |
| 82 | 83 |
| 83 mock_data_fetcher_->WaitForDataRead(); | 84 mock_data_fetcher_->WaitForDataRead(); |
| 84 | 85 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 95 WebGamepads output; | 96 WebGamepads output; |
| 96 | 97 |
| 97 base::subtle::Atomic32 version; | 98 base::subtle::Atomic32 version; |
| 98 do { | 99 do { |
| 99 version = hwbuf->sequence.ReadBegin(); | 100 version = hwbuf->sequence.ReadBegin(); |
| 100 memcpy(&output, &hwbuf->buffer, sizeof(output)); | 101 memcpy(&output, &hwbuf->buffer, sizeof(output)); |
| 101 } while (hwbuf->sequence.ReadRetry(version)); | 102 } while (hwbuf->sequence.ReadRetry(version)); |
| 102 | 103 |
| 103 EXPECT_EQ(1u, output.length); | 104 EXPECT_EQ(1u, output.length); |
| 104 EXPECT_EQ(1u, output.items[0].buttonsLength); | 105 EXPECT_EQ(1u, output.items[0].buttonsLength); |
| 105 EXPECT_EQ(1.f, output.items[0].buttons[0]); | 106 EXPECT_EQ(1.f, output.items[0].buttons[0].value); |
| 107 EXPECT_EQ(true, output.items[0].buttons[0].pressed); |
| 106 EXPECT_EQ(2u, output.items[0].axesLength); | 108 EXPECT_EQ(2u, output.items[0].axesLength); |
| 107 EXPECT_EQ(-1.f, output.items[0].axes[0]); | 109 EXPECT_EQ(-1.f, output.items[0].axes[0]); |
| 108 EXPECT_EQ(0.5f, output.items[0].axes[1]); | 110 EXPECT_EQ(0.5f, output.items[0].axes[1]); |
| 109 } | 111 } |
| 110 | 112 |
| 111 // Tests that waiting for a user gesture works properly. | 113 // Tests that waiting for a user gesture works properly. |
| 112 TEST_F(GamepadProviderTest, UserGesture) { | 114 TEST_F(GamepadProviderTest, UserGesture) { |
| 113 WebGamepads no_button_data; | 115 WebGamepads no_button_data; |
| 114 no_button_data.length = 1; | 116 no_button_data.length = 1; |
| 115 no_button_data.items[0].connected = true; | 117 no_button_data.items[0].connected = true; |
| 116 no_button_data.items[0].timestamp = 0; | 118 no_button_data.items[0].timestamp = 0; |
| 117 no_button_data.items[0].buttonsLength = 1; | 119 no_button_data.items[0].buttonsLength = 1; |
| 118 no_button_data.items[0].axesLength = 2; | 120 no_button_data.items[0].axesLength = 2; |
| 119 no_button_data.items[0].buttons[0] = 0.f; | 121 no_button_data.items[0].buttons[0].value = 0.f; |
| 122 no_button_data.items[0].buttons[0].pressed = false; |
| 120 no_button_data.items[0].axes[0] = -1.f; | 123 no_button_data.items[0].axes[0] = -1.f; |
| 121 no_button_data.items[0].axes[1] = .5f; | 124 no_button_data.items[0].axes[1] = .5f; |
| 122 | 125 |
| 123 WebGamepads button_down_data = no_button_data; | 126 WebGamepads button_down_data = no_button_data; |
| 124 button_down_data.items[0].buttons[0] = 1.f; | 127 button_down_data.items[0].buttons[0].value = 1.f; |
| 128 button_down_data.items[0].buttons[0].pressed = true; |
| 125 | 129 |
| 126 UserGestureListener listener; | 130 UserGestureListener listener; |
| 127 GamepadProvider* provider = CreateProvider(no_button_data); | 131 GamepadProvider* provider = CreateProvider(no_button_data); |
| 128 provider->Resume(); | 132 provider->Resume(); |
| 129 | 133 |
| 130 // Register for a user gesture and make sure the provider reads it twice | 134 // Register for a user gesture and make sure the provider reads it twice |
| 131 // see below for why). | 135 // see below for why). |
| 132 provider->RegisterForUserGesture(listener.GetClosure()); | 136 provider->RegisterForUserGesture(listener.GetClosure()); |
| 133 mock_data_fetcher_->WaitForDataRead(); | 137 mock_data_fetcher_->WaitForDataRead(); |
| 134 mock_data_fetcher_->WaitForDataRead(); | 138 mock_data_fetcher_->WaitForDataRead(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 149 mock_data_fetcher_->WaitForDataRead(); | 153 mock_data_fetcher_->WaitForDataRead(); |
| 150 | 154 |
| 151 // It should have issued our callback. | 155 // It should have issued our callback. |
| 152 message_loop().RunUntilIdle(); | 156 message_loop().RunUntilIdle(); |
| 153 EXPECT_TRUE(listener.has_user_gesture()); | 157 EXPECT_TRUE(listener.has_user_gesture()); |
| 154 } | 158 } |
| 155 | 159 |
| 156 } // namespace | 160 } // namespace |
| 157 | 161 |
| 158 } // namespace content | 162 } // namespace content |
| OLD | NEW |