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.

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

mercurial