mirror of
https://github.com/servo/servo.git
synced 2025-06-23 08:34:42 +01:00
64 lines
2.1 KiB
HTML
64 lines
2.1 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset="utf-8">
|
|
<title>AmbientLightSensor Test: reading</title>
|
|
<link rel="author" title="Intel" href="http://www.intel.com">
|
|
<link rel="help" href="https://www.w3.org/TR/ambient-light/">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<div id="log"></div>
|
|
<script>
|
|
|
|
let sensor, sensor1, sensor2, cachedReading1, cachedReading2;
|
|
|
|
setup(() => {
|
|
sensor = new AmbientLightSensor();
|
|
sensor1 = new AmbientLightSensor();
|
|
sensor2 = new AmbientLightSensor();
|
|
sensor1.start();
|
|
sensor2.start();
|
|
});
|
|
|
|
async_test(t => {
|
|
let sensor = new AmbientLightSensor();
|
|
sensor.start();
|
|
sensor.onactivate = t.step_func_done(() => {
|
|
let cachedReading = sensor.reading;
|
|
let cachedIlluminance = cachedReading.illuminance;
|
|
sensor.stop();
|
|
assert_equals(cachedReading.illuminance, cachedIlluminance);
|
|
});
|
|
sensor.onerror = t.step_func_done(event => {
|
|
assert_unreached(event.error.name + ":" + event.error.message);
|
|
});
|
|
}, "Test that sensor reading must be immutable.");
|
|
|
|
async_test(t => {
|
|
sensor1.onactivate = t.step_func_done(() => {
|
|
cachedReading1 = sensor1.reading;
|
|
cachedReading2 = sensor2.reading;
|
|
//both sensors share the same reading instance
|
|
assert_equals(cachedReading1, cachedReading2);
|
|
//after first sensor stops its reading is null, second sensor remains
|
|
sensor1.stop();
|
|
assert_equals(sensor1.reading, null);
|
|
assert_equals(String(sensor2.reading), "[object AmbientLightSensorReading]");
|
|
});
|
|
sensor1.onerror = t.step_func_done(event => {
|
|
assert_unreached(event.error.name + ":" + event.error.message);
|
|
});
|
|
}, "Test that sensor reading is correct.");
|
|
|
|
async_test(t => {
|
|
t.step_timeout(() => {
|
|
sensor2.onchange = t.step_func_done(() => {
|
|
let cachedReading3 = sensor2.reading;
|
|
assert_not_equals(cachedReading2, cachedReading3);
|
|
sensor2.stop();
|
|
});
|
|
sensor2.onerror = t.step_func_done(event => {
|
|
assert_unreached(event.error.name + ":" + event.error.message);
|
|
});
|
|
}, 1000);
|
|
}, "Test that the sensor reading is updated when time passes.");
|
|
|
|
</script>
|