Update web-platform-tests to revision 26e8a76d7fbea0721468e791a325444ac9939a4f

This commit is contained in:
WPT Sync Bot 2018-03-21 21:10:50 -04:00
parent 1c2bed5a69
commit 6b4026ce2f
89 changed files with 889 additions and 258 deletions

View file

@ -0,0 +1,6 @@
@zqzhang
@dontcallmedom
@riju
@alexshalamov
@pozdnyakov
@Honry

View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>SensorErrorEvent constructor</title>
<link rel="help" href="https://w3c.github.io/sensors/#the-sensor-error-event-interface">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(() => {
assert_equals(SensorErrorEvent.length, 2);
assert_throws(new TypeError, () => new SensorErrorEvent('error'));
}, 'SensorErrorEvent constructor without init dict');
test(() => {
const error = new DOMException;
const event = new SensorErrorEvent('type', { error: error });
assert_equals(event.type, 'type', 'type');
assert_equals(event.error, error, 'error');
}, 'SensorErrorEvent constructor with init dict');
</script>

View file

@ -0,0 +1,159 @@
const feature_policies = {
"AmbientLightSensor" : ["ambient-light-sensor"],
"Accelerometer" : ["accelerometer"],
"LinearAccelerationSensor" : ["accelerometer"],
"GravitySensor" : ["accelerometer"],
"Gyroscope" : ["gyroscope"],
"GeolocationSensor" : ["geolocation"],
"Magnetometer" : ["magnetometer"],
"UncalibratedMagnetometer" : ["magnetometer"],
"AbsoluteOrientationSensor" : ["accelerometer", "gyroscope", "magnetometer"],
"RelativeOrientationSensor" : ["accelerometer", "gyroscope"]
};
const same_origin_src =
"/feature-policy/resources/feature-policy-generic-sensor.html#";
const cross_origin_src =
"https://{{domains[www]}}:{{ports[https][0]}}" + same_origin_src;
const base_src = "/feature-policy/resources/redirect-on-load.html#";
function run_fp_tests_disabled(sensorType) {
const sensorName = sensorType.name;
const featureNameList = feature_policies[sensorName];
const header = "Feature-Policy header " + featureNameList.join(" 'none';") + " 'none'";
const desc = "'new " + sensorName + "()'";
test(() => {
assert_throws("SecurityError", () => {new sensorType()});
}, `${sensorName}: ${header} disallows the top-level document.`);
async_test(t => {
test_feature_availability(
desc,
t,
same_origin_src + sensorName,
expect_feature_unavailable_default
);
}, `${sensorName}: ${header} disallows same-origin iframes.`);
async_test(t => {
test_feature_availability(
desc,
t,
cross_origin_src + sensorName,
expect_feature_unavailable_default
);
}, `${sensorName}: ${header} disallows cross-origin iframes.`);
}
function run_fp_tests_enabled(sensorType) {
const sensorName = sensorType.name;
const featureNameList = feature_policies[sensorName];
const header = "Feature-Policy header " + featureNameList.join(" *;") + " *";
const desc = "'new " + sensorName + "()'";
test(() => {
assert_true(sensorName in window);
}, `${sensorName}: ${header} allows the top-level document.`);
async_test(t => {
test_feature_availability(
desc,
t,
same_origin_src + sensorName,
expect_feature_available_default
);
}, `${sensorName}: ${header} allows same-origin iframes.`);
async_test(t => {
test_feature_availability(
desc,
t,
cross_origin_src + sensorName,
expect_feature_available_default
);
}, `${sensorName}: ${header} allows cross-origin iframes.`);
}
function run_fp_tests_enabled_by_attribute(sensorType) {
const sensorName = sensorType.name;
const featureNameList = feature_policies[sensorName];
const header = "Feature-Policy allow='" + featureNameList.join(" ") + "' attribute";
const desc = "'new " + sensorName + "()'";
async_test(t => {
test_feature_availability(
desc,
t,
same_origin_src + sensorName,
expect_feature_available_default,
featureNameList.join(";")
);
}, `${sensorName}: ${header} allows same-origin iframe`);
async_test(t => {
test_feature_availability(
desc,
t,
cross_origin_src + sensorName,
expect_feature_available_default,
featureNameList.join(";")
);
}, `${sensorName}: ${header} allows cross-origin iframe`);
}
function run_fp_tests_enabled_by_attribute_redirect_on_load(sensorType) {
const sensorName = sensorType.name;
const featureNameList = feature_policies[sensorName];
const header = "Feature-Policy allow='" + featureNameList.join(" ") + "' attribute";
const desc = "'new " + sensorName + "()'";
async_test(t => {
test_feature_availability(
desc,
t,
base_src + same_origin_src + sensorName,
expect_feature_available_default,
featureNameList.join(";")
);
}, `${sensorName}: ${header} allows same-origin relocation`);
async_test(t => {
test_feature_availability(
desc,
t,
base_src + cross_origin_src + sensorName,
expect_feature_unavailable_default,
featureNameList.join(";")
);
}, `${sensorName}: ${header} disallows cross-origin relocation`);
}
function run_fp_tests_enabled_on_self_origin(sensorType) {
const sensorName = sensorType.name;
const featureNameList = feature_policies[sensorName];
const header = "Feature-Policy header " + featureNameList.join(" 'self';") + " 'self'";
const desc = "'new " + sensorName + "()'";
test(() => {
assert_true(sensorName in window);
}, `${sensorName}: ${header} allows the top-level document.`);
async_test(t => {
test_feature_availability(
desc,
t,
same_origin_src + sensorName,
expect_feature_available_default
);
}, `${sensorName}: ${header} allows same-origin iframes.`);
async_test(t => {
test_feature_availability(
desc,
t,
cross_origin_src + sensorName,
expect_feature_unavailable_default
);
}, `${sensorName}: ${header} disallows cross-origin iframes.`);
}

