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

Unified Diff: device/gamepad/gamepad_provider_unittest.cc

Issue 2081583002: Migrating majority of gamepad from content/browser/ to device/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final tweaks 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
« no previous file with comments | « device/gamepad/gamepad_provider.cc ('k') | device/gamepad/gamepad_shared_buffer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/gamepad/gamepad_provider_unittest.cc
diff --git a/content/browser/gamepad/gamepad_provider_unittest.cc b/device/gamepad/gamepad_provider_unittest.cc
similarity index 74%
rename from content/browser/gamepad/gamepad_provider_unittest.cc
rename to device/gamepad/gamepad_provider_unittest.cc
index 19ec02b48dd4d83e6d7f24f0ea42847b01793113..91116cda6d010a7f2ebaffaf02e4a7cff40649dc 100644
--- a/content/browser/gamepad/gamepad_provider_unittest.cc
+++ b/device/gamepad/gamepad_provider_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/gamepad/gamepad_provider.h"
+#include "device/gamepad/gamepad_provider.h"
#include <memory>
@@ -10,13 +10,11 @@
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "build/build_config.h"
-#include "content/browser/gamepad/gamepad_data_fetcher.h"
-#include "content/browser/gamepad/gamepad_test_helpers.h"
-#include "content/common/gamepad_hardware_buffer.h"
-#include "content/common/gamepad_messages.h"
+#include "device/gamepad/gamepad_data_fetcher.h"
+#include "device/gamepad/gamepad_test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace content {
+namespace device {
namespace {
@@ -25,10 +23,7 @@ using blink::WebGamepads;
// Helper class to generate and record user gesture callbacks.
class UserGestureListener {
public:
- UserGestureListener()
- : has_user_gesture_(false),
- weak_factory_(this) {
- }
+ UserGestureListener() : has_user_gesture_(false), weak_factory_(this) {}
base::Closure GetClosure() {
return base::Bind(&UserGestureListener::GotUserGesture,
@@ -38,9 +33,7 @@ class UserGestureListener {
bool has_user_gesture() const { return has_user_gesture_; }
private:
- void GotUserGesture() {
- has_user_gesture_ = true;
- }
+ void GotUserGesture() { has_user_gesture_ = true; }
bool has_user_gesture_;
base::WeakPtrFactory<UserGestureListener> weak_factory_;
@@ -52,13 +45,13 @@ class GamepadProviderTest : public testing::Test, public GamepadTestHelper {
GamepadProvider* CreateProvider(const WebGamepads& test_data) {
mock_data_fetcher_ = new MockGamepadDataFetcher(test_data);
provider_.reset(new GamepadProvider(
- std::unique_ptr<GamepadDataFetcher>(mock_data_fetcher_)));
+ std::unique_ptr<GamepadSharedBuffer>(new MockGamepadSharedBuffer()),
+ nullptr, std::unique_ptr<GamepadDataFetcher>(mock_data_fetcher_)));
return provider_.get();
}
protected:
- GamepadProviderTest() {
- }
+ GamepadProviderTest() {}
std::unique_ptr<GamepadProvider> provider_;
@@ -99,26 +92,18 @@ TEST_F(GamepadProviderTest, MAYBE_PollingAccess) {
base::GetCurrentProcessHandle());
std::unique_ptr<base::SharedMemory> shared_memory(
new base::SharedMemory(handle, true));
- EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer)));
+ EXPECT_TRUE(shared_memory->Map(sizeof(WebGamepads)));
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));
-
- EXPECT_EQ(1u, output.length);
- EXPECT_EQ(1u, output.items[0].buttonsLength);
- EXPECT_EQ(1.f, output.items[0].buttons[0].value);
- EXPECT_EQ(true, output.items[0].buttons[0].pressed);
- EXPECT_EQ(2u, output.items[0].axesLength);
- EXPECT_EQ(-1.f, output.items[0].axes[0]);
- EXPECT_EQ(0.5f, output.items[0].axes[1]);
+ WebGamepads* output = static_cast<WebGamepads*>(mem);
+
+ EXPECT_EQ(1u, output->length);
+ EXPECT_EQ(1u, output->items[0].buttonsLength);
+ EXPECT_EQ(1.f, output->items[0].buttons[0].value);
+ EXPECT_EQ(true, output->items[0].buttons[0].pressed);
+ EXPECT_EQ(2u, output->items[0].axesLength);
+ EXPECT_EQ(-1.f, output->items[0].axes[0]);
+ EXPECT_EQ(0.5f, output->items[0].axes[1]);
}
// Tests that waiting for a user gesture works properly.
@@ -160,4 +145,4 @@ TEST_F(GamepadProviderTest, UserGesture) {
} // namespace
-} // namespace content
+} // namespace device
« no previous file with comments | « device/gamepad/gamepad_provider.cc ('k') | device/gamepad/gamepad_shared_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698