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

Side by Side Diff: device/device_sensors/device_inertial_sensor_browsertest.cc

Issue 1164563003: Extract device_sensors to /device via Mojofication (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/synchronization/waitable_event.h" 6 #include "base/synchronization/waitable_event.h"
7 #include "base/threading/platform_thread.h" 7 #include "base/threading/platform_thread.h"
8 #include "content/browser/device_sensors/data_fetcher_shared_memory.h" 8 #include "device/device_sensors/data_fetcher_shared_memory.h"
9 #include "content/browser/device_sensors/device_inertial_sensor_service.h" 9 #include "device/device_sensors/device_inertial_sensor_service.h"
10 #include "content/common/device_sensors/device_light_hardware_buffer.h" 10 #include "device/device_sensors/device_light_hardware_buffer.h"
11 #include "content/common/device_sensors/device_motion_hardware_buffer.h" 11 #include "device/device_sensors/device_motion_hardware_buffer.h"
12 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" 12 #include "device/device_sensors/device_orientation_hardware_buffer.h"
13 #include "content/public/browser/browser_thread.h" 13 //#include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/web_contents.h" 14 //#include "content/public/browser/web_contents.h"
15 #include "content/public/common/content_switches.h" 15 //#include "content/public/common/content_switches.h"
16 #include "content/public/test/content_browser_test.h" 16 //#include "content/public/test/content_browser_test.h"
17 #include "content/public/test/content_browser_test_utils.h" 17 //#include "content/public/test/content_browser_test_utils.h"
18 #include "content/public/test/test_navigation_observer.h" 18 //#include "content/public/test/test_navigation_observer.h"
19 #include "content/public/test/test_utils.h" 19 //#include "content/public/test/test_utils.h"
20 #include "content/shell/browser/shell.h" 20 //#include "content/shell/browser/shell.h"
21 #include "content/shell/browser/shell_javascript_dialog_manager.h" 21 //#include "content/shell/browser/shell_javascript_dialog_manager.h"
22 22
23 namespace content { 23 namespace content {
24 24
25 namespace { 25 namespace {
26 26
27 class FakeDataFetcher : public DataFetcherSharedMemory { 27 class FakeDataFetcher : public DataFetcherSharedMemory {
28 public: 28 public:
29 FakeDataFetcher() 29 FakeDataFetcher()
30 : started_orientation_(false, false), 30 : started_orientation_(false, false),
31 stopped_orientation_(false, false), 31 stopped_orientation_(false, false),
32 started_motion_(false, false), 32 started_motion_(false, false),
33 stopped_motion_(false, false), 33 stopped_motion_(false, false),
34 started_light_(false, false), 34 started_light_(false, false),
35 stopped_light_(false, false), 35 stopped_light_(false, false),
36 sensor_data_available_(true) {} 36 sensor_data_available_(true) {}
37 ~FakeDataFetcher() override {} 37 ~FakeDataFetcher() override {}
38 38
39 bool Start(ConsumerType consumer_type, void* buffer) override { 39 bool Start(ConsumerType consumer_type, void* buffer) override {
40 EXPECT_TRUE(buffer); 40 EXPECT_TRUE(buffer);
41 41
42 switch (consumer_type) { 42 switch (consumer_type) {
43 case CONSUMER_TYPE_MOTION: 43 case CONSUMER_TYPE_MOTION: {
44 { 44 DeviceMotionHardwareBuffer* motion_buffer =
45 DeviceMotionHardwareBuffer* motion_buffer = 45 static_cast<DeviceMotionHardwareBuffer*>(buffer);
46 static_cast<DeviceMotionHardwareBuffer*>(buffer); 46 if (sensor_data_available_)
47 if (sensor_data_available_) 47 UpdateMotion(motion_buffer);
48 UpdateMotion(motion_buffer); 48 SetMotionBufferReady(motion_buffer);
49 SetMotionBufferReady(motion_buffer); 49 started_motion_.Signal();
50 started_motion_.Signal(); 50 } break;
51 } 51 case CONSUMER_TYPE_ORIENTATION: {
52 break; 52 DeviceOrientationHardwareBuffer* orientation_buffer =
53 case CONSUMER_TYPE_ORIENTATION: 53 static_cast<DeviceOrientationHardwareBuffer*>(buffer);
54 { 54 if (sensor_data_available_)
55 DeviceOrientationHardwareBuffer* orientation_buffer = 55 UpdateOrientation(orientation_buffer);
56 static_cast<DeviceOrientationHardwareBuffer*>(buffer); 56 SetOrientationBufferReady(orientation_buffer);
57 if (sensor_data_available_) 57 started_orientation_.Signal();
58 UpdateOrientation(orientation_buffer); 58 } break;
59 SetOrientationBufferReady(orientation_buffer); 59 case CONSUMER_TYPE_LIGHT: {
60 started_orientation_.Signal(); 60 DeviceLightHardwareBuffer* light_buffer =
61 } 61 static_cast<DeviceLightHardwareBuffer*>(buffer);
62 break; 62 UpdateLight(light_buffer,
63 case CONSUMER_TYPE_LIGHT: 63 sensor_data_available_
64 { 64 ? 100
65 DeviceLightHardwareBuffer* light_buffer = 65 : std::numeric_limits<double>::infinity());
66 static_cast<DeviceLightHardwareBuffer*>(buffer); 66 started_light_.Signal();
67 UpdateLight(light_buffer, 67 } break;
68 sensor_data_available_
69 ? 100
70 : std::numeric_limits<double>::infinity());
71 started_light_.Signal();
72 }
73 break;
74 default: 68 default:
75 return false; 69 return false;
76 } 70 }
77 return true; 71 return true;
78 } 72 }
79 73
80 bool Stop(ConsumerType consumer_type) override { 74 bool Stop(ConsumerType consumer_type) override {
81 switch (consumer_type) { 75 switch (consumer_type) {
82 case CONSUMER_TYPE_MOTION: 76 case CONSUMER_TYPE_MOTION:
83 stopped_motion_.Signal(); 77 stopped_motion_.Signal();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 base::WaitableEvent started_motion_; 161 base::WaitableEvent started_motion_;
168 base::WaitableEvent stopped_motion_; 162 base::WaitableEvent stopped_motion_;
169 base::WaitableEvent started_light_; 163 base::WaitableEvent started_light_;
170 base::WaitableEvent stopped_light_; 164 base::WaitableEvent stopped_light_;
171 bool sensor_data_available_; 165 bool sensor_data_available_;
172 166
173 private: 167 private:
174 DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher); 168 DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher);
175 }; 169 };
176 170
177 171 class DeviceInertialSensorBrowserTest : public ContentBrowserTest {
178 class DeviceInertialSensorBrowserTest : public ContentBrowserTest {
179 public: 172 public:
180 DeviceInertialSensorBrowserTest() 173 DeviceInertialSensorBrowserTest()
181 : fetcher_(nullptr), io_loop_finished_event_(false, false) {} 174 : fetcher_(nullptr), io_loop_finished_event_(false, false) {}
182 175
183 void SetUpOnMainThread() override { 176 void SetUpOnMainThread() override {
184 BrowserThread::PostTask( 177 BrowserThread::PostTask(
185 BrowserThread::IO, FROM_HERE, 178 BrowserThread::IO, FROM_HERE,
186 base::Bind(&DeviceInertialSensorBrowserTest::SetUpOnIOThread, this)); 179 base::Bind(&DeviceInertialSensorBrowserTest::SetUpOnIOThread, this));
187 io_loop_finished_event_.Wait(); 180 io_loop_finished_event_.Wait();
188 } 181 }
189 182
190 void SetUpOnIOThread() { 183 void SetUpOnIOThread() {
191 fetcher_ = new FakeDataFetcher(); 184 fetcher_ = new FakeDataFetcher();
192 DeviceInertialSensorService::GetInstance()-> 185 DeviceInertialSensorService::GetInstance()->SetDataFetcherForTesting(
193 SetDataFetcherForTesting(fetcher_); 186 fetcher_);
194 io_loop_finished_event_.Signal(); 187 io_loop_finished_event_.Signal();
195 } 188 }
196 189
197 void DelayAndQuit(base::TimeDelta delay) { 190 void DelayAndQuit(base::TimeDelta delay) {
198 base::PlatformThread::Sleep(delay); 191 base::PlatformThread::Sleep(delay);
199 base::MessageLoop::current()->QuitWhenIdle(); 192 base::MessageLoop::current()->QuitWhenIdle();
200 } 193 }
201 194
202 void WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta delay) { 195 void WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta delay) {
203 ShellJavaScriptDialogManager* dialog_manager = 196 ShellJavaScriptDialogManager* dialog_manager =
204 static_cast<ShellJavaScriptDialogManager*>( 197 static_cast<ShellJavaScriptDialogManager*>(
205 shell()->GetJavaScriptDialogManager(shell()->web_contents())); 198 shell()->GetJavaScriptDialogManager(shell()->web_contents()));
206 199
207 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner(); 200 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner();
208 dialog_manager->set_dialog_request_callback( 201 dialog_manager->set_dialog_request_callback(base::Bind(
209 base::Bind(&DeviceInertialSensorBrowserTest::DelayAndQuit, this, 202 &DeviceInertialSensorBrowserTest::DelayAndQuit, this, delay));
210 delay));
211 runner->Run(); 203 runner->Run();
212 } 204 }
213 205
214 void EnableExperimentalFeatures() { 206 void EnableExperimentalFeatures() {
215 // TODO(riju): remove when the DeviceLight feature goes stable. 207 // TODO(riju): remove when the DeviceLight feature goes stable.
216 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 208 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
217 if (!cmd_line->HasSwitch(switches::kEnableExperimentalWebPlatformFeatures)) 209 if (!cmd_line->HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
218 cmd_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); 210 cmd_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures);
219 } 211 }
220 212
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // handler and navigates to #pass. 247 // handler and navigates to #pass.
256 GURL test_url = GetTestUrl("device_sensors", "device_motion_test.html"); 248 GURL test_url = GetTestUrl("device_sensors", "device_motion_test.html");
257 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); 249 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2);
258 250
259 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); 251 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
260 fetcher_->started_motion_.Wait(); 252 fetcher_->started_motion_.Wait();
261 fetcher_->stopped_motion_.Wait(); 253 fetcher_->stopped_motion_.Wait();
262 } 254 }
263 255
264 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, 256 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest,
265 LightOneOffInfintyTest) { 257 LightOneOffInfintyTest) {
266 // The test page registers an event handler for light events and expects 258 // The test page registers an event handler for light events and expects
267 // to get an event with value equal to infinity, because no sensor data can 259 // to get an event with value equal to infinity, because no sensor data can
268 // be provided. 260 // be provided.
269 EnableExperimentalFeatures(); 261 EnableExperimentalFeatures();
270 fetcher_->SetSensorDataAvailable(false); 262 fetcher_->SetSensorDataAvailable(false);
271 GURL test_url = GetTestUrl("device_sensors", 263 GURL test_url =
272 "device_light_infinity_test.html"); 264 GetTestUrl("device_sensors", "device_light_infinity_test.html");
273 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); 265 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2);
274 266
275 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); 267 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
276 fetcher_->started_light_.Wait(); 268 fetcher_->started_light_.Wait();
277 fetcher_->stopped_light_.Wait(); 269 fetcher_->stopped_light_.Wait();
278 } 270 }
279 271
280 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, OrientationNullTest) { 272 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, OrientationNullTest) {
281 // The test page registers an event handler for orientation events and 273 // The test page registers an event handler for orientation events and
282 // expects to get an event with null values, because no sensor data can be 274 // expects to get an event with null values, because no sensor data can be
283 // provided. 275 // provided.
284 fetcher_->SetSensorDataAvailable(false); 276 fetcher_->SetSensorDataAvailable(false);
285 GURL test_url = GetTestUrl("device_sensors", 277 GURL test_url =
286 "device_orientation_null_test.html"); 278 GetTestUrl("device_sensors", "device_orientation_null_test.html");
287 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); 279 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2);
288 280
289 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); 281 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
290 fetcher_->started_orientation_.Wait(); 282 fetcher_->started_orientation_.Wait();
291 fetcher_->stopped_orientation_.Wait(); 283 fetcher_->stopped_orientation_.Wait();
292 } 284 }
293 285
294 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, MotionNullTest) { 286 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, MotionNullTest) {
295 // The test page registers an event handler for motion events and 287 // The test page registers an event handler for motion events and
296 // expects to get an event with null values, because no sensor data can be 288 // expects to get an event with null values, because no sensor data can be
297 // provided. 289 // provided.
298 fetcher_->SetSensorDataAvailable(false); 290 fetcher_->SetSensorDataAvailable(false);
299 GURL test_url = GetTestUrl("device_sensors", 291 GURL test_url = GetTestUrl("device_sensors", "device_motion_null_test.html");
300 "device_motion_null_test.html");
301 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); 292 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2);
302 293
303 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); 294 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
304 fetcher_->started_motion_.Wait(); 295 fetcher_->started_motion_.Wait();
305 fetcher_->stopped_motion_.Wait(); 296 fetcher_->stopped_motion_.Wait();
306 } 297 }
307 298
308 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, 299 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest,
309 DISABLED_NullTestWithAlert) { 300 DISABLED_NullTestWithAlert) {
310 // The test page registers an event handlers for motion/orientation events 301 // The test page registers an event handlers for motion/orientation events
311 // and expects to get events with null values. The test raises a modal alert 302 // and expects to get events with null values. The test raises a modal alert
312 // dialog with a delay to test that the one-off null-events still propagate 303 // dialog with a delay to test that the one-off null-events still propagate
313 // to window after the alert is dismissed and the callbacks are invoked which 304 // to window after the alert is dismissed and the callbacks are invoked which
314 // eventually navigate to #pass. 305 // eventually navigate to #pass.
315 fetcher_->SetSensorDataAvailable(false); 306 fetcher_->SetSensorDataAvailable(false);
316 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); 307 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2);
317 308
318 GURL test_url = GetTestUrl("device_sensors", 309 GURL test_url =
319 "device_sensors_null_test_with_alert.html"); 310 GetTestUrl("device_sensors", "device_sensors_null_test_with_alert.html");
320 shell()->LoadURL(test_url); 311 shell()->LoadURL(test_url);
321 312
322 // TODO(timvolodine): investigate if it is possible to test this without 313 // TODO(timvolodine): investigate if it is possible to test this without
323 // delay, crbug.com/360044. 314 // delay, crbug.com/360044.
324 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(500)); 315 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(500));
325 316
326 fetcher_->started_motion_.Wait(); 317 fetcher_->started_motion_.Wait();
327 fetcher_->stopped_motion_.Wait(); 318 fetcher_->stopped_motion_.Wait();
328 fetcher_->started_orientation_.Wait(); 319 fetcher_->started_orientation_.Wait();
329 fetcher_->stopped_orientation_.Wait(); 320 fetcher_->stopped_orientation_.Wait();
330 same_tab_observer.Wait(); 321 same_tab_observer.Wait();
331 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); 322 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
332 } 323 }
333 324
334 } // namespace 325 } // namespace
335 326
336 } // namespace content 327 } // namespace content
OLDNEW
« no previous file with comments | « device/device_sensors/data_fetcher_shared_memory_win.cc ('k') | device/device_sensors/device_inertial_sensor_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698