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

Side by Side Diff: content/renderer/device_sensors/device_motion_event_pump_unittest.cc

Issue 2082343002: Remove calls to deprecated MessageLoop methods in content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR Created 4 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/renderer/device_sensors/device_motion_event_pump.h" 5 #include "content/renderer/device_sensors/device_motion_event_pump.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
16 #include "content/common/device_sensors/device_motion_hardware_buffer.h" 17 #include "content/common/device_sensors/device_motion_hardware_buffer.h"
17 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic eMotionListener.h" 20 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic eMotionListener.h"
20 21
21 namespace content { 22 namespace content {
22 23
23 class MockDeviceMotionListener : public blink::WebDeviceMotionListener { 24 class MockDeviceMotionListener : public blink::WebDeviceMotionListener {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 }; 131 };
131 132
132 TEST_F(DeviceMotionEventPumpTest, DidStartPolling) { 133 TEST_F(DeviceMotionEventPumpTest, DidStartPolling) {
133 base::MessageLoopForUI loop; 134 base::MessageLoopForUI loop;
134 135
135 InitBuffer(true); 136 InitBuffer(true);
136 137
137 motion_pump()->Start(listener()); 138 motion_pump()->Start(listener());
138 motion_pump()->OnDidStart(handle()); 139 motion_pump()->OnDidStart(handle());
139 140
140 base::MessageLoop::current()->Run(); 141 base::RunLoop().Run();
141 142
142 const blink::WebDeviceMotionData& received_data = listener()->data(); 143 const blink::WebDeviceMotionData& received_data = listener()->data();
143 EXPECT_TRUE(listener()->did_change_device_motion()); 144 EXPECT_TRUE(listener()->did_change_device_motion());
144 EXPECT_TRUE(received_data.hasAccelerationX); 145 EXPECT_TRUE(received_data.hasAccelerationX);
145 EXPECT_EQ(1, static_cast<double>(received_data.accelerationX)); 146 EXPECT_EQ(1, static_cast<double>(received_data.accelerationX));
146 EXPECT_TRUE(received_data.hasAccelerationX); 147 EXPECT_TRUE(received_data.hasAccelerationX);
147 EXPECT_EQ(2, static_cast<double>(received_data.accelerationY)); 148 EXPECT_EQ(2, static_cast<double>(received_data.accelerationY));
148 EXPECT_TRUE(received_data.hasAccelerationY); 149 EXPECT_TRUE(received_data.hasAccelerationY);
149 EXPECT_EQ(3, static_cast<double>(received_data.accelerationZ)); 150 EXPECT_EQ(3, static_cast<double>(received_data.accelerationZ));
150 EXPECT_TRUE(received_data.hasAccelerationZ); 151 EXPECT_TRUE(received_data.hasAccelerationZ);
151 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX); 152 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX);
152 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY); 153 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY);
153 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityZ); 154 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityZ);
154 EXPECT_FALSE(received_data.hasRotationRateAlpha); 155 EXPECT_FALSE(received_data.hasRotationRateAlpha);
155 EXPECT_FALSE(received_data.hasRotationRateBeta); 156 EXPECT_FALSE(received_data.hasRotationRateBeta);
156 EXPECT_FALSE(received_data.hasRotationRateGamma); 157 EXPECT_FALSE(received_data.hasRotationRateGamma);
157 } 158 }
158 159
159 TEST_F(DeviceMotionEventPumpTest, DidStartPollingNotAllSensorsActive) { 160 TEST_F(DeviceMotionEventPumpTest, DidStartPollingNotAllSensorsActive) {
160 base::MessageLoopForUI loop; 161 base::MessageLoopForUI loop;
161 162
162 InitBuffer(false); 163 InitBuffer(false);
163 164
164 motion_pump()->Start(listener()); 165 motion_pump()->Start(listener());
165 motion_pump()->OnDidStart(handle()); 166 motion_pump()->OnDidStart(handle());
166 167
167 base::MessageLoop::current()->Run(); 168 base::RunLoop().Run();
168 169
169 const blink::WebDeviceMotionData& received_data = listener()->data(); 170 const blink::WebDeviceMotionData& received_data = listener()->data();
170 // No change in device motion because allAvailableSensorsAreActive is false. 171 // No change in device motion because allAvailableSensorsAreActive is false.
171 EXPECT_FALSE(listener()->did_change_device_motion()); 172 EXPECT_FALSE(listener()->did_change_device_motion());
172 EXPECT_FALSE(received_data.hasAccelerationX); 173 EXPECT_FALSE(received_data.hasAccelerationX);
173 EXPECT_FALSE(received_data.hasAccelerationX); 174 EXPECT_FALSE(received_data.hasAccelerationX);
174 EXPECT_FALSE(received_data.hasAccelerationY); 175 EXPECT_FALSE(received_data.hasAccelerationY);
175 EXPECT_FALSE(received_data.hasAccelerationZ); 176 EXPECT_FALSE(received_data.hasAccelerationZ);
176 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX); 177 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX);
177 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY); 178 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY);
(...skipping 14 matching lines...) Expand all
192 193
193 InitBuffer(true); 194 InitBuffer(true);
194 195
195 motion_pump()->set_stop_on_fire_event(false); 196 motion_pump()->set_stop_on_fire_event(false);
196 motion_pump()->Start(listener()); 197 motion_pump()->Start(listener());
197 motion_pump()->OnDidStart(handle()); 198 motion_pump()->OnDidStart(handle());
198 199
199 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 200 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
200 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 201 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
201 base::TimeDelta::FromMilliseconds(100)); 202 base::TimeDelta::FromMilliseconds(100));
202 base::MessageLoop::current()->Run(); 203 base::RunLoop().Run();
203 motion_pump()->Stop(); 204 motion_pump()->Stop();
204 205
205 // Check that the blink::WebDeviceMotionListener does not receive excess 206 // Check that the blink::WebDeviceMotionListener does not receive excess
206 // events. 207 // events.
207 EXPECT_TRUE(listener()->did_change_device_motion()); 208 EXPECT_TRUE(listener()->did_change_device_motion());
208 EXPECT_GE(6, listener()->number_of_events()); 209 EXPECT_GE(6, listener()->number_of_events());
209 } 210 }
210 211
211 } // namespace content 212 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698