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 { | |
bulach
2013/07/09 09:03:29
nit: align the "int" with the ( above
timvolodine
2013/07/09 18:59:56
Done.
| |
23 return true; | |
24 } | |
25 | |
26 virtual int GetNumberActiveDeviceMotionSensors() OVERRIDE { | |
27 return number_active_sensors_; | |
28 } | |
29 | |
30 void SetNumberActiveDeviceMotionSensors(int numberActiveSensors) { | |
bulach
2013/07/09 09:03:29
nit: param name, number_active_sensors
timvolodine
2013/07/09 18:59:56
Done.
| |
31 number_active_sensors_ = numberActiveSensors; | |
32 } | |
33 | |
34 private: | |
35 int number_active_sensors_; | |
36 }; | |
37 | |
38 class AndroidDataFetcherTest : public testing::Test { | |
39 public: | |
bulach
2013/07/09 09:03:29
nit: can remove the "public" label here..
timvolodine
2013/07/09 18:59:56
Done.
| |
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::Register(base::android::AttachCurrentThread()); | |
50 MockDataFetcherImplAndroid fetcher; | |
51 fetcher.SetNumberActiveDeviceMotionSensors(3); | |
52 | |
53 fetcher.StartFetchingDeviceMotionData(buffer_.get()); | |
54 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
55 | |
56 fetcher.GotAcceleration(0, 0, 1, 2, 3); | |
57 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
58 | |
59 fetcher.GotAccelerationIncludingGravity(0, 0, 1, 2, 3); | |
60 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
61 | |
62 fetcher.GotRotationRate(0, 0, 1, 2, 3); | |
63 ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive); | |
64 | |
65 fetcher.StopFetchingDeviceMotionData(); | |
66 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
67 } | |
68 | |
69 TEST_F(AndroidDataFetcherTest, TwoDeviceMotionSensorsActive) { | |
70 MockDataFetcherImplAndroid::Register(base::android::AttachCurrentThread()); | |
71 MockDataFetcherImplAndroid fetcher; | |
72 fetcher.SetNumberActiveDeviceMotionSensors(2); | |
73 | |
74 fetcher.StartFetchingDeviceMotionData(buffer_.get()); | |
75 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
76 | |
77 fetcher.GotAcceleration(0, 0, 1, 2, 3); | |
78 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
79 | |
80 fetcher.GotAccelerationIncludingGravity(0, 0, 1, 2, 3); | |
81 ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive); | |
82 | |
83 fetcher.StopFetchingDeviceMotionData(); | |
84 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
85 } | |
86 | |
87 TEST_F(AndroidDataFetcherTest, ZeroDeviceMotionSensorsActive) { | |
88 MockDataFetcherImplAndroid::Register(base::android::AttachCurrentThread()); | |
89 MockDataFetcherImplAndroid fetcher; | |
90 fetcher.SetNumberActiveDeviceMotionSensors(0); | |
91 | |
92 fetcher.StartFetchingDeviceMotionData(buffer_.get()); | |
93 ASSERT_TRUE(buffer_->data.allAvailableSensorsAreActive); | |
94 | |
95 fetcher.StopFetchingDeviceMotionData(); | |
96 ASSERT_FALSE(buffer_->data.allAvailableSensorsAreActive); | |
97 } | |
98 | |
99 } // namespace | |
100 | |
101 } // namespace content | |
OLD | NEW |