mirror of
https://github.com/servo/servo.git
synced 2025-08-13 17:35:36 +01:00
Update web-platform-tests to revision 8a2ceb5f18911302b7a5c1cd2791f4ab50ad4326
This commit is contained in:
parent
462c272380
commit
1f531f66ea
5377 changed files with 174916 additions and 84369 deletions
|
@ -433,15 +433,25 @@ policies and contribution forms [3].
|
|||
// all imported scripts have been fetched and executed. It's the
|
||||
// equivalent of an onload event for a document. All tests should have
|
||||
// been added by the time this event is received, thus it's not
|
||||
// necessary to wait until the onactivate event.
|
||||
on_event(self, "install",
|
||||
function(event) {
|
||||
this_obj.all_loaded = true;
|
||||
if (this_obj.on_loaded_callback) {
|
||||
this_obj.on_loaded_callback();
|
||||
}
|
||||
});
|
||||
// necessary to wait until the onactivate event. However, tests for
|
||||
// installed service workers need another event which is equivalent to
|
||||
// the onload event because oninstall is fired only on installation. The
|
||||
// onmessage event is used for that purpose since tests using
|
||||
// testharness.js should ask the result to its service worker by
|
||||
// PostMessage. If the onmessage event is triggered on the service
|
||||
// worker's context, that means the worker's script has been evaluated.
|
||||
on_event(self, "install", on_all_loaded);
|
||||
on_event(self, "message", on_all_loaded);
|
||||
function on_all_loaded() {
|
||||
if (this_obj.all_loaded)
|
||||
return;
|
||||
this_obj.all_loaded = true;
|
||||
if (this_obj.on_loaded_callback) {
|
||||
this_obj.on_loaded_callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ServiceWorkerTestEnvironment.prototype = Object.create(WorkerTestEnvironment.prototype);
|
||||
|
||||
ServiceWorkerTestEnvironment.prototype.add_on_loaded_callback = function(callback) {
|
||||
|
@ -528,7 +538,7 @@ policies and contribution forms [3].
|
|||
}
|
||||
tests.promise_tests = tests.promise_tests.then(function() {
|
||||
var donePromise = new Promise(function(resolve) {
|
||||
test.add_cleanup(resolve);
|
||||
test._add_cleanup(resolve);
|
||||
});
|
||||
var promise = test.step(func, test, test);
|
||||
test.step(function() {
|
||||
|
@ -569,12 +579,21 @@ policies and contribution forms [3].
|
|||
|
||||
var waitingFor = null;
|
||||
|
||||
// This is null unless we are recording all events, in which case it
|
||||
// will be an Array object.
|
||||
var recordedEvents = null;
|
||||
|
||||
var eventHandler = test.step_func(function(evt) {
|
||||
assert_true(!!waitingFor,
|
||||
'Not expecting event, but got ' + evt.type + ' event');
|
||||
assert_equals(evt.type, waitingFor.types[0],
|
||||
'Expected ' + waitingFor.types[0] + ' event, but got ' +
|
||||
evt.type + ' event instead');
|
||||
|
||||
if (Array.isArray(recordedEvents)) {
|
||||
recordedEvents.push(evt);
|
||||
}
|
||||
|
||||
if (waitingFor.types.length > 1) {
|
||||
// Pop first event from array
|
||||
waitingFor.types.shift();
|
||||
|
@ -585,7 +604,10 @@ policies and contribution forms [3].
|
|||
// need to set waitingFor.
|
||||
var resolveFunc = waitingFor.resolve;
|
||||
waitingFor = null;
|
||||
resolveFunc(evt);
|
||||
// Likewise, we should reset the state of recordedEvents.
|
||||
var result = recordedEvents || evt;
|
||||
recordedEvents = null;
|
||||
resolveFunc(result);
|
||||
});
|
||||
|
||||
for (var i = 0; i < eventTypes.length; i++) {
|
||||
|
@ -595,14 +617,36 @@ policies and contribution forms [3].
|
|||
/**
|
||||
* Returns a Promise that will resolve after the specified event or
|
||||
* series of events has occured.
|
||||
*
|
||||
* @param options An optional options object. If the 'record' property
|
||||
* on this object has the value 'all', when the Promise
|
||||
* returned by this function is resolved, *all* Event
|
||||
* objects that were waited for will be returned as an
|
||||
* array.
|
||||
*
|
||||
* For example,
|
||||
*
|
||||
* ```js
|
||||
* const watcher = new EventWatcher(t, div, [ 'animationstart',
|
||||
* 'animationiteration',
|
||||
* 'animationend' ]);
|
||||
* return watcher.wait_for([ 'animationstart', 'animationend' ],
|
||||
* { record: 'all' }).then(evts => {
|
||||
* assert_equals(evts[0].elapsedTime, 0.0);
|
||||
* assert_equals(evts[1].elapsedTime, 2.0);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
this.wait_for = function(types) {
|
||||
this.wait_for = function(types, options) {
|
||||
if (waitingFor) {
|
||||
return Promise.reject('Already waiting for an event or events');
|
||||
}
|
||||
if (typeof types == 'string') {
|
||||
types = [types];
|
||||
}
|
||||
if (options && options.record && options.record === 'all') {
|
||||
recordedEvents = [];
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
waitingFor = {
|
||||
types: types,
|
||||
|
@ -618,7 +662,7 @@ policies and contribution forms [3].
|
|||
}
|
||||
};
|
||||
|
||||
test.add_cleanup(stop_watching);
|
||||
test._add_cleanup(stop_watching);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -952,6 +996,10 @@ policies and contribution forms [3].
|
|||
|
||||
function assert_array_equals(actual, expected, description)
|
||||
{
|
||||
assert(typeof actual === "object" && actual !== null && "length" in actual,
|
||||
"assert_array_equals", description,
|
||||
"value is ${actual}, expected array",
|
||||
{actual:actual});
|
||||
assert(actual.length === expected.length,
|
||||
"assert_array_equals", description,
|
||||
"lengths differ, expected ${expected} got ${actual}",
|
||||
|
@ -971,6 +1019,34 @@ policies and contribution forms [3].
|
|||
}
|
||||
expose(assert_array_equals, "assert_array_equals");
|
||||
|
||||
function assert_array_approx_equals(actual, expected, epsilon, description)
|
||||
{
|
||||
/*
|
||||
* Test if two primitive arrays are equal withing +/- epsilon
|
||||
*/
|
||||
assert(actual.length === expected.length,
|
||||
"assert_array_approx_equals", description,
|
||||
"lengths differ, expected ${expected} got ${actual}",
|
||||
{expected:expected.length, actual:actual.length});
|
||||
|
||||
for (var i = 0; i < actual.length; i++) {
|
||||
assert(actual.hasOwnProperty(i) === expected.hasOwnProperty(i),
|
||||
"assert_array_approx_equals", description,
|
||||
"property ${i}, property expected to be ${expected} but was ${actual}",
|
||||
{i:i, expected:expected.hasOwnProperty(i) ? "present" : "missing",
|
||||
actual:actual.hasOwnProperty(i) ? "present" : "missing"});
|
||||
assert(typeof actual[i] === "number",
|
||||
"assert_array_approx_equals", description,
|
||||
"property ${i}, expected a number but got a ${type_actual}",
|
||||
{i:i, type_actual:typeof actual[i]});
|
||||
assert(Math.abs(actual[i] - expected[i]) <= epsilon,
|
||||
"assert_array_approx_equals", description,
|
||||
"property ${i}, expected ${expected} +/- ${epsilon}, expected ${expected} but got ${actual}",
|
||||
{i:i, expected:expected[i], actual:actual[i]});
|
||||
}
|
||||
}
|
||||
expose(assert_array_approx_equals, "assert_array_approx_equals");
|
||||
|
||||
function assert_approx_equals(actual, expected, epsilon, description)
|
||||
{
|
||||
/*
|
||||
|
@ -1347,6 +1423,7 @@ policies and contribution forms [3].
|
|||
this.steps = [];
|
||||
|
||||
this.cleanup_callbacks = [];
|
||||
this._user_defined_cleanup_count = 0;
|
||||
|
||||
tests.push(this);
|
||||
}
|
||||
|
@ -1471,10 +1548,27 @@ policies and contribution forms [3].
|
|||
}), timeout * tests.timeout_multiplier);
|
||||
}
|
||||
|
||||
Test.prototype.add_cleanup = function(callback) {
|
||||
/*
|
||||
* Private method for registering cleanup functions. `testharness.js`
|
||||
* internals should use this method instead of the public `add_cleanup`
|
||||
* method in order to hide implementation details from the harness status
|
||||
* message in the case errors.
|
||||
*/
|
||||
Test.prototype._add_cleanup = function(callback) {
|
||||
this.cleanup_callbacks.push(callback);
|
||||
};
|
||||
|
||||
/*
|
||||
* Schedule a function to be run after the test result is known, regardless
|
||||
* of passing or failing state. The behavior of this function will not
|
||||
* influence the result of the test, but if an exception is thrown, the
|
||||
* test harness will report an error.
|
||||
*/
|
||||
Test.prototype.add_cleanup = function(callback) {
|
||||
this._user_defined_cleanup_count += 1;
|
||||
this._add_cleanup(callback);
|
||||
};
|
||||
|
||||
Test.prototype.force_timeout = function() {
|
||||
this.set_status(this.TIMEOUT);
|
||||
this.phase = this.phases.HAS_RESULT;
|
||||
|
@ -1545,7 +1639,7 @@ policies and contribution forms [3].
|
|||
});
|
||||
|
||||
if (error_count > 0) {
|
||||
total = this.cleanup_callbacks.length;
|
||||
total = this._user_defined_cleanup_count;
|
||||
tests.status.status = tests.status.ERROR;
|
||||
tests.status.message = "Test named '" + this.name +
|
||||
"' specified " + total + " 'cleanup' function" +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue