Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: content/browser/device_sensors/device_inertial_sensor_browsertest.cc

Issue 292693004: [DeviceLight] Browser+java part (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: null event test case Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
242 // TODO(riju): remove command line args when the feature goes stable.
243 if (!CommandLine::ForCurrentProcess()->HasSwitch(
244 switches::kEnableExperimentalWebPlatformFeatures)) {
245 CommandLine::ForCurrentProcess()->AppendSwitch(
246 switches::kEnableExperimentalWebPlatformFeatures);
247 }
248
249 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2);
250
251 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
252 fetcher_->started_light_.Wait();
253 fetcher_->stopped_light_.Wait();
254 }
255
212 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, MotionTest) { 256 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, MotionTest) {
213 // The test page will register an event handler for motion events, 257 // The test page will register an event handler for motion events,
214 // expects to get an event with fake values, then removes the event 258 // expects to get an event with fake values, then removes the event
215 // handler and navigates to #pass. 259 // handler and navigates to #pass.
216 GURL test_url = GetTestUrl( 260 GURL test_url = GetTestUrl("device_sensors", "device_motion_test.html");
217 "device_orientation", "device_motion_test.html");
218 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); 261 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2);
219 262
220 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); 263 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
221 fetcher_->started_motion_.Wait(); 264 fetcher_->started_motion_.Wait();
222 fetcher_->stopped_motion_.Wait(); 265 fetcher_->stopped_motion_.Wait();
223 } 266 }
224 267
268 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, LightNullTest) {
269 // The test page will register an event handler for light events,
270 // expects to get an event with null(Inf) values. This tests that the one-off
timvolodine 2014/09/10 13:47:25 you seem to use null events and inf values interch
riju_ 2014/09/22 08:22:21 Done.
271 // null-event still propagates to window after the alert is dismissed and
272 // the callback is invoked which navigates to #pass.
273 fetcher_->SetSensorDataAvailable(false);
274
275 // TODO(riju): remove command line args when the feature goes stable.
276 if (!CommandLine::ForCurrentProcess()->HasSwitch(
277 switches::kEnableExperimentalWebPlatformFeatures)) {
278 CommandLine::ForCurrentProcess()->AppendSwitch(
279 switches::kEnableExperimentalWebPlatformFeatures);
280 }
281
282 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2);
283
284 GURL test_url = GetTestUrl("device_sensors", "device_light_null_test.html");
285 shell()->LoadURL(test_url);
286
287 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000));
288
289 fetcher_->started_light_.Wait();
290 fetcher_->stopped_light_.Wait();
291 same_tab_observer.Wait();
292 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
293 }
294
225 // Flaking in the android try bot. See http://crbug.com/360578. 295 // Flaking in the android try bot. See http://crbug.com/360578.
226 #if defined(OS_ANDROID) 296 #if defined(OS_ANDROID)
227 #define MAYBE_OrientationNullTestWithAlert DISABLED_OrientationNullTestWithAlert 297 #define MAYBE_OrientationNullTestWithAlert DISABLED_OrientationNullTestWithAlert
228 #else 298 #else
229 #define MAYBE_OrientationNullTestWithAlert OrientationNullTestWithAlert 299 #define MAYBE_OrientationNullTestWithAlert OrientationNullTestWithAlert
230 #endif 300 #endif
231 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, 301 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest,
232 MAYBE_OrientationNullTestWithAlert) { 302 MAYBE_OrientationNullTestWithAlert) {
233 // The test page will register an event handler for orientation events, 303 // 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 304 // 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 305 // 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 306 // to window after the alert is dismissed and the callback is invoked which
237 // navigates to #pass. 307 // navigates to #pass.
238 fetcher_->SetSensorDataAvailable(false); 308 fetcher_->SetSensorDataAvailable(false);
239 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); 309 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2);
240 310
241 GURL test_url = GetTestUrl( 311 GURL test_url = GetTestUrl("device_sensors",
242 "device_orientation", "device_orientation_null_test_with_alert.html"); 312 "device_orientation_null_test_with_alert.html");
243 shell()->LoadURL(test_url); 313 shell()->LoadURL(test_url);
244 314
245 // TODO(timvolodine): investigate if it is possible to test this without 315 // TODO(timvolodine): investigate if it is possible to test this without
246 // delay, crbug.com/360044. 316 // delay, crbug.com/360044.
247 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000)); 317 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000));
248 318
249 fetcher_->started_orientation_.Wait(); 319 fetcher_->started_orientation_.Wait();
250 fetcher_->stopped_orientation_.Wait(); 320 fetcher_->stopped_orientation_.Wait();
251 same_tab_observer.Wait(); 321 same_tab_observer.Wait();
252 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); 322 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
253 } 323 }
254 324
255 // Flaking in the android try bot. See http://crbug.com/360578. 325 // Flaking in the android try bot. See http://crbug.com/360578.
256 #if defined(OS_ANDROID) 326 #if defined(OS_ANDROID)
257 #define MAYBE_MotionNullTestWithAlert DISABLED_MotionNullTestWithAlert 327 #define MAYBE_MotionNullTestWithAlert DISABLED_MotionNullTestWithAlert
258 #else 328 #else
259 #define MAYBE_MotionNullTestWithAlert MotionNullTestWithAlert 329 #define MAYBE_MotionNullTestWithAlert MotionNullTestWithAlert
260 #endif 330 #endif
261 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest, 331 IN_PROC_BROWSER_TEST_F(DeviceInertialSensorBrowserTest,
262 MAYBE_MotionNullTestWithAlert) { 332 MAYBE_MotionNullTestWithAlert) {
263 // The test page will register an event handler for motion events, 333 // 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 334 // 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 335 // 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 336 // to window after the alert is dismissed and the callback is invoked which
267 // navigates to #pass. 337 // navigates to #pass.
268 fetcher_->SetSensorDataAvailable(false); 338 fetcher_->SetSensorDataAvailable(false);
269 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2); 339 TestNavigationObserver same_tab_observer(shell()->web_contents(), 2);
270 340
271 GURL test_url = GetTestUrl( 341 GURL test_url =
272 "device_orientation", "device_motion_null_test_with_alert.html"); 342 GetTestUrl("device_sensors", "device_motion_null_test_with_alert.html");
273 shell()->LoadURL(test_url); 343 shell()->LoadURL(test_url);
274 344
275 // TODO(timvolodine): investigate if it is possible to test this without 345 // TODO(timvolodine): investigate if it is possible to test this without
276 // delay, crbug.com/360044. 346 // delay, crbug.com/360044.
277 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000)); 347 WaitForAlertDialogAndQuitAfterDelay(base::TimeDelta::FromMilliseconds(1000));
278 348
279 fetcher_->started_motion_.Wait(); 349 fetcher_->started_motion_.Wait();
280 fetcher_->stopped_motion_.Wait(); 350 fetcher_->stopped_motion_.Wait();
281 same_tab_observer.Wait(); 351 same_tab_observer.Wait();
282 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); 352 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
283 } 353 }
284 354
285 } // namespace 355 } // namespace
286 356
287 } // namespace content 357 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698