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

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

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

Powered by Google App Engine
This is Rietveld 408576698