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

Unified Diff: content/browser/gamepad/gamepad_provider_unittest.cc

Issue 1627643002: Revert of Refactoring gamepad polling to support dynamically added sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « content/browser/gamepad/gamepad_provider.cc ('k') | content/browser/gamepad/gamepad_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 98045bf2931894259eec69aab062a1bbf2f85239..7e3a29c88b8d6ac1bec7bfaf4a7cdb11fd8eb9d5 100644
--- a/content/browser/gamepad/gamepad_provider_unittest.cc
+++ b/content/browser/gamepad/gamepad_provider_unittest.cc
@@ -85,7 +85,6 @@
test_data.items[0].axes[1] = .5f;
GamepadProvider* provider = CreateProvider(test_data);
- provider->SetSanitizationEnabled(false);
provider->Resume();
message_loop().RunUntilIdle();
@@ -138,7 +137,6 @@
UserGestureListener listener;
GamepadProvider* provider = CreateProvider(no_button_data);
- provider->SetSanitizationEnabled(false);
provider->Resume();
provider->RegisterForUserGesture(listener.GetClosure());
@@ -157,195 +155,6 @@
EXPECT_TRUE(listener.has_user_gesture());
}
-// Tests that waiting for a user gesture works properly.
-// Crashes on android. Seems to be same issue as the PollingAccess test
-// crbug.com/147549
-#if defined(OS_ANDROID)
-#define MAYBE_Sanitization DISABLED_Sanitization
-#else
-#define MAYBE_Sanitization Sanitization
-#endif
-TEST_F(GamepadProviderTest, MAYBE_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());
- scoped_ptr<base::SharedMemory> shared_memory(
- new base::SharedMemory(handle, true));
- EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer)));
- void* mem = shared_memory->memory();
-
- GamepadHardwareBuffer* hwbuf = static_cast<GamepadHardwareBuffer*>(mem);
- // See gamepad_hardware_buffer.h for details on the read discipline.
- WebGamepads output;
-
- base::subtle::Atomic32 version;
- do {
- version = hwbuf->sequence.ReadBegin();
- memcpy(&output, &hwbuf->buffer, sizeof(output));
- } while (hwbuf->sequence.ReadRetry(version));
-
- // 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();
-
- do {
- version = hwbuf->sequence.ReadBegin();
- memcpy(&output, &hwbuf->buffer, sizeof(output));
- } while (hwbuf->sequence.ReadRetry(version));
-
- // 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();
-
- do {
- version = hwbuf->sequence.ReadBegin();
- memcpy(&output, &hwbuf->buffer, sizeof(output));
- } while (hwbuf->sequence.ReadRetry(version));
-
- // 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]);
-}
-
-// Tests that waiting for a user gesture works properly.
-// Crashes on android. Seems to be same issue as the PollingAccess test
-// crbug.com/147549
-#if defined(OS_ANDROID)
-#define MAYBE_DynamicallyAddedDataFetcher DISABLED_DynamicallyAddedDataFetcher
-#else
-#define MAYBE_DynamicallyAddedDataFetcher DynamicallyAddedDataFetcher
-#endif
-TEST_F(GamepadProviderTest, MAYBE_DynamicallyAddedDataFetcher) {
- 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;
-
- UserGestureListener listener;
- GamepadProvider* provider = CreateProvider(active_data);
- provider->SetSanitizationEnabled(false);
- provider->Resume();
-
- message_loop().RunUntilIdle();
-
- mock_data_fetcher_->WaitForDataRead();
-
- // Renderer-side, pull data out of poll buffer.
- base::SharedMemoryHandle handle = provider->GetSharedMemoryHandleForProcess(
- base::GetCurrentProcessHandle());
- scoped_ptr<base::SharedMemory> shared_memory(
- new base::SharedMemory(handle, true));
- EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer)));
- void* mem = shared_memory->memory();
-
- GamepadHardwareBuffer* hwbuf = static_cast<GamepadHardwareBuffer*>(mem);
- // See gamepad_hardware_buffer.h for details on the read discipline.
- WebGamepads output;
-
- base::subtle::Atomic32 version;
- do {
- version = hwbuf->sequence.ReadBegin();
- memcpy(&output, &hwbuf->buffer, sizeof(output));
- } while (hwbuf->sequence.ReadRetry(version));
-
- // Should still accurately report the test 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]);
-
- WebGamepads active_data_2;
- active_data_2.length = 1;
- active_data_2.items[1].connected = true;
- active_data_2.items[1].timestamp = 0;
- active_data_2.items[1].buttonsLength = 1;
- active_data_2.items[1].axesLength = 1;
- active_data_2.items[1].buttons[0].value = 0.5f;
- active_data_2.items[1].buttons[0].pressed = true;
- active_data_2.items[1].axes[0] = 0.5f;
-
- // Add a new data fetcher.
- provider->AddGamepadDataFetcher(scoped_ptr<GamepadDataFetcher>(
- new MockGamepadDataFetcher(active_data_2)));
- mock_data_fetcher_->WaitForDataReadAndCallbacksIssued();
-
- do {
- version = hwbuf->sequence.ReadBegin();
- memcpy(&output, &hwbuf->buffer, sizeof(output));
- } while (hwbuf->sequence.ReadRetry(version));
-
- // Should now report test data from both data fetchers.
- EXPECT_EQ(2u, 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]);
-
- EXPECT_EQ(1u, output.items[1].buttonsLength);
- EXPECT_EQ(0.5f, output.items[1].buttons[0].value);
- EXPECT_TRUE(output.items[1].buttons[0].pressed);
- EXPECT_EQ(1u, output.items[1].axesLength);
- EXPECT_EQ(0.5f, output.items[1].axes[0]);
-}
-
} // namespace
} // namespace content
« no previous file with comments | « content/browser/gamepad/gamepad_provider.cc ('k') | content/browser/gamepad/gamepad_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698