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: | |
| 64 { | |
| 65 DeviceLightHardwareBuffer* light_buffer = | |
| 66 static_cast<DeviceLightHardwareBuffer*>(buffer); | |
| 67 UpdateLight(light_buffer, | |
| 68 sensor_data_available_ | |
| 69 ? 100 | |
| 70 : std::numeric_limits<double>::infinity()); | |
| 71 started_light_.Signal(); | |
| 72 } | |
| 73 break; | |
| 59 default: | 74 default: |
| 60 return false; | 75 return false; |
| 61 } | 76 } |
| 62 return true; | 77 return true; |
| 63 } | 78 } |
| 64 | 79 |
| 65 virtual bool Stop(ConsumerType consumer_type) OVERRIDE { | 80 virtual bool Stop(ConsumerType consumer_type) OVERRIDE { |
| 66 switch (consumer_type) { | 81 switch (consumer_type) { |
| 67 case CONSUMER_TYPE_MOTION: | 82 case CONSUMER_TYPE_MOTION: |
| 68 stopped_motion_.Signal(); | 83 stopped_motion_.Signal(); |
| 69 break; | 84 break; |
| 70 case CONSUMER_TYPE_ORIENTATION: | 85 case CONSUMER_TYPE_ORIENTATION: |
| 71 stopped_orientation_.Signal(); | 86 stopped_orientation_.Signal(); |
| 72 break; | 87 break; |
| 88 case CONSUMER_TYPE_LIGHT: | |
| 89 stopped_light_.Signal(); | |
| 90 break; | |
| 73 default: | 91 default: |
| 74 return false; | 92 return false; |
| 75 } | 93 } |
| 76 return true; | 94 return true; |
| 77 } | 95 } |
| 78 | 96 |
| 79 virtual void Fetch(unsigned consumer_bitmask) OVERRIDE { | 97 virtual void Fetch(unsigned consumer_bitmask) OVERRIDE { |
| 80 FAIL() << "fetch should not be called"; | 98 FAIL() << "fetch should not be called"; |
| 81 } | 99 } |
| 82 | 100 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 buffer->data.alpha = 1; | 151 buffer->data.alpha = 1; |
| 134 buffer->data.hasAlpha = true; | 152 buffer->data.hasAlpha = true; |
| 135 buffer->data.beta = 2; | 153 buffer->data.beta = 2; |
| 136 buffer->data.hasBeta = true; | 154 buffer->data.hasBeta = true; |
| 137 buffer->data.gamma = 3; | 155 buffer->data.gamma = 3; |
| 138 buffer->data.hasGamma = true; | 156 buffer->data.hasGamma = true; |
| 139 buffer->data.allAvailableSensorsAreActive = true; | 157 buffer->data.allAvailableSensorsAreActive = true; |
| 140 buffer->seqlock.WriteEnd(); | 158 buffer->seqlock.WriteEnd(); |
| 141 } | 159 } |
| 142 | 160 |
| 161 void UpdateLight(DeviceLightHardwareBuffer* buffer, double lux) { | |
| 162 buffer->seqlock.WriteBegin(); | |
| 163 buffer->data.value = lux; | |
| 164 buffer->seqlock.WriteEnd(); | |
| 165 } | |
| 166 | |
| 143 base::WaitableEvent started_orientation_; | 167 base::WaitableEvent started_orientation_; |
| 144 base::WaitableEvent stopped_orientation_; | 168 base::WaitableEvent stopped_orientation_; |
| 145 base::WaitableEvent started_motion_; | 169 base::WaitableEvent started_motion_; |
| 146 base::WaitableEvent stopped_motion_; | 170 base::WaitableEvent stopped_motion_; |
| 171 base::WaitableEvent started_light_; | |
| 172 base::WaitableEvent stopped_light_; | |
| 147 bool sensor_data_available_; | 173 bool sensor_data_available_; |
| 148 | 174 |
| 149 private: | 175 private: |
| 150 DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher); | 176 DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher); |
| 151 }; | 177 }; |
| 152 | 178 |
| 153 | 179 |
| 154 class DeviceInertialSensorBrowserTest : public ContentBrowserTest { | 180 class DeviceInertialSensorBrowserTest : public ContentBrowserTest { |
| 155 public: | 181 public: |
| 156 DeviceInertialSensorBrowserTest() | 182 DeviceInertialSensorBrowserTest() |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 delay)); | 214 delay)); |
| 189 runner->Run(); | 215 runner->Run(); |
| 190 } | 216 } |
| 191 | 217 |
| 192 FakeDataFetcher* fetcher_; | 218 FakeDataFetcher* fetcher_; |
| 193 | 219 |
| 194 private: | 220 private: |
| 195 base::WaitableEvent io_loop_finished_event_; | 221 base::WaitableEvent io_loop_finished_event_; |
| 196 }; | 222 }; |
| 197 | 223 |
| 198 | |
| 199 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, OrientationTest) { | 224 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, OrientationTest) { |
| 200 // The test page will register an event handler for orientation events, | 225 // The test page will register an event handler for orientation events, |
| 201 // expects to get an event with fake values, then removes the event | 226 // expects to get an event with fake values, then removes the event |
| 202 // handler and navigates to #pass. | 227 // handler and navigates to #pass. |
| 203 GURL test_url = GetTestUrl( | 228 GURL test_url = GetTestUrl("device_sensors", "device_orientation_test.html"); |
| 204 "device_orientation", "device_orientation_test.html"); | |
| 205 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 229 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 206 | 230 |
| 207 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 231 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 208 fetcher_->started_orientation_.Wait(); | 232 fetcher_->started_orientation_.Wait(); |
| 209 fetcher_->stopped_orientation_.Wait(); | 233 fetcher_->stopped_orientation_.Wait(); |
| 210 } | 234 } |
| 211 | 235 |
| 236 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, LightTest) { | |
| 237 // The test page will register an event handler for light events, | |
| 238 // expects to get an event with fake values, then removes the event | |
| 239 // handler and navigates to #pass. | |
| 240 GURL test_url = GetTestUrl("device_sensors", "device_light_test.html"); | |
| 241 // TODO(riju): remove command line args when the feature goes stable | |
|
timvolodine
2014/09/08 15:20:19
this looks a bit dense, could you add white line?
timvolodine
2014/09/08 15:20:19
nit "." at eol.
riju_
2014/09/09 14:01:17
Done.
riju_
2014/09/09 14:01:17
Done.
| |
| 242 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 243 switches::kEnableExperimentalWebPlatformFeatures)) | |
|
timvolodine
2014/09/08 15:20:19
this still looks weird to me, I think indent +4sp
timvolodine
2014/09/08 15:20:19
also { } required when multiline
riju_
2014/09/09 14:01:17
Done.
riju_
2014/09/09 14:01:17
Done.
| |
| 244 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 245 switches::kEnableExperimentalWebPlatformFeatures); | |
| 246 | |
| 247 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | |
| 248 | |
| 249 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | |
| 250 fetcher_->started_light_.Wait(); | |
| 251 fetcher_->stopped_light_.Wait(); | |
| 252 } | |
| 253 | |
| 212 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, MotionTest) { | 254 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, MotionTest) { |
| 213 // The test page will register an event handler for motion events, | 255 // The test page will register an event handler for motion events, |
| 214 // expects to get an event with fake values, then removes the event | 256 // expects to get an event with fake values, then removes the event |
| 215 // handler and navigates to #pass. | 257 // handler and navigates to #pass. |
| 216 GURL test_url = GetTestUrl( | 258 GURL test_url = GetTestUrl("device_sensors", "device_motion_test.html"); |
| 217 "device_orientation", "device_motion_test.html"); | |
| 218 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 259 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 219 | 260 |
| 220 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 261 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 221 fetcher_->started_motion_.Wait(); | 262 fetcher_->started_motion_.Wait(); |
| 222 fetcher_->stopped_motion_.Wait(); | 263 fetcher_->stopped_motion_.Wait(); |
| 223 } | 264 } |
| 224 | 265 |
| 266 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, LightNullTest) { | |
| 267 // The test page will register an event handler for light events, | |
| 268 // expects to get an event with null(Inf) values. This tests that the one-off | |
| 269 // null-event still propagates to window after the alert is dismissed and | |
| 270 // the callback is invoked which navigates to #pass. | |
| 271 fetcher_->SetSensorDataAvailable(false); | |
|
timvolodine
2014/09/08 15:20:19
nit : add empty line for readability?
riju_
2014/09/09 14:01:18
Done.
| |
| 272 // TODO(riju): remove command line args when the feature goes stable | |
| 273 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 274 switches::kEnableExperimentalWebPlatformFeatures)) | |
|
timvolodine
2014/09/08 15:20:19
{ .. }
riju_
2014/09/09 14:01:17
Done.
| |
| 275 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 276 switches::kEnableExperimentalWebPlatformFeatures); | |
| 277 | |
| 278 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); | |
| 279 | |
| 280 GURL test_url = GetTestUrl("device_sensors", "device_light_null_test.html"); | |
| 281 shell()->LoadURL(test_url); | |
| 282 | |
| 283 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000)); | |
| 284 | |
| 285 fetcher_->started_light_.Wait(); | |
| 286 fetcher_->stopped_light_.Wait(); | |
| 287 same_tab_observer.Wait(); | |
| 288 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | |
| 289 } | |
| 290 | |
| 225 // Flaking in the android try bot. See http://crbug.com/360578. | 291 // Flaking in the android try bot. See http://crbug.com/360578. |
| 226 #if defined(OS_ANDROID) | 292 #if defined(OS_ANDROID) |
| 227 #define MAYBE_OrientationNullTestWithAlert DISABLED_OrientationNullTestWithAlert | 293 #define MAYBE_OrientationNullTestWithAlert DISABLED_OrientationNullTestWithAlert |
| 228 #else | 294 #else |
| 229 #define MAYBE_OrientationNullTestWithAlert OrientationNullTestWithAlert | 295 #define MAYBE_OrientationNullTestWithAlert OrientationNullTestWithAlert |
| 230 #endif | 296 #endif |
| 231 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, | 297 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, |
| 232 MAYBE_OrientationNullTestWithAlert) { | 298 MAYBE_OrientationNullTestWithAlert) { |
| 233 // The test page will register an event handler for orientation events, | 299 // 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 | 300 // 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 | 301 // 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 | 302 // to window after the alert is dismissed and the callback is invoked which |
| 237 // navigates to #pass. | 303 // navigates to #pass. |
| 238 fetcher_->SetSensorDataAvailable(false); | 304 fetcher_->SetSensorDataAvailable(false); |
| 239 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); | 305 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); |
| 240 | 306 |
| 241 GURL test_url = GetTestUrl( | 307 GURL test_url = GetTestUrl("device_sensors", |
| 242 "device_orientation", "device_orientation_null_test_with_alert.html"); | 308 "device_orientation_null_test_with_alert.html"); |
| 243 shell()->LoadURL(test_url); | 309 shell()->LoadURL(test_url); |
| 244 | 310 |
| 245 // TODO(timvolodine): investigate if it is possible to test this without | 311 // TODO(timvolodine): investigate if it is possible to test this without |
| 246 // delay, crbug.com/360044. | 312 // delay, crbug.com/360044. |
| 247 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000)); | 313 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000)); |
| 248 | 314 |
| 249 fetcher_->started_orientation_.Wait(); | 315 fetcher_->started_orientation_.Wait(); |
| 250 fetcher_->stopped_orientation_.Wait(); | 316 fetcher_->stopped_orientation_.Wait(); |
| 251 same_tab_observer.Wait(); | 317 same_tab_observer.Wait(); |
| 252 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 318 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 253 } | 319 } |
| 254 | 320 |
| 255 // Flaking in the android try bot. See http://crbug.com/360578. | 321 // Flaking in the android try bot. See http://crbug.com/360578. |
| 256 #if defined(OS_ANDROID) | 322 #if defined(OS_ANDROID) |
| 257 #define MAYBE_MotionNullTestWithAlert DISABLED_MotionNullTestWithAlert | 323 #define MAYBE_MotionNullTestWithAlert DISABLED_MotionNullTestWithAlert |
| 258 #else | 324 #else |
| 259 #define MAYBE_MotionNullTestWithAlert MotionNullTestWithAlert | 325 #define MAYBE_MotionNullTestWithAlert MotionNullTestWithAlert |
| 260 #endif | 326 #endif |
| 261 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, | 327 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, |
| 262 MAYBE_MotionNullTestWithAlert) { | 328 MAYBE_MotionNullTestWithAlert) { |
| 263 // The test page will register an event handler for motion events, | 329 // 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 | 330 // 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 | 331 // 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 | 332 // to window after the alert is dismissed and the callback is invoked which |
| 267 // navigates to #pass. | 333 // navigates to #pass. |
| 268 fetcher_->SetSensorDataAvailable(false); | 334 fetcher_->SetSensorDataAvailable(false); |
| 269 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); | 335 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); |
| 270 | 336 |
| 271 GURL test_url = GetTestUrl( | 337 GURL test_url = |
| 272 "device_orientation", "device_motion_null_test_with_alert.html"); | 338 GetTestUrl("device_sensors", "device_motion_null_test_with_alert.html"); |
| 273 shell()->LoadURL(test_url); | 339 shell()->LoadURL(test_url); |
| 274 | 340 |
| 275 // TODO(timvolodine): investigate if it is possible to test this without | 341 // TODO(timvolodine): investigate if it is possible to test this without |
| 276 // delay, crbug.com/360044. | 342 // delay, crbug.com/360044. |
| 277 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000)); | 343 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000)); |
| 278 | 344 |
| 279 fetcher_->started_motion_.Wait(); | 345 fetcher_->started_motion_.Wait(); |
| 280 fetcher_->stopped_motion_.Wait(); | 346 fetcher_->stopped_motion_.Wait(); |
| 281 same_tab_observer.Wait(); | 347 same_tab_observer.Wait(); |
| 282 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 348 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 283 } | 349 } |
| 284 | 350 |
| 285 } // namespace | 351 } // namespace |
| 286 | 352 |
| 287 } // namespace content | 353 } // namespace content |
| OLD | NEW |