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

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

Issue 2472403002: [Sensors] Align sensor reading attribute implementation with the specification (Closed)
Patch Set: Comments from Tim Created 4 years, 1 month 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)
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); 178 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
179 }) 179 })
180 .then((mockSensor) => { 180 .then((mockSensor) => {
181 return new Promise((resolve, reject) => { 181 return new Promise((resolve, reject) => {
182 ambientLightSensor.onstatechange = event => { 182 ambientLightSensor.onstatechange = event => {
183 if (ambientLightSensor.state === 'idle') { 183 if (ambientLightSensor.state === 'idle') {
184 resolve(mockSensor); 184 resolve(mockSensor);
185 } 185 }
186 }; 186 };
187 187
188 ambientLightSensor.onchange = e => { 188 ambientLightSensor.onchange = () => {
189 assert_equals(e.reading.illuminance, kDefaultReadingValue); 189 assert_equals(ambientLightSensor.reading.illuminance, kDefaultReadin gValue);
190 ambientLightSensor.stop(); 190 ambientLightSensor.stop();
191 }; 191 };
192 192
193 ambientLightSensor.onerror = reject; 193 ambientLightSensor.onerror = reject;
194 }); 194 });
195 }) 195 })
196 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); 196 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
197 197
198 return testPromise; 198 return testPromise;
199 }, 'Test that onChange is called and sensor reading is valid.'); 199 }, 'Test that onChange is called and sensor reading is valid.');
200 200
201 sensor_test(sensor => { 201 sensor_test(sensor => {
202 let ambientLightSensor = new AmbientLightSensor({frequency: 60}); 202 let ambientLightSensor = new AmbientLightSensor({frequency: 60});
203 ambientLightSensor.start(); 203 ambientLightSensor.start();
204 let testPromise = sensor.mockSensorProvider.getCreatedSensor() 204 let testPromise = sensor.mockSensorProvider.getCreatedSensor()
205 .then(mockSensor => { 205 .then(mockSensor => {
206 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); 206 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
207 }) 207 })
208 .then((mockSensor) => { 208 .then((mockSensor) => {
209 return new Promise((resolve, reject) => { 209 return new Promise((resolve, reject) => {
210 ambientLightSensor.onstatechange = () => { 210 ambientLightSensor.onstatechange = () => {
211 if (ambientLightSensor.state === 'idle') { 211 if (ambientLightSensor.state === 'idle') {
212 assert_equals(ambientLightSensor.reading, null); 212 assert_equals(ambientLightSensor.reading, null);
213 resolve(mockSensor); 213 resolve(mockSensor);
214 } 214 }
215 } 215 }
216 216
217 ambientLightSensor.onchange = e => { 217 ambientLightSensor.onchange = () => {
218 assert_equals(e.reading.illuminance, kDefaultReadingValue); 218 assert_equals(ambientLightSensor.reading.illuminance, kDefaultReadin gValue);
219 ambientLightSensor.stop(); 219 ambientLightSensor.stop();
220 } 220 }
221 ambientLightSensor.onerror = reject; 221 ambientLightSensor.onerror = reject;
222 }); 222 });
223 }) 223 })
224 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); 224 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
225 225
226 return testPromise; 226 return testPromise;
227 }, 'Test that sensor reading is not updated when sensor is stopped.'); 227 }, 'Test that sensor reading is not updated when sensor is stopped.');
228 228
229 sensor_test(sensor => { 229 sensor_test(sensor => {
230 let ambientLightSensor = new AmbientLightSensor(); 230 let ambientLightSensor = new AmbientLightSensor();
231 ambientLightSensor.start(); 231 ambientLightSensor.start();
232 let testPromise = sensor.mockSensorProvider.getCreatedSensor() 232 let testPromise = sensor.mockSensorProvider.getCreatedSensor()
233 .then(mockSensor => { 233 .then(mockSensor => {
234 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); 234 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
235 }) 235 })
236 .then((mockSensor) => { 236 .then((mockSensor) => {
237 return new Promise((resolve, reject) => { 237 return new Promise((resolve, reject) => {
238 ambientLightSensor.onchange = e => { 238 ambientLightSensor.onchange = () => {
239 if (e.reading.illuminance == kDefaultReadingValue) { 239 if (ambientLightSensor.reading.illuminance == kDefaultReadingValue) {
240 resolve(mockSensor); 240 resolve(mockSensor);
241 } 241 }
242 } 242 }
243 ambientLightSensor.onerror = reject; 243 ambientLightSensor.onerror = reject;
244 }); 244 });
245 }) 245 })
246 .then((mockSensor) => { 246 .then((mockSensor) => {
247 testRunner.setPageVisibility("hidden"); 247 testRunner.setPageVisibility("hidden");
248 return mockSensor.suspendCalled(); 248 return mockSensor.suspendCalled();
249 }) 249 })
(...skipping 11 matching lines...) Expand all
261 ambientLightSensor.stop(); 261 ambientLightSensor.stop();
262 ambientLightSensor.onerror = reject; 262 ambientLightSensor.onerror = reject;
263 }); 263 });
264 }) 264 })
265 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); 265 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
266 266
267 return testPromise; 267 return testPromise;
268 }, 'Test that sensor receives suspend / resume notifications when page' 268 }, 'Test that sensor receives suspend / resume notifications when page'
269 +' visibility changes.'); 269 +' visibility changes.');
270 270
271
272 sensor_test(sensor => {
273 let sensor1 = new AmbientLightSensor({frequency: 60});
274 sensor1.start();
275
276 let sensor2 = new AmbientLightSensor({frequency: 20});
277 sensor2.start();
278 let testPromise = sensor.mockSensorProvider.getCreatedSensor()
279 .then(mockSensor => {
280 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
281 })
282 .then((mockSensor) => {
283 return new Promise((resolve, reject) => {
284 sensor1.onstatechange = event => {
285 if (sensor1.state === 'idle') {
286 resolve(mockSensor);
287 }
288 };
289
290 sensor1.onchange = () => {
291 // Reading value is correct.
292 assert_equals(sensor1.reading.illuminance, kDefaultReadingValue);
293
294 // Both sensors share the same reading instance.
295 let reading = sensor1.reading;
296 assert_equals(reading, sensor2.reading);
297
298 // After first sensor stops its reading is null, reading for second
299 // sensor sensor remains.
300 sensor1.stop();
301 assert_equals(sensor1.reading, null);
302 assert_equals(sensor2.reading.illuminance, kDefaultReadingValue);
303
304 sensor2.stop();
305 assert_equals(sensor2.reading, null);
306
307 // Cached reading remains.
308 assert_equals(reading.illuminance, kDefaultReadingValue);
309 };
310
311 sensor1.onerror = reject;
312 sensor2.onerror = reject;
313 });
314 })
315 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
316
317 return testPromise;
318 }, 'Test that sensor reading is correct.');
319
271 </script> 320 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698