diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/shared/tests/xpcshell/test_invisible_loader.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/shared/tests/xpcshell/test_invisible_loader.js')
-rw-r--r-- | devtools/shared/tests/xpcshell/test_invisible_loader.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/devtools/shared/tests/xpcshell/test_invisible_loader.js b/devtools/shared/tests/xpcshell/test_invisible_loader.js new file mode 100644 index 0000000000..d83efd9c2a --- /dev/null +++ b/devtools/shared/tests/xpcshell/test_invisible_loader.js @@ -0,0 +1,80 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { addDebuggerToGlobal } = ChromeUtils.importESModule( + "resource://gre/modules/jsdebugger.sys.mjs" +); +addDebuggerToGlobal(globalThis); + +/** + * Ensure that sandboxes created via the Dev Tools loader respect the + * invisibleToDebugger flag. + */ +function run_test() { + visible_loader(); + invisible_loader(); + // TODO: invisibleToDebugger should be deprecated in favor of + // useDistinctSystemPrincipalLoader, but we might move out from the loader + // to using only standard imports instead. + distinct_system_principal_loader(); +} + +function visible_loader() { + const loader = new DevToolsLoader({ + invisibleToDebugger: false, + }); + loader.require("resource://devtools/shared/indentation.js"); + + const dbg = new Debugger(); + const sandbox = loader.loader.sharedGlobal; + + try { + dbg.addDebuggee(sandbox); + Assert.ok(true); + } catch (e) { + do_throw("debugger could not add visible value"); + } +} + +function invisible_loader() { + const loader = new DevToolsLoader({ + invisibleToDebugger: true, + }); + loader.require("resource://devtools/shared/indentation.js"); + + const dbg = new Debugger(); + const sandbox = loader.loader.sharedGlobal; + + try { + dbg.addDebuggee(sandbox); + do_throw("debugger added invisible value"); + } catch (e) { + Assert.ok(true); + } +} + +function distinct_system_principal_loader() { + const { + useDistinctSystemPrincipalLoader, + releaseDistinctSystemPrincipalLoader, + } = ChromeUtils.importESModule( + "resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs" + ); + + const requester = {}; + const loader = useDistinctSystemPrincipalLoader(requester); + loader.require("resource://devtools/shared/indentation.js"); + + const dbg = new Debugger(); + const sandbox = loader.loader.sharedGlobal; + + try { + dbg.addDebuggee(sandbox); + do_throw("debugger added invisible value"); + } catch (e) { + Assert.ok(true); + } + releaseDistinctSystemPrincipalLoader(requester); +} |