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

Side by Side Diff: third_party/WebKit/LayoutTests/sensor/ambient-light-sensor.html

Issue 2353493002: [Sensors] Allow Sensor API only on secure top-level browsing contexts and add frequency checks (Closed)
Patch Set: Comments from Tim Created 4 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 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script> 2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script> 3 <script src="../resources/testharnessreport.js"></script>
4 <script src="../resources/mojo-helpers.js"></script> 4 <script src="../resources/mojo-helpers.js"></script>
5 <script src="resources/sensor-helpers.js"></script> 5 <script src="resources/sensor-helpers.js"></script>
6 <script> 6 <script>
7 7
8 'use strict'; 8 'use strict';
9 9
10 if (!window.testRunner) 10 if (!window.testRunner)
11 debug('This test cannot be run without the TestRunner'); 11 debug('This test cannot be run without the TestRunner');
12 12
13 const kDefaultReadingValue = 3.1415; 13 const kDefaultReadingValue = 3.1415;
14 14
15 function update_sensor_reading(buffer) { 15 function update_sensor_reading(buffer) {
16 buffer[0] = window.performance.now(); 16 buffer[0] = window.performance.now();
17 buffer[1] = kDefaultReadingValue; 17 buffer[1] = kDefaultReadingValue;
18 } 18 }
19 19
20 test(() => assert_throws(
21 new RangeError(),
22 () => new AmbientLightSensor({frequency: -60})),
23 'Test that negative frequency causes exception from constructor.');
24
25 sensor_test(sensor => {
26 let ambientLightSensor = new AmbientLightSensor({frequency: 560});
27 ambientLightSensor.start();
28
29 let testPromise = sensor.mockSensorProvider.getCreatedSensor()
30 .then(mockSensor => { return mockSensor.addConfigurationCalled(); })
31 .then(mockSensor => {
32 return new Promise((resolve, reject) => {
33 ambientLightSensor.onstatechange = event => {
34 if (ambientLightSensor.state === 'idle') {
timvolodine 2016/09/20 17:46:37 why is this case needed?
Mikhail 2016/09/21 10:00:42 here we wait when the sensor gets actually stopped
35 resolve(mockSensor);
36 }
37
38 if (ambientLightSensor.state === 'active') {
39 let configuration = mockSensor.active_sensor_configurations_[0];
40 assert_equals(configuration.frequency, 60);
41 ambientLightSensor.stop();
42 }
43 };
44 });
45 })
46 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
47
48 return testPromise;
49 }, 'Test that frequency is capped to 60.0 Hz.');
50
20 sensor_test(sensor => { 51 sensor_test(sensor => {
21 let ambientLightSensor = new AmbientLightSensor({frequency: 60}); 52 let ambientLightSensor = new AmbientLightSensor({frequency: 60});
22 ambientLightSensor.start(); 53 ambientLightSensor.start();
23 let testPromise = sensor.mockSensorProvider.getCreatedSensor() 54 let testPromise = sensor.mockSensorProvider.getCreatedSensor()
24 .then((mockSensor) => { 55 .then((mockSensor) => {
25 return new Promise((resolve, reject) => { 56 return new Promise((resolve, reject) => {
26 ambientLightSensor.onstatechange = event => { 57 ambientLightSensor.onstatechange = event => {
27 if (ambientLightSensor.state === 'idle') { 58 if (ambientLightSensor.state === 'idle') {
28 resolve(mockSensor); 59 resolve(mockSensor);
29 } 60 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 ambientLightSensor.onerror = reject; 211 ambientLightSensor.onerror = reject;
181 }); 212 });
182 }) 213 })
183 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); 214 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
184 215
185 return testPromise; 216 return testPromise;
186 }, 'Test that sensor receives suspend / resume notifications when page' 217 }, 'Test that sensor receives suspend / resume notifications when page'
187 +' visibility changes.'); 218 +' visibility changes.');
188 219
189 </script> 220 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698