toolkit/components/aboutmemory/tests/test_aboutmemory4.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 loading of memory reports from file when specified
michael@0 10 in about:memory's URL (via the "file=" suffix). -->
michael@0 11
michael@0 12 <!-- test results are displayed in the html:body -->
michael@0 13 <body xmlns="http://www.w3.org/1999/xhtml"></body>
michael@0 14
michael@0 15 <!-- test code goes here -->
michael@0 16 <script type="application/javascript">
michael@0 17 <![CDATA[
michael@0 18 "use strict";
michael@0 19
michael@0 20 function makePathname(aFilename) {
michael@0 21 let file = Components.classes["@mozilla.org/file/directory_service;1"]
michael@0 22 .getService(Components.interfaces.nsIProperties)
michael@0 23 .get("CurWorkD", Components.interfaces.nsIFile);
michael@0 24 file.append("chrome");
michael@0 25 file.append("toolkit");
michael@0 26 file.append("components");
michael@0 27 file.append("aboutmemory");
michael@0 28 file.append("tests");
michael@0 29 file.append(aFilename);
michael@0 30 return file.path;
michael@0 31 }
michael@0 32
michael@0 33 // Load the given file into the frame, then copy+paste the entire frame and
michael@0 34 // check that the cut text matches what we expect.
michael@0 35 function test(aFilename, aExpected, aNext) {
michael@0 36 let frame = document.createElementNS("http://www.w3.org/1999/xhtml", "iframe")
michael@0 37 frame.height = 300;
michael@0 38 frame.src = "about:memory?file=" + makePathname(aFilename);
michael@0 39 document.documentElement.appendChild(frame);
michael@0 40 frame.focus();
michael@0 41
michael@0 42 // Initialize the clipboard contents.
michael@0 43 SpecialPowers.clipboardCopyString("initial clipboard value");
michael@0 44
michael@0 45 let numFailures = 0, maxFailures = 30;
michael@0 46
michael@0 47 // Because the file load is async, we don't know when it will finish and
michael@0 48 // the output will show up. So we poll.
michael@0 49 function copyPasteAndCheck() {
michael@0 50 // Copy and paste frame contents, and filter out non-deterministic
michael@0 51 // differences.
michael@0 52 synthesizeKey("A", {accelKey: true});
michael@0 53 synthesizeKey("C", {accelKey: true});
michael@0 54 let actual = SpecialPowers.getClipboardData("text/unicode");
michael@0 55 actual = actual.replace(/\(pid \d+\)/, "(pid NNN)");
michael@0 56
michael@0 57 if (actual === aExpected) {
michael@0 58 SimpleTest.ok(true, "Clipboard has the expected contents");
michael@0 59 aNext();
michael@0 60 } else {
michael@0 61 numFailures++;
michael@0 62 if (numFailures === maxFailures) {
michael@0 63 ok(false, "pasted text doesn't match");
michael@0 64 dump("******EXPECTED******\n");
michael@0 65 dump(aExpected);
michael@0 66 dump("*******ACTUAL*******\n");
michael@0 67 dump(actual);
michael@0 68 dump("********************\n");
michael@0 69 SimpleTest.finish();
michael@0 70 } else {
michael@0 71 setTimeout(copyPasteAndCheck, 100);
michael@0 72 }
michael@0 73 }
michael@0 74 }
michael@0 75 copyPasteAndCheck();
michael@0 76 }
michael@0 77
michael@0 78 // Returns a function that chains together multiple test() calls.
michael@0 79 function chain(aFrameIds) {
michael@0 80 let x = aFrameIds.shift();
michael@0 81 if (x) {
michael@0 82 return function() { test(x.filename, x.expected, chain(aFrameIds)); }
michael@0 83 } else {
michael@0 84 return function() { SimpleTest.finish(); };
michael@0 85 }
michael@0 86 }
michael@0 87
michael@0 88 // This is pretty simple output, but that's ok; this file is about testing
michael@0 89 // the loading of data from file. If we got this far, we're doing fine.
michael@0 90 let expectedGood =
michael@0 91 "\
michael@0 92 Explicit-only process\n\
michael@0 93 \n\
michael@0 94 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\
michael@0 95 Explicit Allocations\n\
michael@0 96 \n\
michael@0 97 0.10 MB (100.0%) -- explicit\n\
michael@0 98 └──0.10 MB (100.0%) ── a/b\n\
michael@0 99 \n\
michael@0 100 Other Measurements\n\
michael@0 101 \n\
michael@0 102 End of Explicit-only process\n\
michael@0 103 Main Process (pid NNN)\n\
michael@0 104 Explicit Allocations\n\
michael@0 105 \n\
michael@0 106 250.00 MB (100.0%) -- explicit\n\
michael@0 107 ├──200.00 MB (80.00%) ── heap-unclassified\n\
michael@0 108 └───50.00 MB (20.00%) ── a/b\n\
michael@0 109 \n\
michael@0 110 Other Measurements\n\
michael@0 111 \n\
michael@0 112 0.00 MB (100.0%) -- compartments\n\
michael@0 113 └──0.00 MB (100.0%) ── system/a\n\
michael@0 114 \n\
michael@0 115 0.00 MB (100.0%) -- ghost-windows\n\
michael@0 116 └──0.00 MB (100.0%) ── a\n\
michael@0 117 \n\
michael@0 118 0.30 MB (100.0%) -- other\n\
michael@0 119 ├──0.20 MB (66.67%) ── a\n\
michael@0 120 └──0.10 MB (33.33%) ── b\n\
michael@0 121 \n\
michael@0 122 0.00 MB (100.0%) -- pss\n\
michael@0 123 └──0.00 MB (100.0%) ── a\n\
michael@0 124 \n\
michael@0 125 0.00 MB (100.0%) -- rss\n\
michael@0 126 └──0.00 MB (100.0%) ── a\n\
michael@0 127 \n\
michael@0 128 0.00 MB (100.0%) -- size\n\
michael@0 129 └──0.00 MB (100.0%) ── a\n\
michael@0 130 \n\
michael@0 131 0.00 MB (100.0%) -- swap\n\
michael@0 132 └──0.00 MB (100.0%) ── a\n\
michael@0 133 \n\
michael@0 134 250.00 MB ── heap-allocated\n\
michael@0 135 \n\
michael@0 136 End of Main Process (pid NNN)\n\
michael@0 137 Other-only process\n\
michael@0 138 Other Measurements\n\
michael@0 139 \n\
michael@0 140 0.19 MB (100.0%) -- a\n\
michael@0 141 ├──0.10 MB (50.00%) ── b\n\
michael@0 142 └──0.10 MB (50.00%) ── c\n\
michael@0 143 \n\
michael@0 144 0.48 MB ── heap-allocated\n\
michael@0 145 \n\
michael@0 146 End of Other-only process\n\
michael@0 147 ";
michael@0 148
michael@0 149 // This is the output for a malformed data file.
michael@0 150 let expectedBad =
michael@0 151 "\
michael@0 152 Invalid memory report(s): missing 'hasMozMallocUsableSize' property";
michael@0 153
michael@0 154 let frames = [
michael@0 155 // This loads a pre-existing file that is valid.
michael@0 156 { filename: "memory-reports-good.json", expected: expectedGood },
michael@0 157
michael@0 158 // This loads a pre-existing file that is valid.
michael@0 159 { filename: "memory-reports-bad.json", expected: expectedBad }
michael@0 160 ];
michael@0 161
michael@0 162 SimpleTest.waitForFocus(chain(frames));
michael@0 163
michael@0 164 SimpleTest.waitForExplicitFinish();
michael@0 165 ]]>
michael@0 166 </script>
michael@0 167 </window>

mercurial