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.

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

mercurial