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