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

Unified Diff: content/browser/device_orientation/data_fetcher_impl_android_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: factored out as much code as possible from the templated reader 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/browser/device_orientation/data_fetcher_impl_android_unittest.cc
diff --git a/content/browser/device_orientation/data_fetcher_impl_android_unittest.cc b/content/browser/device_orientation/data_fetcher_impl_android_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8fbcc80280058bf08467340e43540bd142e450d0
--- /dev/null
+++ b/content/browser/device_orientation/data_fetcher_impl_android_unittest.cc
@@ -0,0 +1,100 @@
+// 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 "base/android/jni_android.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/process_util.h"
+#include "content/browser/device_orientation/data_fetcher_impl_android.h"
+#include "content/common/device_motion_hardware_buffer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+
+namespace content {
+
+namespace {
+
+class MockDataFetcherImplAndroid : public DataFetcherImplAndroid {
+ public:
+ MockDataFetcherImplAndroid() { }
+ virtual ~MockDataFetcherImplAndroid() { }
+
+ virtual bool Start(DeviceData::Type event_type,
+ int rate_in_milliseconds) OVERRIDE {
+ return true;
+ }
+
+ virtual int GetNumberActiveDeviceMotionSensors() OVERRIDE {
+ return number_active_sensors_;
+ }
+
+ void SetNumberActiveDeviceMotionSensors(int numberActiveSensors) {
+ number_active_sensors_ = numberActiveSensors;
+ }
+
+ private:
+ int number_active_sensors_;
+};
+
+class AndroidDataFetcherTest : public testing::Test {
+ public:
+ protected:
+ AndroidDataFetcherTest() {
+ buffer_.reset(new DeviceMotionHardwareBuffer);
+ }
+
+ scoped_ptr<DeviceMotionHardwareBuffer> buffer_;
+};
+
+TEST_F(AndroidDataFetcherTest, ThreeDeviceMotionSensorsActive) {
+ MockDataFetcherImplAndroid::Init(base::android::AttachCurrentThread());
+ MockDataFetcherImplAndroid fetcher;
+ fetcher.SetNumberActiveDeviceMotionSensors(3);
+ fetcher.StartFetchingDeviceMotionData(buffer_.get());
+
+ ASSERT_FALSE(buffer_->is_ready_for_read);
+ fetcher.GotAcceleration(0, 0, 1, 2, 3);
+
+ ASSERT_FALSE(buffer_->is_ready_for_read);
+ fetcher.GotAccelerationIncludingGravity(0, 0, 1, 2, 3);
+
+ ASSERT_FALSE(buffer_->is_ready_for_read);
+ fetcher.GotRotationRate(0, 0, 1, 2, 3);
+
+ ASSERT_TRUE(buffer_->is_ready_for_read);
+
+ fetcher.StopFetchingDeviceMotionData();
+}
+
+TEST_F(AndroidDataFetcherTest, TwoDeviceMotionSensorsActive) {
+ MockDataFetcherImplAndroid::Init(base::android::AttachCurrentThread());
+ MockDataFetcherImplAndroid fetcher;
+ fetcher.SetNumberActiveDeviceMotionSensors(2);
+ fetcher.StartFetchingDeviceMotionData(buffer_.get());
+
+ ASSERT_FALSE(buffer_->is_ready_for_read);
+ fetcher.GotAcceleration(0, 0, 1, 2, 3);
+
+ ASSERT_FALSE(buffer_->is_ready_for_read);
+ fetcher.GotAccelerationIncludingGravity(0, 0, 1, 2, 3);
+
+ ASSERT_TRUE(buffer_->is_ready_for_read);
+
+ fetcher.StopFetchingDeviceMotionData();
+}
+
+TEST_F(AndroidDataFetcherTest, ZeroDeviceMotionSensorsActive) {
+ MockDataFetcherImplAndroid::Init(base::android::AttachCurrentThread());
+ MockDataFetcherImplAndroid fetcher;
+ fetcher.SetNumberActiveDeviceMotionSensors(0);
+ fetcher.StartFetchingDeviceMotionData(buffer_.get());
+
+ ASSERT_TRUE(buffer_->is_ready_for_read);
+
+ fetcher.StopFetchingDeviceMotionData();
+}
+
+} // namespace
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698