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_motion_hardware_buffer.h" | 10 #include "content/common/device_motion_hardware_buffer.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 void MockDeviceMotionListener::didChangeDeviceMotion( | 35 void MockDeviceMotionListener::didChangeDeviceMotion( |
36 const WebKit::WebDeviceMotionData& data) { | 36 const WebKit::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 void OnDidStartDeviceMotion(base::SharedMemoryHandle handle); | 45 |
46 bool SetListener(WebKit::WebDeviceMotionListener*); | 46 void OnDidStart(base::SharedMemoryHandle renderer_handle) { |
47 bool StartFetchingDeviceMotion(); | 47 DeviceMotionEventPump::OnDidStart(renderer_handle); |
48 bool StopFetchingDeviceMotion(); | 48 } |
| 49 virtual bool SendStartMessage() OVERRIDE { return true; } |
| 50 virtual bool SendStopMessage() OVERRIDE { return true; } |
49 }; | 51 }; |
50 | 52 |
51 bool DeviceMotionEventPumpForTesting::StartFetchingDeviceMotion() { | |
52 state_ = PENDING_START; | |
53 return true; | |
54 } | |
55 | |
56 bool DeviceMotionEventPumpForTesting::StopFetchingDeviceMotion() { | |
57 if (timer_.IsRunning()) | |
58 timer_.Stop(); | |
59 state_ = STOPPED; | |
60 return true; | |
61 } | |
62 | |
63 bool DeviceMotionEventPumpForTesting::SetListener( | |
64 WebKit::WebDeviceMotionListener* listener) { | |
65 listener_ = listener; | |
66 return (listener_) ? StartFetchingDeviceMotion() : StopFetchingDeviceMotion(); | |
67 } | |
68 | |
69 void DeviceMotionEventPumpForTesting::OnDidStartDeviceMotion( | |
70 base::SharedMemoryHandle handle) { | |
71 DeviceMotionEventPump::OnDidStartDeviceMotion(handle); | |
72 } | |
73 | |
74 // Always failing in the win try bot. See http://crbug.com/256782. | 53 // Always failing in the win try bot. See http://crbug.com/256782. |
75 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
76 #define MAYBE_DidStartPolling DISABLED_DidStartPolling | 55 #define MAYBE_DidStartPolling DISABLED_DidStartPolling |
77 #else | 56 #else |
78 #define MAYBE_DidStartPolling DidStartPolling | 57 #define MAYBE_DidStartPolling DidStartPolling |
79 #endif | 58 #endif |
80 TEST_F(DeviceMotionEventPumpTest, MAYBE_DidStartPolling) { | 59 TEST_F(DeviceMotionEventPumpTest, MAYBE_DidStartPolling) { |
81 base::MessageLoop loop(base::MessageLoop::TYPE_UI); | 60 base::MessageLoop loop(base::MessageLoop::TYPE_UI); |
82 scoped_ptr<MockDeviceMotionListener> listener(new MockDeviceMotionListener); | 61 scoped_ptr<MockDeviceMotionListener> listener(new MockDeviceMotionListener); |
83 scoped_ptr<DeviceMotionEventPumpForTesting> motion_pump( | 62 scoped_ptr<DeviceMotionEventPumpForTesting> motion_pump( |
(...skipping 11 matching lines...) Expand all Loading... |
95 WebKit::WebDeviceMotionData& data = buffer->data; | 74 WebKit::WebDeviceMotionData& data = buffer->data; |
96 data.accelerationX = 1; | 75 data.accelerationX = 1; |
97 data.hasAccelerationX = true; | 76 data.hasAccelerationX = true; |
98 data.accelerationY = 2; | 77 data.accelerationY = 2; |
99 data.hasAccelerationY = true; | 78 data.hasAccelerationY = true; |
100 data.accelerationZ = 3; | 79 data.accelerationZ = 3; |
101 data.hasAccelerationZ = true; | 80 data.hasAccelerationZ = true; |
102 data.allAvailableSensorsAreActive = true; | 81 data.allAvailableSensorsAreActive = true; |
103 | 82 |
104 motion_pump->SetListener(listener.get()); | 83 motion_pump->SetListener(listener.get()); |
105 motion_pump->OnDidStartDeviceMotion(handle); | 84 motion_pump->OnDidStart(handle); |
106 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( | 85 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
107 DeviceMotionEventPump::GetDelayMillis() * 2)); | 86 motion_pump->GetDelayMillis() * 2)); |
108 RunAllPendingInMessageLoop(); | 87 RunAllPendingInMessageLoop(); |
109 motion_pump->SetListener(0); | 88 motion_pump->SetListener(0); |
110 | 89 |
111 WebKit::WebDeviceMotionData& received_data = listener->data_; | 90 WebKit::WebDeviceMotionData& received_data = listener->data_; |
112 EXPECT_TRUE(listener->did_change_device_motion_); | 91 EXPECT_TRUE(listener->did_change_device_motion_); |
113 EXPECT_TRUE(received_data.hasAccelerationX); | 92 EXPECT_TRUE(received_data.hasAccelerationX); |
114 EXPECT_EQ(1, (double)received_data.accelerationX); | 93 EXPECT_EQ(1, (double)received_data.accelerationX); |
115 EXPECT_TRUE(received_data.hasAccelerationX); | 94 EXPECT_TRUE(received_data.hasAccelerationX); |
116 EXPECT_EQ(2, (double)received_data.accelerationY); | 95 EXPECT_EQ(2, (double)received_data.accelerationY); |
117 EXPECT_TRUE(received_data.hasAccelerationY); | 96 EXPECT_TRUE(received_data.hasAccelerationY); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 WebKit::WebDeviceMotionData& data = buffer->data; | 131 WebKit::WebDeviceMotionData& data = buffer->data; |
153 data.accelerationX = 1; | 132 data.accelerationX = 1; |
154 data.hasAccelerationX = true; | 133 data.hasAccelerationX = true; |
155 data.accelerationY = 2; | 134 data.accelerationY = 2; |
156 data.hasAccelerationY = true; | 135 data.hasAccelerationY = true; |
157 data.accelerationZ = 3; | 136 data.accelerationZ = 3; |
158 data.hasAccelerationZ = true; | 137 data.hasAccelerationZ = true; |
159 data.allAvailableSensorsAreActive = false; | 138 data.allAvailableSensorsAreActive = false; |
160 | 139 |
161 motion_pump->SetListener(listener.get()); | 140 motion_pump->SetListener(listener.get()); |
162 motion_pump->OnDidStartDeviceMotion(handle); | 141 motion_pump->OnDidStart(handle); |
163 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( | 142 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
164 DeviceMotionEventPump::GetDelayMillis() * 2)); | 143 motion_pump->GetDelayMillis() * 2)); |
165 RunAllPendingInMessageLoop(); | 144 RunAllPendingInMessageLoop(); |
166 motion_pump->SetListener(0); | 145 motion_pump->SetListener(0); |
167 | 146 |
168 WebKit::WebDeviceMotionData& received_data = listener->data_; | 147 WebKit::WebDeviceMotionData& received_data = listener->data_; |
169 // No change in device motion because allAvailableSensorsAreActive is false. | 148 // No change in device motion because allAvailableSensorsAreActive is false. |
170 EXPECT_FALSE(listener->did_change_device_motion_); | 149 EXPECT_FALSE(listener->did_change_device_motion_); |
171 EXPECT_FALSE(received_data.hasAccelerationX); | 150 EXPECT_FALSE(received_data.hasAccelerationX); |
172 EXPECT_FALSE(received_data.hasAccelerationX); | 151 EXPECT_FALSE(received_data.hasAccelerationX); |
173 EXPECT_FALSE(received_data.hasAccelerationY); | 152 EXPECT_FALSE(received_data.hasAccelerationY); |
174 EXPECT_FALSE(received_data.hasAccelerationZ); | 153 EXPECT_FALSE(received_data.hasAccelerationZ); |
175 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX); | 154 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX); |
176 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY); | 155 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY); |
177 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityZ); | 156 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityZ); |
178 EXPECT_FALSE(received_data.hasRotationRateAlpha); | 157 EXPECT_FALSE(received_data.hasRotationRateAlpha); |
179 EXPECT_FALSE(received_data.hasRotationRateBeta); | 158 EXPECT_FALSE(received_data.hasRotationRateBeta); |
180 EXPECT_FALSE(received_data.hasRotationRateGamma); | 159 EXPECT_FALSE(received_data.hasRotationRateGamma); |
181 } | 160 } |
182 | 161 |
183 } // namespace content | 162 } // namespace content |
OLD | NEW |