Skip to content

Commit 00e23ac

Browse files
committedJun 20, 2022
test: update wpt tests for encoding
1 parent 028a0a3 commit 00e23ac

27 files changed

+3091
-395
lines changed
 

‎test/common/wpt/worker.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const resource = new ResourceLoader(workerData.wptPath);
88

99
global.self = global;
1010
global.GLOBAL = {
11-
isWindow() { return false; }
11+
isWindow() { return false; },
12+
isShadowRealm() { return false; }
1213
};
1314
global.require = require;
1415

‎test/fixtures/wpt/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Last update:
1313
- common: https://github.com/web-platform-tests/wpt/tree/03c5072aff/common
1414
- console: https://github.com/web-platform-tests/wpt/tree/3b1f72e99a/console
1515
- dom/abort: https://github.com/web-platform-tests/wpt/tree/c49cafb491/dom/abort
16-
- encoding: https://github.com/web-platform-tests/wpt/tree/35f70910d3/encoding
16+
- encoding: https://github.com/web-platform-tests/wpt/tree/0e5b126cd0/encoding
1717
- FileAPI: https://github.com/web-platform-tests/wpt/tree/3b279420d4/FileAPI
1818
- hr-time: https://github.com/web-platform-tests/wpt/tree/9910784394/hr-time
1919
- html/webappapis/atob: https://github.com/web-platform-tests/wpt/tree/f267e1dca6/html/webappapis/atob
@@ -22,7 +22,7 @@ Last update:
2222
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/5873f2d8f1/html/webappapis/timers
2323
- interfaces: https://github.com/web-platform-tests/wpt/tree/fc086c82d5/interfaces
2424
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/17ebc3aea0/performance-timeline
25-
- resources: https://github.com/web-platform-tests/wpt/tree/fbee645164/resources
25+
- resources: https://github.com/web-platform-tests/wpt/tree/1df9d51265/resources
2626
- streams: https://github.com/web-platform-tests/wpt/tree/8f60d94439/streams
2727
- url: https://github.com/web-platform-tests/wpt/tree/77d54aa9e0/url
2828
- user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing

‎test/fixtures/wpt/encoding/encodeInto.any.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,22 @@
120120
});
121121
});
122122

123-
[DataView,
124-
Int8Array,
125-
Int16Array,
126-
Int32Array,
127-
Uint16Array,
128-
Uint32Array,
129-
Uint8ClampedArray,
130-
Float32Array,
131-
Float64Array].forEach(view => {
123+
["DataView",
124+
"Int8Array",
125+
"Int16Array",
126+
"Int32Array",
127+
"Uint16Array",
128+
"Uint32Array",
129+
"Uint8ClampedArray",
130+
"BigInt64Array",
131+
"BigUint64Array",
132+
"Float32Array",
133+
"Float64Array"].forEach(type => {
132134
["ArrayBuffer", "SharedArrayBuffer"].forEach((arrayBufferOrSharedArrayBuffer) => {
133135
test(() => {
134-
assert_throws_js(TypeError, () => new TextEncoder().encodeInto("", new view(createBuffer(arrayBufferOrSharedArrayBuffer, 0))));
135-
}, "Invalid encodeInto() destination: " + view.name + ", backed by: " + arrayBufferOrSharedArrayBuffer);
136+
const viewInstance = new self[type](createBuffer(arrayBufferOrSharedArrayBuffer, 0));
137+
assert_throws_js(TypeError, () => new TextEncoder().encodeInto("", viewInstance));
138+
}, "Invalid encodeInto() destination: " + type + ", backed by: " + arrayBufferOrSharedArrayBuffer);
136139
});
137140
});
138141

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// META: script=/resources/idlharness-shadowrealm.js
2+
idl_test_shadowrealm(["encoding"], ["streams"]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script>
5+
6+
test(() => {
7+
const decoder = new TextDecoder('utf-8');
8+
const buffer = new SharedArrayBuffer(4);
9+
assert_throws_js(TypeError, () => {
10+
decoder.decode(new Uint8Array(buffer));
11+
}, 'constructing TextDecoder with SharedArrayBuffer view should throw');
12+
}, 'decoding SharedArrayBuffer');
13+
14+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cross-Origin-Opener-Policy:same-origin
2+
Cross-Origin-Embedder-Policy:require-corp

‎test/fixtures/wpt/encoding/single-byte-decoder.window.js

+107
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/fixtures/wpt/encoding/streams/decode-utf8.any.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@
4343
const array = await readableStreamToArray(output);
4444
assert_array_equals(array, [expectedOutputString],
4545
'the output should be in one chunk');
46-
}, 'a trailing empty chunk should be ignored- ' + arrayBufferOrSharedArrayBuffer);
46+
}, 'a trailing empty chunk should be ignored - ' + arrayBufferOrSharedArrayBuffer);
47+
48+
promise_test(async () => {
49+
const chunk = new Uint8Array(createBuffer(arrayBufferOrSharedArrayBuffer, 3));
50+
chunk.set([0xF0, 0x9F, 0x92]);
51+
const input = readableStreamFromArray([chunk]);
52+
const output = input.pipeThrough(new TextDecoderStream());
53+
const array = await readableStreamToArray(output);
54+
assert_array_equals(array, ['\uFFFD']);
55+
}, 'UTF-8 EOF handling - ' + arrayBufferOrSharedArrayBuffer);
4756
});
4857

