Skip to content

Commit ed06176

Browse files
committed
fix web-platform tests web-idl parser
1 parent 9a381cb commit ed06176

File tree

8 files changed

+570
-29
lines changed

8 files changed

+570
-29
lines changed

build/wpt_test.bzl

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def wpt_test(name, wpt_directory, config, compat_date = "", compat_flags = [], a
3939
harness = "//src/wpt:harness@js"
4040
wpt_cacert = "@wpt//:tools/certs/cacert.pem"
4141
wpt_common = "@wpt//:common@module"
42+
wpt_resources = "@wpt//:resources@module"
43+
wpt_interfaces = "@wpt//:interfaces@module"
4244

4345
if compat_date == "":
4446
compat_date = "2999-12-31"
@@ -62,6 +64,8 @@ def wpt_test(name, wpt_directory, config, compat_date = "", compat_flags = [], a
6264
autogates = autogates,
6365
wpt_cacert = wpt_cacert,
6466
wpt_common = wpt_common,
67+
wpt_resources = wpt_resources,
68+
wpt_interfaces = wpt_interfaces,
6569
compat_flags = compat_flags + ["experimental", "nodejs_compat", "unsupported_process_actual_platform"],
6670
)
6771

@@ -72,6 +76,8 @@ def wpt_test(name, wpt_directory, config, compat_date = "", compat_flags = [], a
7276
harness, # e.g. wpt/harness/*.ts
7377
wpt_cacert, # i.e. "wpt/tools/certs/cacert.pem",
7478
wpt_common, # i.e. "wpt/common/**"
79+
wpt_resources, # i.e. "wpt/resources/**"
80+
wpt_interfaces, # i.e. "wpt/interfaces/**"
7581
]
7682

7783
wd_test(
@@ -231,11 +237,15 @@ def _wpt_wd_test_gen_impl(ctx):
231237
src = ctx.actions.declare_file("{}.wd-test".format(ctx.attr.test_name))
232238
base = ctx.attr.wpt_directory[WPTModuleInfo].base
233239

234-
# Generate bindings for test directory files plus common/**/*.js
240+
# Generate bindings for test directory files plus common/**/*.js, resources/**/*.js, and interfaces/**/*.idl
235241
bindings = generate_external_bindings(src, base, ctx.attr.wpt_directory.files)
236242
common_base = ctx.attr.wpt_common[WPTModuleInfo].base
237243
common_bindings = generate_common_bindings(src, common_base, ctx.attr.wpt_common.files)
238-
all_bindings = bindings + ",\n" + common_bindings if bindings and common_bindings else (bindings or common_bindings)
244+
resources_base = ctx.attr.wpt_resources[WPTModuleInfo].base
245+
resources_bindings = generate_resources_bindings(src, resources_base, ctx.attr.wpt_resources.files)
246+
interfaces_base = ctx.attr.wpt_interfaces[WPTModuleInfo].base
247+
interfaces_bindings = generate_interfaces_bindings(src, interfaces_base, ctx.attr.wpt_interfaces.files)
248+
all_bindings = ",\n".join([b for b in [bindings, common_bindings, resources_bindings, interfaces_bindings] if b])
239249
ctx.actions.write(
240250
output = src,
241251
content = WPT_WD_TEST_TEMPLATE.format(
@@ -271,6 +281,10 @@ _wpt_wd_test_gen = rule(
271281
"wpt_cacert": attr.label(allow_single_file = True),
272282
# Target specifying the WPT common directory module
273283
"wpt_common": attr.label(),
284+
# Target specifying the WPT resources directory module
285+
"wpt_resources": attr.label(),
286+
# Target specifying the WPT interfaces directory module
287+
"wpt_interfaces": attr.label(),
274288
# A list of autogates to specify in the generated wd-test file
275289
"autogates": attr.string_list(),
276290
# A list of compatibility flags to specify in the generated wd-test file
@@ -392,6 +406,59 @@ def generate_common_bindings(wd_test_file, base, files):
392406

393407
return ",\n".join(result)
394408

409+
def generate_resources_bindings(wd_test_file, base, files):
410+
"""
411+
Generates appropriate bindings for each file in the WPT resources module.
412+
Files are prefixed with /resources/ path.
413+
414+
Only JS files are included. Also adds an alias for /resources/WebIDLParser.js
415+
which points to /resources/webidl2/lib/webidl2.js (matching the WPT server
416+
rewrite rule in tools/serve/serve.py).
417+
"""
418+
419+
result = []
420+
webidl2_file = None
421+
422+
for file in files.to_list():
423+
if file.extension != "js":
424+
# Skip non-JS files
425+
continue
426+
427+
relative_path = module_relative_path(base, file)
428+
file_path = wd_test_relative_path(wd_test_file, file)
429+
result.append('(name = "/resources/{}", text = embed "{}")'.format(relative_path, file_path))
430+
431+
# Track the webidl2.js file for the alias
432+
if relative_path == "webidl2/lib/webidl2.js":
433+
webidl2_file = file_path
434+
435+
# Add the WebIDLParser.js alias (WPT server rewrites this to webidl2/lib/webidl2.js)
436+
if webidl2_file:
437+
result.append('(name = "/resources/WebIDLParser.js", text = embed "{}")'.format(webidl2_file))
438+
439+
return ",\n".join(result)
440+
441+
def generate_interfaces_bindings(wd_test_file, base, files):
442+
"""
443+
Generates appropriate bindings for each file in the WPT interfaces module.
444+
Files are prefixed with /interfaces/ path.
445+
446+
Only IDL files are included (*.idl) which are used by idlharness tests.
447+
"""
448+
449+
result = []
450+
451+
for file in files.to_list():
452+
if file.extension != "idl":
453+
# Skip non-IDL files
454+
continue
455+
456+
relative_path = module_relative_path(base, file)
457+
file_path = wd_test_relative_path(wd_test_file, file)
458+
result.append('(name = "/interfaces/{}", text = embed "{}")'.format(relative_path, file_path))
459+
460+
return ",\n".join(result)
461+
395462
def generate_harness_modules(wd_test_file, files):
396463
"""
397464
Generates a module entry for each file in the harness package

src/wpt/WebCryptoAPI-test.ts

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,79 @@ export default {
212212
],
213213
},
214214
'idlharness.https.any.js': {
215-
comment: 'Test file /resources/WebIDLParser.js not found.',
216-
disabledTests: true,
215+
comment: 'TODO investigate this',
216+
expectedFailures: [
217+
'Crypto interface: existence and properties of interface object',
218+
'Crypto interface object length',
219+
'Crypto interface object name',
220+
'Crypto interface: existence and properties of interface prototype object',
221+
'Crypto interface: existence and properties of interface prototype object\'s "constructor" property',
222+
"Crypto interface: existence and properties of interface prototype object's @@unscopables property",
223+
'Crypto interface: attribute subtle',
224+
'Crypto interface: operation getRandomValues(ArrayBufferView)',
225+
'Crypto interface: operation randomUUID()',
226+
'Crypto must be primary interface of crypto',
227+
'Stringification of crypto',
228+
'Crypto interface: crypto must inherit property "subtle" with the proper type',
229+
'Crypto interface: crypto must inherit property "getRandomValues(ArrayBufferView)" with the proper type',
230+
'Crypto interface: calling getRandomValues(ArrayBufferView) on crypto with too few arguments must throw TypeError',
231+
'Crypto interface: crypto must inherit property "randomUUID()" with the proper type',
232+
'CryptoKey interface: existence and properties of interface object',
233+
'CryptoKey interface object length',
234+
'CryptoKey interface object name',
235+
'CryptoKey interface: existence and properties of interface prototype object',
236+
'CryptoKey interface: existence and properties of interface prototype object\'s "constructor" property',
237+
"CryptoKey interface: existence and properties of interface prototype object's @@unscopables property",
238+
'CryptoKey interface: attribute type',
239+
'CryptoKey interface: attribute extractable',
240+
'CryptoKey interface: attribute algorithm',
241+
'CryptoKey interface: attribute usages',
242+
'SubtleCrypto interface: existence and properties of interface object',
243+
'SubtleCrypto interface object length',
244+
'SubtleCrypto interface object name',
245+
'SubtleCrypto interface: existence and properties of interface prototype object',
246+
'SubtleCrypto interface: existence and properties of interface prototype object\'s "constructor" property',
247+
"SubtleCrypto interface: existence and properties of interface prototype object's @@unscopables property",
248+
'SubtleCrypto interface: operation encrypt(AlgorithmIdentifier, CryptoKey, BufferSource)',
249+
'SubtleCrypto interface: operation decrypt(AlgorithmIdentifier, CryptoKey, BufferSource)',
250+
'SubtleCrypto interface: operation sign(AlgorithmIdentifier, CryptoKey, BufferSource)',
251+
'SubtleCrypto interface: operation verify(AlgorithmIdentifier, CryptoKey, BufferSource, BufferSource)',
252+
'SubtleCrypto interface: operation digest(AlgorithmIdentifier, BufferSource)',
253+
'SubtleCrypto interface: operation generateKey(AlgorithmIdentifier, boolean, sequence<KeyUsage>)',
254+
'SubtleCrypto interface: operation deriveKey(AlgorithmIdentifier, CryptoKey, AlgorithmIdentifier, boolean, sequence<KeyUsage>)',
255+
'SubtleCrypto interface: operation deriveBits(AlgorithmIdentifier, CryptoKey, optional unsigned long?)',
256+
'SubtleCrypto interface: operation importKey(KeyFormat, (BufferSource or JsonWebKey), AlgorithmIdentifier, boolean, sequence<KeyUsage>)',
257+
'SubtleCrypto interface: operation exportKey(KeyFormat, CryptoKey)',
258+
'SubtleCrypto interface: operation wrapKey(KeyFormat, CryptoKey, CryptoKey, AlgorithmIdentifier)',
259+
'SubtleCrypto interface: operation unwrapKey(KeyFormat, BufferSource, CryptoKey, AlgorithmIdentifier, AlgorithmIdentifier, boolean, sequence<KeyUsage>)',
260+
'SubtleCrypto must be primary interface of crypto.subtle',
261+
'Stringification of crypto.subtle',
262+
'SubtleCrypto interface: crypto.subtle must inherit property "encrypt(AlgorithmIdentifier, CryptoKey, BufferSource)" with the proper type',
263+
'SubtleCrypto interface: calling encrypt(AlgorithmIdentifier, CryptoKey, BufferSource) on crypto.subtle with too few arguments must throw TypeError',
264+
'SubtleCrypto interface: crypto.subtle must inherit property "decrypt(AlgorithmIdentifier, CryptoKey, BufferSource)" with the proper type',
265+
'SubtleCrypto interface: calling decrypt(AlgorithmIdentifier, CryptoKey, BufferSource) on crypto.subtle with too few arguments must throw TypeError',
266+
'SubtleCrypto interface: crypto.subtle must inherit property "sign(AlgorithmIdentifier, CryptoKey, BufferSource)" with the proper type',
267+
'SubtleCrypto interface: calling sign(AlgorithmIdentifier, CryptoKey, BufferSource) on crypto.subtle with too few arguments must throw TypeError',
268+
'SubtleCrypto interface: crypto.subtle must inherit property "verify(AlgorithmIdentifier, CryptoKey, BufferSource, BufferSource)" with the proper type',
269+
'SubtleCrypto interface: calling verify(AlgorithmIdentifier, CryptoKey, BufferSource, BufferSource) on crypto.subtle with too few arguments must throw TypeError',
270+
'SubtleCrypto interface: crypto.subtle must inherit property "digest(AlgorithmIdentifier, BufferSource)" with the proper type',
271+
'SubtleCrypto interface: calling digest(AlgorithmIdentifier, BufferSource) on crypto.subtle with too few arguments must throw TypeError',
272+
'SubtleCrypto interface: crypto.subtle must inherit property "generateKey(AlgorithmIdentifier, boolean, sequence<KeyUsage>)" with the proper type',
273+
'SubtleCrypto interface: calling generateKey(AlgorithmIdentifier, boolean, sequence<KeyUsage>) on crypto.subtle with too few arguments must throw TypeError',
274+
'SubtleCrypto interface: crypto.subtle must inherit property "deriveKey(AlgorithmIdentifier, CryptoKey, AlgorithmIdentifier, boolean, sequence<KeyUsage>)" with the proper type',
275+
'SubtleCrypto interface: calling deriveKey(AlgorithmIdentifier, CryptoKey, AlgorithmIdentifier, boolean, sequence<KeyUsage>) on crypto.subtle with too few arguments must throw TypeError',
276+
'SubtleCrypto interface: crypto.subtle must inherit property "deriveBits(AlgorithmIdentifier, CryptoKey, optional unsigned long?)" with the proper type',
277+
'SubtleCrypto interface: calling deriveBits(AlgorithmIdentifier, CryptoKey, optional unsigned long?) on crypto.subtle with too few arguments must throw TypeError',
278+
'SubtleCrypto interface: crypto.subtle must inherit property "importKey(KeyFormat, (BufferSource or JsonWebKey), AlgorithmIdentifier, boolean, sequence<KeyUsage>)" with the proper type',
279+
'SubtleCrypto interface: calling importKey(KeyFormat, (BufferSource or JsonWebKey), AlgorithmIdentifier, boolean, sequence<KeyUsage>) on crypto.subtle with too few arguments must throw TypeError',
280+
'SubtleCrypto interface: crypto.subtle must inherit property "exportKey(KeyFormat, CryptoKey)" with the proper type',
281+
'SubtleCrypto interface: calling exportKey(KeyFormat, CryptoKey) on crypto.subtle with too few arguments must throw TypeError',
282+
'SubtleCrypto interface: crypto.subtle must inherit property "wrapKey(KeyFormat, CryptoKey, CryptoKey, AlgorithmIdentifier)" with the proper type',
283+
'SubtleCrypto interface: calling wrapKey(KeyFormat, CryptoKey, CryptoKey, AlgorithmIdentifier) on crypto.subtle with too few arguments must throw TypeError',
284+
'SubtleCrypto interface: crypto.subtle must inherit property "unwrapKey(KeyFormat, BufferSource, CryptoKey, AlgorithmIdentifier, AlgorithmIdentifier, boolean, sequence<KeyUsage>)" with the proper type',
285+
'SubtleCrypto interface: calling unwrapKey(KeyFormat, BufferSource, CryptoKey, AlgorithmIdentifier, AlgorithmIdentifier, boolean, sequence<KeyUsage>) on crypto.subtle with too few arguments must throw TypeError',
286+
'Window interface: attribute crypto',
287+
],
217288
},
218289

219290
'import_export/crashtests/importKey-unsettled-promise.https.any.js': {},

src/wpt/compression-test.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,26 @@ export default {
5353
],
5454
},
5555
'idlharness.https.any.js': {
56-
comment: 'Test file /resources/WebIDLParser.js not found',
57-
disabledTests: true,
56+
comment:
57+
'Workers expose globals differently than browsers - these interface tests fail',
58+
expectedFailures: [
59+
'CompressionStream interface: existence and properties of interface object',
60+
'CompressionStream interface object length',
61+
'CompressionStream interface object name',
62+
'CompressionStream interface: existence and properties of interface prototype object',
63+
'CompressionStream interface: existence and properties of interface prototype object\'s "constructor" property',
64+
"CompressionStream interface: existence and properties of interface prototype object's @@unscopables property",
65+
'CompressionStream must be primary interface of new CompressionStream("deflate")',
66+
'Stringification of new CompressionStream("deflate")',
67+
'DecompressionStream interface: existence and properties of interface object',
68+
'DecompressionStream interface object length',
69+
'DecompressionStream interface object name',
70+
'DecompressionStream interface: existence and properties of interface prototype object',
71+
'DecompressionStream interface: existence and properties of interface prototype object\'s "constructor" property',
72+
"DecompressionStream interface: existence and properties of interface prototype object's @@unscopables property",
73+
'DecompressionStream must be primary interface of new DecompressionStream("deflate")',
74+
'Stringification of new DecompressionStream("deflate")',
75+
],
5876
},
5977
'third_party/pako/pako_inflate.min.js': {},
6078
} satisfies TestRunnerConfig;

src/wpt/encoding-test.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,59 @@ export default {
1414
expectedFailures: ['encodeInto() and a detached output buffer'],
1515
},
1616
'idlharness.any.js': {
17-
comment: 'Test file /resources/WebIDLParser.js not found',
18-
disabledTests: true,
17+
comment:
18+
'Workers expose globals differently than browsers - these interface tests fail',
19+
expectedFailures: [
20+
'TextDecoder interface: existence and properties of interface object',
21+
'TextDecoder interface object length',
22+
'TextDecoder interface object name',
23+
'TextDecoder interface: existence and properties of interface prototype object',
24+
'TextDecoder interface: existence and properties of interface prototype object\'s "constructor" property',
25+
"TextDecoder interface: existence and properties of interface prototype object's @@unscopables property",
26+
'TextDecoder interface: operation decode(optional AllowSharedBufferSource, optional TextDecodeOptions)',
27+
'TextDecoder interface: attribute encoding',
28+
'TextDecoder interface: attribute fatal',
29+
'TextDecoder interface: attribute ignoreBOM',
30+
'TextDecoder must be primary interface of new TextDecoder()',
31+
'Stringification of new TextDecoder()',
32+
'TextDecoder interface: new TextDecoder() must inherit property "decode(optional AllowSharedBufferSource, optional TextDecodeOptions)" with the proper type',
33+
'TextDecoder interface: calling decode(optional AllowSharedBufferSource, optional TextDecodeOptions) on new TextDecoder() with too few arguments must throw TypeError',
34+
'TextDecoder interface: new TextDecoder() must inherit property "encoding" with the proper type',
35+
'TextDecoder interface: new TextDecoder() must inherit property "fatal" with the proper type',
36+
'TextDecoder interface: new TextDecoder() must inherit property "ignoreBOM" with the proper type',
37+
'TextEncoder interface: existence and properties of interface object',
38+
'TextEncoder interface object length',
39+
'TextEncoder interface object name',
40+
'TextEncoder interface: existence and properties of interface prototype object',
41+
'TextEncoder interface: existence and properties of interface prototype object\'s "constructor" property',
42+
"TextEncoder interface: existence and properties of interface prototype object's @@unscopables property",
43+
'TextEncoder interface: operation encode(optional USVString)',
44+
'TextEncoder interface: operation encodeInto(USVString, Uint8Array)',
45+
'TextEncoder interface: attribute encoding',
46+
'TextEncoder must be primary interface of new TextEncoder()',
47+
'Stringification of new TextEncoder()',
48+
'TextEncoder interface: new TextEncoder() must inherit property "encode(optional USVString)" with the proper type',
49+
'TextEncoder interface: calling encode(optional USVString) on new TextEncoder() with too few arguments must throw TypeError',
50+
'TextEncoder interface: new TextEncoder() must inherit property "encodeInto(USVString, Uint8Array)" with the proper type',
51+
'TextEncoder interface: calling encodeInto(USVString, Uint8Array) on new TextEncoder() with too few arguments must throw TypeError',
52+
'TextEncoder interface: new TextEncoder() must inherit property "encoding" with the proper type',
53+
'TextDecoderStream interface: existence and properties of interface object',
54+
'TextDecoderStream interface object length',
55+
'TextDecoderStream interface object name',
56+
'TextDecoderStream interface: existence and properties of interface prototype object',
57+
'TextDecoderStream interface: existence and properties of interface prototype object\'s "constructor" property',
58+
"TextDecoderStream interface: existence and properties of interface prototype object's @@unscopables property",
59+
'TextDecoderStream interface: attribute encoding',
60+
'TextDecoderStream interface: attribute fatal',
61+
'TextDecoderStream interface: attribute ignoreBOM',
62+
'TextEncoderStream interface: existence and properties of interface object',
63+
'TextEncoderStream interface object length',
64+
'TextEncoderStream interface object name',
65+
'TextEncoderStream interface: existence and properties of interface prototype object',
66+
'TextEncoderStream interface: existence and properties of interface prototype object\'s "constructor" property',
67+
"TextEncoderStream interface: existence and properties of interface prototype object's @@unscopables property",
68+
'TextEncoderStream interface: attribute encoding',
69+
],
1970
},
2071
'iso-2022-jp-decoder.any.js': {
2172
comment: 'TODO investigate this',

0 commit comments

Comments
 (0)