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

Unified 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: Fixed unit test issue and Mac XBoxDataFetcher constructor Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: device/gamepad/gamepad_provider_unittest.cc
diff --git a/device/gamepad/gamepad_provider_unittest.cc b/device/gamepad/gamepad_provider_unittest.cc
index 91116cda6d010a7f2ebaffaf02e4a7cff40649dc..ed64d231c96f20af1140ede0dc571ff276c35ac9 100644
--- a/device/gamepad/gamepad_provider_unittest.cc
+++ b/device/gamepad/gamepad_provider_unittest.cc
@@ -81,6 +81,7 @@ TEST_F(GamepadProviderTest, MAYBE_PollingAccess) {
test_data.items[0].axes[1] = .5f;
GamepadProvider* provider = CreateProvider(test_data);
+ provider->SetSanitizationEnabled(false);
provider->Resume();
base::RunLoop().RunUntilIdle();
@@ -125,6 +126,7 @@ TEST_F(GamepadProviderTest, UserGesture) {
UserGestureListener listener;
GamepadProvider* provider = CreateProvider(no_button_data);
+ provider->SetSanitizationEnabled(false);
provider->Resume();
provider->RegisterForUserGesture(listener.GetClosure());
@@ -143,6 +145,81 @@ TEST_F(GamepadProviderTest, UserGesture) {
EXPECT_TRUE(listener.has_user_gesture());
}
+// Tests that waiting for a user gesture works properly.
denniskempin 2016/07/11 22:44:50 update comment
+TEST_F(GamepadProviderTest, Sanitization) {
+ WebGamepads active_data;
+ active_data.length = 1;
+ active_data.items[0].connected = true;
+ active_data.items[0].timestamp = 0;
+ active_data.items[0].buttonsLength = 1;
+ active_data.items[0].axesLength = 1;
+ active_data.items[0].buttons[0].value = 1.f;
+ active_data.items[0].buttons[0].pressed = true;
+ active_data.items[0].axes[0] = -1.f;
+
+ WebGamepads zero_data;
+ zero_data.length = 1;
+ zero_data.items[0].connected = true;
+ zero_data.items[0].timestamp = 0;
+ zero_data.items[0].buttonsLength = 1;
+ zero_data.items[0].axesLength = 1;
+ zero_data.items[0].buttons[0].value = 0.f;
+ zero_data.items[0].buttons[0].pressed = false;
+ zero_data.items[0].axes[0] = 0.f;
+
+ UserGestureListener listener;
+ GamepadProvider* provider = CreateProvider(active_data);
+ provider->SetSanitizationEnabled(true);
+ provider->Resume();
+
+ message_loop().RunUntilIdle();
+
+ mock_data_fetcher_->WaitForDataRead();
+
+ // Renderer-side, pull data out of poll buffer.
+ base::SharedMemoryHandle handle = provider->GetSharedMemoryHandleForProcess(
+ base::GetCurrentProcessHandle());
+ std::unique_ptr<base::SharedMemory> shared_memory(
+ new base::SharedMemory(handle, true));
+ EXPECT_TRUE(shared_memory->Map(sizeof(WebGamepads)));
+ void* mem = shared_memory->memory();
+
+ WebGamepads* output = static_cast<WebGamepads*>(mem);
+
+ // Initial data should all be zeroed out due to sanitization, even though the
+ // gamepad reported input
+ EXPECT_EQ(1u, output->length);
+ EXPECT_EQ(1u, output->items[0].buttonsLength);
+ EXPECT_EQ(0.f, output->items[0].buttons[0].value);
+ EXPECT_FALSE(output->items[0].buttons[0].pressed);
+ EXPECT_EQ(1u, output->items[0].axesLength);
+ EXPECT_EQ(0.f, output->items[0].axes[0]);
+
+ // Zero out the inputs
+ mock_data_fetcher_->SetTestData(zero_data);
+ mock_data_fetcher_->WaitForDataReadAndCallbacksIssued();
+
+ // Should still read zero, which is now an accurate reflection of the data
+ EXPECT_EQ(1u, output->length);
+ EXPECT_EQ(1u, output->items[0].buttonsLength);
+ EXPECT_EQ(0.f, output->items[0].buttons[0].value);
+ EXPECT_FALSE(output->items[0].buttons[0].pressed);
+ EXPECT_EQ(1u, output->items[0].axesLength);
+ EXPECT_EQ(0.f, output->items[0].axes[0]);
+
+ // Re-set the active inputs
+ mock_data_fetcher_->SetTestData(active_data);
+ mock_data_fetcher_->WaitForDataReadAndCallbacksIssued();
+
+ // Should now accurately reflect the reported data.
+ EXPECT_EQ(1u, output->length);
+ EXPECT_EQ(1u, output->items[0].buttonsLength);
+ EXPECT_EQ(1.f, output->items[0].buttons[0].value);
+ EXPECT_TRUE(output->items[0].buttons[0].pressed);
+ EXPECT_EQ(1u, output->items[0].axesLength);
+ EXPECT_EQ(-1.f, output->items[0].axes[0]);
+}
+
} // namespace
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698