Skip to content
This repository was archived by the owner on Apr 18, 2023. It is now read-only.

Commit 9b2181f

Browse files
committed
[test] Add LICENSE for test resources files.
Move webml.idl Spec into docs floder. Updated idlharness.js and testharness.js align with w3c upstream.
1 parent 67967bb commit 9b2181f

File tree

6 files changed

+139
-20
lines changed

6 files changed

+139
-20
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ $ npm run watch
3636

3737
# License
3838
This project is following [Apache License Version 2.0](./LICENSE_APACHE2).
39+
40+
And all documents in [test/wpt/resources](./test/wpt/resources) are licensed by the [W3C 3-clause BSD License](./test/wpt/resources/LICENSE).

test/wpt/interfaces/webml.idl docs/webml.idl

+2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ interface NeuralNetworkContext {
6767
dictionary OperandOptions {
6868
required long type;
6969
sequence<unsigned long> dimensions;
70+
// scale: an non-negative floating point value
7071
float scale;
72+
// zeroPoint: an integer, in range [0, 255]
7173
long zeroPoint;
7274
};
7375

test/wpt/resources/LICENSE

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
W3C 3-clause BSD License
2+
3+
http://www.w3.org/Consortium/Legal/2008/03-bsd-license.html
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
* Redistributions of works must retain the original copyright notice,
10+
this list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the original copyright
13+
notice, this list of conditions and the following disclaimer in the
14+
documentation and/or other materials provided with the distribution.
15+
16+
* Neither the name of the W3C nor the names of its contributors may be
17+
used to endorse or promote products derived from this work without
18+
specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

test/wpt/resources/idlharness.js

+89-19
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,28 @@ var fround =
123123
})();
124124
//@}
125125

126+
/// IdlHarnessError ///
127+
// Entry point
128+
self.IdlHarnessError = function(message)
129+
//@{
130+
{
131+
/**
132+
* Message to be printed as the error's toString invocation.
133+
*/
134+
this.message = message;
135+
};
136+
137+
IdlHarnessError.prototype = Object.create(Error.prototype);
138+
139+
//@}
140+
IdlHarnessError.prototype.toString = function()
141+
//@{
142+
{
143+
return this.message;
144+
};
145+
146+
//@}
147+
126148
/// IdlArray ///
127149
// Entry point
128150
self.IdlArray = function()
@@ -217,7 +239,7 @@ IdlArray.prototype.internal_add_idls = function(parsed_idls, options)
217239

218240
if (options && options.only && options.except)
219241
{
220-
throw "The only and except options can't be used together."
242+
throw new IdlHarnessError("The only and except options can't be used together.");
221243
}
222244

223245
function should_skip(name)
@@ -235,7 +257,7 @@ IdlArray.prototype.internal_add_idls = function(parsed_idls, options)
235257

