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 numberActiveSensors) { | |
31 number_active_sensors_ = numberActiveSensors; | |
32 } | |
33 | |
34 private: | |
35 int number_active_sensors_; | |
36 }; | |
37 | |
38 class AndroidDataFetcherTest : public testing::Test { | |
39 public: | |
40 protected: | |
41 AndroidDataFetcherTest() { | |
42 buffer_.reset(new DeviceMotionHardwareBuffer); | |
43 } | |
44 | |
45 scoped_ptr<DeviceMotionHardwareBuffer> buffer_; | |
46 }; | |
47 | |
48 TEST_F(AndroidDataFetcherTest, ThreeDeviceMotionSensorsActive) { | |
49 MockDataFetcherImplAndroid::Init(base::android::AttachCurrentThread()); | |
50 MockDataFetcherImplAndroid fetcher; | |
51 fetcher.SetNumberActiveDeviceMotionSensors(3); | |
52 fetcher.StartFetchingDeviceMotionData(buffer_.get()); | |
53 | |
54 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
55 fetcher.GotAcceleration(0, 0, 1, 2, 3); | |
56 | |
57 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
58 fetcher.GotAccelerationIncludingGravity(0, 0, 1, 2, 3); | |
59 | |
60 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
61 fetcher.GotRotationRate(0, 0, 1, 2, 3); | |
62 | |
63 ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive); | |
64 | |
65 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.
| |
66 } | |
67 | |
68 TEST_F(AndroidDataFetcherTest, TwoDeviceMotionSensorsActive) { | |
69 MockDataFetcherImplAndroid::Init(base::android::AttachCurrentThread()); | |
70 MockDataFetcherImplAndroid fetcher; | |
71 fetcher.SetNumberActiveDeviceMotionSensors(2); | |
72 fetcher.StartFetchingDeviceMotionData(buffer_.get()); | |
73 | |
74 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
75 fetcher.GotAcceleration(0, 0, 1, 2, 3); | |
76 | |
77 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
78 fetcher.GotAccelerationIncludingGravity(0, 0, 1, 2, 3); | |
79 | |
80 ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive); | |
81 | |
82 fetcher.StopFetchingDeviceMotionData(); | |
83 } | |
84 | |
85 TEST_F(AndroidDataFetcherTest, ZeroDeviceMotionSensorsActive) { | |
86 MockDataFetcherImplAndroid::Init(base::android::AttachCurrentThread()); | |
87 MockDataFetcherImplAndroid fetcher; | |
88 fetcher.SetNumberActiveDeviceMotionSensors(0); | |
89 fetcher.StartFetchingDeviceMotionData(buffer_.get()); | |
90 | |
91 ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive); | |
92 | |
93 fetcher.StopFetchingDeviceMotionData(); | |
94 } | |
95 | |
96 } // namespace | |
97 | |
98 } // namespace content | |
OLD | NEW |