toolkit/devtools/webconsole/test/test_cached_messages.html

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 <!DOCTYPE HTML>
     2 <html lang="en">
     3 <head>
     4   <meta charset="utf8">
     5   <title>Test for cached messages</title>
     6   <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     7   <script type="text/javascript;version=1.8" src="common.js"></script>
     8   <!-- Any copyright is dedicated to the Public Domain.
     9      - http://creativecommons.org/publicdomain/zero/1.0/ -->
    10 </head>
    11 <body>
    12 <p>Test for cached messages</p>
    14 <script class="testbody" type="application/javascript;version=1.8">
    15 let expectedConsoleCalls = [];
    16 let expectedPageErrors = [];
    18 function doPageErrors()
    19 {
    20   Services.console.reset();
    22   expectedPageErrors = [
    23     {
    24       _type: "PageError",
    25       errorMessage: /fooColor/,
    26       sourceName: /.+/,
    27       category: "CSS Parser",
    28       timeStamp: /^\d+$/,
    29       error: false,
    30       warning: true,
    31       exception: false,
    32       strict: false,
    33     },
    34     {
    35       _type: "PageError",
    36       errorMessage: /doTheImpossible/,
    37       sourceName: /.+/,
    38       category: "chrome javascript",
    39       timeStamp: /^\d+$/,
    40       error: false,
    41       warning: false,
    42       exception: true,
    43       strict: false,
    44     },
    45   ];
    47   let container = document.createElement("script");
    48   document.body.appendChild(container);
    49   container.textContent = "document.body.style.color = 'fooColor';";
    50   document.body.removeChild(container);
    52   SimpleTest.expectUncaughtException();
    54   container = document.createElement("script");
    55   document.body.appendChild(container);
    56   container.textContent = "document.doTheImpossible();";
    57   document.body.removeChild(container);
    58 }
    60 function doConsoleCalls()
    61 {
    62   ConsoleAPIStorage.clearEvents();
    64   top.console.log("foobarBaz-log", undefined);
    65   top.console.info("foobarBaz-info", null);
    66   top.console.warn("foobarBaz-warn", document.body);
    68   expectedConsoleCalls = [
    69     {
    70       _type: "ConsoleAPI",
    71       level: "log",
    72       filename: /test_cached_messages/,
    73       functionName: "doConsoleCalls",
    74       timeStamp: /^\d+$/,
    75       arguments: ["foobarBaz-log", { type: "undefined" }],
    76     },
    77     {
    78       _type: "ConsoleAPI",
    79       level: "info",
    80       filename: /test_cached_messages/,
    81       functionName: "doConsoleCalls",
    82       timeStamp: /^\d+$/,
    83       arguments: ["foobarBaz-info", { type: "null" }],
    84     },
    85     {
    86       _type: "ConsoleAPI",
    87       level: "warn",
    88       filename: /test_cached_messages/,
    89       functionName: "doConsoleCalls",
    90       timeStamp: /^\d+$/,
    91       arguments: ["foobarBaz-warn", { type: "object", actor: /[a-z]/ }],
    92     },
    93   ];
    94 }
    95 </script>
    97 <script class="testbody" type="text/javascript;version=1.8">
    98 SimpleTest.waitForExplicitFinish();
   100 let consoleAPIListener, consoleServiceListener;
   101 let consoleAPICalls = 0;
   102 let pageErrors = 0;
   104 let handlers = {
   105   onConsoleAPICall: function onConsoleAPICall(aMessage)
   106   {
   107     for (let msg of expectedConsoleCalls) {
   108       if (msg.functionName == aMessage.functionName &&
   109           msg.filename.test(aMessage.filename)) {
   110         consoleAPICalls++;
   111         break;
   112       }
   113     }
   114     if (consoleAPICalls == expectedConsoleCalls.length) {
   115       checkConsoleAPICache();
   116     }
   117   },
   119   onConsoleServiceMessage: function onConsoleServiceMessage(aMessage)
   120   {
   121     if (!(aMessage instanceof Ci.nsIScriptError)) {
   122       return;
   123     }
   124     for (let msg of expectedPageErrors) {
   125       if (msg.category == aMessage.category &&
   126           msg.errorMessage.test(aMessage.errorMessage)) {
   127         pageErrors++;
   128         break;
   129       }
   130     }
   131     if (pageErrors == expectedPageErrors.length) {
   132       testPageErrors();
   133     }
   134   },
   135 };
   137 function startTest()
   138 {
   139   removeEventListener("load", startTest);
   141   consoleAPIListener = new ConsoleAPIListener(top, handlers);
   142   consoleAPIListener.init();
   144   doConsoleCalls();
   145 }
   147 function checkConsoleAPICache()
   148 {
   149   consoleAPIListener.destroy();
   150   consoleAPIListener = null;
   151   attachConsole(["ConsoleAPI"], onAttach1);
   152 }
   154 function onAttach1(aState, aResponse)
   155 {
   156   aState.client.getCachedMessages(["ConsoleAPI"],
   157                                   onCachedConsoleAPI.bind(null, aState));
   158 }
   160 function onCachedConsoleAPI(aState, aResponse)
   161 {
   162   let msgs = aResponse.messages;
   163   info("cached console messages: " + msgs.length);
   165   ok(msgs.length >= expectedConsoleCalls.length,
   166      "number of cached console messages");
   168   for (let msg of msgs) {
   169     for (let expected of expectedConsoleCalls) {
   170       if (expected.functionName == msg.functionName &&
   171           expected.filename.test(msg.filename)) {
   172         expectedConsoleCalls.splice(expectedConsoleCalls.indexOf(expected));
   173         checkConsoleAPICall(msg, expected);
   174         break;
   175       }
   176     }
   177   }
   179   is(expectedConsoleCalls.length, 0, "all expected messages have been found");
   181   closeDebugger(aState, function() {
   182     consoleServiceListener = new ConsoleServiceListener(null, handlers);
   183     consoleServiceListener.init();
   184     doPageErrors();
   185   });
   186 }
   188 function testPageErrors()
   189 {
   190   consoleServiceListener.destroy();
   191   consoleServiceListener = null;
   192   attachConsole(["PageError"], onAttach2);
   193 }
   195 function onAttach2(aState, aResponse)
   196 {
   197   aState.client.getCachedMessages(["PageError"],
   198                                   onCachedPageErrors.bind(null, aState));
   199 }
   201 function onCachedPageErrors(aState, aResponse)
   202 {
   203   let msgs = aResponse.messages;
   204   info("cached page errors: " + msgs.length);
   206   ok(msgs.length >= expectedPageErrors.length,
   207      "number of cached page errors");
   209   for (let msg of msgs) {
   210     for (let expected of expectedPageErrors) {
   211       if (expected.category == msg.category &&
   212           expected.errorMessage.test(msg.errorMessage)) {
   213         expectedPageErrors.splice(expectedPageErrors.indexOf(expected));
   214         checkObject(msg, expected);
   215         break;
   216       }
   217     }
   218   }
   220   is(expectedPageErrors.length, 0, "all expected messages have been found");
   222   closeDebugger(aState, function() {
   223     SimpleTest.finish();
   224   });
   225 }
   227 addEventListener("load", startTest);
   228 </script>
   229 </body>
   230 </html>

mercurial