236258
parsed_idls.forEach(function(parsed_idl)
237259
{
238-
if (parsed_idl.type == "interface" && parsed_idl.partial)
260+
if (parsed_idl.partial && ["interface", "dictionary"].includes(parsed_idl.type))
239261
{
240262
if (should_skip(parsed_idl.name))
241263
{
@@ -280,7 +302,7 @@ IdlArray.prototype.internal_add_idls = function(parsed_idls, options)
280302
}
281303
if (parsed_idl.name in this.members)
282304
{
283-
throw "Duplicate identifier " + parsed_idl.name;
305+
throw new IdlHarnessError("Duplicate identifier " + parsed_idl.name);
284306
}
285307
switch(parsed_idl.type)
286308
{
@@ -374,7 +396,7 @@ IdlArray.prototype.recursively_get_implements = function(interface_name)
374396
ret = ret.concat(this.recursively_get_implements(ret[i]));
375397
if (ret.indexOf(ret[i]) != ret.lastIndexOf(ret[i]))
376398
{
377-
throw "Circular implements statements involving " + ret[i];
399+
throw new IdlHarnessError("Circular implements statements involving " + ret[i]);
378400
}
379401
}
380402
return ret;
@@ -404,7 +426,7 @@ IdlArray.prototype.recursively_get_includes = function(interface_name)
404426
ret = ret.concat(this.recursively_get_includes(ret[i]));
405427
if (ret.indexOf(ret[i]) != ret.lastIndexOf(ret[i]))
406428
{
407-
throw "Circular includes statements involving " + ret[i];
429+
throw new IdlHarnessError("Circular includes statements involving " + ret[i]);
408430
}
409431
}
410432
return ret;
@@ -532,8 +554,9 @@ IdlArray.prototype.is_json_type = function(type)
532554

533555
function exposure_set(object, default_set) {
534556
var exposed = object.extAttrs.filter(function(a) { return a.name == "Exposed" });
535-
if (exposed.length > 1 || exposed.length < 0) {
536-
throw "Unexpected Exposed extended attributes on " + memberName + ": " + exposed;
557+
if (exposed.length > 1) {
558+
throw new IdlHarnessError(
559+
`Multiple 'Exposed' extended attributes on ${object.name}`);
537560
}
538561

539562
if (exposed.length === 0) {
@@ -567,7 +590,34 @@ function exposed_in(globals) {
567590
return globals.indexOf("Worker") >= 0 ||
568591
globals.indexOf("ServiceWorker") >= 0;
569592
}
570-
throw "Unexpected global object";
593+
throw new IdlHarnessError("Unexpected global object");
594+
}
595+
596+
//@}
597+
/**
598+
* Asserts that the given error message is thrown for the given function.
599+
* @param {string|IdlHarnessError} error Expected Error message.
600+
* @param {Function} idlArrayFunc Function operating on an IdlArray that should throw.
601+
*/
602+
IdlArray.prototype.assert_throws = function(error, idlArrayFunc)
603+
//@{
604+
{
605+
try {
606+
idlArrayFunc.call(this, this);
607+
} catch (e) {
608+
if (e instanceof AssertionError) {
609+
throw e;
610+
}
611+
// Assertions for behaviour of the idlharness.js engine.
612+
if (error instanceof IdlHarnessError) {
613+
error = error.message;
614+
}
615+
if (e.message !== error) {
616+
throw new IdlHarnessError(`${idlArrayFunc} threw "${e}", not the expected IdlHarnessError "${error}"`);
617+
}
618+
return;
619+
}
620+
throw new IdlHarnessError(`${idlArrayFunc} did not throw the expected IdlHarnessError`);
571621
}
572622

573623
//@}
@@ -581,9 +631,10 @@ IdlArray.prototype.test = function()
581631
this.partials.forEach(function(parsed_idl)
582632
{
583633
if (!(parsed_idl.name in this.members)
584-
|| !(this.members[parsed_idl.name] instanceof IdlInterface))
634+
|| !(this.members[parsed_idl.name] instanceof IdlInterface
635+
|| this.members[parsed_idl.name] instanceof IdlDictionary))
585636
{
586-
throw "Partial interface " + parsed_idl.name + " with no original interface";
637+
throw new IdlHarnessError(`Partial ${parsed_idl.type} ${parsed_idl.name} with no original ${parsed_idl.type}`);
587638
}
588639
if (parsed_idl.extAttrs)
589640
{
@@ -633,6 +684,21 @@ IdlArray.prototype.test = function()
633684
}
634685
this["includes"] = {};
635686

687+
// Assert B defined for A : B
688+
for (var member of Object.values(this.members).filter(m => m.base)) {
689+
const lhs = member.name;
690+
const rhs = member.base;
691+
if (!(rhs in this.members)) throw new IdlHarnessError(`${lhs} inherits ${rhs}, but ${rhs} is undefined.`);
692+
const lhs_is_interface = this.members[lhs] instanceof IdlInterface;
693+
const rhs_is_interface = this.members[rhs] instanceof IdlInterface;
694+
if (rhs_is_interface != lhs_is_interface) {
695+
if (!lhs_is_interface) throw new IdlHarnessError(`${lhs} inherits ${rhs}, but ${lhs} is not an interface.`);
696+
if (!rhs_is_interface) throw new IdlHarnessError(`${lhs} inherits ${rhs}, but ${rhs} is not an interface.`);
697+
}
698+
// Check for circular dependencies.
699+
member.get_inheritance_stack();
700+
}
701+
636702
Object.getOwnPropertyNames(this.members).forEach(function(memberName) {
637703
var member = this.members[memberName];
638704
if (!(member instanceof IdlInterface)) {
@@ -848,7 +914,7 @@ IdlArray.prototype.assert_type_is = function(value, type)
848914

849915
if (!(type in this.members))
850916
{
851-
throw "Unrecognized type " + type;
917+
throw new IdlHarnessError("Unrecognized type " + type);
852918
}
853919

854920
if (this.members[type] instanceof IdlInterface)
@@ -876,7 +942,7 @@ IdlArray.prototype.assert_type_is = function(value, type)
876942
}
877943
else
878944
{
879-
throw "Type " + type + " isn't an interface or dictionary";
945+
throw new IdlHarnessError("Type " + type + " isn't an interface or dictionary");
880946
}
881947
};
882948
//@}
@@ -1061,6 +1127,10 @@ IdlInterface.prototype.get_inheritance_stack = function() {
10611127
var base = this.array.members[idl_interface.base];
10621128
if (!base) {
10631129
throw new Error(idl_interface.type + " " + idl_interface.base + " not found (inherited by " + idl_interface.name + ")");
1130+
} else if (stack.indexOf(base) > -1) {
1131+
stack.push(base);
1132+
let dep_chain = stack.map(i => i.name).join(',');
1133+
throw new IdlHarnessError(`${this.name} has a circular dependency: ${dep_chain}`);
10641134
}
10651135
idl_interface = base;
10661136
stack.push(idl_interface);
@@ -1345,13 +1415,13 @@ IdlInterface.prototype.test_self = function()
13451415
{
13461416
var aliasAttrs = this.extAttrs.filter(function(o) { return o.name === "LegacyWindowAlias"; });
13471417
if (aliasAttrs.length > 1) {
1348-
throw "Invalid IDL: multiple LegacyWindowAlias extended attributes on " + this.name;
1418+
throw new IdlHarnessError("Invalid IDL: multiple LegacyWindowAlias extended attributes on " + this.name);
13491419
}
13501420
if (this.is_callback()) {
1351-
throw "Invalid IDL: LegacyWindowAlias extended attribute on non-interface " + this.name;
1421+
throw new IdlHarnessError("Invalid IDL: LegacyWindowAlias extended attribute on non-interface " + this.name);
13521422
}
13531423
if (this.exposureSet.indexOf("Window") === -1) {
1354-
throw "Invalid IDL: LegacyWindowAlias extended attribute on " + this.name + " which is not exposed in Window";
1424+
throw new IdlHarnessError("Invalid IDL: LegacyWindowAlias extended attribute on " + this.name + " which is not exposed in Window");
13551425
}
13561426
// TODO: when testing of [NoInterfaceObject] interfaces is supported,
13571427
// check that it's not specified together with LegacyWindowAlias.
@@ -1360,7 +1430,7 @@ IdlInterface.prototype.test_self = function()
13601430

13611431
var rhs = aliasAttrs[0].rhs;
13621432
if (!rhs) {
1363-
throw "Invalid IDL: LegacyWindowAlias extended attribute on " + this.name + " without identifier";
1433+
throw new IdlHarnessError("Invalid IDL: LegacyWindowAlias extended attribute on " + this.name + " without identifier");
13641434
}
13651435
var aliases;
13661436
if (rhs.type === "identifier-list") {
@@ -1621,7 +1691,6 @@ IdlInterface.prototype.test_self = function()
16211691
this.name + '.prototype should not have @@unscopables');
16221692
}
16231693
}.bind(this), this.name + ' interface: existence and properties of interface prototype object\'s @@unscopables property');
1624-
16251694
};
16261695

16271696
//@}
@@ -1733,7 +1802,7 @@ IdlInterface.prototype.test_member_const = function(member)
17331802
//@{
17341803
{
17351804
if (!this.has_constants()) {
1736-
throw "Internal error: test_member_const called without any constants";
1805+
throw new IdlHarnessError("Internal error: test_member_const called without any constants");
17371806
}
17381807

17391808
test(function()
@@ -2289,7 +2358,7 @@ IdlInterface.prototype.test_object = function(desc)
22892358
{
22902359
if (!(current_interface.name in this.array.members))
22912360
{
2292-
throw "Interface " + current_interface.name + " not found (inherited by " + this.name + ")";
2361+
throw new IdlHarnessError("Interface " + current_interface.name + " not found (inherited by " + this.name + ")");
22932362
}
22942363
if (current_interface.prevent_multiple_testing && current_interface.already_tested)
22952364
{
@@ -2379,6 +2448,7 @@ IdlInterface.prototype.test_interface_of = function(desc, obj, exception, expect
23792448
}
23802449
if (!exposed_in(exposure_set(member, this.exposureSet))) {
23812450
test(function() {
2451+
assert_equals(exception, null, "Unexpected exception when evaluating object");
23822452
assert_false(member.name in obj);
23832453
}.bind(this), this.name + " interface: " + desc + ' must not have property "' + member.name + '"');
23842454
continue;

test/wpt/resources/testharness.js

+15
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,13 @@ policies and contribution forms [3].
12471247
}
12481248
expose(assert_readonly, "assert_readonly");
12491249

1250+
/**
1251+
* Assert an Exception with the expected code is thrown.
1252+
*
1253+
* @param {object|number|string} code The expected exception code.
1254+
* @param {Function} func Function which should throw.
1255+
* @param {string} description Error description for the case that the error is not thrown.
1256+
*/
12501257
function assert_throws(code, func, description)
12511258
{
12521259
try {
@@ -2270,17 +2277,25 @@ policies and contribution forms [3].
22702277
if (output_document.body) {
22712278
output_document.body.appendChild(node);
22722279
} else {
2280+
var is_html = false;
22732281
var is_svg = false;
22742282
var output_window = output_document.defaultView;
22752283
if (output_window && "SVGSVGElement" in output_window) {
22762284
is_svg = output_document.documentElement instanceof output_window.SVGSVGElement;
2285+
} else if (output_window) {
2286+
is_html = (output_document.namespaceURI == "http://www.w3.org/1999/xhtml" &&
2287+
output_document.localName == "html");
22772288
}
22782289
if (is_svg) {
22792290
var foreignObject = output_document.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
22802291
foreignObject.setAttribute("width", "100%");
22812292
foreignObject.setAttribute("height", "100%");
22822293
output_document.documentElement.appendChild(foreignObject);
22832294
foreignObject.appendChild(node);
2295+
} else if (is_html) {
2296+
var body = output_document.createElementNS("http://www.w3.org/1999/xhtml", "body");
2297+
output_document.documentElement.appendChild(body);
2298+
body.appendChild(node);
22842299
} else {
22852300
output_document.documentElement.appendChild(node);
22862301
}

test/wpt/webml/idlharness.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"use strict";
1111
promise_test(async () => {
1212
const idl_array = new IdlArray();
13-
const ml_idl = await fetch("../interfaces/webml.idl").then(r => r.text());
13+
const ml_idl = await fetch("../../../docs/webml.idl").then(r => r.text());
1414
idl_array.add_untested_idls('interface Navigator {};');
1515
idl_array.add_idls(ml_idl);
1616
idl_array.add_objects({

0 commit comments

Comments
 (0)