Chromium Code Reviews| 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..51786aa513c96027132abff39f9a70983e29cdb1 |
| --- /dev/null |
| +++ b/content/browser/device_orientation/data_fetcher_impl_android_unittest.cc |
| @@ -0,0 +1,98 @@ |
| +// 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 { |
| + 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_->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(); |
|
bulach
2013/07/04 08:23:36
nit: for completeness, could add this after the St
timvolodine
2013/07/04 12:02:52
Done.
|
| +} |
| + |
| +TEST_F(AndroidDataFetcherTest, TwoDeviceMotionSensorsActive) { |
| + MockDataFetcherImplAndroid::Init(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(); |
| +} |
| + |
| +TEST_F(AndroidDataFetcherTest, ZeroDeviceMotionSensorsActive) { |
| + MockDataFetcherImplAndroid::Init(base::android::AttachCurrentThread()); |
| + MockDataFetcherImplAndroid fetcher; |
| + fetcher.SetNumberActiveDeviceMotionSensors(0); |
| + fetcher.StartFetchingDeviceMotionData(buffer_.get()); |
| + |
| + ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive); |
| + |
| + fetcher.StopFetchingDeviceMotionData(); |
| +} |
| + |
| +} // namespace |
| + |
| +} // namespace content |