Skip to content

Commit

Permalink
test: update WPT harness
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Aug 2, 2020
1 parent da4d8de commit d3237c0
Show file tree
Hide file tree
Showing 53 changed files with 4,736 additions and 1,408 deletions.
14 changes: 7 additions & 7 deletions test/fixtures/wpt/README.md
Expand Up @@ -10,13 +10,13 @@ See [test/wpt](../../wpt/README.md) for information on how these tests are run.

Last update:

- console: https://github.com/web-platform-tests/wpt/tree/9786a4b131/console
- encoding: https://github.com/web-platform-tests/wpt/tree/5059d2c777/encoding
- url: https://github.com/web-platform-tests/wpt/tree/43feb7f612/url
- resources: https://github.com/web-platform-tests/wpt/tree/e1fddfbf80/resources
- interfaces: https://github.com/web-platform-tests/wpt/tree/8ada332aea/interfaces
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/0c3bed38df/html/webappapis/microtask-queuing
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/ddfe9c089b/html/webappapis/timers
- console: https://github.com/web-platform-tests/wpt/tree/b0daaa6b86/console
- encoding: https://github.com/web-platform-tests/wpt/tree/ab733fd9f5/encoding
- url: https://github.com/web-platform-tests/wpt/tree/3696f2233a/url
- resources: https://github.com/web-platform-tests/wpt/tree/abfd8c9729/resources
- interfaces: https://github.com/web-platform-tests/wpt/tree/3cbf8e150b/interfaces
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/2c5c3c4c27/html/webappapis/microtask-queuing
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/264f12bc7b/html/webappapis/timers
- hr-time: https://github.com/web-platform-tests/wpt/tree/a5d1774ecf/hr-time

[Web Platform Tests]: https://github.com/web-platform-tests/wpt
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/console/console-label-conversion.any.js
Expand Up @@ -18,7 +18,7 @@ for (const method of methods) {
}, `console.${method}()'s label gets converted to string via label.toString() when label is an object`);

