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" | |
11 #include "content/browser/device_sensors/device_sensor_service.h" | |
12 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
14 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
15 #include "content/public/test/content_browser_test.h" | 13 #include "content/public/test/content_browser_test.h" |
16 #include "content/public/test/content_browser_test_utils.h" | 14 #include "content/public/test/content_browser_test_utils.h" |
17 #include "content/public/test/test_navigation_observer.h" | 15 #include "content/public/test/test_navigation_observer.h" |
18 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
19 #include "content/shell/browser/shell.h" | 17 #include "content/shell/browser/shell.h" |
20 #include "content/shell/browser/shell_javascript_dialog_manager.h" | 18 #include "content/shell/browser/shell_javascript_dialog_manager.h" |
| 19 #include "device/sensors/data_fetcher_shared_memory.h" |
| 20 #include "device/sensors/device_sensor_service.h" |
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 device::DataFetcherSharedMemory { |
30 public: | 30 public: |
31 FakeDataFetcher() : sensor_data_available_(true) {} | 31 FakeDataFetcher() : sensor_data_available_(true) {} |
32 ~FakeDataFetcher() override {} | 32 ~FakeDataFetcher() override {} |
33 | 33 |
34 void SetMotionStartedCallback(base::Closure motion_started_callback) { | 34 void SetMotionStartedCallback(base::Closure motion_started_callback) { |
35 motion_started_callback_ = motion_started_callback; | 35 motion_started_callback_ = motion_started_callback; |
36 } | 36 } |
37 | 37 |
38 void SetMotionStoppedCallback(base::Closure motion_stopped_callback) { | 38 void SetMotionStoppedCallback(base::Closure motion_stopped_callback) { |
39 motion_stopped_callback_ = motion_stopped_callback; | 39 motion_stopped_callback_ = motion_stopped_callback; |
(...skipping 10 matching lines...) Expand all Loading... |
50 void SetOrientationStartedCallback( | 50 void SetOrientationStartedCallback( |
51 base::Closure orientation_started_callback) { | 51 base::Closure orientation_started_callback) { |
52 orientation_started_callback_ = orientation_started_callback; | 52 orientation_started_callback_ = orientation_started_callback; |
53 } | 53 } |
54 | 54 |
55 void SetOrientationStoppedCallback( | 55 void SetOrientationStoppedCallback( |
56 base::Closure orientation_stopped_callback) { | 56 base::Closure orientation_stopped_callback) { |
57 orientation_stopped_callback_ = orientation_stopped_callback; | 57 orientation_stopped_callback_ = orientation_stopped_callback; |
58 } | 58 } |
59 | 59 |
60 bool Start(ConsumerType consumer_type, void* buffer) override { | 60 bool Start(device::ConsumerType consumer_type, void* buffer) override { |
61 EXPECT_TRUE(buffer); | 61 EXPECT_TRUE(buffer); |
62 | 62 |
63 switch (consumer_type) { | 63 switch (consumer_type) { |
64 case CONSUMER_TYPE_MOTION: { | 64 case device::CONSUMER_TYPE_MOTION: { |
65 DeviceMotionHardwareBuffer* motion_buffer = | 65 device::DeviceMotionHardwareBuffer* motion_buffer = |
66 static_cast<DeviceMotionHardwareBuffer*>(buffer); | 66 static_cast<device::DeviceMotionHardwareBuffer*>(buffer); |
67 if (sensor_data_available_) | 67 if (sensor_data_available_) |
68 UpdateMotion(motion_buffer); | 68 UpdateMotion(motion_buffer); |
69 SetMotionBufferReady(motion_buffer); | 69 SetMotionBufferReady(motion_buffer); |
70 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 70 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
71 motion_started_callback_); | 71 motion_started_callback_); |
72 } break; | 72 } break; |
73 case CONSUMER_TYPE_ORIENTATION: { | 73 case device::CONSUMER_TYPE_ORIENTATION: { |
74 DeviceOrientationHardwareBuffer* orientation_buffer = | 74 device::DeviceOrientationHardwareBuffer* orientation_buffer = |
75 static_cast<DeviceOrientationHardwareBuffer*>(buffer); | 75 static_cast<device::DeviceOrientationHardwareBuffer*>(buffer); |
76 if (sensor_data_available_) | 76 if (sensor_data_available_) |
77 UpdateOrientation(orientation_buffer); | 77 UpdateOrientation(orientation_buffer); |
78 SetOrientationBufferReady(orientation_buffer); | 78 SetOrientationBufferReady(orientation_buffer); |
79 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 79 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
80 orientation_started_callback_); | 80 orientation_started_callback_); |
81 } break; | 81 } break; |
82 case CONSUMER_TYPE_LIGHT: { | 82 case device::CONSUMER_TYPE_LIGHT: { |
83 DeviceLightHardwareBuffer* light_buffer = | 83 device::DeviceLightHardwareBuffer* light_buffer = |
84 static_cast<DeviceLightHardwareBuffer*>(buffer); | 84 static_cast<device::DeviceLightHardwareBuffer*>(buffer); |
85 UpdateLight(light_buffer, | 85 UpdateLight(light_buffer, |
86 sensor_data_available_ | 86 sensor_data_available_ |
87 ? 100 | 87 ? 100 |
88 : std::numeric_limits<double>::infinity()); | 88 : std::numeric_limits<double>::infinity()); |
89 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 89 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
90 light_started_callback_); | 90 light_started_callback_); |
91 } break; | 91 } break; |
92 default: | 92 default: |
93 return false; | 93 return false; |
94 } | 94 } |
95 return true; | 95 return true; |
96 } | 96 } |
97 | 97 |
98 bool Stop(ConsumerType consumer_type) override { | 98 bool Stop(device::ConsumerType consumer_type) override { |
99 switch (consumer_type) { | 99 switch (consumer_type) { |
100 case CONSUMER_TYPE_MOTION: | 100 case device::CONSUMER_TYPE_MOTION: |
101 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 101 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
102 motion_stopped_callback_); | 102 motion_stopped_callback_); |
103 break; | 103 break; |
104 case CONSUMER_TYPE_ORIENTATION: | 104 case device::CONSUMER_TYPE_ORIENTATION: |
105 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 105 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
106 orientation_stopped_callback_); | 106 orientation_stopped_callback_); |
107 break; | 107 break; |
108 case CONSUMER_TYPE_LIGHT: | 108 case device::CONSUMER_TYPE_LIGHT: |
109 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 109 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
110 light_stopped_callback_); | 110 light_stopped_callback_); |
111 break; | 111 break; |
112 default: | 112 default: |
113 return false; | 113 return false; |
114 } | 114 } |
115 return true; | 115 return true; |
116 } | 116 } |
117 | 117 |
118 void Fetch(unsigned consumer_bitmask) override { | 118 void Fetch(unsigned consumer_bitmask) override { |
119 FAIL() << "fetch should not be called"; | 119 FAIL() << "fetch should not be called"; |
120 } | 120 } |
121 | 121 |
122 FetcherType GetType() const override { return FETCHER_TYPE_DEFAULT; } | 122 FetcherType GetType() const override { return FETCHER_TYPE_DEFAULT; } |
123 | 123 |
124 void SetSensorDataAvailable(bool available) { | 124 void SetSensorDataAvailable(bool available) { |
125 sensor_data_available_ = available; | 125 sensor_data_available_ = available; |
126 } | 126 } |
127 | 127 |
128 void SetMotionBufferReady(DeviceMotionHardwareBuffer* buffer) { | 128 void SetMotionBufferReady(device::DeviceMotionHardwareBuffer* buffer) { |
129 buffer->seqlock.WriteBegin(); | 129 buffer->seqlock.WriteBegin(); |
130 buffer->data.allAvailableSensorsAreActive = true; | 130 buffer->data.allAvailableSensorsAreActive = true; |
131 buffer->seqlock.WriteEnd(); | 131 buffer->seqlock.WriteEnd(); |
132 } | 132 } |
133 | 133 |
134 void SetOrientationBufferReady(DeviceOrientationHardwareBuffer* buffer) { | 134 void SetOrientationBufferReady( |
| 135 device::DeviceOrientationHardwareBuffer* buffer) { |
135 buffer->seqlock.WriteBegin(); | 136 buffer->seqlock.WriteBegin(); |
136 buffer->data.allAvailableSensorsAreActive = true; | 137 buffer->data.allAvailableSensorsAreActive = true; |
137 buffer->seqlock.WriteEnd(); | 138 buffer->seqlock.WriteEnd(); |
138 } | 139 } |
139 | 140 |
140 void UpdateMotion(DeviceMotionHardwareBuffer* buffer) { | 141 void UpdateMotion(device::DeviceMotionHardwareBuffer* buffer) { |
141 buffer->seqlock.WriteBegin(); | 142 buffer->seqlock.WriteBegin(); |
142 buffer->data.accelerationX = 1; | 143 buffer->data.accelerationX = 1; |
143 buffer->data.hasAccelerationX = true; | 144 buffer->data.hasAccelerationX = true; |
144 buffer->data.accelerationY = 2; | 145 buffer->data.accelerationY = 2; |
145 buffer->data.hasAccelerationY = true; | 146 buffer->data.hasAccelerationY = true; |
146 buffer->data.accelerationZ = 3; | 147 buffer->data.accelerationZ = 3; |
147 buffer->data.hasAccelerationZ = true; | 148 buffer->data.hasAccelerationZ = true; |
148 | 149 |
149 buffer->data.accelerationIncludingGravityX = 4; | 150 buffer->data.accelerationIncludingGravityX = 4; |
150 buffer->data.hasAccelerationIncludingGravityX = true; | 151 buffer->data.hasAccelerationIncludingGravityX = true; |
151 buffer->data.accelerationIncludingGravityY = 5; | 152 buffer->data.accelerationIncludingGravityY = 5; |
152 buffer->data.hasAccelerationIncludingGravityY = true; | 153 buffer->data.hasAccelerationIncludingGravityY = true; |
153 buffer->data.accelerationIncludingGravityZ = 6; | 154 buffer->data.accelerationIncludingGravityZ = 6; |
154 buffer->data.hasAccelerationIncludingGravityZ = true; | 155 buffer->data.hasAccelerationIncludingGravityZ = true; |
155 | 156 |
156 buffer->data.rotationRateAlpha = 7; | 157 buffer->data.rotationRateAlpha = 7; |
157 buffer->data.hasRotationRateAlpha = true; | 158 buffer->data.hasRotationRateAlpha = true; |
158 buffer->data.rotationRateBeta = 8; | 159 buffer->data.rotationRateBeta = 8; |
159 buffer->data.hasRotationRateBeta = true; | 160 buffer->data.hasRotationRateBeta = true; |
160 buffer->data.rotationRateGamma = 9; | 161 buffer->data.rotationRateGamma = 9; |
161 buffer->data.hasRotationRateGamma = true; | 162 buffer->data.hasRotationRateGamma = true; |
162 | 163 |
163 buffer->data.interval = 100; | 164 buffer->data.interval = 100; |
164 buffer->data.allAvailableSensorsAreActive = true; | 165 buffer->data.allAvailableSensorsAreActive = true; |
165 buffer->seqlock.WriteEnd(); | 166 buffer->seqlock.WriteEnd(); |
166 } | 167 } |
167 | 168 |
168 void UpdateOrientation(DeviceOrientationHardwareBuffer* buffer) { | 169 void UpdateOrientation(device::DeviceOrientationHardwareBuffer* buffer) { |
169 buffer->seqlock.WriteBegin(); | 170 buffer->seqlock.WriteBegin(); |
170 buffer->data.alpha = 1; | 171 buffer->data.alpha = 1; |
171 buffer->data.hasAlpha = true; | 172 buffer->data.hasAlpha = true; |
172 buffer->data.beta = 2; | 173 buffer->data.beta = 2; |
173 buffer->data.hasBeta = true; | 174 buffer->data.hasBeta = true; |
174 buffer->data.gamma = 3; | 175 buffer->data.gamma = 3; |
175 buffer->data.hasGamma = true; | 176 buffer->data.hasGamma = true; |
176 buffer->data.allAvailableSensorsAreActive = true; | 177 buffer->data.allAvailableSensorsAreActive = true; |
177 buffer->seqlock.WriteEnd(); | 178 buffer->seqlock.WriteEnd(); |
178 } | 179 } |
179 | 180 |
180 void UpdateLight(DeviceLightHardwareBuffer* buffer, double lux) { | 181 void UpdateLight(device::DeviceLightHardwareBuffer* buffer, double lux) { |
181 buffer->seqlock.WriteBegin(); | 182 buffer->seqlock.WriteBegin(); |
182 buffer->data.value = lux; | 183 buffer->data.value = lux; |
183 buffer->seqlock.WriteEnd(); | 184 buffer->seqlock.WriteEnd(); |
184 } | 185 } |
185 | 186 |
186 // The below callbacks should be run on the UI thread. | 187 // The below callbacks should be run on the UI thread. |
187 base::Closure motion_started_callback_; | 188 base::Closure motion_started_callback_; |
188 base::Closure orientation_started_callback_; | 189 base::Closure orientation_started_callback_; |
189 base::Closure light_started_callback_; | 190 base::Closure light_started_callback_; |
190 base::Closure motion_stopped_callback_; | 191 base::Closure motion_stopped_callback_; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 void SetUpFetcher() { | 229 void SetUpFetcher() { |
229 fetcher_ = new FakeDataFetcher(); | 230 fetcher_ = new FakeDataFetcher(); |
230 fetcher_->SetLightStartedCallback(light_started_runloop_->QuitClosure()); | 231 fetcher_->SetLightStartedCallback(light_started_runloop_->QuitClosure()); |
231 fetcher_->SetLightStoppedCallback(light_stopped_runloop_->QuitClosure()); | 232 fetcher_->SetLightStoppedCallback(light_stopped_runloop_->QuitClosure()); |
232 fetcher_->SetMotionStartedCallback(motion_started_runloop_->QuitClosure()); | 233 fetcher_->SetMotionStartedCallback(motion_started_runloop_->QuitClosure()); |
233 fetcher_->SetMotionStoppedCallback(motion_stopped_runloop_->QuitClosure()); | 234 fetcher_->SetMotionStoppedCallback(motion_stopped_runloop_->QuitClosure()); |
234 fetcher_->SetOrientationStartedCallback( | 235 fetcher_->SetOrientationStartedCallback( |
235 orientation_started_runloop_->QuitClosure()); | 236 orientation_started_runloop_->QuitClosure()); |
236 fetcher_->SetOrientationStoppedCallback( | 237 fetcher_->SetOrientationStoppedCallback( |
237 orientation_stopped_runloop_->QuitClosure()); | 238 orientation_stopped_runloop_->QuitClosure()); |
238 DeviceSensorService::GetInstance()->SetDataFetcherForTesting(fetcher_); | 239 device::DeviceSensorService::GetInstance()->SetDataFetcherForTesting( |
| 240 fetcher_); |
239 } | 241 } |
240 | 242 |
241 void SetUpOnIOThread() { | 243 void SetUpOnIOThread() { |
242 SetUpFetcher(); | 244 SetUpFetcher(); |
243 io_loop_finished_event_.Signal(); | 245 io_loop_finished_event_.Signal(); |
244 } | 246 } |
245 | 247 |
246 void DelayAndQuit(base::TimeDelta delay) { | 248 void DelayAndQuit(base::TimeDelta delay) { |
247 base::PlatformThread::Sleep(delay); | 249 base::PlatformThread::Sleep(delay); |
248 base::MessageLoop::current()->QuitWhenIdle(); | 250 base::MessageLoop::current()->QuitWhenIdle(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 motion_stopped_runloop_->Run(); | 384 motion_stopped_runloop_->Run(); |
383 orientation_started_runloop_->Run(); | 385 orientation_started_runloop_->Run(); |
384 orientation_stopped_runloop_->Run(); | 386 orientation_stopped_runloop_->Run(); |
385 same_tab_observer.Wait(); | 387 same_tab_observer.Wait(); |
386 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 388 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
387 } | 389 } |
388 | 390 |
389 } // namespace | 391 } // namespace |
390 | 392 |
391 } // namespace content | 393 } // namespace content |
OLD | NEW |