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

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

Issue 446603002: Refactor code listening to platform events in content/renderer/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webkitplatform_impl_start_stop
Patch Set: rebase Created 6 years, 4 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 "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_sensors/device_motion_hardware_buffer.h" 10 #include "content/common/device_sensors/device_motion_hardware_buffer.h"
(...skipping 25 matching lines...) Expand all
36 36
37 private: 37 private:
38 bool did_change_device_motion_; 38 bool did_change_device_motion_;
39 blink::WebDeviceMotionData data_; 39 blink::WebDeviceMotionData data_;
40 40
41 DISALLOW_COPY_AND_ASSIGN(MockDeviceMotionListener); 41 DISALLOW_COPY_AND_ASSIGN(MockDeviceMotionListener);
42 }; 42 };
43 43
44 class DeviceMotionEventPumpForTesting : public DeviceMotionEventPump { 44 class DeviceMotionEventPumpForTesting : public DeviceMotionEventPump {
45 public: 45 public:
46 DeviceMotionEventPumpForTesting() { } 46 DeviceMotionEventPumpForTesting()
47 : DeviceMotionEventPump(0) { }
47 virtual ~DeviceMotionEventPumpForTesting() { } 48 virtual ~DeviceMotionEventPumpForTesting() { }
48 49
49 void OnDidStart(base::SharedMemoryHandle renderer_handle) { 50 void OnDidStart(base::SharedMemoryHandle renderer_handle) {
50 DeviceMotionEventPump::OnDidStart(renderer_handle); 51 DeviceMotionEventPump::OnDidStart(renderer_handle);
51 } 52 }
52 virtual bool SendStartMessage() OVERRIDE { return true; } 53 virtual void SendStartMessage() OVERRIDE { }
53 virtual bool SendStopMessage() OVERRIDE { return true; } 54 virtual void SendStopMessage() OVERRIDE { }
54 virtual void FireEvent() OVERRIDE { 55 virtual void FireEvent() OVERRIDE {
55 DeviceMotionEventPump::FireEvent(); 56 DeviceMotionEventPump::FireEvent();
56 Stop(); 57 Stop();
57 base::MessageLoop::current()->QuitWhenIdle(); 58 base::MessageLoop::current()->QuitWhenIdle();
58 } 59 }
59 60
60 private: 61 private:
61 DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPumpForTesting); 62 DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPumpForTesting);
62 }; 63 };
63 64
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 DeviceMotionHardwareBuffer* buffer_; 104 DeviceMotionHardwareBuffer* buffer_;
104 105
105 DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPumpTest); 106 DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPumpTest);
106 }; 107 };
107 108
108 TEST_F(DeviceMotionEventPumpTest, DidStartPolling) { 109 TEST_F(DeviceMotionEventPumpTest, DidStartPolling) {
109 base::MessageLoopForUI loop; 110 base::MessageLoopForUI loop;
110 111
111 InitBuffer(true); 112 InitBuffer(true);
112 113
113 motion_pump()->SetListener(listener()); 114 motion_pump()->Start(listener());
114 motion_pump()->OnDidStart(handle()); 115 motion_pump()->OnDidStart(handle());
115 116
116 base::MessageLoop::current()->Run(); 117 base::MessageLoop::current()->Run();
117 118
118 const blink::WebDeviceMotionData& received_data = listener()->data(); 119 const blink::WebDeviceMotionData& received_data = listener()->data();
119 EXPECT_TRUE(listener()->did_change_device_motion()); 120 EXPECT_TRUE(listener()->did_change_device_motion());
120 EXPECT_TRUE(received_data.hasAccelerationX); 121 EXPECT_TRUE(received_data.hasAccelerationX);
121 EXPECT_EQ(1, static_cast<double>(received_data.accelerationX)); 122 EXPECT_EQ(1, static_cast<double>(received_data.accelerationX));
122 EXPECT_TRUE(received_data.hasAccelerationX); 123 EXPECT_TRUE(received_data.hasAccelerationX);
123 EXPECT_EQ(2, static_cast<double>(received_data.accelerationY)); 124 EXPECT_EQ(2, static_cast<double>(received_data.accelerationY));
124 EXPECT_TRUE(received_data.hasAccelerationY); 125 EXPECT_TRUE(received_data.hasAccelerationY);
125 EXPECT_EQ(3, static_cast<double>(received_data.accelerationZ)); 126 EXPECT_EQ(3, static_cast<double>(received_data.accelerationZ));
126 EXPECT_TRUE(received_data.hasAccelerationZ); 127 EXPECT_TRUE(received_data.hasAccelerationZ);
127 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX); 128 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX);
128 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY); 129 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY);
129 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityZ); 130 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityZ);
130 EXPECT_FALSE(received_data.hasRotationRateAlpha); 131 EXPECT_FALSE(received_data.hasRotationRateAlpha);
131 EXPECT_FALSE(received_data.hasRotationRateBeta); 132 EXPECT_FALSE(received_data.hasRotationRateBeta);
132 EXPECT_FALSE(received_data.hasRotationRateGamma); 133 EXPECT_FALSE(received_data.hasRotationRateGamma);
133 } 134 }
134 135
135 TEST_F(DeviceMotionEventPumpTest, DidStartPollingNotAllSensorsActive) { 136 TEST_F(DeviceMotionEventPumpTest, DidStartPollingNotAllSensorsActive) {
136 base::MessageLoopForUI loop; 137 base::MessageLoopForUI loop;
137 138
138 InitBuffer(false); 139 InitBuffer(false);
139 140
140 motion_pump()->SetListener(listener()); 141 motion_pump()->Start(listener());
141 motion_pump()->OnDidStart(handle()); 142 motion_pump()->OnDidStart(handle());
142 143
143 base::MessageLoop::current()->Run(); 144 base::MessageLoop::current()->Run();
144 145
145 const blink::WebDeviceMotionData& received_data = listener()->data(); 146 const blink::WebDeviceMotionData& received_data = listener()->data();
146 // No change in device motion because allAvailableSensorsAreActive is false. 147 // No change in device motion because allAvailableSensorsAreActive is false.
147 EXPECT_FALSE(listener()->did_change_device_motion()); 148 EXPECT_FALSE(listener()->did_change_device_motion());
148 EXPECT_FALSE(received_data.hasAccelerationX); 149 EXPECT_FALSE(received_data.hasAccelerationX);
149 EXPECT_FALSE(received_data.hasAccelerationX); 150 EXPECT_FALSE(received_data.hasAccelerationX);
150 EXPECT_FALSE(received_data.hasAccelerationY); 151 EXPECT_FALSE(received_data.hasAccelerationY);
151 EXPECT_FALSE(received_data.hasAccelerationZ); 152 EXPECT_FALSE(received_data.hasAccelerationZ);
152 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX); 153 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityX);
153 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY); 154 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityY);
154 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityZ); 155 EXPECT_FALSE(received_data.hasAccelerationIncludingGravityZ);
155 EXPECT_FALSE(received_data.hasRotationRateAlpha); 156 EXPECT_FALSE(received_data.hasRotationRateAlpha);
156 EXPECT_FALSE(received_data.hasRotationRateBeta); 157 EXPECT_FALSE(received_data.hasRotationRateBeta);
157 EXPECT_FALSE(received_data.hasRotationRateGamma); 158 EXPECT_FALSE(received_data.hasRotationRateGamma);
158 } 159 }
159 160
160 } // namespace content 161 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698