test(() => {
assert_throws({name: 'Error'}, () => {
assert_throws_js(Error, () => {
console[method]({
toString() {
throw new Error('conversion error');
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/encoding/api-invalid-label.any.js
Expand Up @@ -19,6 +19,6 @@ setup(function() {

tests.forEach(function(input) {
test(function() {
assert_throws(new RangeError(), function() { new TextDecoder(input); });
assert_throws_js(RangeError, function() { new TextDecoder(input); });
}, 'Invalid label ' + format_value(input) + ' should be rejected by TextDecoder.');
});
3 changes: 2 additions & 1 deletion test/fixtures/wpt/encoding/api-replacement-encodings.any.js
Expand Up @@ -7,8 +7,9 @@ encodings_table.forEach(function(section) {
}).forEach(function(encoding) {
encoding.labels.forEach(function(label) {
test(function() {
assert_throws(new RangeError(), function() { new TextDecoder(label); });
assert_throws_js(RangeError, function() { new TextDecoder(label); });
}, 'Label for "replacement" should be rejected by API: ' + label);
});
});
});

86 changes: 47 additions & 39 deletions test/fixtures/wpt/encoding/encodeInto.any.js
Expand Up @@ -74,44 +74,46 @@
"filler": "random"
}
].forEach(destinationData => {
test(() => {
// Setup
const bufferLength = testData.destinationLength + destinationData.bufferIncrease,
destinationOffset = destinationData.destinationOffset,
destinationLength = testData.destinationLength,
destinationFiller = destinationData.filler,
encoder = new TextEncoder(),
buffer = new ArrayBuffer(bufferLength),
view = new Uint8Array(buffer, destinationOffset, destinationLength),
fullView = new Uint8Array(buffer),
control = new Array(bufferLength);
let byte = destinationFiller;
for (let i = 0; i < bufferLength; i++) {
if (destinationFiller === "random") {
byte = Math.floor(Math.random() * 256);
["ArrayBuffer", "SharedArrayBuffer"].forEach(arrayBufferOrSharedArrayBuffer => {
test(() => {
// Setup
const bufferLength = testData.destinationLength + destinationData.bufferIncrease,
destinationOffset = destinationData.destinationOffset,
destinationLength = testData.destinationLength,
destinationFiller = destinationData.filler,
encoder = new TextEncoder(),
buffer = new self[arrayBufferOrSharedArrayBuffer](bufferLength),
view = new Uint8Array(buffer, destinationOffset, destinationLength),
fullView = new Uint8Array(buffer),
control = new Array(bufferLength);
let byte = destinationFiller;
for (let i = 0; i < bufferLength; i++) {
if (destinationFiller === "random") {
byte = Math.floor(Math.random() * 256);
}
control[i] = byte;
fullView[i] = byte;
}
control[i] = byte;
fullView[i] = byte;
}

// It's happening
const result = encoder.encodeInto(testData.input, view);
// It's happening
const result = encoder.encodeInto(testData.input, view);

// Basics
assert_equals(view.byteLength, destinationLength);
assert_equals(view.length, destinationLength);
// Basics
assert_equals(view.byteLength, destinationLength);
assert_equals(view.length, destinationLength);

// Remainder
assert_equals(result.read, testData.read);
assert_equals(result.written, testData.written.length);
for (let i = 0; i < bufferLength; i++) {
if (i < destinationOffset || i >= (destinationOffset + testData.written.length)) {
assert_equals(fullView[i], control[i]);
} else {
assert_equals(fullView[i], testData.written[i - destinationOffset]);
// Remainder
assert_equals(result.read, testData.read);
assert_equals(result.written, testData.written.length);
for (let i = 0; i < bufferLength; i++) {
if (i < destinationOffset || i >= (destinationOffset + testData.written.length)) {
assert_equals(fullView[i], control[i]);
} else {
assert_equals(fullView[i], testData.written[i - destinationOffset]);
}
}
}
}, "encodeInto() with " + testData.input + " and destination length " + testData.destinationLength + ", offset " + destinationData.destinationOffset + ", filler " + destinationData.filler);
}, "encodeInto() into " + arrayBufferOrSharedArrayBuffer + " with " + testData.input + " and destination length " + testData.destinationLength + ", offset " + destinationData.destinationOffset + ", filler " + destinationData.filler);
})
});
});

Expand All @@ -124,14 +126,20 @@
Uint8ClampedArray,
Float32Array,
Float64Array].forEach(view => {
["ArrayBuffer", "SharedArrayBuffer"].forEach((arrayBufferOrSharedArrayBuffer) => {
test(() => {
assert_throws_js(TypeError, () => new TextEncoder().encodeInto("", new view(new self[arrayBufferOrSharedArrayBuffer](0))));
}, "Invalid encodeInto() destination: " + view.name + ", backed by: " + arrayBufferOrSharedArrayBuffer);
});
});

["ArrayBuffer", "SharedArrayBuffer"].forEach((arrayBufferOrSharedArrayBuffer) => {
test(() => {
assert_throws(new TypeError(), () => new TextEncoder().encodeInto("", new view(new ArrayBuffer(0))));
}, "Invalid encodeInto() destination: " + view.name);
});
assert_throws_js(TypeError, () => new TextEncoder().encodeInto("", new self[arrayBufferOrSharedArrayBuffer](10)));
}, "Invalid encodeInto() destination: " + arrayBufferOrSharedArrayBuffer);
});


test(() => {
assert_throws(new TypeError(), () => new TextEncoder().encodeInto("", new ArrayBuffer(10)));
}, "Invalid encodeInto() destination: ArrayBuffer");

test(() => {
const buffer = new ArrayBuffer(10),
Expand Down
Expand Up @@ -41,3 +41,4 @@

</body>
</html>

Expand Up @@ -129,3 +129,4 @@
</script>
</body>
</html>

Expand Up @@ -41,3 +41,4 @@

</body>
</html>

Expand Up @@ -41,3 +41,4 @@

</body>
</html>

Expand Up @@ -104,3 +104,4 @@
</script>
</body>
</html>

Expand Up @@ -40,3 +40,4 @@
<script src="../../resources/encode-form-common.js"></script>
</body>
</html>

Expand Up @@ -51,3 +51,4 @@
<script src="../../resources/encode-form-common.js"></script>
</body>
</html>

Expand Up @@ -47,3 +47,4 @@
<script src="../../resources/encode-form-common.js"></script>
</body>
</html>

Expand Up @@ -47,3 +47,4 @@
<script src="../../resources/encode-href-common.js"></script>
</body>
</html>

Expand Up @@ -43,3 +43,4 @@
<script src="../../resources/encode-href-common.js"></script>
</body>
</html>

12 changes: 6 additions & 6 deletions test/fixtures/wpt/encoding/streams/backpressure.any.js
Expand Up @@ -4,11 +4,11 @@

const classes = [
{
constructor: TextDecoderStream,
name: 'TextDecoderStream',
input: new Uint8Array([65])
},
{
constructor: TextEncoderStream,
name: 'TextEncoderStream',
input: 'A'
}
];
Expand All @@ -17,7 +17,7 @@ const microtasksRun = () => new Promise(resolve => step_timeout(resolve, 0));

for (const streamClass of classes) {
promise_test(async () => {
const stream = new streamClass.constructor();
const stream = new self[streamClass.name]();
const writer = stream.writable.getWriter();
const reader = stream.readable.getReader();
const events = [];
Expand All @@ -32,10 +32,10 @@ for (const streamClass of classes) {
assert_array_equals(events, ['paused', 'read', 'write'],
'write should happen after read');
}, 'write() should not complete until read relieves backpressure for ' +
`${streamClass.constructor.name}`);
`${streamClass.name}`);

promise_test(async () => {
const stream = new streamClass.constructor();
const stream = new self[streamClass.name]();
const writer = stream.writable.getWriter();
const reader = stream.readable.getReader();
const events = [];
Expand All @@ -56,5 +56,5 @@ for (const streamClass of classes) {
'write2'],
'writes should not happen before read2');
}, 'additional writes should wait for backpressure to be relieved for ' +
`class ${streamClass.constructor.name}`);
`class ${streamClass.name}`);
}
22 changes: 11 additions & 11 deletions test/fixtures/wpt/encoding/streams/decode-attributes.any.js
Expand Up @@ -46,26 +46,26 @@ for (const trueValue of [true, 1, {}, [], 'yes']) {
}

test(() => {
assert_throws(new RangeError(), () => new TextDecoderStream(''),
'the constructor should throw');
assert_throws_js(RangeError, () => new TextDecoderStream(''),
'the constructor should throw');
}, 'constructing with an invalid encoding should throw');

test(() => {
assert_throws(new TypeError(), () => new TextDecoderStream({
assert_throws_js(TypeError, () => new TextDecoderStream({
toString() { return {}; }
}), 'the constructor should throw');
}, 'constructing with a non-stringifiable encoding should throw');

test(() => {
assert_throws(new Error(),
() => new TextDecoderStream('utf-8', {
get fatal() { throw new Error(); }
}), 'the constructor should throw');
assert_throws_js(Error,
() => new TextDecoderStream('utf-8', {
get fatal() { throw new Error(); }
}), 'the constructor should throw');
}, 'a throwing fatal member should cause the constructor to throw');

test(() => {
assert_throws(new Error(),
() => new TextDecoderStream('utf-8', {
get ignoreBOM() { throw new Error(); }
}), 'the constructor should throw');
assert_throws_js(Error,
() => new TextDecoderStream('utf-8', {
get ignoreBOM() { throw new Error(); }
}), 'the constructor should throw');
}, 'a throwing ignoreBOM member should cause the constructor to throw');
18 changes: 2 additions & 16 deletions test/fixtures/wpt/encoding/streams/decode-bad-chunks.any.js
Expand Up @@ -22,20 +22,6 @@ const badChunks = [
{
name: 'array',
value: [65]
},
{
name: 'SharedArrayBuffer',
// Use a getter to postpone construction so that all tests don't fail where
// SharedArrayBuffer is not yet implemented.
get value() {
return new SharedArrayBuffer();
}
},
{
name: 'shared Uint8Array',
get value() {
new Uint8Array(new SharedArrayBuffer())
}
}
];

Expand All @@ -46,7 +32,7 @@ for (const chunk of badChunks) {
const writer = tds.writable.getWriter();
const writePromise = writer.write(chunk.value);
const readPromise = reader.read();
await promise_rejects(t, new TypeError(), writePromise, 'write should reject');
await promise_rejects(t, new TypeError(), readPromise, 'read should reject');
await promise_rejects_js(t, TypeError, writePromise, 'write should reject');
await promise_rejects_js(t, TypeError, readPromise, 'read should reject');
}, `chunk of type ${chunk.name} should error the stream`);
}
Expand Up @@ -19,6 +19,6 @@ promise_test(async t => {
const output = input.pipeThrough(new TextDecoderStream(
'utf-8', {fatal: true}));
const reader = output.getReader();
await promise_rejects(t, new TypeError(), reader.read(),
await promise_rejects_js(t, TypeError, reader.read(),
'read should reject');
}, 'incomplete input with error mode "fatal" should error the stream');
4 changes: 2 additions & 2 deletions test/fixtures/wpt/encoding/streams/decode-non-utf8.any.js
Expand Up @@ -67,9 +67,9 @@ for (const encoding of encodings) {
const writer = stream.writable.getWriter();
const writePromise = writer.write(new Uint8Array(encoding.invalid));
const closePromise = writer.close();
await promise_rejects(t, new TypeError(), reader.read(),
await promise_rejects_js(t, TypeError, reader.read(),
'readable should be errored');
await promise_rejects(t, new TypeError(),
await promise_rejects_js(t, TypeError,
Promise.all([writePromise, closePromise]),
'writable should be errored');
}, `TextDecoderStream should be able to reject invalid sequences in ` +
Expand Down

0 comments on commit d3237c0

Please sign in to comment.