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

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

Issue 2129003002: Refactored gamepad polling to support dynamic sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disabled sanitization test on Android. Suffers from same bug as PollingAccess test Created 4 years, 4 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
« no previous file with comments | « device/gamepad/gamepad_provider.cc ('k') | device/gamepad/gamepad_test_helpers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "device/gamepad/gamepad_provider.h" 5 #include "device/gamepad/gamepad_provider.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 test_data.items[0].connected = true; 74 test_data.items[0].connected = true;
75 test_data.items[0].timestamp = 0; 75 test_data.items[0].timestamp = 0;
76 test_data.items[0].buttonsLength = 1; 76 test_data.items[0].buttonsLength = 1;
77 test_data.items[0].axesLength = 2; 77 test_data.items[0].axesLength = 2;
78 test_data.items[0].buttons[0].value = 1.f; 78 test_data.items[0].buttons[0].value = 1.f;
79 test_data.items[0].buttons[0].pressed = true; 79 test_data.items[0].buttons[0].pressed = true;
80 test_data.items[0].axes[0] = -1.f; 80 test_data.items[0].axes[0] = -1.f;
81 test_data.items[0].axes[1] = .5f; 81 test_data.items[0].axes[1] = .5f;
82 82
83 GamepadProvider* provider = CreateProvider(test_data); 83 GamepadProvider* provider = CreateProvider(test_data);
84 provider->SetSanitizationEnabled(false);
84 provider->Resume(); 85 provider->Resume();
85 86
86 base::RunLoop().RunUntilIdle(); 87 base::RunLoop().RunUntilIdle();
87 88
88 mock_data_fetcher_->WaitForDataRead(); 89 mock_data_fetcher_->WaitForDataRead();
89 90
90 // Renderer-side, pull data out of poll buffer. 91 // Renderer-side, pull data out of poll buffer.
91 base::SharedMemoryHandle handle = provider->GetSharedMemoryHandleForProcess( 92 base::SharedMemoryHandle handle = provider->GetSharedMemoryHandleForProcess(
92 base::GetCurrentProcessHandle()); 93 base::GetCurrentProcessHandle());
93 std::unique_ptr<base::SharedMemory> shared_memory( 94 std::unique_ptr<base::SharedMemory> shared_memory(
(...skipping 24 matching lines...) Expand all
118 no_button_data.items[0].buttons[0].pressed = false; 119 no_button_data.items[0].buttons[0].pressed = false;
119 no_button_data.items[0].axes[0] = 0.f; 120 no_button_data.items[0].axes[0] = 0.f;
120 no_button_data.items[0].axes[1] = .4f; 121 no_button_data.items[0].axes[1] = .4f;
121 122
122 WebGamepads button_down_data = no_button_data; 123 WebGamepads button_down_data = no_button_data;
123 button_down_data.items[0].buttons[0].value = 1.f; 124 button_down_data.items[0].buttons[0].value = 1.f;
124 button_down_data.items[0].buttons[0].pressed = true; 125 button_down_data.items[0].buttons[0].pressed = true;
125 126
126 UserGestureListener listener; 127 UserGestureListener listener;
127 GamepadProvider* provider = CreateProvider(no_button_data); 128 GamepadProvider* provider = CreateProvider(no_button_data);
129 provider->SetSanitizationEnabled(false);
128 provider->Resume(); 130 provider->Resume();
129 131
130 provider->RegisterForUserGesture(listener.GetClosure()); 132 provider->RegisterForUserGesture(listener.GetClosure());
131 mock_data_fetcher_->WaitForDataReadAndCallbacksIssued(); 133 mock_data_fetcher_->WaitForDataReadAndCallbacksIssued();
132 134
133 // It should not have issued our callback. 135 // It should not have issued our callback.
134 base::RunLoop().RunUntilIdle(); 136 base::RunLoop().RunUntilIdle();
135 EXPECT_FALSE(listener.has_user_gesture()); 137 EXPECT_FALSE(listener.has_user_gesture());
136 138
137 // Set a button down and wait for it to be read twice. 139 // Set a button down and wait for it to be read twice.
138 mock_data_fetcher_->SetTestData(button_down_data); 140 mock_data_fetcher_->SetTestData(button_down_data);
139 mock_data_fetcher_->WaitForDataReadAndCallbacksIssued(); 141 mock_data_fetcher_->WaitForDataReadAndCallbacksIssued();
140 142
141 // It should have issued our callback. 143 // It should have issued our callback.
142 base::RunLoop().RunUntilIdle(); 144 base::RunLoop().RunUntilIdle();
143 EXPECT_TRUE(listener.has_user_gesture()); 145 EXPECT_TRUE(listener.has_user_gesture());
144 } 146 }
145 147
148 // Crashes. http://crbug.com/106163
149 // crbug.com/147549
150 #if defined(OS_ANDROID)
151 #define MAYBE_Sanitization DISABLED_Sanitization
152 #else
153 #define MAYBE_Sanitization Sanitization
154 #endif
155 // Tests that waiting for a user gesture works properly.
156 TEST_F(GamepadProviderTest, MAYBE_Sanitization) {
157 WebGamepads active_data;
158 active_data.length = 1;
159 active_data.items[0].connected = true;
160 active_data.items[0].timestamp = 0;
161 active_data.items[0].buttonsLength = 1;
162 active_data.items[0].axesLength = 1;
163 active_data.items[0].buttons[0].value = 1.f;
164 active_data.items[0].buttons[0].pressed = true;
165 active_data.items[0].axes[0] = -1.f;
166
167 WebGamepads zero_data;
168 zero_data.length = 1;
169 zero_data.items[0].connected = true;
170 zero_data.items[0].timestamp = 0;
171 zero_data.items[0].buttonsLength = 1;
172 zero_data.items[0].axesLength = 1;
173 zero_data.items[0].buttons[0].value = 0.f;
174 zero_data.items[0].buttons[0].pressed = false;
175 zero_data.items[0].axes[0] = 0.f;
176
177 UserGestureListener listener;
178 GamepadProvider* provider = CreateProvider(active_data);
179 provider->SetSanitizationEnabled(true);
180 provider->Resume();
181
182 base::RunLoop().RunUntilIdle();
183
184 mock_data_fetcher_->WaitForDataRead();
185
186 // Renderer-side, pull data out of poll buffer.
187 base::SharedMemoryHandle handle = provider->GetSharedMemoryHandleForProcess(
188 base::GetCurrentProcessHandle());
189 std::unique_ptr<base::SharedMemory> shared_memory(
190 new base::SharedMemory(handle, true));
191 EXPECT_TRUE(shared_memory->Map(sizeof(WebGamepads)));
192 void* mem = shared_memory->memory();
193
194 WebGamepads* output = static_cast<WebGamepads*>(mem);
195
196 // Initial data should all be zeroed out due to sanitization, even though the
197 // gamepad reported input
198 EXPECT_EQ(1u, output->length);
199 EXPECT_EQ(1u, output->items[0].buttonsLength);
200 EXPECT_EQ(0.f, output->items[0].buttons[0].value);
201 EXPECT_FALSE(output->items[0].buttons[0].pressed);
202 EXPECT_EQ(1u, output->items[0].axesLength);
203 EXPECT_EQ(0.f, output->items[0].axes[0]);
204
205 // Zero out the inputs
206 mock_data_fetcher_->SetTestData(zero_data);
207 mock_data_fetcher_->WaitForDataReadAndCallbacksIssued();
208
209 // Should still read zero, which is now an accurate reflection of the data
210 EXPECT_EQ(1u, output->length);
211 EXPECT_EQ(1u, output->items[0].buttonsLength);
212 EXPECT_EQ(0.f, output->items[0].buttons[0].value);
213 EXPECT_FALSE(output->items[0].buttons[0].pressed);
214 EXPECT_EQ(1u, output->items[0].axesLength);
215 EXPECT_EQ(0.f, output->items[0].axes[0]);
216
217 // Re-set the active inputs
218 mock_data_fetcher_->SetTestData(active_data);
219 mock_data_fetcher_->WaitForDataReadAndCallbacksIssued();
220
221 // Should now accurately reflect the reported data.
222 EXPECT_EQ(1u, output->length);
223 EXPECT_EQ(1u, output->items[0].buttonsLength);
224 EXPECT_EQ(1.f, output->items[0].buttons[0].value);
225 EXPECT_TRUE(output->items[0].buttons[0].pressed);
226 EXPECT_EQ(1u, output->items[0].axesLength);
227 EXPECT_EQ(-1.f, output->items[0].axes[0]);
228 }
229
146 } // namespace 230 } // namespace
147 231
148 } // namespace device 232 } // namespace device
OLDNEW
« no previous file with comments | « device/gamepad/gamepad_provider.cc ('k') | device/gamepad/gamepad_test_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698