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/heapsnapshot/tests/xpcshell/test_SaveHeapSnapshot.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/shared/heapsnapshot/tests/xpcshell/test_SaveHeapSnapshot.js')
-rw-r--r-- | devtools/shared/heapsnapshot/tests/xpcshell/test_SaveHeapSnapshot.js | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/devtools/shared/heapsnapshot/tests/xpcshell/test_SaveHeapSnapshot.js b/devtools/shared/heapsnapshot/tests/xpcshell/test_SaveHeapSnapshot.js new file mode 100644 index 0000000000..33367af7f7 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/xpcshell/test_SaveHeapSnapshot.js @@ -0,0 +1,121 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test the ChromeUtils interface. +// eslint-disable-next-line +if (typeof Debugger != "function") { + const { addDebuggerToGlobal } = ChromeUtils.importESModule( + "resource://gre/modules/jsdebugger.sys.mjs" + ); + addDebuggerToGlobal(globalThis); +} + +function run_test() { + ok(ChromeUtils, "Should be able to get the ChromeUtils interface"); + + testBadParameters(); + testGoodParameters(); + + do_test_finished(); +} + +function testBadParameters() { + Assert.throws( + () => ChromeUtils.saveHeapSnapshot(), + /NS_ERROR_ILLEGAL_VALUE/, + "Should throw if arguments aren't passed in." + ); + + Assert.throws( + () => ChromeUtils.saveHeapSnapshot(null), + /NS_ERROR_ILLEGAL_VALUE/, + "Should throw if boundaries isn't an object." + ); + + Assert.throws( + () => ChromeUtils.saveHeapSnapshot({}), + /NS_ERROR_ILLEGAL_VALUE/, + "Should throw if the boundaries object doesn't have any properties." + ); + + Assert.throws( + () => ChromeUtils.saveHeapSnapshot({ runtime: true, globals: [this] }), + /NS_ERROR_ILLEGAL_VALUE/, + "Should throw if the boundaries object has more than one property." + ); + + Assert.throws( + () => ChromeUtils.saveHeapSnapshot({ debugger: {} }), + /NS_ERROR_ILLEGAL_VALUE/, + "Should throw if the debuggees object is not a Debugger object" + ); + + Assert.throws( + () => ChromeUtils.saveHeapSnapshot({ globals: [{}] }), + /NS_ERROR_ILLEGAL_VALUE/, + "Should throw if the globals array contains non-global objects." + ); + + Assert.throws( + () => ChromeUtils.saveHeapSnapshot({ runtime: false }), + /NS_ERROR_ILLEGAL_VALUE/, + "Should throw if runtime is supplied and is not true." + ); + + Assert.throws( + () => ChromeUtils.saveHeapSnapshot({ globals: null }), + /TypeError:.*can't be converted to a sequence/, + "Should throw if globals is not an object." + ); + + Assert.throws( + () => ChromeUtils.saveHeapSnapshot({ globals: {} }), + /TypeError:.*can't be converted to a sequence/, + "Should throw if globals is not an array." + ); + + Assert.throws( + () => ChromeUtils.saveHeapSnapshot({ debugger: Debugger.prototype }), + /NS_ERROR_ILLEGAL_VALUE/, + "Should throw if debugger is the Debugger.prototype object." + ); + + Assert.throws( + () => + ChromeUtils.saveHeapSnapshot({ + get globals() { + return [this]; + }, + }), + /NS_ERROR_ILLEGAL_VALUE/, + "Should throw if boundaries property is a getter." + ); +} + +const makeNewSandbox = () => + Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")()); + +function testGoodParameters() { + const sandbox = makeNewSandbox(); + let dbg = new Debugger(sandbox); + + ChromeUtils.saveHeapSnapshot({ debugger: dbg }); + ok(true, "Should be able to save a snapshot for a debuggee global."); + + dbg = new Debugger(); + const sandboxes = Array(10).fill(null).map(makeNewSandbox); + sandboxes.forEach(sb => dbg.addDebuggee(sb)); + + ChromeUtils.saveHeapSnapshot({ debugger: dbg }); + ok(true, "Should be able to save a snapshot for many debuggee globals."); + + dbg = new Debugger(); + ChromeUtils.saveHeapSnapshot({ debugger: dbg }); + ok(true, "Should be able to save a snapshot with no debuggee globals."); + + ChromeUtils.saveHeapSnapshot({ globals: [this] }); + ok(true, "Should be able to save a snapshot for a specific global."); + + ChromeUtils.saveHeapSnapshot({ runtime: true }); + ok(true, "Should be able to save a snapshot of the full runtime."); +} |