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