OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/android/jni_android.h" |
| 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/memory/weak_ptr.h" |
| 8 #include "base/process_util.h" |
| 9 #include "content/browser/device_orientation/data_fetcher_impl_android.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 namespace { |
| 15 |
| 16 class MockDataFetcherImplAndroid : public DataFetcherImplAndroid { |
| 17 public: |
| 18 MockDataFetcherImplAndroid() { } |
| 19 virtual ~MockDataFetcherImplAndroid() { } |
| 20 |
| 21 virtual bool Start(DeviceData::Type event_type, |
| 22 int rate_in_milliseconds) OVERRIDE { |
| 23 return true; |
| 24 } |
| 25 |
| 26 virtual int GetNumberActiveDeviceMotionSensors() OVERRIDE { |
| 27 return number_active_sensors_; |
| 28 } |
| 29 |
| 30 void SetNumberActiveDeviceMotionSensors(int number_active_sensors) { |
| 31 number_active_sensors_ = number_active_sensors; |
| 32 } |
| 33 |
| 34 private: |
| 35 int number_active_sensors_; |
| 36 }; |
| 37 |
| 38 class AndroidDataFetcherTest : public testing::Test { |
| 39 protected: |
| 40 AndroidDataFetcherTest() { |
| 41 buffer_.reset(new DeviceMotionHardwareBuffer); |
| 42 } |
| 43 |
| 44 scoped_ptr<DeviceMotionHardwareBuffer> buffer_; |
| 45 }; |
| 46 |
| 47 TEST_F(AndroidDataFetcherTest, ThreeDeviceMotionSensorsActive) { |
| 48 MockDataFetcherImplAndroid::Register(base::android::AttachCurrentThread()); |
| 49 MockDataFetcherImplAndroid fetcher; |
| 50 fetcher.SetNumberActiveDeviceMotionSensors(3); |
| 51 |
| 52 fetcher.StartFetchingDeviceMotionData(buffer_.get()); |
| 53 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); |
| 54 |
| 55 fetcher.GotAcceleration(0, 0, 1, 2, 3); |
| 56 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); |
| 57 |
| 58 fetcher.GotAccelerationIncludingGravity(0, 0, 1, 2, 3); |
| 59 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); |
| 60 |
| 61 fetcher.GotRotationRate(0, 0, 1, 2, 3); |
| 62 ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive); |
| 63 |
| 64 fetcher.StopFetchingDeviceMotionData(); |
| 65 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); |
| 66 } |
| 67 |
| 68 TEST_F(AndroidDataFetcherTest, TwoDeviceMotionSensorsActive) { |
| 69 MockDataFetcherImplAndroid::Register(base::android::AttachCurrentThread()); |
| 70 MockDataFetcherImplAndroid fetcher; |
| 71 fetcher.SetNumberActiveDeviceMotionSensors(2); |
| 72 |
| 73 fetcher.StartFetchingDeviceMotionData(buffer_.get()); |
| 74 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); |
| 75 |
| 76 fetcher.GotAcceleration(0, 0, 1, 2, 3); |
| 77 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); |
| 78 |
| 79 fetcher.GotAccelerationIncludingGravity(0, 0, 1, 2, 3); |
| 80 ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive); |
| 81 |
| 82 fetcher.StopFetchingDeviceMotionData(); |
| 83 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); |
| 84 } |
| 85 |
| 86 TEST_F(AndroidDataFetcherTest, ZeroDeviceMotionSensorsActive) { |
| 87 MockDataFetcherImplAndroid::Register(base::android::AttachCurrentThread()); |
| 88 MockDataFetcherImplAndroid fetcher; |
| 89 fetcher.SetNumberActiveDeviceMotionSensors(0); |
| 90 |
| 91 fetcher.StartFetchingDeviceMotionData(buffer_.get()); |
| 92 ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive); |
| 93 |
| 94 fetcher.StopFetchingDeviceMotionData(); |
| 95 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); |
| 96 } |
| 97 |
| 98 } // namespace |
| 99 |
| 100 } // namespace content |
OLD | NEW |