tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_console_styling.html (3672B)


      1 <!DOCTYPE HTML>
      2 <html lang="en">
      3 <head>
      4  <meta charset="utf8">
      5  <title>Test for console.log styling with %c</title>
      6  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      7  <script type="text/javascript" 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 console.log styling with %c</p>
     13 
     14 <script class="testbody" type="text/javascript">
     15 "use strict";
     16 
     17 SimpleTest.waitForExplicitFinish();
     18 
     19 let expectedConsoleCalls = [];
     20 
     21 function doConsoleCalls()
     22 {
     23  top.console.log("%cOne formatter with no styles");
     24  top.console.log("%cOne formatter", "color: red");
     25  top.console.log("%cTwo formatters%cEach with an arg",
     26    "color: red", "background: red");
     27  top.console.log("%c%cTwo formatters next to each other",
     28    "color: red", "background: red");
     29  top.console.log("%c%c%cThree formatters next to each other",
     30    "color: red", "background: red", "font-size: 150%");
     31  top.console.log("%c%cTwo formatters%cWith a third separated",
     32    "color: red", "background: red", "font-size: 150%");
     33  top.console.log("%cOne formatter", "color: red",
     34                  "Second arg with no styles");
     35  top.console.log("%cOne formatter", "color: red",
     36                  "%cSecond formatter is ignored", "background: blue")
     37 
     38  expectedConsoleCalls = [
     39    {
     40      level: "log",
     41      styles: undefined,
     42      arguments: ["%cOne formatter with no styles"],
     43    },
     44    {
     45      level: "log",
     46      styles: /^color: red$/,
     47      arguments: ["One formatter"],
     48    },
     49    {
     50      level: "log",
     51      styles: /^color: red,background: red$/,
     52      arguments: ["Two formatters", "Each with an arg"],
     53    },
     54    {
     55      level: "log",
     56      styles: /^background: red$/,
     57      arguments: ["Two formatters next to each other"],
     58    },
     59    {
     60      level: "log",
     61      styles: /^font-size: 150%$/,
     62      arguments: ["Three formatters next to each other"],
     63    },
     64    {
     65      level: "log",
     66      styles: /^background: red,font-size: 150%$/,
     67      arguments: ["Two formatters", "With a third separated"],
     68    },
     69    {
     70      level: "log",
     71      styles: /^color: red$/,
     72      arguments: ["One formatter", "Second arg with no styles"],
     73    },
     74    {
     75      level: "log",
     76      styles: /^color: red$/,
     77      arguments: ["One formatter",
     78                  "%cSecond formatter is ignored",
     79                  "background: blue"],
     80    },
     81  ];
     82 }
     83 
     84 async function startTest()
     85 {
     86  removeEventListener("load", startTest);
     87 
     88  const {state, response} = await attachConsoleToTab(["ConsoleAPI"]);
     89  onAttach(state, response);
     90 }
     91 
     92 function onAttach(state)
     93 {
     94  onConsoleAPICall = onConsoleAPICall.bind(null, state);
     95  state.webConsoleFront.on("consoleAPICall", onConsoleAPICall);
     96  doConsoleCalls(state.actor);
     97 }
     98 
     99 let consoleCalls = [];
    100 
    101 function onConsoleAPICall(state, packet)
    102 {
    103  info("received message level: " + packet.message.level);
    104 
    105  consoleCalls.push(packet.message);
    106  if (consoleCalls.length != expectedConsoleCalls.length) {
    107    return;
    108  }
    109 
    110  state.webConsoleFront.off("consoleAPICall", onConsoleAPICall);
    111 
    112  expectedConsoleCalls.forEach(function(message, index) {
    113    info("checking received console call #" + index);
    114    const expected = expectedConsoleCalls[index];
    115    const consoleCall = consoleCalls[index];
    116    if (expected.styles == undefined) {
    117      delete expected.styles;
    118      is(consoleCall.styles, undefined, "No 'styles' property")
    119    }
    120    checkConsoleAPICall(consoleCall, expected);
    121  });
    122 
    123 
    124  consoleCalls = [];
    125 
    126  closeDebugger(state, function() {
    127    SimpleTest.finish();
    128  });
    129 }
    130 
    131 addEventListener("load", startTest);
    132 </script>
    133 </body>
    134 </html>