diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/components/aboutmemory/tests/test_aboutmemory4.xul | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/aboutmemory/tests/test_aboutmemory4.xul')
-rw-r--r-- | toolkit/components/aboutmemory/tests/test_aboutmemory4.xul | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/toolkit/components/aboutmemory/tests/test_aboutmemory4.xul b/toolkit/components/aboutmemory/tests/test_aboutmemory4.xul new file mode 100644 index 000000000..f2c752ac5 --- /dev/null +++ b/toolkit/components/aboutmemory/tests/test_aboutmemory4.xul @@ -0,0 +1,179 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<window title="about:memory" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> + + <!-- This file tests the loading of memory reports from file when specified + in about:memory's URL (via the "file=" suffix). --> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"></body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + "use strict"; + + function makePathname(aFilename) { + let file = Components.classes["@mozilla.org/file/directory_service;1"] + .getService(Components.interfaces.nsIProperties) + .get("CurWorkD", Components.interfaces.nsIFile); + file.append("chrome"); + file.append("toolkit"); + file.append("components"); + file.append("aboutmemory"); + file.append("tests"); + file.append(aFilename); + return file.path; + } + + // Load the given file into the frame, then copy+paste the entire frame and + // check that the cut text matches what we expect. + function test(aFilename, aExpected, aNext) { + let frame = document.createElementNS("http://www.w3.org/1999/xhtml", "iframe") + frame.height = 300; + frame.src = "about:memory?file=" + makePathname(aFilename); + document.documentElement.appendChild(frame); + frame.focus(); + + // Initialize the clipboard contents. + SpecialPowers.clipboardCopyString("initial clipboard value"); + + let numFailures = 0, maxFailures = 30; + + // Because the file load is async, we don't know when it will finish and + // the output will show up. So we poll. + function copyPasteAndCheck() { + // Copy and paste frame contents, and filter out non-deterministic + // differences. + synthesizeKey("A", {accelKey: true}); + synthesizeKey("C", {accelKey: true}); + let actual = SpecialPowers.getClipboardData("text/unicode"); + actual = actual.replace(/\(pid \d+\)/, "(pid NNN)"); + + if (actual.trim() === aExpected.trim()) { + SimpleTest.ok(true, "Clipboard has the expected contents"); + aNext(); + } else { + numFailures++; + if (numFailures === maxFailures) { + ok(false, "pasted text doesn't match"); + dump("******EXPECTED******\n"); + dump(aExpected); + dump("*******ACTUAL*******\n"); + dump(actual); + dump("********************\n"); + SimpleTest.finish(); + } else { + setTimeout(copyPasteAndCheck, 100); + } + } + } + copyPasteAndCheck(); + } + + // Returns a function that chains together multiple test() calls. + function chain(aFrameIds) { + let x = aFrameIds.shift(); + if (x) { + return function() { test(x.filename, x.expected, chain(aFrameIds)); } + } else { + return function() { SimpleTest.finish(); }; + } + } + + // This is pretty simple output, but that's ok; this file is about testing + // the loading of data from file. If we got this far, we're doing fine. + let expectedGood = +"\ +Explicit-only process\n\ +\n\ +WARNING: the 'heap-allocated' memory reporter does not work for this platform and/or configuration. This means that 'heap-unclassified' is not shown and the 'explicit' tree shows less memory than it should.\n\ +Explicit Allocations\n\ +\n\ +0.10 MB (100.0%) -- explicit\n\ +└──0.10 MB (100.0%) ── a/b\n\ +\n\ +Other Measurements\n\ +\n\ +End of Explicit-only process\n\ +Heap-unclassified process\n\ +Explicit Allocations\n\ +\n\ +250.00 MB (100.0%) -- explicit\n\ +├──200.00 MB (80.00%) ── heap-unclassified\n\ +└───50.00 MB (20.00%) ── a/b\n\ +\n\ +Other Measurements\n\ +\n\ +250.00 MB ── heap-allocated\n\ +\n\ +End of Heap-unclassified process\n\ +Main Process (pid NNN)\n\ +Explicit Allocations\n\ +\n\ +250.00 MB (100.0%) -- explicit\n\ +├──200.00 MB (80.00%) ── heap-unclassified\n\ +└───50.00 MB (20.00%) ── a/b\n\ +\n\ +Other Measurements\n\ +\n\ +0.00 MB (100.0%) -- compartments\n\ +└──0.00 MB (100.0%) ── system/a\n\ +\n\ +0.00 MB (100.0%) -- ghost-windows\n\ +└──0.00 MB (100.0%) ── a\n\ +\n\ +0.30 MB (100.0%) -- other\n\ +├──0.20 MB (66.67%) ── a\n\ +└──0.10 MB (33.33%) ── b\n\ +\n\ +0.00 MB (100.0%) -- pss\n\ +└──0.00 MB (100.0%) ── a\n\ +\n\ +0.00 MB (100.0%) -- rss\n\ +└──0.00 MB (100.0%) ── a\n\ +\n\ +0.00 MB (100.0%) -- size\n\ +└──0.00 MB (100.0%) ── a\n\ +\n\ +0.00 MB (100.0%) -- swap\n\ +└──0.00 MB (100.0%) ── a\n\ +\n\ +250.00 MB ── heap-allocated\n\ +\n\ +End of Main Process (pid NNN)\n\ +Other-only process\n\ +Other Measurements\n\ +\n\ +0.19 MB (100.0%) -- a\n\ +├──0.10 MB (50.00%) ── b\n\ +└──0.10 MB (50.00%) ── c\n\ +\n\ +0.48 MB ── heap-allocated\n\ +\n\ +End of Other-only process\n\ +"; + + // This is the output for a malformed data file. + let expectedBad = +"\ +Error: Invalid memory report(s): missing 'hasMozMallocUsableSize' property"; + + let frames = [ + // This loads a pre-existing file that is valid. + { filename: "memory-reports-good.json", expected: expectedGood }, + + // This loads a pre-existing file that is valid. + { filename: "memory-reports-bad.json", expected: expectedBad } + ]; + + SimpleTest.waitForFocus(chain(frames)); + + SimpleTest.waitForExplicitFinish(); + ]]> + </script> +</window> |