From f4b0ea4ace5c75d6ed0547be886466bb0c09ba7d Mon Sep 17 00:00:00 2001 From: Bryan Thrall Date: Tue, 17 May 2022 16:29:04 +0000 Subject: [PATCH] Bug 1757833 - Add mochitest for compressed bytecode caching r=nbp Differential Revision: https://phabricator.services.mozilla.com/D145346 --- .../test/test_script_loader_js_cache.html | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/dom/base/test/test_script_loader_js_cache.html b/dom/base/test/test_script_loader_js_cache.html index ae9c08e9f99e..de168ad109ca 100644 --- a/dom/base/test/test_script_loader_js_cache.html +++ b/dom/base/test/test_script_loader_js_cache.html @@ -231,6 +231,30 @@ }, "Do not save bytecode on compilation errors"); + promise_test(async function() { + // (see above) + await SpecialPowers.pushPrefEnv({set: [ + ['dom.script_loader.bytecode_cache.enabled', true], + ['dom.expose_test_interfaces', true], + ['dom.script_loader.bytecode_cache.strategy', -1], + ['browser.cache.jsbc_compression_level', 2] + ]}); + + // Load the test page, and verify that the code path taken by the + // nsScriptLoadRequest corresponds to the code path which is loading a + // source and saving it as compressed bytecode. + var stateMachineResult = WaitForScriptTagEvent(`file_js_cache.html`); + assert_equals(await stateMachineResult, `bytecode_saved`, + `[1-script] ScriptLoadRequest status after the first visit`); + + // Reload the same test page, and verify that the code path taken by + // the nsScriptLoadRequest corresponds to the code path which is + // loading compressed bytecode, decompressing it, and executing it. + stateMachineResult = WaitForScriptTagEvent(`file_js_cache.html`); + assert_equals(await stateMachineResult, `bytecode_exec`, + `[2-script] ScriptLoadRequest status after the second visit`); + }, "Check the JS bytecode cache can save and load compressed bytecode"); + done();