4958
promise_test(async () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
test(() => {
2+
// Truncated sequences
3+
assert_equals(new TextDecoder().decode(new Uint8Array([0xF0])), "\uFFFD");
4+
assert_equals(new TextDecoder().decode(new Uint8Array([0xF0, 0x9F])), "\uFFFD");
5+
assert_equals(new TextDecoder().decode(new Uint8Array([0xF0, 0x9F, 0x92])), "\uFFFD");
6+
7+
// Errors near end-of-queue
8+
assert_equals(new TextDecoder().decode(new Uint8Array([0xF0, 0x9F, 0x41])), "\uFFFDA");
9+
assert_equals(new TextDecoder().decode(new Uint8Array([0xF0, 0x41, 0x42])), "\uFFFDAB");
10+
assert_equals(new TextDecoder().decode(new Uint8Array([0xF0, 0x41, 0xF0])), "\uFFFDA\uFFFD");
11+
assert_equals(new TextDecoder().decode(new Uint8Array([0xF0, 0x8F, 0x92])), "\uFFFD\uFFFD\uFFFD");
12+
}, "TextDecoder end-of-queue handling");
13+
14+
test(() => {
15+
const decoder = new TextDecoder();
16+
decoder.decode(new Uint8Array([0xF0]), { stream: true });
17+
assert_equals(decoder.decode(), "\uFFFD");
18+
19+
decoder.decode(new Uint8Array([0xF0]), { stream: true });
20+
decoder.decode(new Uint8Array([0x9F]), { stream: true });
21+
assert_equals(decoder.decode(), "\uFFFD");
22+
23+
decoder.decode(new Uint8Array([0xF0, 0x9F]), { stream: true });
24+
assert_equals(decoder.decode(new Uint8Array([0x92])), "\uFFFD");
25+
26+
assert_equals(decoder.decode(new Uint8Array([0xF0, 0x9F]), { stream: true }), "");
27+
assert_equals(decoder.decode(new Uint8Array([0x41]), { stream: true }), "\uFFFDA");
28+
assert_equals(decoder.decode(), "");
29+
30+
assert_equals(decoder.decode(new Uint8Array([0xF0, 0x41, 0x42]), { stream: true }), "\uFFFDAB");
31+
assert_equals(decoder.decode(), "");
32+
33+
assert_equals(decoder.decode(new Uint8Array([0xF0, 0x41, 0xF0]), { stream: true }), "\uFFFDA");
34+
assert_equals(decoder.decode(), "\uFFFD");
35+
36+
assert_equals(decoder.decode(new Uint8Array([0xF0]), { stream: true }), "");
37+
assert_equals(decoder.decode(new Uint8Array([0x8F]), { stream: true }), "\uFFFD\uFFFD");
38+
assert_equals(decoder.decode(new Uint8Array([0x92]), { stream: true }), "\uFFFD");
39+
assert_equals(decoder.decode(), "");
40+
}, "TextDecoder end-of-queue handling using stream: true");

‎test/fixtures/wpt/encoding/textdecoder-streaming.any.js

+50-3
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,62 @@ var octets = {
2828
var decoder = new TextDecoder(encoding);
2929
for (var i = 0; i < encoded.length; i += len) {
3030
var sub = [];
31-
for (var j = i; j < encoded.length && j < i + len; ++j)
31+
for (var j = i; j < encoded.length && j < i + len; ++j) {
3232
sub.push(encoded[j]);
33-
var uintArray = new Uint8Array(createBuffer(arrayBufferOrSharedArrayBuffer, sub.length));
34-
uintArray.set(sub);
33+
}
34+
var uintArray = new Uint8Array(createBuffer(arrayBufferOrSharedArrayBuffer, sub.length));
35+
uintArray.set(sub);
3536
out += decoder.decode(uintArray, {stream: true});
3637
}
3738
out += decoder.decode();
3839
assert_equals(out, string);
3940
}, 'Streaming decode: ' + encoding + ', ' + len + ' byte window (' + arrayBufferOrSharedArrayBuffer + ')');
4041
}
4142
});
43+
44+
test(() => {
45+
function bytes(byteArray) {
46+
const view = new Uint8Array(createBuffer(arrayBufferOrSharedArrayBuffer, byteArray.length));
47+
view.set(byteArray);
48+
return view;
49+
}
50+
51+
const decoder = new TextDecoder();
52+
53+
assert_equals(decoder.decode(bytes([0xC1]), {stream: true}), "\uFFFD");
54+
assert_equals(decoder.decode(), "");
55+
56+
assert_equals(decoder.decode(bytes([0xF5]), {stream: true}), "\uFFFD");
57+
assert_equals(decoder.decode(), "");
58+
59+
assert_equals(decoder.decode(bytes([0xE0, 0x41]), {stream: true}), "\uFFFDA");
60+
assert_equals(decoder.decode(bytes([0x42])), "B");
61+
62+
assert_equals(decoder.decode(bytes([0xE0, 0x80]), {stream: true}), "\uFFFD\uFFFD");
63+
assert_equals(decoder.decode(bytes([0x80])), "\uFFFD");
64+
65+
assert_equals(decoder.decode(bytes([0xED, 0xA0]), {stream: true}), "\uFFFD\uFFFD");
66+
assert_equals(decoder.decode(bytes([0x80])), "\uFFFD");
67+
68+
assert_equals(decoder.decode(bytes([0xF0, 0x41]), {stream: true}), "\uFFFDA");
69+
assert_equals(decoder.decode(bytes([0x42]), {stream: true}), "B");
70+
assert_equals(decoder.decode(bytes([0x43])), "C");
71+
72+
assert_equals(decoder.decode(bytes([0xF0, 0x80]), {stream: true}), "\uFFFD\uFFFD");
73+
assert_equals(decoder.decode(bytes([0x80]), {stream: true}), "\uFFFD");
74+
assert_equals(decoder.decode(bytes([0x80])), "\uFFFD");
75+
76+
assert_equals(decoder.decode(bytes([0xF4, 0xA0]), {stream: true}), "\uFFFD\uFFFD");
77+
assert_equals(decoder.decode(bytes([0x80]), {stream: true}), "\uFFFD");
78+
assert_equals(decoder.decode(bytes([0x80])), "\uFFFD");
79+
80+
assert_equals(decoder.decode(bytes([0xF0, 0x90, 0x41]), {stream: true}), "\uFFFDA");
81+
assert_equals(decoder.decode(bytes([0x42])), "B");
82+
83+
// 4-byte UTF-8 sequences always correspond to non-BMP characters. Here
84+
// we make sure that, although the first 3 bytes are enough to emit the
85+
// lead surrogate, it only gets emitted when the fourth byte is read.
86+
assert_equals(decoder.decode(bytes([0xF0, 0x9F, 0x92]), {stream: true}), "");
87+
assert_equals(decoder.decode(bytes([0xA9])), "\u{1F4A9}");
88+
}, `Streaming decode: UTF-8 chunk tests (${arrayBufferOrSharedArrayBuffer})`);
4289
})
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Function that sends an accesskey using the proper key combination depending on the browser and OS.
3+
*
4+
* This needs that the test imports the following scripts:
5+
* <script src="/resources/testdriver.js"></script>
6+
* <script src="/resources/testdriver-actions.js"></script>
7+
* <script src="/resources/testdriver-vendor.js"></script>
8+
*/
9+
function pressAccessKey(accessKey){
10+
let controlKey = '\uE009'; // left Control key
11+
let altKey = '\uE00A'; // left Alt key
12+
let optionKey = altKey; // left Option key
13+
let shiftKey = '\uE008'; // left Shift key
14+
// There are differences in using accesskey across browsers and OS's.
15+
// See: // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/accesskey
16+
let isMacOSX = navigator.userAgent.indexOf("Mac") != -1;
17+
let osAccessKey = isMacOSX ? [controlKey, optionKey] : [shiftKey, altKey];
18+
let actions = new test_driver.Actions();
19+
// Press keys.
20+
for (let key of osAccessKey) {
21+
actions = actions.keyDown(key);
22+
}
23+
actions = actions
24+
.keyDown(accessKey)
25+
.addTick()
26+
.keyUp(accessKey);
27+
osAccessKey.reverse();
28+
for (let key of osAccessKey) {
29+
actions = actions.keyUp(key);
30+
}
31+
return actions.send();
32+
}
33+
34+
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Blank Page</title>
6+
<script>
7+
window.onload = function(event) {
8+
// This is needed to ensure the onload event fires when this page is
9+
// opened as a popup.
10+
// See https://github.com/web-platform-tests/wpt/pull/18157
11+
};
12+
</script>
13+
</head>
14+
<body>
15+
</body>
16+
</html>

0 commit comments

Comments
 (0)