mirror of
https://github.com/servo/servo.git
synced 2025-09-03 19:48:21 +01:00
Update web-platform-tests to revision 3137d1d2d7757366a69f8a449b458b5057e0e81e
This commit is contained in:
parent
81ca858678
commit
d6ba94ca28
2339 changed files with 89274 additions and 9328 deletions
|
@ -6,26 +6,28 @@
|
|||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<iframe src="support-iframe.html" id="frame" style="display:none">
|
||||
<iframe src="support-iframe.html" id="frame" style="display:none" sandbox="allow-scripts">
|
||||
</iframe>
|
||||
<script>
|
||||
|
||||
async_test(function (t) {
|
||||
document.getElementById('frame').onload = t.step_func_done(function(event) {
|
||||
var iframe = document.getElementById('frame').contentWindow;
|
||||
let reading = iframe.document.getElementById('reading').value;
|
||||
assert_equals(reading, "null");
|
||||
async_test(t => {
|
||||
window.onmessage = t.step_func(e => {
|
||||
assert_equals(e.data, "SecurityError");
|
||||
t.done();
|
||||
});
|
||||
}, "sensor readings can not be fired within iframes");
|
||||
}, "throw a 'SecurityError' when firing sensor readings within iframes");
|
||||
|
||||
test(function() {
|
||||
async_test(t => {
|
||||
let sensor = new AmbientLightSensor();
|
||||
sensor.start();
|
||||
var win = window.open('', '_blank');
|
||||
let reading = String(sensor.reading);
|
||||
win.close();
|
||||
sensor.stop();
|
||||
assert_equals(reading, "null");
|
||||
sensor.onactivate = t.step_func_done(() => {
|
||||
assert_not_equals(sensor.reading, null);
|
||||
let cachedReading = sensor.reading;
|
||||
let win = window.open('', '_blank');
|
||||
assert_equals(sensor.reading, cachedReading);
|
||||
win.close();
|
||||
sensor.stop();
|
||||
});
|
||||
}, "sensor readings can not be fired on the background tab");
|
||||
|
||||
</script>
|
|
@ -0,0 +1,23 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>AmbientLightSensor Test: insecure context</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>
|
||||
<h2>Precondition</h2>
|
||||
<ol>
|
||||
<li>
|
||||
Run test in an insecure context, e.g. http://example.com/.
|
||||
</li>
|
||||
</ol>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
|
||||
test(() => {
|
||||
assert_throws('SecurityError', () => {
|
||||
let sensor = new AmbientLightSensor();
|
||||
});
|
||||
}, "throw a 'SecurityError' when construct AmbientLightSensor in an insecure context");
|
||||
|
||||
</script>
|
|
@ -5,30 +5,20 @@
|
|||
<link rel="help" href="https://www.w3.org/TR/ambient-light/">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
|
||||
<h2>Description</h2>
|
||||
<p>
|
||||
This test validates that the "onchange" event can be invoked when changing the ambient light illuminance of the device.
|
||||
</p>
|
||||
|
||||
<h2>Precondition</h2>
|
||||
<ol>
|
||||
<li>
|
||||
Change the ambient light illuminance of the device.
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
|
||||
async_test(function(t) {
|
||||
async_test(t => {
|
||||
let sensor = new AmbientLightSensor();
|
||||
sensor.start();
|
||||
|
||||
sensor.onchange = t.step_func_done(function(event) {
|
||||
sensor.onchange = t.step_func_done(() => {
|
||||
assert_greater_than_equal(sensor.reading.illuminance, 0);
|
||||
assert_equals(sensor.state, "activated");
|
||||
sensor.stop();
|
||||
});
|
||||
|
||||
sensor.onerror = t.step_func_done(function(event) {
|
||||
sensor.onerror = t.step_func_done(event => {
|
||||
assert_unreached(event.error.name + ":" + event.error.message);
|
||||
});
|
||||
}, "event change fired");
|
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>AmbientLightSensor Test: onerror</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>
|
||||
<h2>Precondition</h2>
|
||||
<ol>
|
||||
<li>
|
||||
Disable the Ambient Light Sensor or run test on a device without Amibent Light Sensor.
|
||||
</li>
|
||||
</ol>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
let sensor;
|
||||
setup(() => {
|
||||
sensor = new AmbientLightSensor();
|
||||
});
|
||||
|
||||
async_test(t => {
|
||||
sensor.onactivate = t.step_func_done(assert_unreached);
|
||||
|
||||
sensor.onerror = t.step_func_done(event => {
|
||||
assert_equals(sensor.state, 'errored');
|
||||
assert_equals(event.error.name, 'NotFoundError');
|
||||
});
|
||||
|
||||
sensor.start();
|
||||
}, "Test that 'onerror' event is fired when sensor is not supported");
|
||||
|
||||
</script>
|
|
@ -1,39 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>AmbientLightSensor Test: onstatechange</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>
|
||||
var sensor;
|
||||
setup(function() {
|
||||
sensor = new AmbientLightSensor();
|
||||
});
|
||||
|
||||
test(function() {
|
||||
assert_equals(sensor.state, "idle");
|
||||
}, "The default sensor.state is 'idle'.");
|
||||
|
||||
async_test(function(t) {
|
||||
sensor.onstatechange = t.step_func_done(function(event) {
|
||||
assert_equals(sensor.state, "activating");
|
||||
});
|
||||
sensor.onerror = t.step_func_done(function(event) {
|
||||
assert_unreached(event.error.name + ":" + event.error.message);
|
||||
});
|
||||
sensor.start();
|
||||
}, "The sensor.state changes to 'activating' after sensor.start().");
|
||||
|
||||
async_test(function(t) {
|
||||
sensor.onstatechange = t.step_func_done(function(event) {
|
||||
assert_equals(sensor.state, "idle");
|
||||
});
|
||||
sensor.onerror = t.step_func_done(function(event) {
|
||||
assert_unreached(event.error.name + ":" + event.error.message);
|
||||
});
|
||||
sensor.stop();
|
||||
}, "The sensor.state changes to 'idle' after sensor.stop().");
|
||||
|
||||
</script>
|
|
@ -0,0 +1,64 @@
|
|||
<!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>
|
|
@ -7,25 +7,37 @@
|
|||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var sensor, start_return;
|
||||
|
||||
setup(function() {
|
||||
let sensor, start_return;
|
||||
|
||||
setup(() => {
|
||||
sensor = new AmbientLightSensor();
|
||||
start_return = sensor.start();
|
||||
});
|
||||
|
||||
test(function() {
|
||||
assert_equals(String(sensor.reading), "[object AmbientLightSensorReading]");
|
||||
}, "the sensor.reading is AmbientLightSensorReading after executing start() method");
|
||||
test(() => {
|
||||
assert_equals(sensor.reading, null);
|
||||
}, "The default sensor.reading is 'null'");
|
||||
|
||||
test(function() {
|
||||
assert_throws("InvalidStateError", function() { sensor.start(); }, "start() twice");
|
||||
}, "throw an InvalidStateError exception when state is neither idle nor errored");
|
||||
test(() => {
|
||||
assert_equals(sensor.state, "idle");
|
||||
}, "The default sensor.state is 'idle'");
|
||||
|
||||
test(() => {
|
||||
start_return = sensor.start();
|
||||
assert_equals(sensor.state, "activating");
|
||||
}, "The sensor.state changes to 'activating' after sensor.start()");
|
||||
|
||||
//TODO: The permission is not ready.
|
||||
|
||||
test(function() {
|
||||
test(() => {
|
||||
assert_equals(start_return, undefined);
|
||||
}, "the sensor.start() return undefined");
|
||||
|
||||
test(() => {
|
||||
assert_throws("InvalidStateError", () => { sensor.start(); }, "start() twice");
|
||||
sensor.stop();
|
||||
}, "throw an InvalidStateError exception when state is neither idle nor errored");
|
||||
|
||||
|
||||
|
||||
</script>
|
|
@ -8,22 +8,27 @@
|
|||
<div id="log"></div>
|
||||
<script>
|
||||
|
||||
var sensor, stop_return;
|
||||
setup(function() {
|
||||
let sensor, stop_return;
|
||||
|
||||
setup(() => {
|
||||
sensor = new AmbientLightSensor();
|
||||
sensor.start();
|
||||
stop_return = sensor.stop();
|
||||
});
|
||||
|
||||
test(function() {
|
||||
assert_equals(String(sensor.reading), "null");
|
||||
test(() => {
|
||||
assert_equals(sensor.state, "idle");
|
||||
}, "The sensor.state changes to 'idle' after sensor.stop()");
|
||||
|
||||
test(() => {
|
||||
assert_equals(sensor.reading, null);
|
||||
}, "the sensor.reading is null after executing stop() method");
|
||||
|
||||
test(function() {
|
||||
assert_throws("InvalidStateError", function() { sensor.stop(); }, "stop() twice");
|
||||
test(() => {
|
||||
assert_throws("InvalidStateError", () => { sensor.stop(); }, "stop() twice");
|
||||
}, "throw an InvalidStateError exception when state is either idle or errored");
|
||||
|
||||
test(function() {
|
||||
test(() => {
|
||||
assert_equals(stop_return, undefined);
|
||||
}, "the sensor.stop() returns undefined");
|
||||
|
|
@ -18,6 +18,12 @@
|
|||
interface Event {
|
||||
};
|
||||
|
||||
interface EventTarget {
|
||||
};
|
||||
|
||||
interface EventHandler {
|
||||
};
|
||||
|
||||
interface Error {
|
||||
};
|
||||
|
||||
|
@ -26,13 +32,14 @@ dictionary EventInit {
|
|||
</pre>
|
||||
|
||||
<pre id="generic-idl">
|
||||
[SecureContext]
|
||||
interface Sensor : EventTarget {
|
||||
readonly attribute SensorState state;
|
||||
readonly attribute SensorReading? reading;
|
||||
void start();
|
||||
void stop();
|
||||
attribute EventHandler onchange;
|
||||
attribute EventHandler onstatechange;
|
||||
attribute EventHandler onactivate;
|
||||
attribute EventHandler onerror;
|
||||
};
|
||||
|
||||
|
@ -43,37 +50,29 @@ dictionary SensorOptions {
|
|||
enum SensorState {
|
||||
"idle",
|
||||
"activating",
|
||||
"active",
|
||||
"activated",
|
||||
"errored"
|
||||
};
|
||||
|
||||
[SecureContext]
|
||||
interface SensorReading {
|
||||
readonly attribute DOMHighResTimeStamp timeStamp;
|
||||
};
|
||||
|
||||
[Constructor(DOMString type, SensorReadingEventInit eventInitDict)]
|
||||
interface SensorReadingEvent : Event {
|
||||
readonly attribute SensorReading reading;
|
||||
};
|
||||
|
||||
dictionary SensorReadingEventInit : EventInit {
|
||||
SensorReading reading;
|
||||
};
|
||||
|
||||
[Constructor(DOMString type, SensorErrorEventInit errorEventInitDict)]
|
||||
[SecureContext, Constructor(DOMString type, SensorErrorEventInit errorEventInitDict)]
|
||||
interface SensorErrorEvent : Event {
|
||||
readonly attribute Error error;
|
||||
};
|
||||
|
||||
dictionary SensorErrorEventInit : EventInit {
|
||||
Error error;
|
||||
required Error error;
|
||||
};
|
||||
|
||||
</pre>
|
||||
|
||||
<pre id="ambient-light-idl">
|
||||
[Constructor(optional SensorOptions sensorOptions)]
|
||||
interface AmbientLightSensor : Sensor {
|
||||
readonly attribute AmbientLightSensorReading? reading;
|
||||
};
|
||||
|
||||
[Constructor(AmbientLightSensorReadingInit ambientLightSensorReadingInit)]
|
||||
|
@ -82,13 +81,12 @@ interface AmbientLightSensorReading : SensorReading {
|
|||
};
|
||||
|
||||
dictionary AmbientLightSensorReadingInit {
|
||||
unrestricted double illuminance;
|
||||
required unrestricted double illuminance;
|
||||
};
|
||||
|
||||
</pre>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
(() => {
|
||||
"use strict";
|
||||
var idl_array = new IdlArray();
|
||||
idl_array.add_untested_idls(document.getElementById('idl').textContent);
|
||||
|
@ -97,8 +95,7 @@ dictionary AmbientLightSensorReadingInit {
|
|||
|
||||
idl_array.add_objects({
|
||||
AmbientLightSensor: ['new AmbientLightSensor();'],
|
||||
AmbientLightSensorReading: ['new AmbientLightSensorReading({ illuminance: 750 });'],
|
||||
SensorReadingEvent: ['new SensorReadingEvent("reading", { reading: new AmbientLightSensorReading({ illuminance: 750 }) });']
|
||||
AmbientLightSensorReading: ['new AmbientLightSensorReading({ illuminance: 750 });']
|
||||
});
|
||||
|
||||
idl_array.test();
|
|
@ -1,11 +1,10 @@
|
|||
<!DOCTYPE HTML>
|
||||
<meta charset="utf-8">
|
||||
<input type="text" id="reading" />
|
||||
<script>
|
||||
|
||||
let sensor = new AmbientLightSensor();
|
||||
sensor.start();
|
||||
document.getElementById("reading").value = String(sensor.reading);
|
||||
sensor.stop();
|
||||
|
||||
try {
|
||||
let sensor = new AmbientLightSensor();
|
||||
parent.postMessage( "sensor.start() can be fired within iframes" , '*');
|
||||
} catch (e) {
|
||||
parent.postMessage( e.name , '*');
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue