| 1 |
// META: global=window |
| 2 |
|
| 3 |
"use strict"; |
| 4 |
|
| 5 |
promise_test(async t => { |
| 6 |
t.add_cleanup(async () => { |
| 7 |
await SpecialPowers.popPrefEnv(); |
| 8 |
}); |
| 9 |
await SpecialPowers.pushPrefEnv({ |
| 10 |
set: [["dom.compression_streams.zstd.enabled", false]], |
| 11 |
}); |
| 12 |
|
| 13 |
assert_throws_js( |
| 14 |
TypeError, |
| 15 |
() => new DecompressionStream("zstd"), |
| 16 |
'Constructor given "zstd" should throw' |
| 17 |
); |
| 18 |
}, '"zstd" should be an invalid DecompressionStream format in an unprivileged context with the pref set to false'); |
| 19 |
|
| 20 |
promise_test(async t => { |
| 21 |
t.add_cleanup(async () => { |
| 22 |
await SpecialPowers.popPrefEnv(); |
| 23 |
}); |
| 24 |
await SpecialPowers.pushPrefEnv({ |
| 25 |
set: [["dom.compression_streams.zstd.enabled", true]], |
| 26 |
}); |
| 27 |
|
| 28 |
const ds = new DecompressionStream("zstd"); |
| 29 |
assert_equals(ds.constructor.name, "DecompressionStream", ""); |
| 30 |
}, '"zstd" should be a valid DecompressionStream format in an unprivileged context with the pref set to true'); |
| 31 |
|
| 32 |
promise_test(async t => { |
| 33 |
t.add_cleanup(async () => { |
| 34 |
await SpecialPowers.popPrefEnv(); |
| 35 |
}); |
| 36 |
await SpecialPowers.pushPrefEnv({ |
| 37 |
set: [["dom.compression_streams.zstd.enabled", true]], |
| 38 |
}); |
| 39 |
|
| 40 |
const constructorSucceeded = await SpecialPowers.spawnChrome( |
| 41 |
[], |
| 42 |
() => { |
| 43 |
const ds = new this.browsingContext.topChromeWindow.DecompressionStream( |
| 44 |
"zstd" |
| 45 |
); |
| 46 |
|
| 47 |
if (!ds) { |
| 48 |
throw new Error( |
| 49 |
'Failed to construct DecompressionStream with "zstd" format in privileged context.' |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
return true; |
| 54 |
} |
| 55 |
); |
| 56 |
|
| 57 |
assert_true( |
| 58 |
constructorSucceeded, |
| 59 |
'Constructor given "zstd" should succeed in a privileged context' |
| 60 |
); |
| 61 |
}, '"zstd" should be a valid DecompressionStream format in a privileged context with the pref set to false'); |
| 62 |
|
| 63 |
promise_test(async t => { |
| 64 |
t.add_cleanup(async () => { |
| 65 |
await SpecialPowers.popPrefEnv(); |
| 66 |
}); |
| 67 |
await SpecialPowers.pushPrefEnv({ |
| 68 |
set: [["dom.compression_streams.zstd.enabled", true]], |
| 69 |
}); |
| 70 |
|
| 71 |
const constructorSucceeded = await SpecialPowers.spawnChrome( |
| 72 |
[], |
| 73 |
() => { |
| 74 |
const ds = new this.browsingContext.topChromeWindow.DecompressionStream( |
| 75 |
"zstd" |
| 76 |
); |
| 77 |
|
| 78 |
if (!ds) { |
| 79 |
throw new Error( |
| 80 |
'Failed to construct DecompressionStream with "zstd" format in privileged context.' |
| 81 |
); |
| 82 |
} |
| 83 |
|
| 84 |
return true; |
| 85 |
} |
| 86 |
); |
| 87 |
|
| 88 |
assert_true( |
| 89 |
constructorSucceeded, |
| 90 |
'Constructor given "zstd" should succeed in a privileged context' |
| 91 |
); |
| 92 |
}, '"zstd" should be a valid DecompressionStream format in a privileged context with the pref set to true'); |