summaryrefslogtreecommitdiffstats
path: root/dom/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-02-22 17:32:39 -0500
committerMatt A. Tobin <email@mattatobin.com>2020-02-22 17:32:39 -0500
commit4e2e9be6abed3225406b466099e397acc0f914d2 (patch)
tree023551018892b8e76ae80e63a08d9d6a27c21a77 /dom/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js
parenta7888b8cf20691a4090715ab9b055ec3cb75f5e8 (diff)
downloadUXP-4e2e9be6abed3225406b466099e397acc0f914d2.tar
UXP-4e2e9be6abed3225406b466099e397acc0f914d2.tar.gz
UXP-4e2e9be6abed3225406b466099e397acc0f914d2.tar.lz
UXP-4e2e9be6abed3225406b466099e397acc0f914d2.tar.xz
UXP-4e2e9be6abed3225406b466099e397acc0f914d2.zip
Reclassify heapsnapshot and nsJSInspector as not part of devtools
This resolves Issue #316
Diffstat (limited to 'dom/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js')
-rw-r--r--dom/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/dom/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js b/dom/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js
new file mode 100644
index 000000000..affd8d1e4
--- /dev/null
+++ b/dom/heapsnapshot/tests/unit/test_SaveHeapSnapshot.js
@@ -0,0 +1,82 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test the ChromeUtils interface.
+
+if (typeof Debugger != "function") {
+ const { addDebuggerToGlobal } = Cu.import("resource://gre/modules/jsdebugger.jsm", {});
+ addDebuggerToGlobal(this);
+}
+
+function run_test() {
+ ok(ChromeUtils, "Should be able to get the ChromeUtils interface");
+
+ testBadParameters();
+ testGoodParameters();
+
+ do_test_finished();
+}
+
+function testBadParameters() {
+ throws(() => ChromeUtils.saveHeapSnapshot(),
+ "Should throw if arguments aren't passed in.");
+
+ throws(() => ChromeUtils.saveHeapSnapshot(null),
+ "Should throw if boundaries isn't an object.");
+
+ throws(() => ChromeUtils.saveHeapSnapshot({}),
+ "Should throw if the boundaries object doesn't have any properties.");
+
+ throws(() => ChromeUtils.saveHeapSnapshot({ runtime: true,
+ globals: [this] }),
+ "Should throw if the boundaries object has more than one property.");
+
+ throws(() => ChromeUtils.saveHeapSnapshot({ debugger: {} }),
+ "Should throw if the debuggees object is not a Debugger object");
+
+ throws(() => ChromeUtils.saveHeapSnapshot({ globals: [{}] }),
+ "Should throw if the globals array contains non-global objects.");
+
+ throws(() => ChromeUtils.saveHeapSnapshot({ runtime: false }),
+ "Should throw if runtime is supplied and is not true.");
+
+ throws(() => ChromeUtils.saveHeapSnapshot({ globals: null }),
+ "Should throw if globals is not an object.");
+
+ throws(() => ChromeUtils.saveHeapSnapshot({ globals: {} }),
+ "Should throw if globals is not an array.");
+
+ throws(() => ChromeUtils.saveHeapSnapshot({ debugger: Debugger.prototype }),
+ "Should throw if debugger is the Debugger.prototype object.");
+
+ throws(() => ChromeUtils.saveHeapSnapshot({ get globals() { return [this]; } }),
+ "Should throw if boundaries property is a getter.");
+}
+
+const makeNewSandbox = () =>
+ Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")());
+
+function testGoodParameters() {
+ let 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;
+ let 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.");
+}