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/synchronization/waitable_event.h" | 5 #include "base/synchronization/waitable_event.h" |
| 6 #include "base/threading/platform_thread.h" | 6 #include "base/threading/platform_thread.h" |
| 7 #include "content/browser/device_sensors/data_fetcher_shared_memory.h" | 7 #include "content/browser/device_sensors/data_fetcher_shared_memory.h" |
| 8 #include "content/browser/device_sensors/device_inertial_sensor_service.h" | 8 #include "content/browser/device_sensors/device_inertial_sensor_service.h" |
| 9 #include "content/common/device_sensors/device_light_hardware_buffer.h" | |
| 9 #include "content/common/device_sensors/device_motion_hardware_buffer.h" | 10 #include "content/common/device_sensors/device_motion_hardware_buffer.h" |
| 10 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" | 11 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" |
| 11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/test/content_browser_test.h" | 14 #include "content/public/test/content_browser_test.h" |
| 14 #include "content/public/test/content_browser_test_utils.h" | 15 #include "content/public/test/content_browser_test_utils.h" |
| 15 #include "content/public/test/test_navigation_observer.h" | 16 #include "content/public/test/test_navigation_observer.h" |
| 16 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
| 17 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
| 18 #include "content/shell/browser/shell_javascript_dialog_manager.h" | 19 #include "content/shell/browser/shell_javascript_dialog_manager.h" |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 class FakeDataFetcher : public DataFetcherSharedMemory { | 25 class FakeDataFetcher : public DataFetcherSharedMemory { |
| 25 public: | 26 public: |
| 26 FakeDataFetcher() | 27 FakeDataFetcher() |
| 27 : started_orientation_(false, false), | 28 : started_orientation_(false, false), |
| 28 stopped_orientation_(false, false), | 29 stopped_orientation_(false, false), |
| 29 started_motion_(false, false), | 30 started_motion_(false, false), |
| 30 stopped_motion_(false, false), | 31 stopped_motion_(false, false), |
| 31 sensor_data_available_(true) { | 32 started_light_(false, false), |
| 32 } | 33 stopped_light_(false, false), |
| 34 sensor_data_available_(true) {} | |
| 33 virtual ~FakeDataFetcher() { } | 35 virtual ~FakeDataFetcher() { } |
| 34 | 36 |
| 35 virtual bool Start(ConsumerType consumer_type, void* buffer) OVERRIDE { | 37 virtual bool Start(ConsumerType consumer_type, void* buffer) OVERRIDE { |
| 36 EXPECT_TRUE(buffer); | 38 EXPECT_TRUE(buffer); |
| 37 | 39 |
| 38 switch (consumer_type) { | 40 switch (consumer_type) { |
| 39 case CONSUMER_TYPE_MOTION: | 41 case CONSUMER_TYPE_MOTION: |
| 40 { | 42 { |
| 41 DeviceMotionHardwareBuffer* motion_buffer = | 43 DeviceMotionHardwareBuffer* motion_buffer = |
| 42 static_cast<DeviceMotionHardwareBuffer*>(buffer); | 44 static_cast<DeviceMotionHardwareBuffer*>(buffer); |
| 43 if (sensor_data_available_) | 45 if (sensor_data_available_) |
| 44 UpdateMotion(motion_buffer); | 46 UpdateMotion(motion_buffer); |
| 45 SetMotionBufferReady(motion_buffer); | 47 SetMotionBufferReady(motion_buffer); |
| 46 started_motion_.Signal(); | 48 started_motion_.Signal(); |
| 47 } | 49 } |
| 48 break; | 50 break; |
| 49 case CONSUMER_TYPE_ORIENTATION: | 51 case CONSUMER_TYPE_ORIENTATION: |
| 50 { | 52 { |
| 51 DeviceOrientationHardwareBuffer* orientation_buffer = | 53 DeviceOrientationHardwareBuffer* orientation_buffer = |
| 52 static_cast<DeviceOrientationHardwareBuffer*>(buffer); | 54 static_cast<DeviceOrientationHardwareBuffer*>(buffer); |
| 53 if (sensor_data_available_) | 55 if (sensor_data_available_) |
| 54 UpdateOrientation(orientation_buffer); | 56 UpdateOrientation(orientation_buffer); |
| 55 SetOrientationBufferReady(orientation_buffer); | 57 SetOrientationBufferReady(orientation_buffer); |
| 56 started_orientation_.Signal(); | 58 started_orientation_.Signal(); |
| 57 } | 59 } |
| 58 break; | 60 break; |
| 61 case CONSUMER_TYPE_LIGHT: { | |
|
timvolodine
2014/07/16 15:39:38
indentation
riju_
2014/07/18 15:59:17
Done. I ran git cl format, and clang format did th
| |
| 62 DeviceLightHardwareBuffer* light_buffer = | |
| 63 static_cast<DeviceLightHardwareBuffer*>(buffer); | |
| 64 if (sensor_data_available_) | |
| 65 UpdateLight(light_buffer); | |
| 66 started_light_.Signal(); | |
| 67 } break; | |
|
timvolodine
2014/07/16 15:39:38
break on new line
riju_
2014/07/18 15:59:17
Done.
| |
| 59 default: | 68 default: |
| 60 return false; | 69 return false; |
| 61 } | 70 } |
| 62 return true; | 71 return true; |
| 63 } | 72 } |
| 64 | 73 |
| 65 virtual bool Stop(ConsumerType consumer_type) OVERRIDE { | 74 virtual bool Stop(ConsumerType consumer_type) OVERRIDE { |
| 66 switch (consumer_type) { | 75 switch (consumer_type) { |
| 67 case CONSUMER_TYPE_MOTION: | 76 case CONSUMER_TYPE_MOTION: |
| 68 stopped_motion_.Signal(); | 77 stopped_motion_.Signal(); |
| 69 break; | 78 break; |
| 70 case CONSUMER_TYPE_ORIENTATION: | 79 case CONSUMER_TYPE_ORIENTATION: |
| 71 stopped_orientation_.Signal(); | 80 stopped_orientation_.Signal(); |
| 72 break; | 81 break; |
| 82 case CONSUMER_TYPE_LIGHT: | |
| 83 stopped_light_.Signal(); | |
| 84 break; | |
| 73 default: | 85 default: |
| 74 return false; | 86 return false; |
| 75 } | 87 } |
| 76 return true; | 88 return true; |
| 77 } | 89 } |
| 78 | 90 |
| 79 virtual void Fetch(unsigned consumer_bitmask) OVERRIDE { | 91 virtual void Fetch(unsigned consumer_bitmask) OVERRIDE { |
| 80 FAIL() << "fetch should not be called"; | 92 FAIL() << "fetch should not be called"; |
| 81 } | 93 } |
| 82 | 94 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 buffer->data.alpha = 1; | 145 buffer->data.alpha = 1; |
| 134 buffer->data.hasAlpha = true; | 146 buffer->data.hasAlpha = true; |
| 135 buffer->data.beta = 2; | 147 buffer->data.beta = 2; |
| 136 buffer->data.hasBeta = true; | 148 buffer->data.hasBeta = true; |
| 137 buffer->data.gamma = 3; | 149 buffer->data.gamma = 3; |
| 138 buffer->data.hasGamma = true; | 150 buffer->data.hasGamma = true; |
| 139 buffer->data.allAvailableSensorsAreActive = true; | 151 buffer->data.allAvailableSensorsAreActive = true; |
| 140 buffer->seqlock.WriteEnd(); | 152 buffer->seqlock.WriteEnd(); |
| 141 } | 153 } |
| 142 | 154 |
| 155 void UpdateLight(DeviceLightHardwareBuffer* buffer) { | |
| 156 buffer->seqlock.WriteBegin(); | |
| 157 buffer->data.value = 100; | |
| 158 buffer->seqlock.WriteEnd(); | |
| 159 } | |
| 160 | |
| 143 base::WaitableEvent started_orientation_; | 161 base::WaitableEvent started_orientation_; |
| 144 base::WaitableEvent stopped_orientation_; | 162 base::WaitableEvent stopped_orientation_; |
| 145 base::WaitableEvent started_motion_; | 163 base::WaitableEvent started_motion_; |
| 146 base::WaitableEvent stopped_motion_; | 164 base::WaitableEvent stopped_motion_; |
| 165 base::WaitableEvent started_light_; | |
| 166 base::WaitableEvent stopped_light_; | |
| 147 bool sensor_data_available_; | 167 bool sensor_data_available_; |
| 148 | 168 |
| 149 private: | 169 private: |
| 150 DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher); | 170 DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher); |
| 151 }; | 171 }; |
| 152 | 172 |
| 153 | 173 |
| 154 class DeviceInertialSensorBrowserTest : public ContentBrowserTest { | 174 class DeviceInertialSensorBrowserTest : public ContentBrowserTest { |
| 155 public: | 175 public: |
| 156 DeviceInertialSensorBrowserTest() | 176 DeviceInertialSensorBrowserTest() |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 delay)); | 208 delay)); |
| 189 runner->Run(); | 209 runner->Run(); |
| 190 } | 210 } |
| 191 | 211 |
| 192 FakeDataFetcher* fetcher_; | 212 FakeDataFetcher* fetcher_; |
| 193 | 213 |
| 194 private: | 214 private: |
| 195 base::WaitableEvent io_loop_finished_event_; | 215 base::WaitableEvent io_loop_finished_event_; |
| 196 }; | 216 }; |
| 197 | 217 |
| 218 // TODO(riju) : Add light test | |
|
timvolodine
2014/07/16 15:39:38
I think the browsertest should either be in a sepa
riju_
2014/07/18 15:59:17
Yes. I agree with you. I am renaming the "device_o
| |
| 198 | 219 |
| 199 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, OrientationTest) { | 220 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, OrientationTest) { |
| 200 // The test page will register an event handler for orientation events, | 221 // The test page will register an event handler for orientation events, |
| 201 // expects to get an event with fake values, then removes the event | 222 // expects to get an event with fake values, then removes the event |
| 202 // handler and navigates to #pass. | 223 // handler and navigates to #pass. |
| 203 GURL test_url = GetTestUrl( | 224 GURL test_url = GetTestUrl( |
| 204 "device_orientation", "device_orientation_test.html"); | 225 "device_orientation", "device_orientation_test.html"); |
| 205 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 226 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
| 206 | 227 |
| 207 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 228 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 | 299 |
| 279 fetcher_->started_motion_.Wait(); | 300 fetcher_->started_motion_.Wait(); |
| 280 fetcher_->stopped_motion_.Wait(); | 301 fetcher_->stopped_motion_.Wait(); |
| 281 same_tab_observer.Wait(); | 302 same_tab_observer.Wait(); |
| 282 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 303 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
| 283 } | 304 } |
| 284 | 305 |
| 285 } // namespace | 306 } // namespace |
| 286 | 307 |
| 287 } // namespace content | 308 } // namespace content |
| OLD | NEW |