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

Unified Diff: content/renderer/device_orientation/device_motion_event_pump_unittest.cc

Issue 14678012: Implement the content/renderer and content/browser part of the Device Motion API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: implemented async messaging for obtaining the shared memory handle Created 7 years, 6 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: content/renderer/device_orientation/device_motion_event_pump_unittest.cc
diff --git a/content/renderer/device_orientation/device_motion_event_pump_unittest.cc b/content/renderer/device_orientation/device_motion_event_pump_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d27f2fffe02860d5b55456251b60a3fb518f78aa
--- /dev/null
+++ b/content/renderer/device_orientation/device_motion_event_pump_unittest.cc
@@ -0,0 +1,111 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "device_motion_event_pump.h"
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "content/public/test/test_utils.h"
+#include "device_motion_shared_memory_reader.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/public/platform/WebDeviceMotionData.h"
+#include "third_party/WebKit/public/platform/WebDeviceMotionListener.h"
+
+namespace content {
+
+class DeviceMotionEventPumpTest : public testing::Test {
+};
+
+class MockDeviceMotionListener : public WebKit::WebDeviceMotionListener {
+ public:
+ MockDeviceMotionListener();
+ virtual ~MockDeviceMotionListener() { }
+ virtual void didChangeDeviceMotion(
+ const WebKit::WebDeviceMotionData&) OVERRIDE;
+ bool did_change_device_motion_;
+ WebKit::WebDeviceMotionData data_;
+};
+
+MockDeviceMotionListener::MockDeviceMotionListener()
+ : did_change_device_motion_(false) {
+ memset(&data_, 0, sizeof(data_));
+}
+
+void MockDeviceMotionListener::didChangeDeviceMotion(
+ const WebKit::WebDeviceMotionData& data) {
+ memcpy(&data_, &data, sizeof(data));
+ did_change_device_motion_ = true;
+}
+
+class MockDeviceMotionSharedMemoryReader
+ : public DeviceMotionSharedMemoryReader {
+ public:
+ MockDeviceMotionSharedMemoryReader();
+ ~MockDeviceMotionSharedMemoryReader() { }
+ virtual bool GetLatestDeviceMotionData(
+ WebKit::WebDeviceMotionData& data) OVERRIDE;
+ virtual void StartUpdating() OVERRIDE;
+ virtual void StopUpdating() OVERRIDE;
+ int count_start_updating_;
+ int count_stop_updating_;
+ int count_latest_data_;
+};
+
+MockDeviceMotionSharedMemoryReader::MockDeviceMotionSharedMemoryReader()
+ : count_start_updating_(0),
+ count_stop_updating_(0),
+ count_latest_data_(0) {
+}
+
+bool MockDeviceMotionSharedMemoryReader::GetLatestDeviceMotionData(
+ WebKit::WebDeviceMotionData& data) {
+ data.accelerationX = 1;
+ data.hasAccelerationX = true;
+ data.accelerationY = 2;
+ data.hasAccelerationY = true;
+ data.accelerationZ = 3;
+ data.hasAccelerationZ = true;
+ count_latest_data_++;
+ return true;
+}
+
+void MockDeviceMotionSharedMemoryReader::StartUpdating() {
+ count_start_updating_++;
+}
+
+void MockDeviceMotionSharedMemoryReader::StopUpdating() {
+ count_stop_updating_++;
+}
+
+TEST_F(DeviceMotionEventPumpTest, StartUpdateStop) {
+ base::MessageLoop loop(base::MessageLoop::TYPE_UI);
+ scoped_ptr<MockDeviceMotionListener> listener(new MockDeviceMotionListener);
+ MockDeviceMotionSharedMemoryReader* reader =
+ new MockDeviceMotionSharedMemoryReader;
+ scoped_ptr<DeviceMotionEventPump> motion_pump(new DeviceMotionEventPump);
+ motion_pump->SetDeviceMotionReader(reader);
+ motion_pump->SetListener(listener.get());
+ base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
+ RunAllPendingInMessageLoop();
+ motion_pump->SetListener(0);
+ EXPECT_EQ(1, reader->count_start_updating_);
+ EXPECT_EQ(1, reader->count_latest_data_);
+ EXPECT_EQ(1, reader->count_stop_updating_);
+ EXPECT_TRUE(listener->did_change_device_motion_);
+ EXPECT_EQ(1, listener->data_.accelerationX);
+ EXPECT_TRUE(listener->data_.hasAccelerationX);
+ EXPECT_EQ(2, listener->data_.accelerationY);
+ EXPECT_TRUE(listener->data_.hasAccelerationY);
+ EXPECT_EQ(3, listener->data_.accelerationZ);
+ EXPECT_TRUE(listener->data_.hasAccelerationZ);
+ EXPECT_FALSE(listener->data_.hasAccelerationIncludingGravityX);
+ EXPECT_FALSE(listener->data_.hasAccelerationIncludingGravityY);
+ EXPECT_FALSE(listener->data_.hasAccelerationIncludingGravityZ);
+ EXPECT_FALSE(listener->data_.hasRotationRateAlpha);
+ EXPECT_FALSE(listener->data_.hasRotationRateBeta);
+ EXPECT_FALSE(listener->data_.hasRotationRateGamma);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698