mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Update web-platform-tests to revision be5419e845d39089ba6dc338c1bd0fa279108317
This commit is contained in:
parent
aa199307c8
commit
2b6f573eb5
3440 changed files with 109438 additions and 41750 deletions
|
@ -1,15 +1,16 @@
|
|||
let unreached = event => {
|
||||
assert_unreached(event.error.name + ": " + event.error.message);
|
||||
};
|
||||
|
||||
let properties = {
|
||||
const properties = {
|
||||
'AmbientLightSensor' : ['timestamp', 'illuminance'],
|
||||
'Accelerometer' : ['timestamp', 'x', 'y', 'z'],
|
||||
'LinearAccelerationSensor' : ['timestamp', 'x', 'y', 'z'],
|
||||
"GravitySensor" : ['timestamp', 'x', 'y', 'z'],
|
||||
'Gyroscope' : ['timestamp', 'x', 'y', 'z'],
|
||||
'Magnetometer' : ['timestamp', 'x', 'y', 'z'],
|
||||
"UncalibratedMagnetometer" : ['timestamp', 'x', 'y', 'z',
|
||||
'xBias', 'yBias', 'zBias'],
|
||||
'AbsoluteOrientationSensor' : ['timestamp', 'quaternion'],
|
||||
'RelativeOrientationSensor' : ['timestamp', 'quaternion']
|
||||
'RelativeOrientationSensor' : ['timestamp', 'quaternion'],
|
||||
'GeolocationSensor' : ['timestamp', 'latitude', 'longitude', 'altitude',
|
||||
'accuracy', 'altitudeAccuracy', 'heading', 'speed']
|
||||
};
|
||||
|
||||
function assert_reading_not_null(sensor) {
|
||||
|
@ -27,7 +28,7 @@ function assert_reading_null(sensor) {
|
|||
}
|
||||
|
||||
function reading_to_array(sensor) {
|
||||
let arr = new Array();
|
||||
const arr = new Array();
|
||||
for (let property in properties[sensor.constructor.name]) {
|
||||
let propertyName = properties[sensor.constructor.name][property];
|
||||
arr[property] = sensor[propertyName];
|
||||
|
@ -36,159 +37,129 @@ function reading_to_array(sensor) {
|
|||
}
|
||||
|
||||
function runGenericSensorTests(sensorType) {
|
||||
async_test(t => {
|
||||
let sensor = new sensorType();
|
||||
sensor.onreading = t.step_func_done(() => {
|
||||
assert_reading_not_null(sensor);
|
||||
assert_true(sensor.hasReading);
|
||||
sensor.stop();
|
||||
assert_reading_null(sensor);
|
||||
assert_false(sensor.hasReading);
|
||||
});
|
||||
sensor.onerror = t.step_func_done(unreached);
|
||||
promise_test(async t => {
|
||||
const sensor = new sensorType();
|
||||
const sensorWatcher = new EventWatcher(t, sensor, ["reading", "error"]);
|
||||
sensor.start();
|
||||
|
||||
await sensorWatcher.wait_for("reading");
|
||||
assert_reading_not_null(sensor);
|
||||
assert_true(sensor.hasReading);
|
||||
|
||||
sensor.stop();
|
||||
assert_reading_null(sensor);
|
||||
assert_false(sensor.hasReading);
|
||||
}, `${sensorType.name}: Test that 'onreading' is called and sensor reading is valid`);
|
||||
|
||||
async_test(t => {
|
||||
let sensor1 = new sensorType();
|
||||
let sensor2 = new sensorType();
|
||||
sensor1.onreading = t.step_func_done(() => {
|
||||
// Reading values are correct for both sensors.
|
||||
assert_reading_not_null(sensor1);
|
||||
assert_reading_not_null(sensor2);
|
||||
|
||||
//After first sensor stops its reading values are null,
|
||||
//reading values for the second sensor remains
|
||||
sensor1.stop();
|
||||
assert_reading_null(sensor1);
|
||||
assert_reading_not_null(sensor2);
|
||||
sensor2.stop();
|
||||
assert_reading_null(sensor2);
|
||||
});
|
||||
sensor1.onerror = t.step_func_done(unreached);
|
||||
sensor2.onerror = t.step_func_done(unreached);
|
||||
promise_test(async t => {
|
||||
const sensor1 = new sensorType();
|
||||
const sensor2 = new sensorType();
|
||||
const sensorWatcher = new EventWatcher(t, sensor1, ["reading", "error"]);
|
||||
sensor2.start();
|
||||
sensor1.start();
|
||||
|
||||
await sensorWatcher.wait_for("reading");
|
||||
// Reading values are correct for both sensors.
|
||||
assert_reading_not_null(sensor1);
|
||||
assert_reading_not_null(sensor2);
|
||||
|
||||
//After first sensor stops its reading values are null,
|
||||
//reading values for the second sensor remains
|
||||
sensor1.stop();
|
||||
assert_reading_null(sensor1);
|
||||
assert_reading_not_null(sensor2);
|
||||
sensor2.stop();
|
||||
assert_reading_null(sensor2);
|
||||
}, `${sensorType.name}: sensor reading is correct`);
|
||||
|
||||
async_test(t => {
|
||||
let sensor = new sensorType();
|
||||
let cachedTimeStamp1;
|
||||
sensor.onreading = () => {
|
||||
cachedTimeStamp1 = sensor.timestamp;
|
||||
};
|
||||
sensor.onerror = t.step_func_done(unreached);
|
||||
promise_test(async t => {
|
||||
const sensor = new sensorType();
|
||||
const sensorWatcher = new EventWatcher(t, sensor, ["reading", "error"]);
|
||||
sensor.start();
|
||||
t.step_timeout(() => {
|
||||
sensor.onreading = t.step_func_done(() => {
|
||||
//sensor.timestamp changes.
|
||||
let cachedTimeStamp2 = sensor.timestamp;
|
||||
assert_greater_than(cachedTimeStamp2, cachedTimeStamp1);
|
||||
sensor.stop();
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
await sensorWatcher.wait_for("reading");
|
||||
const cachedTimeStamp1 = sensor.timestamp;
|
||||
|
||||
await sensorWatcher.wait_for("reading");
|
||||
const cachedTimeStamp2 = sensor.timestamp;
|
||||
|
||||
assert_greater_than(cachedTimeStamp2, cachedTimeStamp1);
|
||||
sensor.stop();
|
||||
}, `${sensorType.name}: sensor timestamp is updated when time passes`);
|
||||
|
||||
async_test(t => {
|
||||
let sensor = new sensorType();
|
||||
sensor.onerror = t.step_func_done(unreached);
|
||||
promise_test(async t => {
|
||||
const sensor = new sensorType();
|
||||
const sensorWatcher = new EventWatcher(t, sensor, ["activate", "error"]);
|
||||
assert_false(sensor.activated);
|
||||
sensor.onreading = t.step_func_done(() => {
|
||||
assert_true(sensor.activated);
|
||||
sensor.stop();
|
||||
assert_false(sensor.activated);
|
||||
});
|
||||
sensor.start();
|
||||
assert_false(sensor.activated);
|
||||
|
||||
await sensorWatcher.wait_for("activate");
|
||||
assert_true(sensor.activated);
|
||||
|
||||
sensor.stop();
|
||||
assert_false(sensor.activated);
|
||||
}, `${sensorType.name}: Test that sensor can be successfully created and its states are correct.`);
|
||||
|
||||
test(() => {
|
||||
let sensor, start_return;
|
||||
sensor = new sensorType();
|
||||
sensor.onerror = unreached;
|
||||
start_return = sensor.start();
|
||||
promise_test(async t => {
|
||||
const sensor = new sensorType();
|
||||
const sensorWatcher = new EventWatcher(t, sensor, ["activate", "error"]);
|
||||
const start_return = sensor.start();
|
||||
|
||||
await sensorWatcher.wait_for("activate");
|
||||
assert_equals(start_return, undefined);
|
||||
sensor.stop();
|
||||
}, `${sensorType.name}: sensor.start() returns undefined`);
|
||||
|
||||
test(() => {
|
||||
try {
|
||||
let sensor = new sensorType();
|
||||
sensor.onerror = unreached;
|
||||
sensor.start();
|
||||
sensor.start();
|
||||
assert_false(sensor.activated);
|
||||
sensor.stop();
|
||||
} catch (e) {
|
||||
assert_unreached(e.name + ": " + e.message);
|
||||
}
|
||||
promise_test(async t => {
|
||||
const sensor = new sensorType();
|
||||
const sensorWatcher = new EventWatcher(t, sensor, ["activate", "error"]);
|
||||
sensor.start();
|
||||
sensor.start();
|
||||
|
||||
await sensorWatcher.wait_for("activate");
|
||||
assert_true(sensor.activated);
|
||||
sensor.stop();
|
||||
}, `${sensorType.name}: no exception is thrown when calling start() on already started sensor`);
|
||||
|
||||
test(() => {
|
||||
let sensor, stop_return;
|
||||
sensor = new sensorType();
|
||||
sensor.onerror = unreached;
|
||||
promise_test(async t => {
|
||||
const sensor = new sensorType();
|
||||
const sensorWatcher = new EventWatcher(t, sensor, ["activate", "error"]);
|
||||
sensor.start();
|
||||
stop_return = sensor.stop();
|
||||
|
||||
await sensorWatcher.wait_for("activate");
|
||||
const stop_return = sensor.stop();
|
||||
assert_equals(stop_return, undefined);
|
||||
}, `${sensorType.name}: sensor.stop() returns undefined`);
|
||||
|
||||
test(() => {
|
||||
try {
|
||||
let sensor = new sensorType();
|
||||
sensor.onerror = unreached;
|
||||
sensor.start();
|
||||
sensor.stop();
|
||||
sensor.stop();
|
||||
assert_false(sensor.activated);
|
||||
} catch (e) {
|
||||
assert_unreached(e.name + ": " + e.message);
|
||||
}
|
||||
promise_test(async t => {
|
||||
const sensor = new sensorType();
|
||||
const sensorWatcher = new EventWatcher(t, sensor, ["activate", "error"]);
|
||||
sensor.start();
|
||||
|
||||
await sensorWatcher.wait_for("activate");
|
||||
sensor.stop();
|
||||
sensor.stop();
|
||||
assert_false(sensor.activated);
|
||||
}, `${sensorType.name}: no exception is thrown when calling stop() on already stopped sensor`);
|
||||
|
||||
promise_test(() => {
|
||||
return new Promise((resolve,reject) => {
|
||||
let iframe = document.createElement('iframe');
|
||||
iframe.srcdoc = '<script>' +
|
||||
' window.onmessage = message => {' +
|
||||
' if (message.data === "LOADED") {' +
|
||||
' try {' +
|
||||
' new ' + sensorType.name + '();' +
|
||||
' parent.postMessage("FAIL", "*");' +
|
||||
' } catch (e) {' +
|
||||
' parent.postMessage(e.name, "*");' +
|
||||
' }' +
|
||||
' }' +
|
||||
' };' +
|
||||
'<\/script>';
|
||||
iframe.onload = () => iframe.contentWindow.postMessage('LOADED', '*');
|
||||
document.body.appendChild(iframe);
|
||||
window.onmessage = message => {
|
||||
if (message.data == 'SecurityError') {
|
||||
resolve();
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
}
|
||||
});
|
||||
}, `${sensorType.name}: throw a 'SecurityError' when constructing sensor object within iframe`);
|
||||
|
||||
async_test(t => {
|
||||
let sensor = new sensorType();
|
||||
sensor.onreading = t.step_func(() => {
|
||||
assert_reading_not_null(sensor);
|
||||
let cachedSensor1 = reading_to_array(sensor);
|
||||
let win = window.open('', '_blank');
|
||||
t.step_timeout(() => {
|
||||
let cachedSensor2 = reading_to_array(sensor);
|
||||
win.close();
|
||||
sensor.stop();
|
||||
assert_array_equals(cachedSensor1, cachedSensor2);
|
||||
t.done();
|
||||
}, 1000);
|
||||
});
|
||||
sensor.onerror = t.step_func_done(unreached);
|
||||
promise_test(async t => {
|
||||
const sensor = new sensorType();
|
||||
const sensorWatcher = new EventWatcher(t, sensor, ["reading", "error"]);
|
||||
const visibilityChangeWatcher = new EventWatcher(t, document, "visibilitychange");
|
||||
sensor.start();
|
||||
|
||||
await sensorWatcher.wait_for("reading");
|
||||
assert_reading_not_null(sensor);
|
||||
const cachedSensor1 = reading_to_array(sensor);
|
||||
|
||||
const win = window.open('', '_blank');
|
||||
await visibilityChangeWatcher.wait_for("visibilitychange");
|
||||
const cachedSensor2 = reading_to_array(sensor);
|
||||
|
||||
win.close();
|
||||
sensor.stop();
|
||||
assert_array_equals(cachedSensor1, cachedSensor2);
|
||||
}, `${sensorType.name}: sensor readings can not be fired on the background tab`);
|
||||
}
|
||||
|
||||
|
@ -199,13 +170,13 @@ function runGenericSensorInsecureContext(sensorType) {
|
|||
}
|
||||
|
||||
function runGenericSensorOnerror(sensorType) {
|
||||
async_test(t => {
|
||||
let sensor = new sensorType();
|
||||
sensor.onactivate = t.step_func_done(assert_unreached);
|
||||
sensor.onerror = t.step_func_done(event => {
|
||||
assert_false(sensor.activated);
|
||||
assert_equals(event.error.name, 'NotReadableError');
|
||||
});
|
||||
promise_test(async t => {
|
||||
const sensor = new sensorType();
|
||||
const sensorWatcher = new EventWatcher(t, sensor, ["error", "activate"]);
|
||||
sensor.start();
|
||||
|
||||
const event = await sensorWatcher.wait_for("error");
|
||||
assert_false(sensor.activated);
|
||||
assert_equals(event.error.name, 'NotReadableError');
|
||||
}, `${sensorType.name}: 'onerror' event is fired when sensor is not supported`);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue