Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
michael@0 | 3 | <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
michael@0 | 4 | <window title="about:memory" |
michael@0 | 5 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 6 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
michael@0 | 7 | <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 8 | |
michael@0 | 9 | <!-- This file tests the saving and loading of memory reports to/from file in |
michael@0 | 10 | about:memory in the presence of child processes. It is also notable |
michael@0 | 11 | for being an about:memory test that uses the real reporters, rather |
michael@0 | 12 | than fake deterministic ones, and so tends to show up problems in the |
michael@0 | 13 | real reporters (like bogus negative values). --> |
michael@0 | 14 | |
michael@0 | 15 | <!-- test results are displayed in the html:body --> |
michael@0 | 16 | <body xmlns="http://www.w3.org/1999/xhtml"></body> |
michael@0 | 17 | |
michael@0 | 18 | <iframe id="amFrame" height="400" src="about:memory"></iframe> |
michael@0 | 19 | |
michael@0 | 20 | <script type="application/javascript"> |
michael@0 | 21 | <![CDATA[ |
michael@0 | 22 | "use strict"; |
michael@0 | 23 | |
michael@0 | 24 | const Cc = Components.classes; |
michael@0 | 25 | const Ci = Components.interfaces; |
michael@0 | 26 | let mgr = Cc["@mozilla.org/memory-reporter-manager;1"]. |
michael@0 | 27 | getService(Ci.nsIMemoryReporterManager); |
michael@0 | 28 | |
michael@0 | 29 | let numRemotes = 3; |
michael@0 | 30 | let numReady = 0; |
michael@0 | 31 | |
michael@0 | 32 | // Create some remote processes, and set up message-passing so that |
michael@0 | 33 | // we know when each child is fully initialized. |
michael@0 | 34 | let remotes = []; |
michael@0 | 35 | |
michael@0 | 36 | let prefs = [ |
michael@0 | 37 | ["dom.ipc.processCount", 3], // Allow up to 3 child processes |
michael@0 | 38 | ["memory.system_memory_reporter", true] // Test SystemMemoryReporter |
michael@0 | 39 | ]; |
michael@0 | 40 | |
michael@0 | 41 | SpecialPowers.pushPrefEnv({"set": prefs}, function() { |
michael@0 | 42 | for (let i = 0; i < numRemotes; i++) { |
michael@0 | 43 | let w = remotes[i] = window.open("remote.xul", "", "chrome"); |
michael@0 | 44 | |
michael@0 | 45 | w.addEventListener("load", function loadHandler() { |
michael@0 | 46 | w.removeEventListener("load", loadHandler); |
michael@0 | 47 | let remoteBrowser = w.document.getElementById("remote"); |
michael@0 | 48 | let mm = remoteBrowser.messageManager; |
michael@0 | 49 | mm.addMessageListener("test:ready", function readyHandler() { |
michael@0 | 50 | mm.removeMessageListener("test:ready", readyHandler); |
michael@0 | 51 | numReady++; |
michael@0 | 52 | if (numReady == numRemotes) { |
michael@0 | 53 | // All the remote processes are ready. |
michael@0 | 54 | SimpleTest.waitForFocus(onFocus); |
michael@0 | 55 | } |
michael@0 | 56 | }); |
michael@0 | 57 | mm.loadFrameScript("data:," + encodeURI("sendAsyncMessage('test:ready');"), true); |
michael@0 | 58 | }); |
michael@0 | 59 | } |
michael@0 | 60 | }); |
michael@0 | 61 | |
michael@0 | 62 | // Load the given file into the frame, then copy+paste the entire frame and |
michael@0 | 63 | // check that the cut text matches what we expect. |
michael@0 | 64 | function onFocus() { |
michael@0 | 65 | let frame = document.getElementById("amFrame"); |
michael@0 | 66 | frame.focus(); |
michael@0 | 67 | |
michael@0 | 68 | function getFilePath(aFilename) { |
michael@0 | 69 | let file = Cc["@mozilla.org/file/directory_service;1"] |
michael@0 | 70 | .getService(Components.interfaces.nsIProperties) |
michael@0 | 71 | .get("CurWorkD", Components.interfaces.nsIFile); |
michael@0 | 72 | file.append("chrome"); |
michael@0 | 73 | file.append("toolkit"); |
michael@0 | 74 | file.append("components"); |
michael@0 | 75 | file.append("aboutmemory"); |
michael@0 | 76 | file.append("tests"); |
michael@0 | 77 | file.append(aFilename); |
michael@0 | 78 | return file.path; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | let filePath = getFilePath("memory-reports-dumped.json.gz"); |
michael@0 | 82 | |
michael@0 | 83 | let e = document.createEvent('Event'); |
michael@0 | 84 | e.initEvent('change', true, true); |
michael@0 | 85 | |
michael@0 | 86 | let dumper = Cc["@mozilla.org/memory-info-dumper;1"]. |
michael@0 | 87 | getService(Ci.nsIMemoryInfoDumper); |
michael@0 | 88 | dumper.dumpMemoryReportsToNamedFile(filePath, loadAndCheck, null); |
michael@0 | 89 | |
michael@0 | 90 | function loadAndCheck() { |
michael@0 | 91 | // Load the file. |
michael@0 | 92 | let fileInput1 = |
michael@0 | 93 | frame.contentWindow.document.getElementById("fileInput1"); |
michael@0 | 94 | fileInput1.value = filePath; // this works because it's a chrome test |
michael@0 | 95 | fileInput1.dispatchEvent(e); |
michael@0 | 96 | |
michael@0 | 97 | // Initialize the clipboard contents. |
michael@0 | 98 | SpecialPowers.clipboardCopyString("initial clipboard value"); |
michael@0 | 99 | |
michael@0 | 100 | let numFailures = 0, maxFailures = 30; |
michael@0 | 101 | |
michael@0 | 102 | copyPasteAndCheck(); |
michael@0 | 103 | |
michael@0 | 104 | // Because the file load is async, we don't know when it will finish and |
michael@0 | 105 | // the output will show up. So we poll. |
michael@0 | 106 | function copyPasteAndCheck() { |
michael@0 | 107 | // Copy and paste frame contents, and filter out non-deterministic |
michael@0 | 108 | // differences. |
michael@0 | 109 | synthesizeKey("A", {accelKey: true}); |
michael@0 | 110 | synthesizeKey("C", {accelKey: true}); |
michael@0 | 111 | let actual = SpecialPowers.getClipboardData("text/unicode"); |
michael@0 | 112 | |
michael@0 | 113 | // If we have more than 1000 chars, we've probably successfully |
michael@0 | 114 | // copy+pasted. |
michael@0 | 115 | if (actual.length > 1000) { |
michael@0 | 116 | |
michael@0 | 117 | let good = true; |
michael@0 | 118 | |
michael@0 | 119 | if (actual.match("End of System")) { |
michael@0 | 120 | let m1 = actual.match("anonymous") && |
michael@0 | 121 | actual.match("shared-libraries"); |
michael@0 | 122 | ok(m1, "system-wide reporter") |
michael@0 | 123 | good = good && !!m1; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | // Note: Match "vsize" but not "vsize-max-contiguous". |
michael@0 | 127 | let vsizes = actual.match(/vsize[^-]/g); |
michael@0 | 128 | let endOfBrowsers = actual.match(/End of Browser/g); |
michael@0 | 129 | let m2 = (vsizes.length == 4 && endOfBrowsers.length == 3); |
michael@0 | 130 | ok(m2, "three child processes present in loaded data"); |
michael@0 | 131 | good = good && !!m2; |
michael@0 | 132 | |
michael@0 | 133 | if (!good) { |
michael@0 | 134 | dump("*******ACTUAL*******\n"); |
michael@0 | 135 | dump(actual); |
michael@0 | 136 | dump("********************\n"); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | // Close the remote processes. |
michael@0 | 140 | for (let i = 0; i < numRemotes; i++) { |
michael@0 | 141 | remotes[i].close(); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | SimpleTest.finish(); |
michael@0 | 145 | |
michael@0 | 146 | } else { |
michael@0 | 147 | numFailures++; |
michael@0 | 148 | if (numFailures === maxFailures) { |
michael@0 | 149 | ok(false, "not enough chars in pasted output"); |
michael@0 | 150 | SimpleTest.finish(); |
michael@0 | 151 | } else { |
michael@0 | 152 | setTimeout(copyPasteAndCheck, 100); |
michael@0 | 153 | } |
michael@0 | 154 | } |
michael@0 | 155 | } |
michael@0 | 156 | } |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 160 | ]]> |
michael@0 | 161 | </script> |
michael@0 | 162 | </window> |