mirror of
https://github.com/servo/servo.git
synced 2025-08-15 18:35:33 +01:00
Update web-platform-tests to revision be959408023fe02cf79abe70f6018598a7004a88
This commit is contained in:
parent
a76777b115
commit
761c8bc2a9
171 changed files with 2434 additions and 907 deletions
|
@ -17,6 +17,10 @@ const cross_origin_src =
|
|||
"https://{{domains[www]}}:{{ports[https][0]}}" + same_origin_src;
|
||||
const base_src = "/feature-policy/resources/redirect-on-load.html#";
|
||||
|
||||
function get_feature_policies_for_sensor(sensorType) {
|
||||
return feature_policies[sensorType];
|
||||
}
|
||||
|
||||
function run_fp_tests_disabled(sensorName) {
|
||||
const sensorType = self[sensorName];
|
||||
const featureNameList = feature_policies[sensorName];
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
async function send_message_to_iframe(iframe, message, reply) {
|
||||
if (reply === undefined) {
|
||||
reply = 'success';
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let messageHandler = e => {
|
||||
|
||||
if (e.data.command !== message.command) {
|
||||
return;
|
||||
}
|
||||
window.removeEventListener('message', messageHandler);
|
||||
if (e.data.result === reply) {
|
||||
resolve();
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
}
|
||||
window.addEventListener('message', messageHandler);
|
||||
iframe.contentWindow.postMessage(message, '*');
|
||||
});
|
||||
}
|
||||
|
||||
function run_generic_sensor_iframe_tests(sensorName) {
|
||||
const sensorType = self[sensorName];
|
||||
const featurePolicies = get_feature_policies_for_sensor(sensorName);
|
||||
|
||||
sensor_test(async t => {
|
||||
assert_true(sensorName in self);
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.allow = featurePolicies.join(';') + ';';
|
||||
iframe.src = 'https://{{domains[www1]}}:{{ports[https][0]}}/generic-sensor/resources/iframe_sensor_handler.html';
|
||||
|
||||
// Create sensor inside cross-origin nested browsing context.
|
||||
const iframeLoadWatcher = new EventWatcher(t, iframe, 'load');
|
||||
document.body.appendChild(iframe);
|
||||
await iframeLoadWatcher.wait_for('load');
|
||||
await send_message_to_iframe(iframe, {command: 'create_sensor',
|
||||
type: sensorName});
|
||||
|
||||
// Focus on the main frame and test that sensor recieves readings.
|
||||
window.focus();
|
||||
const sensor = new sensorType();
|
||||
const sensorWatcher = new EventWatcher(t, sensor, ['reading']);
|
||||
sensor.start();
|
||||
|
||||
await sensorWatcher.wait_for('reading');
|
||||
const cachedTimeStamp = sensor.timestamp;
|
||||
|
||||
// Focus on the cross-origin frame and verify that sensor reading updates in
|
||||
// the top level browsing context are suspended.
|
||||
iframe.contentWindow.focus();
|
||||
await send_message_to_iframe(iframe, {command: 'start_sensor'});
|
||||
assert_equals(cachedTimeStamp, sensor.timestamp);
|
||||
|
||||
// Focus on the main frame, verify that sensor reading updates are resumed.
|
||||
window.focus();
|
||||
await sensorWatcher.wait_for('reading');
|
||||
assert_greater_than(sensor.timestamp, cachedTimeStamp);
|
||||
sensor.stop();
|
||||
|
||||
// Verify that sensor in cross-origin frame is suspended.
|
||||
await send_message_to_iframe(iframe, {command: 'is_sensor_suspended'}, true);
|
||||
await send_message_to_iframe(iframe, {command: 'reset_sensor_backend'});
|
||||
|
||||
// Remove iframe from main document.
|
||||
iframe.parentNode.removeChild(iframe);
|
||||
}, `${sensorName}: sensor is suspended and resumed when focus traverses from\
|
||||
to cross-origin frame`);
|
||||
|
||||
sensor_test(async t => {
|
||||
assert_true(sensorName in self);
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.allow = featurePolicies.join(';') + ';';
|
||||
iframe.src = 'https://{{host}}:{{ports[https][0]}}/generic-sensor/resources/iframe_sensor_handler.html';
|
||||
|
||||
// Create sensor inside same-origin nested browsing context.
|
||||
const iframeLoadWatcher = new EventWatcher(t, iframe, 'load');
|
||||
document.body.appendChild(iframe);
|
||||
await iframeLoadWatcher.wait_for('load');
|
||||
await send_message_to_iframe(iframe, {command: 'create_sensor',
|
||||
type: sensorName});
|
||||
|
||||
// Focus on main frame and test that sensor recieves readings.
|
||||
window.focus();
|
||||
const sensor = new sensorType();
|
||||
const sensorWatcher = new EventWatcher(t, sensor, ['reading']);
|
||||
sensor.start();
|
||||
await sensorWatcher.wait_for('reading');
|
||||
let cachedTimeStamp = sensor.timestamp;
|
||||
|
||||
// Stop sensor in main frame, so that sensorWatcher would not receive
|
||||
// readings while sensor in iframe is started. Sensors that are active
|
||||
// and belong to the same-origin context are not suspended, therefore,
|
||||
// we might get unexpeted 'reading' event, thus, failing the test.
|
||||
sensor.stop();
|
||||
iframe.contentWindow.focus();
|
||||
await send_message_to_iframe(iframe, {command: 'start_sensor'});
|
||||
|
||||
// Start sensor on main frame, verify that readings are updated.
|
||||
window.focus();
|
||||
sensor.start();
|
||||
await sensorWatcher.wait_for('reading');
|
||||
assert_greater_than(sensor.timestamp, cachedTimeStamp);
|
||||
cachedTimeStamp = sensor.timestamp;
|
||||
|
||||
// Verify that sensor in nested browsing context is not suspended.
|
||||
await send_message_to_iframe(iframe, {command: 'is_sensor_suspended'}, false);
|
||||
|
||||
// Verify that sensor in top level browsing context is receiving readings.
|
||||
iframe.contentWindow.focus();
|
||||
sensor.start();
|
||||
await sensorWatcher.wait_for('reading');
|
||||
assert_greater_than(sensor.timestamp, cachedTimeStamp);
|
||||
sensor.stop();
|
||||
await send_message_to_iframe(iframe, {command: 'reset_sensor_backend'});
|
||||
|
||||
// Remove iframe from main document.
|
||||
iframe.parentNode.removeChild(iframe);
|
||||
}, `${sensorName}: sensor is not suspended when focus traverses from\
|
||||
to same-origin frame`);
|
||||
}
|
|
@ -33,14 +33,19 @@ let loadChromiumResources = Promise.resolve().then(() => {
|
|||
return chain;
|
||||
});
|
||||
|
||||
async function initialize_generic_sensor_tests() {
|
||||
if (typeof GenericSensorTest === 'undefined') {
|
||||
await loadChromiumResources;
|
||||
}
|
||||
assert_true(typeof GenericSensorTest !== 'undefined');
|
||||
let sensorTest = new GenericSensorTest();
|
||||
await sensorTest.initialize();
|
||||
return sensorTest;
|
||||
}
|
||||
|
||||
function sensor_test(func, name, properties) {
|
||||
promise_test(async (t) => {
|
||||
if (typeof GenericSensorTest === 'undefined') {
|
||||
await loadChromiumResources;
|
||||
}
|
||||
assert_true(typeof GenericSensorTest !== 'undefined');
|
||||
let sensorTest = new GenericSensorTest();
|
||||
await sensorTest.initialize();
|
||||
let sensorTest = await initialize_generic_sensor_tests();
|
||||
try {
|
||||
await func(t);
|
||||
} finally {
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>iframe sensor tester</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/generic-sensor/generic-sensor-tests.js"></script>
|
||||
<script>
|
||||
let mockBackend = null;
|
||||
// Minimum frequency supported by the mock backend is 5Hz. Using 200ms
|
||||
// update period + 50ms threshold.
|
||||
const maxUpdatePeriod = 250;
|
||||
let sensor = null;
|
||||
let lastTimestamp = null;
|
||||
|
||||
window.onmessage = (e) => {
|
||||
if (e.data.command === 'create_sensor') {
|
||||
assert_equals(sensor, null);
|
||||
initialize_generic_sensor_tests().then((backend) => {
|
||||
mockBackend = backend;
|
||||
try {
|
||||
sensor = new self[e.data.type]();
|
||||
e.source.postMessage({command: e.data.command,
|
||||
result: 'success'}, '*');
|
||||
} catch (e) {
|
||||
e.source.postMessage({command: e.data.command, result: ''}, '*');
|
||||
}
|
||||
});
|
||||
} else if (e.data.command === 'start_sensor') {
|
||||
assert_not_equals(sensor, null);
|
||||
try {
|
||||
sensor.start();
|
||||
sensor.onreading = () => lastTimestamp = sensor.timestamp;
|
||||
let onReadingListener = () => {
|
||||
e.source.postMessage({command: e.data.command,
|
||||
result: 'success'}, '*');
|
||||
}
|
||||
sensor.addEventListener('reading', onReadingListener, {once: true});
|
||||
} catch (e) {
|
||||
e.source.postMessage({command: e.data.command, result: ''}, '*');
|
||||
}
|
||||
} else if (e.data.command === 'is_sensor_suspended') {
|
||||
let cachedTimestamp = lastTimestamp;
|
||||
let timeoutId = setTimeout(() => {
|
||||
e.source.postMessage({command: e.data.command,
|
||||
result: cachedTimestamp === lastTimestamp}, '*');
|
||||
}, maxUpdatePeriod);
|
||||
|
||||
let suspendListener = () => {
|
||||
clearTimeout(timeoutId);
|
||||
e.source.postMessage({command: e.data.command,
|
||||
result: cachedTimestamp === lastTimestamp}, '*');
|
||||
}
|
||||
sensor.addEventListener('reading', suspendListener, {once: true});
|
||||
} else if (e.data.command === 'reset_sensor_backend') {
|
||||
if (sensor) {
|
||||
sensor.stop();
|
||||
}
|
||||
mockBackend.reset().then(() => {
|
||||
e.source.postMessage({command: e.data.command,
|
||||
result: 'success'}, '*');
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue