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/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
| 6 #include "base/threading/platform_thread.h" | 7 #include "base/threading/platform_thread.h" |
| 7 #include "content/browser/device_sensors/data_fetcher_shared_memory.h" | 8 #include "content/browser/device_sensors/data_fetcher_shared_memory.h" |
| 8 #include "content/browser/device_sensors/device_inertial_sensor_service.h" | 9 #include "content/browser/device_sensors/device_inertial_sensor_service.h" |
| 10 #include "content/common/device_sensors/device_light_hardware_buffer.h" | |
| 9 #include "content/common/device_sensors/device_motion_hardware_buffer.h" | 11 #include "content/common/device_sensors/device_motion_hardware_buffer.h" |
| 10 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" | 12 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" |
| 11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/common/content_switches.h" | |
| 13 #include "content/public/test/content_browser_test.h" | 16 #include "content/public/test/content_browser_test.h" |
| 14 #include "content/public/test/content_browser_test_utils.h" | 17 #include "content/public/test/content_browser_test_utils.h" |
| 15 #include "content/public/test/test_navigation_observer.h" | 18 #include "content/public/test/test_navigation_observer.h" |
| 16 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
| 17 #include "content/shell/browser/shell.h" | 20 #include "content/shell/browser/shell.h" |
| 18 #include "content/shell/browser/shell_javascript_dialog_manager.h" | 21 #include "content/shell/browser/shell_javascript_dialog_manager.h" |
| 19 | 22 |
| 20 namespace content { | 23 namespace content { |
| 21 | 24 |
| 22 namespace { | 25 namespace { |
| 23 | 26 |
| 24 class FakeDataFetcher : public DataFetcherSharedMemory { | 27 class FakeDataFetcher : public DataFetcherSharedMemory { |
| 25 public: | 28 public: |
| 26 FakeDataFetcher() | 29 FakeDataFetcher() |
| 27 : started_orientation_(false, false), | 30 : started_orientation_(false, false), |
| 28 stopped_orientation_(false, false), | 31 stopped_orientation_(false, false), |
| 29 started_motion_(false, false), | 32 started_motion_(false, false), |
| 30 stopped_motion_(false, false), | 33 stopped_motion_(false, false), |
| 31 sensor_data_available_(true) { | 34 started_light_(false, false), |
| 32 } | 35 stopped_light_(false, false), |
| 36 sensor_data_available_(true) {} | |
| 33 virtual ~FakeDataFetcher() { } | 37 virtual ~FakeDataFetcher() { } |
| 34 | 38 |
| 35 virtual bool Start(ConsumerType consumer_type, void* buffer) OVERRIDE { | 39 virtual bool Start(ConsumerType consumer_type, void* buffer) OVERRIDE { |
| 36 EXPECT_TRUE(buffer); | 40 EXPECT_TRUE(buffer); |
| 37 | 41 |
| 38 switch (consumer_type) { | 42 switch (consumer_type) { |
| 39 case CONSUMER_TYPE_MOTION: | 43 case CONSUMER_TYPE_MOTION: |
| 40 { | 44 { |
| 41 DeviceMotionHardwareBuffer* motion_buffer = | 45 DeviceMotionHardwareBuffer* motion_buffer = |
| 42 static_cast<DeviceMotionHardwareBuffer*>(buffer); | 46 static_cast<DeviceMotionHardwareBuffer*>(buffer); |
| 43 if (sensor_data_available_) | 47 if (sensor_data_available_) |
| 44 UpdateMotion(motion_buffer); | 48 UpdateMotion(motion_buffer); |
| 45 SetMotionBufferReady(motion_buffer); | 49 SetMotionBufferReady(motion_buffer); |
| 46 started_motion_.Signal(); | 50 started_motion_.Signal(); |
| 47 } | 51 } |
| 48 break; | 52 break; |
| 49 case CONSUMER_TYPE_ORIENTATION: | 53 case CONSUMER_TYPE_ORIENTATION: |
| 50 { | 54 { |
| 51 DeviceOrientationHardwareBuffer* orientation_buffer = | 55 DeviceOrientationHardwareBuffer* orientation_buffer = |
| 52 static_cast<DeviceOrientationHardwareBuffer*>(buffer); | 56 static_cast<DeviceOrientationHardwareBuffer*>(buffer); |
| 53 if (sensor_data_available_) | 57 if (sensor_data_available_) |
| 54 UpdateOrientation(orientation_buffer); | 58 UpdateOrientation(orientation_buffer); |
| 55 SetOrientationBufferReady(orientation_buffer); | 59 SetOrientationBufferReady(orientation_buffer); |
| 56 started_orientation_.Signal(); | 60 started_orientation_.Signal(); |
| 57 } | 61 } |
| 58 break; | 62 break; |
| 63 case CONSUMER_TYPE_LIGHT: | |
|
timvolodine
2014/09/04 17:16:57
indent -2
riju_
2014/09/08 09:26:17
Done.
| |
| 64 { | |
| 65 DeviceLightHardwareBuffer* light_buffer = | |
| 66 static_cast<DeviceLightHardwareBuffer*>(buffer); | |
| 67 if (sensor_data_available_) | |
| 68 UpdateLight(light_buffer); | |
| 69 else { | |
| 70 // Null event scenario | |
|
timvolodine
2014/09/04 17:16:57
if you allow UpdateLight to take a value as well t
riju_
2014/09/08 09:26:17
Done.
| |
| 71 light_buffer->seqlock.WriteBegin(); | |
| 72 light_buffer->data.value = std::numeric_limits<double>::infinity(); | |
| 73 light_buffer->seqlock.WriteEnd(); | |
| 74 } | |
| 75 started_light_.Signal(); | |
| 76 } | |
| 77 break; | |
| 59 default: | 78 default: |
| 60 return false; | 79 return false; |
| 61 } | 80 } |
| 62 return true; | 81 return true; |
| 63 } | 82 } |
| 64 | 83 |
| 65 virtual bool Stop(ConsumerType consumer_type) OVERRIDE { | 84 virtual bool Stop(ConsumerType consumer_type) OVERRIDE { |
| 66 switch (consumer_type) { | 85 switch (consumer_type) { |
| 67 case CONSUMER_TYPE_MOTION: | 86 case CONSUMER_TYPE_MOTION: |
| 68 stopped_motion_.Signal(); | 87 stopped_motion_.Signal(); |
| 69 break; | 88 break; |
| 70 case CONSUMER_TYPE_ORIENTATION: | 89 case CONSUMER_TYPE_ORIENTATION: |
| 71 stopped_orientation_.Signal(); | 90 stopped_orientation_.Signal(); |
| 72 break; | 91 break; |
| 92 case CONSUMER_TYPE_LIGHT: | |
| 93 stopped_light_.Signal(); | |
| 94 break; | |
| 73 default: | 95 default: |
| 74 return false; | 96 return false; |
| 75 } | 97 } |
| 76 return true; | 98 return true; |
| 77 } | 99 } |
| 78 | 100 |
| 79 virtual void Fetch(unsigned consumer_bitmask) OVERRIDE { | 101 virtual void Fetch(unsigned consumer_bitmask) OVERRIDE { |
| 80 FAIL() << "fetch should not be called"; | 102 FAIL() << "fetch should not be called"; |
| 81 } | 103 } |
| 82 | 104 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 buffer->data.alpha = 1; | 155 buffer->data.alpha = 1; |
| 134 buffer->data.hasAlpha = true; | 156 buffer->data.hasAlpha = true; |
| 135 buffer->data.beta = 2; | 157 buffer->data.beta = 2; |
| 136 buffer->data.hasBeta = true; | 158 buffer->data.hasBeta = true; |
| 137 buffer->data.gamma = 3; | 159 buffer->data.gamma = 3; |
| 138 buffer->data.hasGamma = true; | 160 buffer->data.hasGamma = true; |
| 139 buffer->data.allAvailableSensorsAreActive = true; | 161 buffer->data.allAvailableSensorsAreActive = true; |
| 140 buffer->seqlock.WriteEnd(); | 162 buffer->seqlock.WriteEnd(); |
| 141 } | 163 } |
| 142 | 164 |
| 165 void UpdateLight(DeviceLightHardwareBuffer* buffer) { | |
| 166 buffer->seqlock.WriteBegin(); | |
| 167 buffer->data.value = 100; | |
| 168 buffer->seqlock.WriteEnd(); | |
| 169 } | |
| 170 | |
| 143 base::WaitableEvent started_orientation_; | 171 base::WaitableEvent started_orientation_; |
| 144 base::WaitableEvent stopped_orientation_; | 172 base::WaitableEvent stopped_orientation_; |
| 145 base::WaitableEvent started_motion_; | 173 base::WaitableEvent started_motion_; |
| 146 base::WaitableEvent stopped_motion_; | 174 base::WaitableEvent stopped_motion_; |
| 175 base::WaitableEvent started_light_; | |
| 176 base::WaitableEvent stopped_light_; | |
| 147 bool sensor_data_available_; | 177 bool sensor_data_available_; |
| 148 | 178 |
| 149 private: | 179 private: |
| 150 DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher); | 180 DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher); |
| 151 }; | 181 }; |
| 152 | 182 |
| 153 | 183 |
| 154 class DeviceInertialSensorBrowserTest : public ContentBrowserTest { | 184 class DeviceInertialSensorBrowserTest : public ContentBrowserTest { |
| 155 public: | 185 public: |
| 156 DeviceInertialSensorBrowserTest() | 186 DeviceInertialSensorBrowserTest() |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 delay)); | 218 delay)); |
| 189 runner->Run(); | 219 runner->Run(); |
| 190 } | 220 } |
| 191 | 221 |
| 192 FakeDataFetcher* fetcher_; | 222 FakeDataFetcher* fetcher_; |
| 193 | 223 |
| 194 private: | 224 private: |
| 195 base::WaitableEvent io_loop_finished_event_; | 225 base::WaitableEvent io_loop_finished_event_; |
| 196 }; | 226 }; |
| 197 | 227 |
| 198 | |
| 199 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, OrientationTest) { | 228 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, OrientationTest) { |
| 200 // The test page will register an event handler for orientation events, | 229 // The test page will register an event handler for orientation events, |
| 201 // expects to get an event with fake values, then removes the event | 230 // expects to get an event with fake values, then removes the event |
| 202 // handler and navigates to #pass. | 231 // handler and navigates to #pass. |
| 203 GURL test_url = GetTestUrl( | 232 GURL test_url = GetTestUrl("device_sensors", "device_orientation_test.html"); |
| 204 "device_orientation", "device_orientation_test.html"); | |
| 205 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 233 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 206 | 234 |
| 207 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 235 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 208 fetcher_->started_orientation_.Wait(); | 236 fetcher_->started_orientation_.Wait(); |
| 209 fetcher_->stopped_orientation_.Wait(); | 237 fetcher_->stopped_orientation_.Wait(); |
| 210 } | 238 } |
| 211 | 239 |
| 240 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, LightTest) { | |
| 241 // The test page will register an event handler for light events, | |
| 242 // expects to get an event with fake values, then removes the event | |
| 243 // handler and navigates to #pass. | |
| 244 GURL test_url = GetTestUrl("device_sensors", "device_light_test.html"); | |
| 245 // TODO(riju): remove command line args later | |
|
timvolodine
2014/09/04 17:16:57
nit: later -> "when the feature goes stable"
riju_
2014/09/08 09:26:17
Done.
| |
| 246 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 247 switches::kEnableExperimentalWebPlatformFeatures)) | |
|
timvolodine
2014/09/04 17:16:57
indentation?
riju_
2014/09/08 09:26:17
git cl format tells me to keep it like this.
| |
| 248 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 249 switches::kEnableExperimentalWebPlatformFeatures); | |
| 250 | |
| 251 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | |
| 252 | |
| 253 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | |
| 254 fetcher_->started_light_.Wait(); | |
| 255 fetcher_->stopped_light_.Wait(); | |
| 256 } | |
| 257 | |
| 212 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, MotionTest) { | 258 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, MotionTest) { |
| 213 // The test page will register an event handler for motion events, | 259 // The test page will register an event handler for motion events, |
| 214 // expects to get an event with fake values, then removes the event | 260 // expects to get an event with fake values, then removes the event |
| 215 // handler and navigates to #pass. | 261 // handler and navigates to #pass. |
| 216 GURL test_url = GetTestUrl( | 262 GURL test_url = GetTestUrl("device_sensors", "device_motion_test.html"); |
| 217 "device_orientation", "device_motion_test.html"); | |
| 218 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 263 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 219 | 264 |
| 220 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 265 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 221 fetcher_->started_motion_.Wait(); | 266 fetcher_->started_motion_.Wait(); |
| 222 fetcher_->stopped_motion_.Wait(); | 267 fetcher_->stopped_motion_.Wait(); |
| 223 } | 268 } |
| 224 | 269 |
| 270 #if defined(OS_ANDROID) | |
| 271 #define MAYBE_LightNullTestWithAlert DISABLED_LightNullTestWithAlert | |
| 272 #else | |
| 273 #define MAYBE_LightNullTestWithAlert LightNullTestWithAlert | |
| 274 #endif | |
| 275 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, | |
| 276 MAYBE_LightNullTestWithAlert) { | |
|
timvolodine
2014/09/04 17:16:57
the test with alert is kind of involved, maybe jus
riju_
2014/09/08 09:26:17
Let me take out #ifdef android and see its its fla
| |
| 277 // The test page will register an event handler for light events, | |
| 278 // expects to get an event with null values. The test raises a modal alert | |
| 279 // dialog with a delay to test that the one-off null-event still propagates | |
| 280 // to window after the alert is dismissed and the callback is invoked which | |
| 281 // navigates to #pass. | |
| 282 fetcher_->SetSensorDataAvailable(false); | |
| 283 // TODO(riju): remove command line args later | |
| 284 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 285 switches::kEnableExperimentalWebPlatformFeatures)) | |
|
timvolodine
2014/09/04 17:16:57
indent
riju_
2014/09/08 09:26:17
git cl format tells me to keep it like this.
| |
| 286 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 287 switches::kEnableExperimentalWebPlatformFeatures); | |
| 288 | |
| 289 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); | |
| 290 | |
| 291 GURL test_url = | |
| 292 GetTestUrl("device_sensors", "device_light_null_test_with_alert.html"); | |
| 293 shell()->LoadURL(test_url); | |
| 294 | |
| 295 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000)); | |
| 296 | |
| 297 fetcher_->started_light_.Wait(); | |
| 298 fetcher_->stopped_light_.Wait(); | |
| 299 same_tab_observer.Wait(); | |
| 300 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | |
| 301 } | |
| 302 | |
| 225 // Flaking in the android try bot. See http://crbug.com/360578. | 303 // Flaking in the android try bot. See http://crbug.com/360578. |
| 226 #if defined(OS_ANDROID) | 304 #if defined(OS_ANDROID) |
| 227 #define MAYBE_OrientationNullTestWithAlert DISABLED_OrientationNullTestWithAlert | 305 #define MAYBE_OrientationNullTestWithAlert DISABLED_OrientationNullTestWithAlert |
| 228 #else | 306 #else |
| 229 #define MAYBE_OrientationNullTestWithAlert OrientationNullTestWithAlert | 307 #define MAYBE_OrientationNullTestWithAlert OrientationNullTestWithAlert |
| 230 #endif | 308 #endif |
| 231 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, | 309 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, |
| 232 MAYBE_OrientationNullTestWithAlert) { | 310 MAYBE_OrientationNullTestWithAlert) { |
| 233 // The test page will register an event handler for orientation events, | 311 // The test page will register an event handler for orientation events, |
| 234 // expects to get an event with null values. The test raises a modal alert | 312 // expects to get an event with null values. The test raises a modal alert |
| 235 // dialog with a delay to test that the one-off null-event still propagates | 313 // dialog with a delay to test that the one-off null-event still propagates |
| 236 // to window after the alert is dismissed and the callback is invoked which | 314 // to window after the alert is dismissed and the callback is invoked which |
| 237 // navigates to #pass. | 315 // navigates to #pass. |
| 238 fetcher_->SetSensorDataAvailable(false); | 316 fetcher_->SetSensorDataAvailable(false); |
| 239 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); | 317 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); |
| 240 | 318 |
| 241 GURL test_url = GetTestUrl( | 319 GURL test_url = GetTestUrl("device_sensors", |
| 242 "device_orientation", "device_orientation_null_test_with_alert.html"); | 320 "device_orientation_null_test_with_alert.html"); |
| 243 shell()->LoadURL(test_url); | 321 shell()->LoadURL(test_url); |
| 244 | 322 |
| 245 // TODO(timvolodine): investigate if it is possible to test this without | 323 // TODO(timvolodine): investigate if it is possible to test this without |
| 246 // delay, crbug.com/360044. | 324 // delay, crbug.com/360044. |
| 247 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000)); | 325 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000)); |
| 248 | 326 |
| 249 fetcher_->started_orientation_.Wait(); | 327 fetcher_->started_orientation_.Wait(); |
| 250 fetcher_->stopped_orientation_.Wait(); | 328 fetcher_->stopped_orientation_.Wait(); |
| 251 same_tab_observer.Wait(); | 329 same_tab_observer.Wait(); |
| 252 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 330 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 253 } | 331 } |
| 254 | 332 |
| 255 // Flaking in the android try bot. See http://crbug.com/360578. | 333 // Flaking in the android try bot. See http://crbug.com/360578. |
| 256 #if defined(OS_ANDROID) | 334 #if defined(OS_ANDROID) |
| 257 #define MAYBE_MotionNullTestWithAlert DISABLED_MotionNullTestWithAlert | 335 #define MAYBE_MotionNullTestWithAlert DISABLED_MotionNullTestWithAlert |
| 258 #else | 336 #else |
| 259 #define MAYBE_MotionNullTestWithAlert MotionNullTestWithAlert | 337 #define MAYBE_MotionNullTestWithAlert MotionNullTestWithAlert |
| 260 #endif | 338 #endif |
| 261 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, | 339 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, |
| 262 MAYBE_MotionNullTestWithAlert) { | 340 MAYBE_MotionNullTestWithAlert) { |
| 263 // The test page will register an event handler for motion events, | 341 // The test page will register an event handler for motion events, |
| 264 // expects to get an event with null values. The test raises a modal alert | 342 // expects to get an event with null values. The test raises a modal alert |
| 265 // dialog with a delay to test that the one-off null-event still propagates | 343 // dialog with a delay to test that the one-off null-event still propagates |
| 266 // to window after the alert is dismissed and the callback is invoked which | 344 // to window after the alert is dismissed and the callback is invoked which |
| 267 // navigates to #pass. | 345 // navigates to #pass. |
| 268 fetcher_->SetSensorDataAvailable(false); | 346 fetcher_->SetSensorDataAvailable(false); |
| 269 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); | 347 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); |
| 270 | 348 |
| 271 GURL test_url = GetTestUrl( | 349 GURL test_url = |
| 272 "device_orientation", "device_motion_null_test_with_alert.html"); | 350 GetTestUrl("device_sensors", "device_motion_null_test_with_alert.html"); |
| 273 shell()->LoadURL(test_url); | 351 shell()->LoadURL(test_url); |
| 274 | 352 |
| 275 // TODO(timvolodine): investigate if it is possible to test this without | 353 // TODO(timvolodine): investigate if it is possible to test this without |
| 276 // delay, crbug.com/360044. | 354 // delay, crbug.com/360044. |
| 277 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000)); | 355 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000)); |
| 278 | 356 |
| 279 fetcher_->started_motion_.Wait(); | 357 fetcher_->started_motion_.Wait(); |
| 280 fetcher_->stopped_motion_.Wait(); | 358 fetcher_->stopped_motion_.Wait(); |
| 281 same_tab_observer.Wait(); | 359 same_tab_observer.Wait(); |
| 282 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 360 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 283 } | 361 } |
| 284 | 362 |
| 285 } // namespace | 363 } // namespace |
| 286 | 364 |
| 287 } // namespace content | 365 } // namespace content |
| OLD | NEW |