mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Update web-platform-tests to revision dc5cbf088edcdb266541d4e5a76149a2c6e716a0
This commit is contained in:
parent
1d40075f03
commit
079092dfea
2381 changed files with 90360 additions and 17722 deletions
|
@ -1,4 +1,4 @@
|
|||
/* globals add_completion_callback, Promise, done, assert_true, Ajv, on_event */
|
||||
/* globals add_completion_callback, Promise, showdown, done, assert_true, Ajv, on_event */
|
||||
|
||||
/**
|
||||
* Creates a JSONtest object. If the parameters are supplied
|
||||
|
@ -24,16 +24,34 @@ function JSONtest(params) {
|
|||
this.Assertions = []; // object that will contain the assertions to process
|
||||
this.AssertionText = ""; // string that holds the titles of all the assertions in use
|
||||
this.DescriptionText = "";
|
||||
this.Base = null; // URI "base" for the tests being run
|
||||
this.Base = null; // URI "base" for the test suite being run
|
||||
this.TestDir = null; // URI "base" for the test case being run
|
||||
this.Params = null; // paramaters passed in
|
||||
this.Promise = null; // master Promise that resolves when intialization is complete
|
||||
this.Properties = null; // testharness_properties from the opening window
|
||||
this.Test = null; // test being run
|
||||
this.AssertionCounter = 0;// keeps track of which assertion is being processed
|
||||
|
||||
this._assertionText = []; // Array of text or nested arrays of assertions
|
||||
this._assertionCache = [];// Array to put loaded assertions into
|
||||
this._assertionText = []; // Array of text or nested arrays of assertions
|
||||
this._loading = true;
|
||||
|
||||
showdown.extension('strip', function() {
|
||||
return [
|
||||
{ type: 'output',
|
||||
regex: /<p>/,
|
||||
replace: ''
|
||||
},
|
||||
{ type: 'output',
|
||||
regex: /<\/p>$/,
|
||||
replace: ''
|
||||
}
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
this.markdown = new showdown.Converter({ extensions: [ 'strip' ] }) ;
|
||||
|
||||
var pending = [] ;
|
||||
|
||||
// set up in case DOM finishes loading early
|
||||
|
@ -52,6 +70,7 @@ function JSONtest(params) {
|
|||
|
||||
var l = document.location;
|
||||
var p = l.pathname;
|
||||
this.TestDir = p.substr(0, 1+p.lastIndexOf('/'));
|
||||
this.Base = p.substr(0, 1+p.indexOf('/', 1));
|
||||
|
||||
// if we are under runner, then there are props in the parent window
|
||||
|
@ -103,6 +122,28 @@ function JSONtest(params) {
|
|||
this.DescriptionText = test.description;
|
||||
}
|
||||
|
||||
if (test.content) {
|
||||
// we have content
|
||||
if (typeof test.content === "string") {
|
||||
// the test content is a string - meaning it is a reference to a file of content
|
||||
var cPromise = new Promise(function(resolve, reject) {
|
||||
this.loadDefinition(test.content)
|
||||
.then(function(content) {
|
||||
if (typeof content === 'string') {
|
||||
content = JSON.parse(content) ;
|
||||
}
|
||||
test.content = content;
|
||||
resolve(true);
|
||||
}.bind(this))
|
||||
.catch(function(err) {
|
||||
reject("Loading " + test.content + ": " + JSON.stringify(err));
|
||||
});
|
||||
|
||||
}.bind(this));
|
||||
pending.push(cPromise);
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (test.assertions &&
|
||||
typeof test.assertions === "object") {
|
||||
|
@ -119,6 +160,12 @@ function JSONtest(params) {
|
|||
.then(function (assertContents) {
|
||||
// assertContents has assertions in document order
|
||||
|
||||
var typeMap = {
|
||||
'must' : "<b>[MANDATORY]</b> ",
|
||||
'may' : "<b>[OPTIONAL]</b> ",
|
||||
'should' : "<b>[RECOMMENDED]</b> "
|
||||
};
|
||||
|
||||
var assertIdx = 0;
|
||||
|
||||
// populate the display of assertions that are being exercised
|
||||
|
@ -132,14 +179,22 @@ function JSONtest(params) {
|
|||
// accumulate the assertions - but only when level is 0
|
||||
var list = [] ;
|
||||
|
||||
var type = "";
|
||||
if (assertions) {
|
||||
if (typeof assertions === "object" && assertions.hasOwnProperty('assertions')) {
|
||||
// this is a conditionObject
|
||||
if (level === 0) {
|
||||
list.push(assertContents[assertIdx]);
|
||||
}
|
||||
type = assertContents[assertIdx].hasOwnProperty('assertionType') ?
|
||||
assertContents[assertIdx].assertionType : "must" ;
|
||||
|
||||
this.AssertionText += "<li>" + assertContents[assertIdx++].title;
|
||||
// ensure type defaults to must
|
||||
if (!typeMap.hasOwnProperty(type)) {
|
||||
type = "must";
|
||||
}
|
||||
|
||||
this.AssertionText += "<li>" + typeMap[type] + this.markdown.makeHtml(assertContents[assertIdx++].title);
|
||||
this.AssertionText += "<ol>";
|
||||
buildList(assertions.assertions, level+1) ;
|
||||
this.AssertionText += "</ol></li>\n";
|
||||
|
@ -151,12 +206,22 @@ function JSONtest(params) {
|
|||
// it is a nested list - recurse
|
||||
buildList(assert, level+1) ;
|
||||
this.AssertionText += "</ol>\n";
|
||||
} else if (typeof assert === "object" && !Array.isArray(assert) && assert.hasOwnProperty('assertions')) {
|
||||
} else if (typeof assert === "object" &&
|
||||
!Array.isArray(assert) &&
|
||||
assert.hasOwnProperty('assertions')) {
|
||||
if (level === 0) {
|
||||
list.push(assertContents[assertIdx]);
|
||||
}
|
||||
type = assertContents[assertIdx].hasOwnProperty('assertionType') ?
|
||||
assertContents[assertIdx].assertionType : "must" ;
|
||||
|
||||
// ensure type defaults to must
|
||||
if (!typeMap.hasOwnProperty(type)) {
|
||||
type = "must";
|
||||
}
|
||||
|
||||
// there is a condition object in the array
|
||||
this.AssertionText += "<li>" + assertContents[assertIdx++].title;
|
||||
this.AssertionText += "<li>" + typeMap[type] + this.markdown.makeHtml(assertContents[assertIdx++].title);
|
||||
this.AssertionText += "<ol>";
|
||||
buildList(assert, level+1) ; // capture the children too
|
||||
this.AssertionText += "</ol></li>\n";
|
||||
|
@ -164,7 +229,15 @@ function JSONtest(params) {
|
|||
if (level === 0) {
|
||||
list.push(assertContents[assertIdx]);
|
||||
}
|
||||
this.AssertionText += "<li>" + assertContents[assertIdx++].title + "</li>\n";
|
||||
type = assertContents[assertIdx].hasOwnProperty('assertionType') ?
|
||||
assertContents[assertIdx].assertionType : "must" ;
|
||||
|
||||
// ensure type defaults to must
|
||||
if (!typeMap.hasOwnProperty(type)) {
|
||||
type = "must";
|
||||
}
|
||||
|
||||
this.AssertionText += "<li>" + typeMap[type] + this.markdown.makeHtml(assertContents[assertIdx++].title) + "</li>\n";
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
@ -189,19 +262,23 @@ function JSONtest(params) {
|
|||
}.bind(this));
|
||||
}.bind(this)));
|
||||
|
||||
// once the DOM and the test / assertions are loaded... set us up
|
||||
Promise.all(pending)
|
||||
.then(function() {
|
||||
this.loading = false;
|
||||
this.init();
|
||||
}.bind(this))
|
||||
.catch(function(err) {
|
||||
// loading the components failed somehow - report the errors and mark the test failed
|
||||
test( function() {
|
||||
assert_true(false, "Loading of test components failed: " +JSON.stringify(err)) ;
|
||||
}, "Loading test components");
|
||||
done() ;
|
||||
return ;
|
||||
this.Promise = new Promise(function(resolve, reject) {
|
||||
// once the DOM and the test / assertions are loaded... set us up
|
||||
Promise.all(pending)
|
||||
.then(function() {
|
||||
this.loading = false;
|
||||
this.init();
|
||||
resolve(this);
|
||||
}.bind(this))
|
||||
.catch(function(err) {
|
||||
// loading the components failed somehow - report the errors and mark the test failed
|
||||
test( function() {
|
||||
assert_true(false, "Loading of test components failed: " +JSON.stringify(err)) ;
|
||||
}, "Loading test components");
|
||||
done() ;
|
||||
reject("Loading of test components failed: "+JSON.stringify(err));
|
||||
return ;
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
|
||||
return this;
|
||||
|
@ -222,8 +299,10 @@ JSONtest.prototype = {
|
|||
var desc = document.getElementById("testDescription") ;
|
||||
|
||||
if (!this.loading) {
|
||||
runButton.disabled = false;
|
||||
runButton.value = "Check JSON";
|
||||
if (runButton) {
|
||||
runButton.disabled = false;
|
||||
runButton.value = "Check JSON";
|
||||
}
|
||||
if (desc) {
|
||||
desc.innerHTML = this.DescriptionText;
|
||||
}
|
||||
|
@ -249,32 +328,34 @@ JSONtest.prototype = {
|
|||
}.bind(this));
|
||||
}
|
||||
|
||||
on_event(runButton, "click", function() {
|
||||
// user clicked
|
||||
var content = testInput.value;
|
||||
runButton.disabled = true;
|
||||
if (runButton) {
|
||||
on_event(runButton, "click", function() {
|
||||
// user clicked
|
||||
var content = testInput.value;
|
||||
runButton.disabled = true;
|
||||
|
||||
// make sure content is an object
|
||||
if (typeof content === "string") {
|
||||
try {
|
||||
content = JSON.parse(content) ;
|
||||
} catch(err) {
|
||||
// if the parsing failed, create a special test and mark it failed
|
||||
test( function() {
|
||||
assert_true(false, "Parse of JSON failed: " + err) ;
|
||||
}, "Parsing submitted input");
|
||||
// and just give up
|
||||
done();
|
||||
return ;
|
||||
// make sure content is an object
|
||||
if (typeof content === "string") {
|
||||
try {
|
||||
content = JSON.parse(content) ;
|
||||
} catch(err) {
|
||||
// if the parsing failed, create a special test and mark it failed
|
||||
test( function() {
|
||||
assert_true(false, "Parse of JSON failed: " + err) ;
|
||||
}, "Parsing submitted input");
|
||||
// and just give up
|
||||
done();
|
||||
return ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// iterate over all of the tests for this instance
|
||||
this.runTests(this.Assertions, content);
|
||||
// iterate over all of the tests for this instance
|
||||
this.runTests(this.Assertions, content);
|
||||
|
||||
// explicitly tell the test framework we are done
|
||||
done();
|
||||
}.bind(this));
|
||||
// explicitly tell the test framework we are done
|
||||
done();
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
// runTests - process tests
|
||||
|
@ -304,6 +385,13 @@ JSONtest.prototype = {
|
|||
compareWith = 'and';
|
||||
}
|
||||
|
||||
var typeMap = {
|
||||
'must' : "",
|
||||
'may' : "INFORMATIONAL: ",
|
||||
'should' : "WARNING: "
|
||||
};
|
||||
|
||||
|
||||
// for each assertion (in order) load the external json schema if
|
||||
// one is referenced, or use the inline schema if supplied
|
||||
// validate content against the referenced schema
|
||||
|
@ -314,8 +402,15 @@ JSONtest.prototype = {
|
|||
|
||||
assertions.forEach( function(assert, num) {
|
||||
|
||||
var expected = assert.hasOwnProperty('expectedResult') ? assert.expectedResult : 'valid' ;
|
||||
var message = assert.hasOwnProperty('message') ? assert.message : "Result was not " + expected;
|
||||
var expected = assert.hasOwnProperty('expectedResult') ?
|
||||
assert.expectedResult : 'valid' ;
|
||||
var message = assert.hasOwnProperty('errorMessage') ?
|
||||
assert.errorMessage : "Result was not " + expected;
|
||||
var type = assert.hasOwnProperty('assertionType') ?
|
||||
assert.assertionType : "must" ;
|
||||
if (!typeMap.hasOwnProperty(type)) {
|
||||
type = "must";
|
||||
}
|
||||
|
||||
// first - what is the type of the assert
|
||||
if (typeof assert === "object" && !Array.isArray(assert)) {
|
||||
|
@ -365,7 +460,7 @@ JSONtest.prototype = {
|
|||
} else {
|
||||
assert_true(result, err) ;
|
||||
}
|
||||
}.bind(this), assert.title);
|
||||
}.bind(this), "" + level + ":" + (num+1) + " " + assert.title);
|
||||
// we are going to return out of this
|
||||
return;
|
||||
}
|
||||
|
@ -384,6 +479,18 @@ JSONtest.prototype = {
|
|||
|
||||
var schemaName = "inline " + level + ":" + (num+1);
|
||||
|
||||
if (typeof assert === "string") {
|
||||
// the assertion passed in is a file name; find it in the cache
|
||||
if (this._assertionCache[assert]) {
|
||||
assert = this._assertionCache[assert];
|
||||
} else {
|
||||
test( function() {
|
||||
assert_true(false, "Reference to assertion " + assert + " at level " + level + ":" + (num+1) + " unresolved") ;
|
||||
}, "Processing " + assert);
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
if (assert.assertionFile) {
|
||||
schemaName = "external file " + assert.assertionFile + " " + level + ":" + (num+1);
|
||||
}
|
||||
|
@ -428,11 +535,11 @@ JSONtest.prototype = {
|
|||
}
|
||||
if (result === false) {
|
||||
// test result was unexpected; use message
|
||||
assert_true(result, message + err);
|
||||
assert_true(result, typeMap[type] + message + err);
|
||||
} else {
|
||||
assert_true(result, err) ;
|
||||
}
|
||||
}.bind(this), assert.title);
|
||||
}.bind(this), "" + level + ":" + (num+1) + " " + assert.title);
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
@ -497,6 +604,7 @@ JSONtest.prototype = {
|
|||
this._loadFile("GET", theFile, true)
|
||||
.then(function(data) {
|
||||
data.assertionFile = afile;
|
||||
this._assertionCache[afile] = data;
|
||||
resolve(data);
|
||||
}.bind(this))
|
||||
.catch(function(err) {
|
||||
|
@ -581,7 +689,7 @@ JSONtest.prototype = {
|
|||
if (theURI.indexOf('/') === -1) {
|
||||
// no slash - it's relative to where we are
|
||||
// so just use it
|
||||
return theURI;
|
||||
return this.TestDir + theURI;
|
||||
} else if (theURI.indexOf('/') === 0 || theURI.indexOf('http:') === 0 || theURI.indexOf('https:') === 0) {
|
||||
// it is an absolute URI so just use it
|
||||
return theURI;
|
||||
|
@ -619,7 +727,8 @@ JSONtest.prototype = {
|
|||
} else if (typeof assert === "object") {
|
||||
ret.push(assert) ;
|
||||
if (assert.hasOwnProperty("assertions")) {
|
||||
ret.push(this._assertionRefs(assert.assertions));
|
||||
// there are embedded assertions; get those too
|
||||
ret.concat(this._assertionRefs(assert.assertions));
|
||||
}
|
||||
} else {
|
||||
// it is a file name
|
||||
|
|
4
tests/wpt/web-platform-tests/annotation-model/scripts/showdown.min.js
vendored
Normal file
4
tests/wpt/web-platform-tests/annotation-model/scripts/showdown.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue