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..cbd395600b3e603bcadc1371c6d5edcd83520a2d |
| --- /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" |
|
bulach
2013/07/12 16:07:43
nit: I just learned the file under test should be
timvolodine
2013/07/12 17:43:56
Done.
|
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| + |
| +class MockDataFetcherImplAndroid : public DataFetcherImplAndroid { |
|
bulach
2013/07/12 16:07:43
nit: this should be named as "Fake" instead of "Mo
timvolodine
2013/07/12 17:43:56
Done.
|
| + public: |
| + MockDataFetcherImplAndroid() { } |
| + virtual ~MockDataFetcherImplAndroid() { } |
| + |
| + bool Start(DeviceData::Type event_type, |
| + int rate_in_milliseconds) OVERRIDE { |
|
bulach
2013/07/12 16:07:43
nit: indent
timvolodine
2013/07/12 17:43:56
Done.
|
| + return true; |
| + } |
| + |
| + int GetNumberActiveDeviceMotionSensors() OVERRIDE { |
| + return number_active_sensors_; |
| + } |
| + |
| + void SetNumberActiveDeviceMotionSensors(int number_active_sensors) { |
| + number_active_sensors_ = number_active_sensors; |
| + } |
| + |
| + private: |
| + int number_active_sensors_; |
| +}; |
| + |
| +class AndroidDataFetcherTest : public testing::Test { |
| + 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(); |
| + ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); |
| +} |
| + |
| +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(); |
| + ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); |
| +} |
| + |
| +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(); |
| + ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); |
| +} |
| + |
| +} // namespace |
| + |
| +} // namespace content |