View file

@ -0,0 +1,331 @@
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'],
'GeolocationSensor' : ['timestamp', 'latitude', 'longitude', 'altitude',
'accuracy', 'altitudeAccuracy', 'heading', 'speed'],
'ProximitySensor' : ['timestamp', 'max']
};
const spatialSensors = ['Accelerometer',
'LinearAccelerationSensor',
'GravitySensor',
'Gyroscope',
'Magnetometer',
'UncalibratedMagnetometer',
'AbsoluteOrientationSensor',
'RelativeOrientationSensor'];
function assert_reading_not_null(sensor) {
for (let property in properties[sensor.constructor.name]) {
let propertyName = properties[sensor.constructor.name][property];
assert_not_equals(sensor[propertyName], null);
}
}
function assert_reading_null(sensor) {
for (let property in properties[sensor.constructor.name]) {
let propertyName = properties[sensor.constructor.name][property];
assert_equals(sensor[propertyName], null);
}
}
function reading_to_array(sensor) {
const arr = new Array();
for (let property in properties[sensor.constructor.name]) {
let propertyName = properties[sensor.constructor.name][property];
arr[property] = sensor[propertyName];
}
return arr;
}
function runGenericSensorTests(sensorType) {
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`);
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`);
promise_test(async t => {
const sensor = new sensorType();
const sensorWatcher = new EventWatcher(t, sensor, ["reading", "error"]);
sensor.start();
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`);
promise_test(async t => {
const sensor = new sensorType();
const sensorWatcher = new EventWatcher(t, sensor, ["activate", "error"]);
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.`);
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`);
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`);
promise_test(async t => {
const sensor = new sensorType();
const sensorWatcher = new EventWatcher(t, sensor, ["activate", "error"]);
sensor.start();
await sensorWatcher.wait_for("activate");
const stop_return = sensor.stop();
assert_equals(stop_return, undefined);
}, `${sensorType.name}: sensor.stop() returns undefined`);
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(async t => {
const sensor = new sensorType();
const sensorWatcher = new EventWatcher(t, sensor, ["reading", "error"]);
sensor.start();
await sensorWatcher.wait_for("reading");
assert_true(sensor.hasReading);
const timestamp = sensor.timestamp;
sensor.stop();
assert_false(sensor.hasReading);
sensor.start();
await sensorWatcher.wait_for("reading");
assert_true(sensor.hasReading);
assert_greater_than(timestamp, 0);
assert_greater_than(sensor.timestamp, timestamp);
sensor.stop();
}, `${sensorType.name}: Test that fresh reading is fetched on start()`);
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_object_equals(cachedSensor1, cachedSensor2);
}, `${sensorType.name}: sensor readings can not be fired on the background tab`);
promise_test(async t => {
const fastSensor = new sensorType({frequency: 30});
const slowSensor = new sensorType({frequency: 5});
slowSensor.start();
const fastCounter = await new Promise((resolve, reject) => {
let fastCounter = 0;
let slowCounter = 0;
fastSensor.onreading = () => {
fastCounter++;
}
slowSensor.onreading = () => {
slowCounter++;
if (slowCounter == 1) {
fastSensor.start();
} else if (slowCounter == 3) {
fastSensor.stop();
slowSensor.stop();
resolve(fastCounter);
}
}
fastSensor.onerror = reject;
slowSensor.onerror = reject;
});
assert_greater_than(fastCounter, 2,
"Fast sensor overtakes the slow one");
}, `${sensorType.name}: frequency hint works`);
promise_test(async t => {
// Create a focused editbox inside a cross-origin iframe,
// sensor notification must suspend.
const iframeSrc = 'data:text/html;charset=utf-8,<html><body>'
+ '<input type="text" autofocus></body></html>';
const iframe = document.createElement('iframe');
iframe.src = encodeURI(iframeSrc);
const sensor = new sensorType();
const sensorWatcher = new EventWatcher(t, sensor, ["reading", "error"]);
sensor.start();
await sensorWatcher.wait_for("reading");
assert_reading_not_null(sensor);
const cachedTimestamp = sensor.timestamp;
const cachedSensor1 = reading_to_array(sensor);
const iframeWatcher = new EventWatcher(t, iframe, "load");
document.body.appendChild(iframe);
await iframeWatcher.wait_for("load");
const cachedSensor2 = reading_to_array(sensor);
assert_array_equals(cachedSensor1, cachedSensor2);
iframe.remove();
await sensorWatcher.wait_for("reading");
const cachedSensor3 = reading_to_array(sensor);
assert_greater_than(sensor.timestamp, cachedTimestamp);
sensor.stop();
}, `${sensorType.name}: sensor receives suspend / resume notifications when\
cross-origin subframe is focused`);
test(() => {
assert_throws("NotSupportedError", () => { new sensorType({invalid: 1}) });
assert_throws("NotSupportedError", () => { new sensorType({frequency: 60, invalid: 1}) });
if (spatialSensors.indexOf(sensorType.name) == -1) {
assert_throws("NotSupportedError", () => { new sensorType({referenceFrame: "screen"}) });
}
}, `${sensorType.name}: throw 'NotSupportedError' for an unsupported sensor option`);
test(() => {
const invalidFreqs = [
"invalid",
NaN,
Infinity,
-Infinity,
{},
undefined
];
invalidFreqs.map(freq => {
assert_throws(new TypeError(),
() => { new sensorType({frequency: freq}) },
`when freq is ${freq}`);
});
}, `${sensorType.name}: throw 'TypeError' if frequency is invalid`);
if (spatialSensors.indexOf(sensorType.name) == -1) {
// The sensorType does not represent a spatial sensor.
return;
}
promise_test(async t => {
const sensor = new sensorType({referenceFrame: "screen"});
const sensorWatcher = new EventWatcher(t, sensor, ["reading", "error"]);
sensor.start();
await sensorWatcher.wait_for("reading");
//TODO use mock data to verify sensor readings, blocked by issue:
// https://github.com/w3c/web-platform-tests/issues/9686
assert_reading_not_null(sensor);
sensor.stop();
}, `${sensorType.name}: sensor reading is correct when options.referenceFrame is 'screen'`);
test(() => {
const invalidRefFrames = [
"invalid",
null,
123,
{},
"",
true,
undefined
];
invalidRefFrames.map(refFrame => {
assert_throws(new TypeError(),
() => { new sensorType({referenceFrame: refFrame}) },
`when refFrame is ${refFrame}`);
});
}, `${sensorType.name}: throw 'TypeError' if referenceFrame is not one of enumeration values`);
}
function runGenericSensorInsecureContext(sensorType) {
test(() => {
assert_false(sensorType in window, `${sensorType} must not be exposed`);
}, `${sensorType} is not exposed in an insecure context`);
}
function runGenericSensorOnerror(sensorType) {
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_true(event.error.name == 'NotReadableError' ||
event.error.name == 'NotAllowedError');
}, `${sensorType.name}: 'onerror' event is fired when sensor is not supported`);
}

View file

@ -0,0 +1,33 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Generic Sensor IDL tests</title>
<link rel="author" title="Tobie Langel" href="http://www.codespeaks.com">
<link rel="help" href="https://w3c.github.io/sensors">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/WebIDLParser.js"></script>
<script src="/resources/idlharness.js"></script>
<script>
"use strict";
function doTest([dom, generic_sensor]) {
var idl_array = new IdlArray();
idl_array.add_untested_idls(dom);
idl_array.add_untested_idls('interface DOMException {};');
idl_array.add_idls(generic_sensor);
idl_array.add_objects({
SensorErrorEvent: ['new SensorErrorEvent("error", { error: new DOMException });']
});
idl_array.test();
}
function fetchText(url) {
return fetch(url).then((response) => response.text());
}
promise_test(() => {
return Promise.all(["/interfaces/dom.idl",
"/interfaces/sensors.idl"].map(fetchText))
.then(doTest);
}, "Test IDL implementation of Generic Sensor");
</script>