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

Unified Diff: content/browser/device_orientation/data_fetcher_impl_android_unittest.cc

Issue 18572014: Implement Android shared memory data fetcher for Device Motion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@renderer-sync-12June-tryASYNC-2-bis-tryRebase-6
Patch Set: fixed some includes Created 7 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: 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..32a2f46ff66f7d3064eb4182dd374b51a9224e12
--- /dev/null
+++ b/content/browser/device_orientation/data_fetcher_impl_android_unittest.cc
@@ -0,0 +1,101 @@
+// 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 "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 {
bulach 2013/07/09 09:03:29 nit: align the "int" with the ( above
timvolodine 2013/07/09 18:59:56 Done.
+ return true;
+ }
+
+ virtual int GetNumberActiveDeviceMotionSensors() OVERRIDE {
+ return number_active_sensors_;
+ }
+
+ void SetNumberActiveDeviceMotionSensors(int numberActiveSensors) {
bulach 2013/07/09 09:03:29 nit: param name, number_active_sensors
timvolodine 2013/07/09 18:59:56 Done.
+ number_active_sensors_ = numberActiveSensors;
+ }
+
+ private:
+ int number_active_sensors_;
+};
+
+class AndroidDataFetcherTest : public testing::Test {
+ public:
bulach 2013/07/09 09:03:29 nit: can remove the "public" label here..
timvolodine 2013/07/09 18:59:56 Done.
+ protected:
+ AndroidDataFetcherTest() {
+ buffer_.reset(new DeviceMotionHardwareBuffer);
+ }
+
+ scoped_ptr<DeviceMotionHardwareBuffer> buffer_;
+};
+
+TEST_F(AndroidDataFetcherTest, ThreeDeviceMotionSensorsActive) {
+ MockDataFetcherImplAndroid::Register(base::android::AttachCurrentThread());
+ MockDataFetcherImplAndroid fetcher;
+ fetcher.SetNumberActiveDeviceMotionSensors(3);
+
+ fetcher.StartFetchingDeviceMotionData(buffer_.get());
+ ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive);
+
+ fetcher.GotAcceleration(0, 0, 1, 2, 3);
+ ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive);
+
+ fetcher.GotAccelerationIncludingGravity(0, 0, 1, 2, 3);
+ ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive);
+
+ fetcher.GotRotationRate(0, 0, 1, 2, 3);
+ ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive);
+
+ fetcher.StopFetchingDeviceMotionData();
+ ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive);
+}
+
+TEST_F(AndroidDataFetcherTest, TwoDeviceMotionSensorsActive) {
+ MockDataFetcherImplAndroid::Register(base::android::AttachCurrentThread());
+ MockDataFetcherImplAndroid fetcher;
+ fetcher.SetNumberActiveDeviceMotionSensors(2);
+
+ fetcher.StartFetchingDeviceMotionData(buffer_.get());
+ ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive);
+
+ fetcher.GotAcceleration(0, 0, 1, 2, 3);
+ ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive);
+
+ fetcher.GotAccelerationIncludingGravity(0, 0, 1, 2, 3);
+ ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive);
+
+ fetcher.StopFetchingDeviceMotionData();
+ ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive);
+}
+
+TEST_F(AndroidDataFetcherTest, ZeroDeviceMotionSensorsActive) {
+ MockDataFetcherImplAndroid::Register(base::android::AttachCurrentThread());
+ MockDataFetcherImplAndroid fetcher;
+ fetcher.SetNumberActiveDeviceMotionSensors(0);
+
+ fetcher.StartFetchingDeviceMotionData(buffer_.get());
+ ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive);
+
+ fetcher.StopFetchingDeviceMotionData();
+ ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive);
+}
+
+} // namespace
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698