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

Side by Side Diff: content/renderer/device_sensors/device_orientation_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_orientation_event_pump.h" 5 #include "device_orientation_event_pump.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" 9 #include "content/common/device_sensors/device_orientation_hardware_buffer.h"
10 #include "content/public/test/test_utils.h" 10 #include "content/public/test/test_utils.h"
(...skipping 28 matching lines...) Expand all
39 39
40 private: 40 private:
41 bool did_change_device_orientation_; 41 bool did_change_device_orientation_;
42 blink::WebDeviceOrientationData data_; 42 blink::WebDeviceOrientationData data_;
43 43
44 DISALLOW_COPY_AND_ASSIGN(MockDeviceOrientationListener); 44 DISALLOW_COPY_AND_ASSIGN(MockDeviceOrientationListener);
45 }; 45 };
46 46
47 class DeviceOrientationEventPumpForTesting : public DeviceOrientationEventPump { 47 class DeviceOrientationEventPumpForTesting : public DeviceOrientationEventPump {
48 public: 48 public:
49 DeviceOrientationEventPumpForTesting() 49 DeviceOrientationEventPumpForTesting() { }
50 : DeviceOrientationEventPump(0) { }
51 virtual ~DeviceOrientationEventPumpForTesting() { } 50 virtual ~DeviceOrientationEventPumpForTesting() { }
52 51
53 void OnDidStart(base::SharedMemoryHandle renderer_handle) { 52 void OnDidStart(base::SharedMemoryHandle renderer_handle) {
54 DeviceOrientationEventPump::OnDidStart(renderer_handle); 53 DeviceOrientationEventPump::OnDidStart(renderer_handle);
55 } 54 }
56 virtual void SendStartMessage() OVERRIDE { } 55 virtual bool SendStartMessage() OVERRIDE { return true; }
57 virtual void SendStopMessage() OVERRIDE { } 56 virtual bool SendStopMessage() OVERRIDE { return true; }
58 virtual void FireEvent() OVERRIDE { 57 virtual void FireEvent() OVERRIDE {
59 DeviceOrientationEventPump::FireEvent(); 58 DeviceOrientationEventPump::FireEvent();
60 Stop(); 59 Stop();
61 base::MessageLoop::current()->QuitWhenIdle(); 60 base::MessageLoop::current()->QuitWhenIdle();
62 } 61 }
63 62
64 private: 63 private:
65 DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPumpForTesting); 64 DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPumpForTesting);
66 }; 65 };
67 66
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 base::SharedMemory shared_memory_; 114 base::SharedMemory shared_memory_;
116 DeviceOrientationHardwareBuffer* buffer_; 115 DeviceOrientationHardwareBuffer* buffer_;
117 116
118 DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPumpTest); 117 DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPumpTest);
119 }; 118 };
120 119
121 TEST_F(DeviceOrientationEventPumpTest, DidStartPolling) { 120 TEST_F(DeviceOrientationEventPumpTest, DidStartPolling) {
122 base::MessageLoop loop; 121 base::MessageLoop loop;
123 122
124 InitBuffer(); 123 InitBuffer();
125 orientation_pump()->Start(listener()); 124 orientation_pump()->SetListener(listener());
126 orientation_pump()->OnDidStart(handle()); 125 orientation_pump()->OnDidStart(handle());
127 126
128 base::MessageLoop::current()->Run(); 127 base::MessageLoop::current()->Run();
129 128
130 const blink::WebDeviceOrientationData& received_data = listener()->data(); 129 const blink::WebDeviceOrientationData& received_data = listener()->data();
131 EXPECT_TRUE(listener()->did_change_device_orientation()); 130 EXPECT_TRUE(listener()->did_change_device_orientation());
132 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); 131 EXPECT_TRUE(received_data.allAvailableSensorsAreActive);
133 EXPECT_EQ(1, static_cast<double>(received_data.alpha)); 132 EXPECT_EQ(1, static_cast<double>(received_data.alpha));
134 EXPECT_TRUE(received_data.hasAlpha); 133 EXPECT_TRUE(received_data.hasAlpha);
135 EXPECT_EQ(2, static_cast<double>(received_data.beta)); 134 EXPECT_EQ(2, static_cast<double>(received_data.beta));
136 EXPECT_TRUE(received_data.hasBeta); 135 EXPECT_TRUE(received_data.hasBeta);
137 EXPECT_EQ(3, static_cast<double>(received_data.gamma)); 136 EXPECT_EQ(3, static_cast<double>(received_data.gamma));
138 EXPECT_TRUE(received_data.hasGamma); 137 EXPECT_TRUE(received_data.hasGamma);
139 } 138 }
140 139
141 TEST_F(DeviceOrientationEventPumpTest, FireAllNullEvent) { 140 TEST_F(DeviceOrientationEventPumpTest, FireAllNullEvent) {
142 base::MessageLoop loop; 141 base::MessageLoop loop;
143 142
144 InitBufferNoData(); 143 InitBufferNoData();
145 orientation_pump()->Start(listener()); 144 orientation_pump()->SetListener(listener());
146 orientation_pump()->OnDidStart(handle()); 145 orientation_pump()->OnDidStart(handle());
147 146
148 base::MessageLoop::current()->Run(); 147 base::MessageLoop::current()->Run();
149 148
150 const blink::WebDeviceOrientationData& received_data = listener()->data(); 149 const blink::WebDeviceOrientationData& received_data = listener()->data();
151 EXPECT_TRUE(listener()->did_change_device_orientation()); 150 EXPECT_TRUE(listener()->did_change_device_orientation());
152 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); 151 EXPECT_TRUE(received_data.allAvailableSensorsAreActive);
153 EXPECT_FALSE(received_data.hasAlpha); 152 EXPECT_FALSE(received_data.hasAlpha);
154 EXPECT_FALSE(received_data.hasBeta); 153 EXPECT_FALSE(received_data.hasBeta);
155 EXPECT_FALSE(received_data.hasGamma); 154 EXPECT_FALSE(received_data.hasGamma);
156 } 155 }
157 156
158 TEST_F(DeviceOrientationEventPumpTest, UpdateRespectsOrientationThreshold) { 157 TEST_F(DeviceOrientationEventPumpTest, UpdateRespectsOrientationThreshold) {
159 base::MessageLoop loop; 158 base::MessageLoop loop;
160 159
161 InitBuffer(); 160 InitBuffer();
162 orientation_pump()->Start(listener()); 161 orientation_pump()->SetListener(listener());
163 orientation_pump()->OnDidStart(handle()); 162 orientation_pump()->OnDidStart(handle());
164 163
165 base::MessageLoop::current()->Run(); 164 base::MessageLoop::current()->Run();
166 165
167 const blink::WebDeviceOrientationData& received_data = listener()->data(); 166 const blink::WebDeviceOrientationData& received_data = listener()->data();
168 EXPECT_TRUE(listener()->did_change_device_orientation()); 167 EXPECT_TRUE(listener()->did_change_device_orientation());
169 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); 168 EXPECT_TRUE(received_data.allAvailableSensorsAreActive);
170 EXPECT_EQ(1, static_cast<double>(received_data.alpha)); 169 EXPECT_EQ(1, static_cast<double>(received_data.alpha));
171 EXPECT_TRUE(received_data.hasAlpha); 170 EXPECT_TRUE(received_data.hasAlpha);
172 EXPECT_EQ(2, static_cast<double>(received_data.beta)); 171 EXPECT_EQ(2, static_cast<double>(received_data.beta));
173 EXPECT_TRUE(received_data.hasBeta); 172 EXPECT_TRUE(received_data.hasBeta);
174 EXPECT_EQ(3, static_cast<double>(received_data.gamma)); 173 EXPECT_EQ(3, static_cast<double>(received_data.gamma));
175 EXPECT_TRUE(received_data.hasGamma); 174 EXPECT_TRUE(received_data.hasGamma);
176 175
177 buffer()->data.alpha = 176 buffer()->data.alpha =
178 1 + DeviceOrientationEventPump::kOrientationThreshold / 2.0; 177 1 + DeviceOrientationEventPump::kOrientationThreshold / 2.0;
179 listener()->set_did_change_device_orientation(false); 178 listener()->set_did_change_device_orientation(false);
180 179
181 // Reset the pump's listener.
182 orientation_pump()->Start(listener());
183
184 base::MessageLoop::current()->PostTask(FROM_HERE, 180 base::MessageLoop::current()->PostTask(FROM_HERE,
185 base::Bind(&DeviceOrientationEventPumpForTesting::FireEvent, 181 base::Bind(&DeviceOrientationEventPumpForTesting::FireEvent,
186 base::Unretained(orientation_pump()))); 182 base::Unretained(orientation_pump())));
187 base::MessageLoop::current()->Run(); 183 base::MessageLoop::current()->Run();
188 184
189 EXPECT_FALSE(listener()->did_change_device_orientation()); 185 EXPECT_FALSE(listener()->did_change_device_orientation());
190 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); 186 EXPECT_TRUE(received_data.allAvailableSensorsAreActive);
191 EXPECT_EQ(1, static_cast<double>(received_data.alpha)); 187 EXPECT_EQ(1, static_cast<double>(received_data.alpha));
192 EXPECT_TRUE(received_data.hasAlpha); 188 EXPECT_TRUE(received_data.hasAlpha);
193 EXPECT_EQ(2, static_cast<double>(received_data.beta)); 189 EXPECT_EQ(2, static_cast<double>(received_data.beta));
194 EXPECT_TRUE(received_data.hasBeta); 190 EXPECT_TRUE(received_data.hasBeta);
195 EXPECT_EQ(3, static_cast<double>(received_data.gamma)); 191 EXPECT_EQ(3, static_cast<double>(received_data.gamma));
196 EXPECT_TRUE(received_data.hasGamma); 192 EXPECT_TRUE(received_data.hasGamma);
197 193
198 buffer()->data.alpha = 194 buffer()->data.alpha =
199 1 + DeviceOrientationEventPump::kOrientationThreshold; 195 1 + DeviceOrientationEventPump::kOrientationThreshold;
200 listener()->set_did_change_device_orientation(false); 196 listener()->set_did_change_device_orientation(false);
201 197
202 // Reset the pump's listener.
203 orientation_pump()->Start(listener());
204
205 base::MessageLoop::current()->PostTask(FROM_HERE, 198 base::MessageLoop::current()->PostTask(FROM_HERE,
206 base::Bind(&DeviceOrientationEventPumpForTesting::FireEvent, 199 base::Bind(&DeviceOrientationEventPumpForTesting::FireEvent,
207 base::Unretained(orientation_pump()))); 200 base::Unretained(orientation_pump())));
208 base::MessageLoop::current()->Run(); 201 base::MessageLoop::current()->Run();
209 202
210 EXPECT_TRUE(listener()->did_change_device_orientation()); 203 EXPECT_TRUE(listener()->did_change_device_orientation());
211 EXPECT_EQ(1 + DeviceOrientationEventPump::kOrientationThreshold, 204 EXPECT_EQ(1 + DeviceOrientationEventPump::kOrientationThreshold,
212 static_cast<double>(received_data.alpha)); 205 static_cast<double>(received_data.alpha));
213 } 206 }
214 207
215 } // namespace content 208 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698