Files
sousa-gecko/testing/web-platform/mozilla/tests/compression/zstd/decompression-constructor.tentative.any.js
T
Erik Nordin a1eac30f1a Bug 1947431 - Implement ZstdDecompressionAlgorithms r=saschanaz,jesup
This patch introduces a DecompressionStreamAlgorithms abstract base
class, which is implemented by ZLibDecompressionStreamAlgorithms and
ZstdDecompressionStreamAlgorithms.

It also introduces a new static pref for the "zstd" format to be used
with CompressionStream and DecompressionStream, and introduces new WPTs
for zstd DecompressionStream with equivalent coverage to those for ZLib.

Differential Revision: https://phabricator.services.mozilla.com/D238685
2025-03-03 21:26:53 +00:00

93 lines
2.5 KiB
JavaScript

// META: global=window
"use strict";
promise_test(async t => {
t.add_cleanup(async () => {
await SpecialPowers.popPrefEnv();
});
await SpecialPowers.pushPrefEnv({
set: [["dom.compression_streams.zstd.enabled", false]],
});
assert_throws_js(
TypeError,
() => new DecompressionStream("zstd"),
'Constructor given "zstd" should throw'
);
}, '"zstd" should be an invalid DecompressionStream format in an unprivileged context with the pref set to false');
promise_test(async t => {
t.add_cleanup(async () => {
await SpecialPowers.popPrefEnv();
});
await SpecialPowers.pushPrefEnv({
set: [["dom.compression_streams.zstd.enabled", true]],
});
const ds = new DecompressionStream("zstd");
assert_equals(ds.constructor.name, "DecompressionStream", "");
}, '"zstd" should be a valid DecompressionStream format in an unprivileged context with the pref set to true');
promise_test(async t => {
t.add_cleanup(async () => {
await SpecialPowers.popPrefEnv();
});
await SpecialPowers.pushPrefEnv({
set: [["dom.compression_streams.zstd.enabled", true]],
});
const constructorSucceeded = await SpecialPowers.spawnChrome(
[],
() => {
const ds = new this.browsingContext.topChromeWindow.DecompressionStream(
"zstd"
);
if (!ds) {
throw new Error(
'Failed to construct DecompressionStream with "zstd" format in privileged context.'
);
}
return true;
}
);
assert_true(
constructorSucceeded,
'Constructor given "zstd" should succeed in a privileged context'
);
}, '"zstd" should be a valid DecompressionStream format in a privileged context with the pref set to false');
promise_test(async t => {
t.add_cleanup(async () => {
await SpecialPowers.popPrefEnv();
});
await SpecialPowers.pushPrefEnv({
set: [["dom.compression_streams.zstd.enabled", true]],
});
const constructorSucceeded = await SpecialPowers.spawnChrome(
[],
() => {
const ds = new this.browsingContext.topChromeWindow.DecompressionStream(
"zstd"
);
if (!ds) {
throw new Error(
'Failed to construct DecompressionStream with "zstd" format in privileged context.'
);
}
return true;
}
);
assert_true(
constructorSucceeded,
'Constructor given "zstd" should succeed in a privileged context'
);
}, '"zstd" should be a valid DecompressionStream format in a privileged context with the pref set to true');