compression-constructor.tentative.any.js (2516B)
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 CompressionStream("zstd"), 16 'Constructor given "zstd" should throw' 17 ); 18 }, '"zstd" should be an invalid CompressionStream 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 assert_throws_js( 29 TypeError, 30 () => new CompressionStream("zstd"), 31 'Constructor given "zstd" should throw' 32 ); 33 }, '"zstd" should be an invalid CompressionStream format in an unprivileged context with the pref set to true'); 34 35 promise_test(async t => { 36 t.add_cleanup(async () => { 37 await SpecialPowers.popPrefEnv(); 38 }); 39 await SpecialPowers.pushPrefEnv({ 40 set: [["dom.compression_streams.zstd.enabled", false]], 41 }); 42 43 const constructorFailed = await SpecialPowers.spawnChrome([], () => { 44 let cs; 45 46 try { 47 cs = new this.browsingContext.topChromeWindow.CompressionStream("zstd"); 48 } catch { 49 return true; 50 } 51 52 if (cs) { 53 throw new Error( 54 'Constructed a CompressionStream with "zstd" format, when that should be disallowed' 55 ); 56 } 57 }); 58 59 assert_true( 60 constructorFailed, 61 'Constructor given "zstd" should throw, even in a privileged context' 62 ); 63 }, '"zstd" should be an invalid CompressionStream format in a privileged context with the pref set to false'); 64 65 promise_test(async t => { 66 t.add_cleanup(async () => { 67 await SpecialPowers.popPrefEnv(); 68 }); 69 await SpecialPowers.pushPrefEnv({ 70 set: [["dom.compression_streams.zstd.enabled", true]], 71 }); 72 73 const constructorFailed = await SpecialPowers.spawnChrome([], () => { 74 let cs; 75 76 try { 77 cs = new this.browsingContext.topChromeWindow.CompressionStream("zstd"); 78 } catch { 79 return true; 80 } 81 82 if (cs) { 83 throw new Error( 84 'Constructed a CompressionStream with "zstd" format, when that should be disallowed' 85 ); 86 } 87 }); 88 89 assert_true( 90 constructorFailed, 91 'Constructor given "zstd" should throw, even in a privileged context' 92 ); 93 }, '"zstd" should be an invalid CompressionStream format in a privileged context with the pref set to true');