| 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 // Initialize the RunLoops now that the main thread has been created. |
| 209 light_started_runloop_.reset(new base::RunLoop()); |
| 210 light_stopped_runloop_.reset(new base::RunLoop()); |
| 211 motion_started_runloop_.reset(new base::RunLoop()); |
| 212 motion_stopped_runloop_.reset(new base::RunLoop()); |
| 213 orientation_started_runloop_.reset(new base::RunLoop()); |
| 214 orientation_stopped_runloop_.reset(new base::RunLoop()); |
| 215 #if defined(OS_ANDROID) |
| 216 // On Android, the DeviceSensorService lives on the UI thread. |
| 217 SetUpFetcher(); |
| 218 #else |
| 219 // On all other platforms, the DeviceSensorService lives on the IO thread. |
| 188 BrowserThread::PostTask( | 220 BrowserThread::PostTask( |
| 189 BrowserThread::IO, FROM_HERE, | 221 BrowserThread::IO, FROM_HERE, |
| 190 base::Bind(&DeviceSensorBrowserTest::SetUpOnIOThread, | 222 base::Bind(&DeviceSensorBrowserTest::SetUpOnIOThread, |
| 191 base::Unretained(this))); | 223 base::Unretained(this))); |
| 192 io_loop_finished_event_.Wait(); | 224 io_loop_finished_event_.Wait(); |
| 225 #endif |
| 226 } |
| 227 |
| 228 void SetUpFetcher() { |
| 229 fetcher_ = new FakeDataFetcher(); |
| 230 fetcher_->SetLightStartedCallback(light_started_runloop_->QuitClosure()); |
| 231 fetcher_->SetLightStoppedCallback(light_stopped_runloop_->QuitClosure()); |
| 232 fetcher_->SetMotionStartedCallback(motion_started_runloop_->QuitClosure()); |
| 233 fetcher_->SetMotionStoppedCallback(motion_stopped_runloop_->QuitClosure()); |
| 234 fetcher_->SetOrientationStartedCallback( |
| 235 orientation_started_runloop_->QuitClosure()); |
| 236 fetcher_->SetOrientationStoppedCallback( |
| 237 orientation_stopped_runloop_->QuitClosure()); |
| 238 DeviceSensorService::GetInstance()->SetDataFetcherForTesting(fetcher_); |
| 193 } | 239 } |
| 194 | 240 |
| 195 void SetUpOnIOThread() { | 241 void SetUpOnIOThread() { |
| 196 fetcher_ = new FakeDataFetcher(); | 242 SetUpFetcher(); |
| 197 DeviceSensorService::GetInstance()->SetDataFetcherForTesting(fetcher_); | |
| 198 io_loop_finished_event_.Signal(); | 243 io_loop_finished_event_.Signal(); |
| 199 } | 244 } |
| 200 | 245 |
| 201 void DelayAndQuit(base::TimeDelta delay) { | 246 void DelayAndQuit(base::TimeDelta delay) { |
| 202 base::PlatformThread::Sleep(delay); | 247 base::PlatformThread::Sleep(delay); |
| 203 base::MessageLoop::current()->QuitWhenIdle(); | 248 base::MessageLoop::current()->QuitWhenIdle(); |
| 204 } | 249 } |
| 205 | 250 |
| 206 void WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta delay) { | 251 void WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta delay) { |
| 207 ShellJavaScriptDialogManager* dialog_manager = | 252 ShellJavaScriptDialogManager* dialog_manager = |
| 208 static_cast<ShellJavaScriptDialogManager*>( | 253 static_cast<ShellJavaScriptDialogManager*>( |
| 209 shell()->GetJavaScriptDialogManager(shell()->web_contents())); | 254 shell()->GetJavaScriptDialogManager(shell()->web_contents())); |
| 210 | 255 |
| 211 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner(); | 256 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner(); |
| 212 dialog_manager->set_dialog_request_callback( | 257 dialog_manager->set_dialog_request_callback( |
| 213 base::Bind(&DeviceSensorBrowserTest::DelayAndQuit, | 258 base::Bind(&DeviceSensorBrowserTest::DelayAndQuit, |
| 214 base::Unretained(this), delay)); | 259 base::Unretained(this), delay)); |
| 215 runner->Run(); | 260 runner->Run(); |
| 216 } | 261 } |
| 217 | 262 |
| 218 void EnableExperimentalFeatures() { | 263 void EnableExperimentalFeatures() { |
| 219 // TODO(riju): remove when the DeviceLight feature goes stable. | 264 // TODO(riju): remove when the DeviceLight feature goes stable. |
| 220 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 265 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 221 if (!cmd_line->HasSwitch(switches::kEnableExperimentalWebPlatformFeatures)) | 266 if (!cmd_line->HasSwitch(switches::kEnableExperimentalWebPlatformFeatures)) |
| 222 cmd_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); | 267 cmd_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); |
| 223 } | 268 } |
| 224 | 269 |
| 225 FakeDataFetcher* fetcher_; | 270 FakeDataFetcher* fetcher_; |
| 226 | 271 |
| 272 // NOTE: These can only be initialized once the main thread has been created |
| 273 // and so must be pointers instead of plain objects. |
| 274 std::unique_ptr<base::RunLoop> light_started_runloop_; |
| 275 std::unique_ptr<base::RunLoop> light_stopped_runloop_; |
| 276 std::unique_ptr<base::RunLoop> motion_started_runloop_; |
| 277 std::unique_ptr<base::RunLoop> motion_stopped_runloop_; |
| 278 std::unique_ptr<base::RunLoop> orientation_started_runloop_; |
| 279 std::unique_ptr<base::RunLoop> orientation_stopped_runloop_; |
| 280 |
| 227 private: | 281 private: |
| 228 base::WaitableEvent io_loop_finished_event_; | 282 base::WaitableEvent io_loop_finished_event_; |
| 229 }; | 283 }; |
| 230 | 284 |
| 231 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, OrientationTest) { | 285 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, OrientationTest) { |
| 232 // The test page will register an event handler for orientation events, | 286 // The test page will register an event handler for orientation events, |
| 233 // 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 |
| 234 // handler and navigates to #pass. | 288 // handler and navigates to #pass. |
| 235 GURL test_url = GetTestUrl("device_sensors", "device_orientation_test.html"); | 289 GURL test_url = GetTestUrl("device_sensors", "device_orientation_test.html"); |
| 236 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 290 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 237 | 291 |
| 238 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 292 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 239 fetcher_->started_orientation_.Wait(); | 293 orientation_started_runloop_->Run(); |
| 240 fetcher_->stopped_orientation_.Wait(); | 294 orientation_stopped_runloop_->Run(); |
| 241 } | 295 } |
| 242 | 296 |
| 243 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, LightTest) { | 297 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, LightTest) { |
| 244 // The test page will register an event handler for light events, | 298 // The test page will register an event handler for light events, |
| 245 // expects to get an event with fake values, then removes the event | 299 // expects to get an event with fake values, then removes the event |
| 246 // handler and navigates to #pass. | 300 // handler and navigates to #pass. |
| 247 EnableExperimentalFeatures(); | 301 EnableExperimentalFeatures(); |
| 248 GURL test_url = GetTestUrl("device_sensors", "device_light_test.html"); | 302 GURL test_url = GetTestUrl("device_sensors", "device_light_test.html"); |
| 249 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 303 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 250 | 304 |
| 251 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 305 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 252 fetcher_->started_light_.Wait(); | 306 light_started_runloop_->Run(); |
| 253 fetcher_->stopped_light_.Wait(); | 307 light_stopped_runloop_->Run(); |
| 254 } | 308 } |
| 255 | 309 |
| 256 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, MotionTest) { | 310 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, MotionTest) { |
| 257 // The test page will register an event handler for motion events, | 311 // The test page will register an event handler for motion events, |
| 258 // expects to get an event with fake values, then removes the event | 312 // expects to get an event with fake values, then removes the event |
| 259 // handler and navigates to #pass. | 313 // handler and navigates to #pass. |
| 260 GURL test_url = GetTestUrl("device_sensors", "device_motion_test.html"); | 314 GURL test_url = GetTestUrl("device_sensors", "device_motion_test.html"); |
| 261 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 315 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 262 | 316 |
| 263 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 317 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 264 fetcher_->started_motion_.Wait(); | 318 motion_started_runloop_->Run(); |
| 265 fetcher_->stopped_motion_.Wait(); | 319 motion_stopped_runloop_->Run(); |
| 266 } | 320 } |
| 267 | 321 |
| 268 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, LightOneOffInfintyTest) { | 322 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, LightOneOffInfintyTest) { |
| 269 // The test page registers an event handler for light events and expects | 323 // 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 | 324 // to get an event with value equal to infinity, because no sensor data can |
| 271 // be provided. | 325 // be provided. |
| 272 EnableExperimentalFeatures(); | 326 EnableExperimentalFeatures(); |
| 273 fetcher_->SetSensorDataAvailable(false); | 327 fetcher_->SetSensorDataAvailable(false); |
| 274 GURL test_url = | 328 GURL test_url = |
| 275 GetTestUrl("device_sensors", "device_light_infinity_test.html"); | 329 GetTestUrl("device_sensors", "device_light_infinity_test.html"); |
| 276 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 330 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 277 | 331 |
| 278 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 332 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 279 fetcher_->started_light_.Wait(); | 333 light_started_runloop_->Run(); |
| 280 fetcher_->stopped_light_.Wait(); | 334 light_stopped_runloop_->Run(); |
| 281 } | 335 } |
| 282 | 336 |
| 283 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, OrientationNullTest) { | 337 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, OrientationNullTest) { |
| 284 // The test page registers an event handler for orientation events and | 338 // 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 | 339 // expects to get an event with null values, because no sensor data can be |
| 286 // provided. | 340 // provided. |
| 287 fetcher_->SetSensorDataAvailable(false); | 341 fetcher_->SetSensorDataAvailable(false); |
| 288 GURL test_url = | 342 GURL test_url = |
| 289 GetTestUrl("device_sensors", "device_orientation_null_test.html"); | 343 GetTestUrl("device_sensors", "device_orientation_null_test.html"); |
| 290 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 344 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 291 | 345 |
| 292 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 346 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 293 fetcher_->started_orientation_.Wait(); | 347 orientation_started_runloop_->Run(); |
| 294 fetcher_->stopped_orientation_.Wait(); | 348 orientation_stopped_runloop_->Run(); |
| 295 } | 349 } |
| 296 | 350 |
| 297 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, MotionNullTest) { | 351 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, MotionNullTest) { |
| 298 // The test page registers an event handler for motion events and | 352 // 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 | 353 // expects to get an event with null values, because no sensor data can be |
| 300 // provided. | 354 // provided. |
| 301 fetcher_->SetSensorDataAvailable(false); | 355 fetcher_->SetSensorDataAvailable(false); |
| 302 GURL test_url = GetTestUrl("device_sensors", "device_motion_null_test.html"); | 356 GURL test_url = GetTestUrl("device_sensors", "device_motion_null_test.html"); |
| 303 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 357 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 304 | 358 |
| 305 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 359 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 306 fetcher_->started_motion_.Wait(); | 360 motion_started_runloop_->Run(); |
| 307 fetcher_->stopped_motion_.Wait(); | 361 motion_stopped_runloop_->Run(); |
| 308 } | 362 } |
| 309 | 363 |
| 310 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, NullTestWithAlert) { | 364 IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, NullTestWithAlert) { |
| 311 // The test page registers an event handlers for motion/orientation events | 365 // The test page registers an event handlers for motion/orientation events and |
| 312 // and expects to get events with null values. The test raises a modal alert | 366 // 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 | 367 // dialog with a delay to test that the one-off null-events still propagate to |
| 314 // to window after the alert is dismissed and the callbacks are invoked which | 368 // window after the alert is dismissed and the callbacks are invoked which |
| 315 // eventually navigate to #pass. | 369 // eventually navigate to #pass. |
| 316 fetcher_->SetSensorDataAvailable(false); | 370 fetcher_->SetSensorDataAvailable(false); |
| 317 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); | 371 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); |
| 318 | 372 |
| 319 GURL test_url = | 373 GURL test_url = |
| 320 GetTestUrl("device_sensors", "device_sensors_null_test_with_alert.html"); | 374 GetTestUrl("device_sensors", "device_sensors_null_test_with_alert.html"); |
| 321 shell()->LoadURL(test_url); | 375 shell()->LoadURL(test_url); |
| 322 | 376 |
| 323 // TODO(timvolodine): investigate if it is possible to test this without | 377 // TODO(timvolodine): investigate if it is possible to test this without |
| 324 // delay, crbug.com/360044. | 378 // delay, crbug.com/360044. |
| 325 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(500)); | 379 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(500)); |
| 326 | 380 |
| 327 fetcher_->started_motion_.Wait(); | 381 motion_started_runloop_->Run(); |
| 328 fetcher_->stopped_motion_.Wait(); | 382 motion_stopped_runloop_->Run(); |
| 329 fetcher_->started_orientation_.Wait(); | 383 orientation_started_runloop_->Run(); |
| 330 fetcher_->stopped_orientation_.Wait(); | 384 orientation_stopped_runloop_->Run(); |
| 331 same_tab_observer.Wait(); | 385 same_tab_observer.Wait(); |
| 332 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 386 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 333 } | 387 } |
| 334 | 388 |
| 335 } // namespace | 389 } // namespace |
| 336 | 390 |
| 337 } // namespace content | 391 } // namespace content |
| OLD | NEW |