Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: content/browser/device_orientation/data_fetcher_impl_android_unittest.cc

Issue 18572014: Implement Android shared memory data fetcher for Device Motion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@renderer-sync-12June-tryASYNC-2-bis-tryRebase-6
Patch Set: fixed comments Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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"
bulach 2013/07/12 16:07:43 nit: I just learned the file under test should be
timvolodine 2013/07/12 17:43:56 Done.
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace content {
13
14 namespace {
15
16 class MockDataFetcherImplAndroid : public DataFetcherImplAndroid {
bulach 2013/07/12 16:07:43 nit: this should be named as "Fake" instead of "Mo
timvolodine 2013/07/12 17:43:56 Done.
17 public:
18 MockDataFetcherImplAndroid() { }
19 virtual ~MockDataFetcherImplAndroid() { }
20
21 bool Start(DeviceData::Type event_type,
22 int rate_in_milliseconds) OVERRIDE {
bulach 2013/07/12 16:07:43 nit: indent
timvolodine 2013/07/12 17:43:56 Done.
23 return true;
24 }
25
26 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::Init(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::Init(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::Init(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698