OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device_motion_event_pump.h" | 5 #include "device_motion_event_pump.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "content/common/device_orientation/device_motion_hardware_buffer.h" | 10 #include "content/common/device_orientation/device_motion_hardware_buffer.h" |
11 #include "content/public/test/test_utils.h" | 11 #include "content/public/test/test_utils.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/WebKit/public/platform/WebDeviceMotionListener.h" | 13 #include "third_party/WebKit/public/platform/WebDeviceMotionListener.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 class DeviceMotionEventPumpTest : public testing::Test { | 17 class DeviceMotionEventPumpTest : public testing::Test { |
18 }; | 18 }; |
19 | 19 |
20 class MockDeviceMotionListener : public WebKit::WebDeviceMotionListener { | 20 class MockDeviceMotionListener : public blink::WebDeviceMotionListener { |
21 public: | 21 public: |
22 MockDeviceMotionListener(); | 22 MockDeviceMotionListener(); |
23 virtual ~MockDeviceMotionListener() { } | 23 virtual ~MockDeviceMotionListener() { } |
24 virtual void didChangeDeviceMotion( | 24 virtual void didChangeDeviceMotion( |
25 const WebKit::WebDeviceMotionData&) OVERRIDE; | 25 const blink::WebDeviceMotionData&) OVERRIDE; |
26 bool did_change_device_motion_; | 26 bool did_change_device_motion_; |
27 WebKit::WebDeviceMotionData data_; | 27 blink::WebDeviceMotionData data_; |
28 }; | 28 }; |
29 | 29 |
30 MockDeviceMotionListener::MockDeviceMotionListener() | 30 MockDeviceMotionListener::MockDeviceMotionListener() |
31 : did_change_device_motion_(false) { | 31 : did_change_device_motion_(false) { |
32 memset(&data_, 0, sizeof(data_)); | 32 memset(&data_, 0, sizeof(data_)); |
33 } | 33 } |
34 | 34 |
35 void MockDeviceMotionListener::didChangeDeviceMotion( | 35 void MockDeviceMotionListener::didChangeDeviceMotion( |
36 const WebKit::WebDeviceMotionData& data) { | 36 const blink::WebDeviceMotionData& data) { |
37 memcpy(&data_, &data, sizeof(data)); | 37 memcpy(&data_, &data, sizeof(data)); |
38 did_change_device_motion_ = true; | 38 did_change_device_motion_ = true; |
39 } | 39 } |
40 | 40 |
41 class DeviceMotionEventPumpForTesting : public DeviceMotionEventPump { | 41 class DeviceMotionEventPumpForTesting : public DeviceMotionEventPump { |
42 public: | 42 public: |
43 DeviceMotionEventPumpForTesting() { } | 43 DeviceMotionEventPumpForTesting() { } |
44 virtual ~DeviceMotionEventPumpForTesting() { } | 44 virtual ~DeviceMotionEventPumpForTesting() { } |
45 | 45 |
46 void OnDidStart(base::SharedMemoryHandle renderer_handle) { | 46 void OnDidStart(base::SharedMemoryHandle renderer_handle) { |
(...skipping 17 matching lines...) Expand all Loading... |
64 | 64 |
65 base::SharedMemoryHandle handle; | 65 base::SharedMemoryHandle handle; |
66 base::SharedMemory shared_memory; | 66 base::SharedMemory shared_memory; |
67 EXPECT_TRUE(shared_memory.CreateAndMapAnonymous( | 67 EXPECT_TRUE(shared_memory.CreateAndMapAnonymous( |
68 sizeof(DeviceMotionHardwareBuffer))); | 68 sizeof(DeviceMotionHardwareBuffer))); |
69 DeviceMotionHardwareBuffer* buffer = | 69 DeviceMotionHardwareBuffer* buffer = |
70 static_cast<DeviceMotionHardwareBuffer*>(shared_memory.memory()); | 70 static_cast<DeviceMotionHardwareBuffer*>(shared_memory.memory()); |
71 memset(buffer, 0, sizeof(DeviceMotionHardwareBuffer)); | 71 memset(buffer, 0, sizeof(DeviceMotionHardwareBuffer)); |
72 shared_memory.ShareToProcess(base::kNullProcessHandle, &handle); | 72 shared_memory.ShareToProcess(base::kNullProcessHandle, &handle); |
73 | 73 |
74 WebKit::WebDeviceMotionData& data = buffer->data; | 74 blink::WebDeviceMotionData& data = buffer->data; |
75 data.accelerationX = 1; | 75 data.accelerationX = 1; |
76 data.hasAccelerationX = true; | 76 data.hasAccelerationX = true; |
77 data.accelerationY = 2; | 77 data.accelerationY = 2; |
78 data.hasAccelerationY = true; | 78 data.hasAccelerationY = true; |
79 data.accelerationZ = 3; | 79 data.accelerationZ = 3; |
80 data.hasAccelerationZ = true; | 80 data.hasAccelerationZ = true; |
81 data.allAvailableSensorsAreActive = true; | 81 data.allAvailableSensorsAreActive = true; |
82 | 82 |
83 motion_pump->SetListener(listener.get()); | 83 motion_pump->SetListener(listener.get()); |
84 motion_pump->OnDidStart(handle); | 84 motion_pump->OnDidStart(handle); |
85 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( | 85 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
86 motion_pump->GetDelayMillis() * 2)); | 86 motion_pump->GetDelayMillis() * 2)); |
87 RunAllPendingInMessageLoop(); | 87 RunAllPendingInMessageLoop(); |
88 motion_pump->SetListener(0); | 88 motion_pump->SetListener(0); |
89 | 89 |
90 WebKit::WebDeviceMotionData& received_data = listener->data_; | 90 blink::WebDeviceMotionData& received_data = listener->data_; |
91 EXPECT_TRUE(listener->did_change_device_motion_); | 91 EXPECT_TRUE(listener->did_change_device_motion_); |
92 EXPECT_TRUE(received_data.hasAccelerationX); | 92 EXPECT_TRUE(received_data.hasAccelerationX); |
93 EXPECT_EQ(1, (double)received_data.accelerationX); | 93 EXPECT_EQ(1, (double)received_data.accelerationX); |
94 EXPECT_TRUE(received_data.hasAccelerationX); | 94 EXPECT_TRUE(received_data.hasAccelerationX); |
95 EXPECT_EQ(2, (double)received_data.accelerationY); | 95 EXPECT_EQ(2, (double)received_data.accelerationY); |
96 EXPECT_TRUE(received_data.hasAccelerationY); | 96 EXPECT_TRUE(received_data.hasAccelerationY); |
97 EXPECT_EQ(3, (double)received_data.accelerationZ); | 97 EXPECT_EQ(3, (double)received_data.accelerationZ); |
98 EXPECT_TRUE(received_data.hasAccelerationZ); | 98 EXPECT_TRUE(received_data.hasAccelerationZ); |
99 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX); | 99 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX); |
100 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY); | 100 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY); |
(...skipping 20 matching lines...) Expand all Loading... |
121 | 121 |
122 base::SharedMemoryHandle handle; | 122 base::SharedMemoryHandle handle; |
123 base::SharedMemory shared_memory; | 123 base::SharedMemory shared_memory; |
124 EXPECT_TRUE(shared_memory.CreateAndMapAnonymous( | 124 EXPECT_TRUE(shared_memory.CreateAndMapAnonymous( |
125 sizeof(DeviceMotionHardwareBuffer))); | 125 sizeof(DeviceMotionHardwareBuffer))); |
126 DeviceMotionHardwareBuffer* buffer = | 126 DeviceMotionHardwareBuffer* buffer = |
127 static_cast<DeviceMotionHardwareBuffer*>(shared_memory.memory()); | 127 static_cast<DeviceMotionHardwareBuffer*>(shared_memory.memory()); |
128 memset(buffer, 0, sizeof(DeviceMotionHardwareBuffer)); | 128 memset(buffer, 0, sizeof(DeviceMotionHardwareBuffer)); |
129 shared_memory.ShareToProcess(base::kNullProcessHandle, &handle); | 129 shared_memory.ShareToProcess(base::kNullProcessHandle, &handle); |
130 | 130 |
131 WebKit::WebDeviceMotionData& data = buffer->data; | 131 blink::WebDeviceMotionData& data = buffer->data; |
132 data.accelerationX = 1; | 132 data.accelerationX = 1; |
133 data.hasAccelerationX = true; | 133 data.hasAccelerationX = true; |
134 data.accelerationY = 2; | 134 data.accelerationY = 2; |
135 data.hasAccelerationY = true; | 135 data.hasAccelerationY = true; |
136 data.accelerationZ = 3; | 136 data.accelerationZ = 3; |
137 data.hasAccelerationZ = true; | 137 data.hasAccelerationZ = true; |
138 data.allAvailableSensorsAreActive = false; | 138 data.allAvailableSensorsAreActive = false; |
139 | 139 |
140 motion_pump->SetListener(listener.get()); | 140 motion_pump->SetListener(listener.get()); |
141 motion_pump->OnDidStart(handle); | 141 motion_pump->OnDidStart(handle); |
142 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( | 142 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
143 motion_pump->GetDelayMillis() * 2)); | 143 motion_pump->GetDelayMillis() * 2)); |
144 RunAllPendingInMessageLoop(); | 144 RunAllPendingInMessageLoop(); |
145 motion_pump->SetListener(0); | 145 motion_pump->SetListener(0); |
146 | 146 |
147 WebKit::WebDeviceMotionData& received_data = listener->data_; | 147 blink::WebDeviceMotionData& received_data = listener->data_; |
148 // No change in device motion because allAvailableSensorsAreActive is false. | 148 // No change in device motion because allAvailableSensorsAreActive is false. |
149 EXPECT_FALSE(listener->did_change_device_motion_); | 149 EXPECT_FALSE(listener->did_change_device_motion_); |
150 EXPECT_FALSE(received_data.hasAccelerationX); | 150 EXPECT_FALSE(received_data.hasAccelerationX); |
151 EXPECT_FALSE(received_data.hasAccelerationX); | 151 EXPECT_FALSE(received_data.hasAccelerationX); |
152 EXPECT_FALSE(received_data.hasAccelerationY); | 152 EXPECT_FALSE(received_data.hasAccelerationY); |
153 EXPECT_FALSE(received_data.hasAccelerationZ); | 153 EXPECT_FALSE(received_data.hasAccelerationZ); |
154 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX); | 154 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX); |
155 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY); | 155 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY); |
156 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityZ); | 156 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityZ); |
157 EXPECT_FALSE(received_data.hasRotationRateAlpha); | 157 EXPECT_FALSE(received_data.hasRotationRateAlpha); |
158 EXPECT_FALSE(received_data.hasRotationRateBeta); | 158 EXPECT_FALSE(received_data.hasRotationRateBeta); |
159 EXPECT_FALSE(received_data.hasRotationRateGamma); | 159 EXPECT_FALSE(received_data.hasRotationRateGamma); |
160 } | 160 } |
161 | 161 |
162 } // namespace content | 162 } // namespace content |
OLD | NEW |