Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Last update:
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
- web-locks: https://github.com/web-platform-tests/wpt/tree/10a122a6bc/web-locks
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/1e4933113d/WebCryptoAPI
- webidl: https://github.com/web-platform-tests/wpt/tree/63ca529a02/webidl
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/2f96fa1996/webidl/ecmascript-binding/es-exceptions
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/6495c91853/webmessaging/broadcastchannel
- webstorage: https://github.com/web-platform-tests/wpt/tree/1d2c5fb36a/webstorage
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
"commit": "1e4933113d2028e092d07a9e865db8f606b21026",
"path": "WebCryptoAPI"
},
"webidl": {
"commit": "63ca529a021fec15b2996db82fd7dd04c11abe85",
"path": "webidl"
},
"webidl/ecmascript-binding/es-exceptions": {
"commit": "2f96fa19966d6bc19e979a09479ac8a7aa337c54",
"path": "webidl/ecmascript-binding/es-exceptions"
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/wpt/webidl/META.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spec: https://webidl.spec.whatwg.org/
suggested_reviewers:
- yuki3
1 change: 1 addition & 0 deletions test/fixtures/wpt/webidl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tests for the [Web IDL Standard](https://webidl.spec.whatwg.org/).
168 changes: 168 additions & 0 deletions test/fixtures/wpt/webidl/current-realm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<!-- This tests the agreed upon outcome for https://www.w3.org/Bugs/Public/show_bug.cgi?id=24652
that has not been reflected in the IDL standard yet due to lack of editing resources.

TODO: https://github.com/w3c/webcrypto/issues/85 -->
<!DOCTYPE html>
<meta charset=utf-8>
<title>Current Realm</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<iframe srcdoc="<body test>"></iframe>
<script>
setup({explicit_done:true})

function isObjectFromGlobal(object, global) {
return object instanceof global.Object;
}
function assert_global(obj) {
assert_false(isObjectFromGlobal(obj, self), obj + " should not be from top-level Realm")
assert_true(isObjectFromGlobal(obj, self[0]), obj + " should be from <iframe> Realm")
}

onload = function() {
[["querySelectorAll", "test"],
["createElement", "x"],
["createElementNS", null, "x"],
["createDocumentFragment"],
["createTextNode", "test"],
["createComment", "test"],
["createProcessingInstruction", "x", "x"],
["createAttribute", "x"],
["createAttributeNS", "x", "x"],
["createEvent", "Event"],
["createRange"],
["createNodeIterator", document.head],
["createTreeWalker", document.head]].forEach(function(val) {
test(function() {
const method = val.shift();
let obj = self[0].document[method](...val);
assert_global(obj)

obj = Document.prototype[method].call(self[0].document, ...val);
assert_global(obj)
}, val[0])
})

;["Request", "Response"].forEach(val => {
test(() => {
const obj = new self[0][val]("about:blank");
assert_global(obj);

const cloneObj = obj.clone();
assert_global(cloneObj);

const involvedCloneObj = self[val].prototype["clone"].call(cloneObj);
assert_global(cloneObj);
}, val)
})

// Note: these are not [NewObject] and can be cached. But across globals?
;[["getElementsByTagName", "x"],
["getElementsByTagNameNS", null, "x"],
["getElementsByClassName", "x"]].forEach(function(val) {
test(function() {
const method = val.shift();
const obj = self[0].document[method](...val);
assert_global(obj)

const obj2 = Document.prototype[method].call(self[0].document, ...val);
assert_global(obj)

assert_equals(obj, obj2) // XXX this might be controversial
}, val[0])
})

;[["createDocumentType", "x", "", ""],
["createDocument", null, "", null],
["createHTMLDocument", "x"]].forEach(function(val) {
test(function() {
const method = val.shift();
let obj = self[0].document.implementation[method](...val);
assert_global(obj)

obj = DOMImplementation.prototype[method].call(self[0].document.implementation, ...val);
assert_global(obj)
}, val[0])
})

;[["item", 0],
["getNamedItem", "test"],
["getNamedItemNS", null, "test"]].forEach(function(val) {
test(function() {
const method = val.shift();
const obj = self[0].document.body.attributes[method](...val);
assert_global(obj)

const obj2 = NamedNodeMap.prototype[method].call(self[0].document.body.attributes, ...val);
assert_global(obj)

assert_equals(obj, obj2)
}, "NamedNodeMap " + val[0])
})

test(function() {
var c = self[0].document.createTextNode(""),
obj = c.splitText(0)
assert_global(obj)

obj = Text.prototype.splitText.call(c, "")
assert_global(obj)
}, "splitText")

;["extractContents",
"cloneContents",
"cloneRange"].forEach(function(val) {
test(function() {
var c = self[0].document.createRange(),
obj = c[val]()
assert_global(obj)

obj = Range.prototype[val].call(c)
assert_global(obj)
}, val)
})

;["2d", "webgl"].forEach(function(val) {
test(function() {
var c = self[0].document.createElement("canvas"),
obj = c.getContext(val)

// WebGL might not be enabled in this environment
if (!obj && val === "webgl") {
return;
}

assert_global(obj)
obj = HTMLCanvasElement.prototype.getContext.call(c, val)
assert_global(obj)
}, "getContext " + val)
})

;[["createImageData", 5, 5],
["getImageData", 5, 5, 5, 5]].forEach(function(val) {
test(function() {
const method = val.shift();
const c = self[0].document.createElement("canvas").getContext("2d");
let obj = c[method](...val);
assert_global(obj)
assert_global(obj.data)

obj = CanvasRenderingContext2D.prototype[method].call(c, ...val);
assert_global(obj)
assert_global(obj.data)
}, val[0])
})

test(function() {
var c = new self[0].FontFace("test", "about:blank"),
obj = c.load()
assert_global(obj)

obj = FontFace.prototype.load.call(c)
assert_global(obj)
}, "FontFace's load()")

done()
}
</script>
31 changes: 31 additions & 0 deletions test/fixtures/wpt/webidl/ecmascript-binding/allow-resizable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/sab.js"></script>
<script type="module">
test(t => {
// Fixed-length ABs should not throw
const ab = new ArrayBuffer(16);
new Response(new Uint8Array(ab));

const rab = new ArrayBuffer(16, { maxByteLength: 1024 });
// Response doesn't have [AllowResizable] or [AllowShared]
assert_throws_js(TypeError, () => {
new Response(new Uint8Array(rab));
});
}, "APIs without [AllowResizable] throw when passed resizable ArrayBuffers");

test(t => {
const enc = new TextEncoder();

// Fixed-length SABs should not throw
const sab = createBuffer('SharedArrayBuffer', 16);
enc.encodeInto("foobar", new Uint8Array(sab));

const gsab = createBuffer('SharedArrayBuffer', 16, { maxByteLength: 1024 });
// TextEncoder.encodeInto doesn't have [AllowResizable] but has [AllowShared]
assert_throws_js(TypeError, () => {
enc.encodeInto("foobar", new Uint8Array(gsab));
});
}, "APIs with [AllowShared] but without [AllowResizable] throw when passed growable SharedArrayBuffers");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>All attributes accessors are unique function objects</title>
<link rel="help" href="https://webidl.spec.whatwg.org/#idl-interface-mixins">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";

test(() => {
const seenPrototypes = new WeakSet([Function.prototype]);
const seenFunctions = new WeakMap();

for (const windowKey of Object.getOwnPropertyNames(window)) {
const windowValue = window[windowKey];
if (typeof windowValue !== "function") continue;

const {prototype} = windowValue;
if (!prototype || seenPrototypes.has(prototype)) continue;
seenPrototypes.add(prototype);

for (const key of Object.getOwnPropertyNames(prototype)) {
const assert_not_seen = (fn, field) => {
const fnInfo = `${windowKey}.${key}.${field}`;
assert_equals(seenFunctions.get(fn), undefined, fnInfo);
seenFunctions.set(fn, fnInfo);
};

const desc = Object.getOwnPropertyDescriptor(prototype, key);
if (desc.get) assert_not_seen(desc.get, "[[Get]]");
if (desc.set) assert_not_seen(desc.set, "[[Set]]");
}
}
}, "For attributes, each copy of the accessor property has distinct built-in function objects for its getters and setters.");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

test(() => {
const ownPropKeys = Reflect.ownKeys(Blob).slice(0, 3);
assert_array_equals(ownPropKeys, ["length", "name", "prototype"]);
}, 'Constructor property enumeration order of "length", "name", and "prototype"');

test(() => {
assert_own_property(Blob.prototype, "slice");

const ownPropKeys = Reflect.ownKeys(Blob.prototype.slice).slice(0, 2);
assert_array_equals(ownPropKeys, ["length", "name"]);
}, 'Method property enumeration order of "length" and "name"');

test(() => {
assert_own_property(Blob.prototype, "size");

const desc = Reflect.getOwnPropertyDescriptor(Blob.prototype, "size");
assert_equals(typeof desc.get, "function");

const ownPropKeys = Reflect.ownKeys(desc.get).slice(0, 2);
assert_array_equals(ownPropKeys, ["length", "name"]);
}, 'Getter property enumeration order of "length" and "name"');
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"use strict";

test(() => {
assert_own_property(Blob.prototype, Symbol.toStringTag);

const propDesc = Object.getOwnPropertyDescriptor(Blob.prototype, Symbol.toStringTag);
assert_equals(propDesc.value, "Blob", "value");
assert_equals(propDesc.configurable, true, "configurable");
assert_equals(propDesc.enumerable, false, "enumerable");
assert_equals(propDesc.writable, false, "writable");
}, "@@toStringTag exists on the prototype with the appropriate descriptor");

test(() => {
assert_not_own_property(new Blob(), Symbol.toStringTag);
}, "@@toStringTag must not exist on the instance");

test(() => {
assert_equals(Object.prototype.toString.call(Blob.prototype), "[object Blob]");
}, "Object.prototype.toString applied to the prototype");

test(() => {
assert_equals(Object.prototype.toString.call(new Blob()), "[object Blob]");
}, "Object.prototype.toString applied to an instance");

test(t => {
assert_own_property(Blob.prototype, Symbol.toStringTag, "Precondition for this test: @@toStringTag on the prototype");

t.add_cleanup(() => {
Object.defineProperty(Blob.prototype, Symbol.toStringTag, { value: "Blob" });
});

Object.defineProperty(Blob.prototype, Symbol.toStringTag, { value: "NotABlob" });
assert_equals(Object.prototype.toString.call(Blob.prototype), "[object NotABlob]", "prototype");
assert_equals(Object.prototype.toString.call(new Blob()), "[object NotABlob]", "instance");
}, "Object.prototype.toString applied after modifying the prototype's @@toStringTag");

test(t => {
const instance = new Blob();
assert_not_own_property(instance, Symbol.toStringTag, "Precondition for this test: no @@toStringTag on the instance");

Object.defineProperty(instance, Symbol.toStringTag, { value: "NotABlob" });
assert_equals(Object.prototype.toString.call(instance), "[object NotABlob]");
}, "Object.prototype.toString applied to the instance after modifying the instance's @@toStringTag");

// Chrome had a bug (https://bugs.chromium.org/p/chromium/issues/detail?id=793406) where if there
// was no @@toStringTag in the prototype, it would fall back to a magic class string. This tests
// that the bug is fixed.

test(() => {
const instance = new Blob();
Object.setPrototypeOf(instance, null);

assert_equals(Object.prototype.toString.call(instance), "[object Object]");
}, "Object.prototype.toString applied to a null-prototype instance");

// This test must be last.
test(() => {
delete Blob.prototype[Symbol.toStringTag];

assert_equals(Object.prototype.toString.call(Blob.prototype), "[object Object]", "prototype");
assert_equals(Object.prototype.toString.call(new Blob()), "[object Object]", "instance");
}, "Object.prototype.toString applied after deleting @@toStringTag");
Loading
Loading