Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "content/browser/device_sensors/data_fetcher_shared_memory.h" | 10 #include "content/browser/device_sensors/data_fetcher_shared_memory.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "device/sensors/public/cpp/device_light_hardware_buffer.h" | 21 #include "device/sensors/public/cpp/device_light_hardware_buffer.h" |
| 22 #include "device/sensors/public/cpp/device_motion_hardware_buffer.h" | 22 #include "device/sensors/public/cpp/device_motion_hardware_buffer.h" |
| 23 #include "device/sensors/public/cpp/device_orientation_hardware_buffer.h" | 23 #include "device/sensors/public/cpp/device_orientation_hardware_buffer.h" |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 class FakeDataFetcher : public DataFetcherSharedMemory { | 29 class FakeDataFetcher : public DataFetcherSharedMemory { |
| 30 public: | 30 public: |
| 31 FakeDataFetcher() | 31 FakeDataFetcher() : sensor_data_available_(true) {} |
| 32 : started_orientation_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 33 base::WaitableEvent::InitialState::NOT_SIGNALED), | |
| 34 stopped_orientation_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 35 base::WaitableEvent::InitialState::NOT_SIGNALED), | |
| 36 started_motion_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 37 base::WaitableEvent::InitialState::NOT_SIGNALED), | |
| 38 stopped_motion_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 39 base::WaitableEvent::InitialState::NOT_SIGNALED), | |
| 40 started_light_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 41 base::WaitableEvent::InitialState::NOT_SIGNALED), | |
| 42 stopped_light_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 43 base::WaitableEvent::InitialState::NOT_SIGNALED), | |
| 44 sensor_data_available_(true) {} | |
| 45 ~FakeDataFetcher() override {} | 32 ~FakeDataFetcher() override {} |
| 46 | 33 |
| 34 void SetMotionStartedCallback(base::Closure motion_started_callback) { | |
| 35 motion_started_callback_ = motion_started_callback; | |
| 36 } | |
| 37 | |
| 38 void SetMotionStoppedCallback(base::Closure motion_stopped_callback) { | |
| 39 motion_stopped_callback_ = motion_stopped_callback; | |
| 40 } | |
| 41 | |
| 42 void SetLightStartedCallback(base::Closure light_started_callback) { | |
| 43 light_started_callback_ = light_started_callback; | |
| 44 } | |
| 45 | |
| 46 void SetLightStoppedCallback(base::Closure light_stopped_callback) { | |
| 47 light_stopped_callback_ = light_stopped_callback; | |
| 48 } | |
| 49 | |
| 50 void SetOrientationStartedCallback( | |
| 51 base::Closure orientation_started_callback) { | |
| 52 orientation_started_callback_ = orientation_started_callback; | |
| 53 } | |
| 54 | |
| 55 void SetOrientationStoppedCallback( | |
| 56 base::Closure orientation_stopped_callback) { | |
| 57 orientation_stopped_callback_ = orientation_stopped_callback; | |
| 58 } | |
| 59 | |
| 47 bool Start(ConsumerType consumer_type, void* buffer) override { | 60 bool Start(ConsumerType consumer_type, void* buffer) override { |
| 48 EXPECT_TRUE(buffer); | 61 EXPECT_TRUE(buffer); |
| 49 | 62 |
| 50 switch (consumer_type) { | 63 switch (consumer_type) { |
| 51 case CONSUMER_TYPE_MOTION: { | 64 case CONSUMER_TYPE_MOTION: { |
| 52 DeviceMotionHardwareBuffer* motion_buffer = | 65 DeviceMotionHardwareBuffer* motion_buffer = |
| 53 static_cast<DeviceMotionHardwareBuffer*>(buffer); | 66 static_cast<DeviceMotionHardwareBuffer*>(buffer); |
| 54 if (sensor_data_available_) | 67 if (sensor_data_available_) |
| 55 UpdateMotion(motion_buffer); | 68 UpdateMotion(motion_buffer); |
| 56 SetMotionBufferReady(motion_buffer); | 69 SetMotionBufferReady(motion_buffer); |
| 57 started_motion_.Signal(); | 70 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 71 motion_started_callback_); | |
| 58 } break; | 72 } break; |
| 59 case CONSUMER_TYPE_ORIENTATION: { | 73 case CONSUMER_TYPE_ORIENTATION: { |
| 60 DeviceOrientationHardwareBuffer* orientation_buffer = | 74 DeviceOrientationHardwareBuffer* orientation_buffer = |
| 61 static_cast<DeviceOrientationHardwareBuffer*>(buffer); | 75 static_cast<DeviceOrientationHardwareBuffer*>(buffer); |
| 62 if (sensor_data_available_) | 76 if (sensor_data_available_) |
| 63 UpdateOrientation(orientation_buffer); | 77 UpdateOrientation(orientation_buffer); |
| 64 SetOrientationBufferReady(orientation_buffer); | 78 SetOrientationBufferReady(orientation_buffer); |
| 65 started_orientation_.Signal(); | 79 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 80 orientation_started_callback_); | |
| 66 } break; | 81 } break; |
| 67 case CONSUMER_TYPE_LIGHT: { | 82 case CONSUMER_TYPE_LIGHT: { |
| 68 DeviceLightHardwareBuffer* light_buffer = | 83 DeviceLightHardwareBuffer* light_buffer = |
| 69 static_cast<DeviceLightHardwareBuffer*>(buffer); | 84 static_cast<DeviceLightHardwareBuffer*>(buffer); |
| 70 UpdateLight(light_buffer, | 85 UpdateLight(light_buffer, |
| 71 sensor_data_available_ | 86 sensor_data_available_ |
| 72 ? 100 | 87 ? 100 |
| 73 : std::numeric_limits<double>::infinity()); | 88 : std::numeric_limits<double>::infinity()); |
| 74 started_light_.Signal(); | 89 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 90 light_started_callback_); | |
| 75 } break; | 91 } break; |
| 76 default: | 92 default: |
| 77 return false; | 93 return false; |
| 78 } | 94 } |
| 79 return true; | 95 return true; |
| 80 } | 96 } |
| 81 | 97 |
| 82 bool Stop(ConsumerType consumer_type) override { | 98 bool Stop(ConsumerType consumer_type) override { |
| 83 switch (consumer_type) { | 99 switch (consumer_type) { |
| 84 case CONSUMER_TYPE_MOTION: | 100 case CONSUMER_TYPE_MOTION: |
| 85 stopped_motion_.Signal(); | 101 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 102 motion_stopped_callback_); | |
| 86 break; | 103 break; |
| 87 case CONSUMER_TYPE_ORIENTATION: | 104 case CONSUMER_TYPE_ORIENTATION: |
| 88 stopped_orientation_.Signal(); | 105 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 106 orientation_stopped_callback_); | |
| 89 break; | 107 break; |
| 90 case CONSUMER_TYPE_LIGHT: | 108 case CONSUMER_TYPE_LIGHT: |
| 91 stopped_light_.Signal(); | 109 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 110 light_stopped_callback_); | |
| 92 break; | 111 break; |
| 93 default: | 112 default: |
| 94 return false; | 113 return false; |
| 95 } | 114 } |
| 96 return true; | 115 return true; |
| 97 } | 116 } |
| 98 | 117 |
| 99 void Fetch(unsigned consumer_bitmask) override { | 118 void Fetch(unsigned consumer_bitmask) override { |
| 100 FAIL() << "fetch should not be called"; | 119 FAIL() << "fetch should not be called"; |
| 101 } | 120 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 buffer->data.allAvailableSensorsAreActive = true; | 176 buffer->data.allAvailableSensorsAreActive = true; |
| 158 buffer->seqlock.WriteEnd(); | 177 buffer->seqlock.WriteEnd(); |
| 159 } | 178 } |
| 160 | 179 |
| 161 void UpdateLight(DeviceLightHardwareBuffer* buffer, double lux) { | 180 void UpdateLight(DeviceLightHardwareBuffer* buffer, double lux) { |
| 162 buffer->seqlock.WriteBegin(); | 181 buffer->seqlock.WriteBegin(); |
| 163 buffer->data.value = lux; | 182 buffer->data.value = lux; |
| 164 buffer->seqlock.WriteEnd(); | 183 buffer->seqlock.WriteEnd(); |
| 165 } | 184 } |
| 166 | 185 |
| 167 base::WaitableEvent started_orientation_; | 186 // The below callbacks should be run on the UI thread. |
| 168 base::WaitableEvent stopped_orientation_; | 187 base::Closure motion_started_callback_; |
| 169 base::WaitableEvent started_motion_; | 188 base::Closure orientation_started_callback_; |
| 170 base::WaitableEvent stopped_motion_; | 189 base::Closure light_started_callback_; |
| 171 base::WaitableEvent started_light_; | 190 base::Closure motion_stopped_callback_; |
| 172 base::WaitableEvent stopped_light_; | 191 base::Closure orientation_stopped_callback_; |
| 192 base::Closure light_stopped_callback_; | |
| 173 bool sensor_data_available_; | 193 bool sensor_data_available_; |
| 174 | 194 |
| 175 private: | 195 private: |
| 176 DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher); | 196 DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher); |
| 177 }; | 197 }; |
| 178 | 198 |
| 179 class DeviceSensorBrowserTest : public ContentBrowserTest { | 199 class DeviceSensorBrowserTest : public ContentBrowserTest { |
| 180 public: | 200 public: |
| 181 DeviceSensorBrowserTest() | 201 DeviceSensorBrowserTest() |
| 182 : fetcher_(nullptr), | 202 : fetcher_(nullptr), |
| 183 io_loop_finished_event_( | 203 io_loop_finished_event_( |
| 184 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 204 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 185 base::WaitableEvent::InitialState::NOT_SIGNALED) {} | 205 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
| 186 | 206 |
| 187 void SetUpOnMainThread() override { | 207 void SetUpOnMainThread() override { |
| 208 #if defined(OS_ANDROID) | |
| 209 // On Android, the DeviceSensorService lives on the UI thread. | |
| 210 SetUpFetcher(); | |
| 211 #else | |
| 212 // On all other platforms, the DeviceSensorService lives on the IO thread. | |
| 188 BrowserThread::PostTask( | 213 BrowserThread::PostTask( |
| 189 BrowserThread::IO, FROM_HERE, | 214 BrowserThread::IO, FROM_HERE, |
| 190 base::Bind(&DeviceSensorBrowserTest::SetUpOnIOThread, | 215 base::Bind(&DeviceSensorBrowserTest::SetUpOnIOThread, |
| 191 base::Unretained(this))); | 216 base::Unretained(this))); |
| 192 io_loop_finished_event_.Wait(); | 217 io_loop_finished_event_.Wait(); |
| 218 #endif | |
| 219 } | |
| 220 | |
| 221 void SetUpFetcher() { | |
| 222 fetcher_ = new FakeDataFetcher(); | |
| 223 DeviceSensorService::GetInstance()->SetDataFetcherForTesting(fetcher_); | |
| 193 } | 224 } |
| 194 | 225 |
| 195 void SetUpOnIOThread() { | 226 void SetUpOnIOThread() { |
| 196 fetcher_ = new FakeDataFetcher(); | 227 SetUpFetcher(); |
| 197 DeviceSensorService::GetInstance()->SetDataFetcherForTesting(fetcher_); | |
| 198 io_loop_finished_event_.Signal(); | 228 io_loop_finished_event_.Signal(); |
| 199 } | 229 } |
| 200 | 230 |
| 201 void DelayAndQuit(base::TimeDelta delay) { | 231 void DelayAndQuit(base::TimeDelta delay) { |
| 202 base::PlatformThread::Sleep(delay); | 232 base::PlatformThread::Sleep(delay); |
| 203 base::MessageLoop::current()->QuitWhenIdle(); | 233 base::MessageLoop::current()->QuitWhenIdle(); |
| 204 } | 234 } |
| 205 | 235 |
| 206 void WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta delay) { | 236 void WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta delay) { |
| 207 ShellJavaScriptDialogManager* dialog_manager = | 237 ShellJavaScriptDialogManager* dialog_manager = |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 222 cmd_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); | 252 cmd_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); |
| 223 } | 253 } |
| 224 | 254 |
| 225 FakeDataFetcher* fetcher_; | 255 FakeDataFetcher* fetcher_; |
| 226 | 256 |
| 227 private: | 257 private: |
| 228 base::WaitableEvent io_loop_finished_event_; | 258 base::WaitableEvent io_loop_finished_event_; |
| 229 }; | 259 }; |
| 230 | 260 |
| 231 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, OrientationTest) { | 261 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, OrientationTest) { |
| 262 base::RunLoop orientation_started_runloop; | |
| 263 fetcher_->SetOrientationStartedCallback( | |
| 264 orientation_started_runloop.QuitClosure()); | |
| 265 base::RunLoop orientation_stopped_runloop; | |
| 266 fetcher_->SetOrientationStoppedCallback( | |
| 267 orientation_stopped_runloop.QuitClosure()); | |
| 268 | |
| 232 // The test page will register an event handler for orientation events, | 269 // The test page will register an event handler for orientation events, |
| 233 // expects to get an event with fake values, then removes the event | 270 // expects to get an event with fake values, then removes the event |
| 234 // handler and navigates to #pass. | 271 // handler and navigates to #pass. |
| 235 GURL test_url = GetTestUrl("device_sensors", "device_orientation_test.html"); | 272 GURL test_url = GetTestUrl("device_sensors", "device_orientation_test.html"); |
| 236 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 273 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 237 | 274 |
| 238 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 275 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 239 fetcher_->started_orientation_.Wait(); | 276 orientation_started_runloop.Run(); |
| 240 fetcher_->stopped_orientation_.Wait(); | 277 orientation_stopped_runloop.Run(); |
| 241 } | 278 } |
| 242 | 279 |
| 243 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, LightTest) { | 280 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, LightTest) { |
| 281 base::RunLoop light_started_runloop; | |
| 282 fetcher_->SetLightStartedCallback(light_started_runloop.QuitClosure()); | |
| 283 base::RunLoop light_stopped_runloop; | |
| 284 fetcher_->SetLightStoppedCallback(light_stopped_runloop.QuitClosure()); | |
| 285 | |
| 244 // The test page will register an event handler for light events, | 286 // The test page will register an event handler for light events, |
| 245 // expects to get an event with fake values, then removes the event | 287 // expects to get an event with fake values, then removes the event |
| 246 // handler and navigates to #pass. | 288 // handler and navigates to #pass. |
| 247 EnableExperimentalFeatures(); | 289 EnableExperimentalFeatures(); |
| 248 GURL test_url = GetTestUrl("device_sensors", "device_light_test.html"); | 290 GURL test_url = GetTestUrl("device_sensors", "device_light_test.html"); |
| 249 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 291 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 250 | 292 |
| 251 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 293 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 252 fetcher_->started_light_.Wait(); | 294 light_started_runloop.Run(); |
| 253 fetcher_->stopped_light_.Wait(); | 295 light_stopped_runloop.Run(); |
| 254 } | 296 } |
| 255 | 297 |
| 256 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, MotionTest) { | 298 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, MotionTest) { |
| 299 base::RunLoop motion_started_runloop; | |
| 300 fetcher_->SetMotionStartedCallback(motion_started_runloop.QuitClosure()); | |
| 301 base::RunLoop motion_stopped_runloop; | |
| 302 fetcher_->SetMotionStoppedCallback(motion_stopped_runloop.QuitClosure()); | |
| 303 | |
| 257 // The test page will register an event handler for motion events, | 304 // The test page will register an event handler for motion events, |
| 258 // expects to get an event with fake values, then removes the event | 305 // expects to get an event with fake values, then removes the event |
| 259 // handler and navigates to #pass. | 306 // handler and navigates to #pass. |
| 260 GURL test_url = GetTestUrl("device_sensors", "device_motion_test.html"); | 307 GURL test_url = GetTestUrl("device_sensors", "device_motion_test.html"); |
| 261 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 308 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 262 | 309 |
| 263 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 310 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 264 fetcher_->started_motion_.Wait(); | 311 motion_started_runloop.Run(); |
| 265 fetcher_->stopped_motion_.Wait(); | 312 motion_stopped_runloop.Run(); |
| 266 } | 313 } |
| 267 | 314 |
| 268 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, LightOneOffInfintyTest) { | 315 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, LightOneOffInfintyTest) { |
| 316 base::RunLoop light_started_runloop; | |
| 317 fetcher_->SetLightStartedCallback(light_started_runloop.QuitClosure()); | |
| 318 base::RunLoop light_stopped_runloop; | |
| 319 fetcher_->SetLightStoppedCallback(light_stopped_runloop.QuitClosure()); | |
| 320 | |
| 269 // The test page registers an event handler for light events and expects | 321 // The test page registers an event handler for light events and expects |
| 270 // to get an event with value equal to infinity, because no sensor data can | 322 // to get an event with value equal to infinity, because no sensor data can |
| 271 // be provided. | 323 // be provided. |
| 272 EnableExperimentalFeatures(); | 324 EnableExperimentalFeatures(); |
| 273 fetcher_->SetSensorDataAvailable(false); | 325 fetcher_->SetSensorDataAvailable(false); |
| 274 GURL test_url = | 326 GURL test_url = |
| 275 GetTestUrl("device_sensors", "device_light_infinity_test.html"); | 327 GetTestUrl("device_sensors", "device_light_infinity_test.html"); |
| 276 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 328 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 277 | 329 |
| 278 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 330 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 279 fetcher_->started_light_.Wait(); | 331 light_started_runloop.Run(); |
| 280 fetcher_->stopped_light_.Wait(); | 332 light_stopped_runloop.Run(); |
| 281 } | 333 } |
| 282 | 334 |
| 283 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, OrientationNullTest) { | 335 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, OrientationNullTest) { |
| 336 base::RunLoop orientation_started_runloop; | |
| 337 fetcher_->SetOrientationStartedCallback( | |
| 338 orientation_started_runloop.QuitClosure()); | |
| 339 base::RunLoop orientation_stopped_runloop; | |
| 340 fetcher_->SetOrientationStoppedCallback( | |
| 341 orientation_stopped_runloop.QuitClosure()); | |
| 342 | |
| 284 // The test page registers an event handler for orientation events and | 343 // The test page registers an event handler for orientation events and |
| 285 // expects to get an event with null values, because no sensor data can be | 344 // expects to get an event with null values, because no sensor data can be |
| 286 // provided. | 345 // provided. |
| 287 fetcher_->SetSensorDataAvailable(false); | 346 fetcher_->SetSensorDataAvailable(false); |
| 288 GURL test_url = | 347 GURL test_url = |
| 289 GetTestUrl("device_sensors", "device_orientation_null_test.html"); | 348 GetTestUrl("device_sensors", "device_orientation_null_test.html"); |
| 290 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 349 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 291 | 350 |
| 292 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 351 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 293 fetcher_->started_orientation_.Wait(); | 352 orientation_started_runloop.Run(); |
| 294 fetcher_->stopped_orientation_.Wait(); | 353 orientation_stopped_runloop.Run(); |
| 295 } | 354 } |
| 296 | 355 |
| 297 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, MotionNullTest) { | 356 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, MotionNullTest) { |
| 357 base::RunLoop motion_started_runloop; | |
| 358 fetcher_->SetMotionStartedCallback(motion_started_runloop.QuitClosure()); | |
| 359 base::RunLoop motion_stopped_runloop; | |
| 360 fetcher_->SetMotionStoppedCallback(motion_stopped_runloop.QuitClosure()); | |
| 361 | |
| 298 // The test page registers an event handler for motion events and | 362 // The test page registers an event handler for motion events and |
| 299 // expects to get an event with null values, because no sensor data can be | 363 // expects to get an event with null values, because no sensor data can be |
| 300 // provided. | 364 // provided. |
| 301 fetcher_->SetSensorDataAvailable(false); | 365 fetcher_->SetSensorDataAvailable(false); |
| 302 GURL test_url = GetTestUrl("device_sensors", "device_motion_null_test.html"); | 366 GURL test_url = GetTestUrl("device_sensors", "device_motion_null_test.html"); |
| 303 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 367 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 304 | 368 |
| 305 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 369 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 306 fetcher_->started_motion_.Wait(); | 370 motion_started_runloop.Run(); |
| 307 fetcher_->stopped_motion_.Wait(); | 371 motion_stopped_runloop.Run(); |
| 308 } | 372 } |
| 309 | 373 |
| 310 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, NullTestWithAlert) { | 374 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, NullTestWithAlert) { |
| 311 // The test page registers an event handlers for motion/orientation events | 375 base::RunLoop motion_started_runloop; |
|
timvolodine
2016/10/31 15:51:44
would it be simpler to just declare run loops in t
blundell
2016/11/09 15:07:43
Good idea, done.
| |
| 376 fetcher_->SetMotionStartedCallback(motion_started_runloop.QuitClosure()); | |
| 377 base::RunLoop motion_stopped_runloop; | |
| 378 fetcher_->SetMotionStoppedCallback(motion_stopped_runloop.QuitClosure()); | |
| 379 base::RunLoop orientation_started_runloop; | |
| 380 fetcher_->SetOrientationStartedCallback( | |
| 381 orientation_started_runloop.QuitClosure()); | |
| 382 base::RunLoop orientation_stopped_runloop; | |
| 383 fetcher_->SetOrientationStoppedCallback( | |
| 384 orientation_stopped_runloop.QuitClosure()); | |
| 385 | |
| 386 // The test page registers an event handlers for orientation/orientation | |
| 387 // events | |
| 312 // and expects to get events with null values. The test raises a modal alert | 388 // and expects to get events with null values. The test raises a modal alert |
| 313 // dialog with a delay to test that the one-off null-events still propagate | 389 // dialog with a delay to test that the one-off null-events still propagate |
| 314 // to window after the alert is dismissed and the callbacks are invoked which | 390 // to window after the alert is dismissed and the callbacks are invoked which |
| 315 // eventually navigate to #pass. | 391 // eventually navigate to #pass. |
| 316 fetcher_->SetSensorDataAvailable(false); | 392 fetcher_->SetSensorDataAvailable(false); |
| 317 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); | 393 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); |
| 318 | 394 |
| 319 GURL test_url = | 395 GURL test_url = |
| 320 GetTestUrl("device_sensors", "device_sensors_null_test_with_alert.html"); | 396 GetTestUrl("device_sensors", "device_sensors_null_test_with_alert.html"); |
| 321 shell()->LoadURL(test_url); | 397 shell()->LoadURL(test_url); |
| 322 | 398 |
| 323 // TODO(timvolodine): investigate if it is possible to test this without | 399 // TODO(timvolodine): investigate if it is possible to test this without |
| 324 // delay, crbug.com/360044. | 400 // delay, crbug.com/360044. |
| 325 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(500)); | 401 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(500)); |
| 326 | 402 |
| 327 fetcher_->started_motion_.Wait(); | 403 motion_started_runloop.Run(); |
| 328 fetcher_->stopped_motion_.Wait(); | 404 motion_stopped_runloop.Run(); |
| 329 fetcher_->started_orientation_.Wait(); | 405 orientation_started_runloop.Run(); |
| 330 fetcher_->stopped_orientation_.Wait(); | 406 orientation_stopped_runloop.Run(); |
| 331 same_tab_observer.Wait(); | 407 same_tab_observer.Wait(); |
| 332 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 408 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 333 } | 409 } |
| 334 | 410 |
| 335 } // namespace | 411 } // namespace |
| 336 | 412 |
| 337 } // namespace content | 413 } // namespace content |
| OLD | NEW |