tor-browser

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

test_console_group_styling.html (3435B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test for console.group 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  <script>
     11 "use strict";
     12 
     13 window.onload = async function () {
     14  SimpleTest.waitForExplicitFinish();
     15  let state;
     16  try {
     17    state = (await attachConsole(["ConsoleAPI"])).state
     18    const consoleFront = state.webConsoleFront;
     19 
     20    await testSingleCustomStyleGroup(consoleFront);
     21    await testSingleCustomStyleGroupCollapsed(consoleFront);
     22    await testMultipleCustomStyleGroup(consoleFront);
     23    await testMultipleCustomStyleGroupCollapsed(consoleFront);
     24    await testFormatterWithNoStyleGroup(consoleFront);
     25    await testFormatterWithNoStyleGroupCollapsed(consoleFront);
     26  } catch (e) {
     27    ok(false, `Error thrown: ${e.message}`);
     28  }
     29 
     30  await closeDebugger(state);
     31  SimpleTest.finish();
     32 };
     33 
     34 async function testSingleCustomStyleGroup(consoleFront) {
     35  info("Testing console.group with a custom style");
     36  const packet = await consoleAPICall(
     37    consoleFront,
     38    () => top.console.group("%cfoobar", "color:red")
     39  );
     40 
     41  checkConsoleAPICall(packet.message, {
     42    arguments: ["foobar"],
     43    styles: ["color:red"]
     44  });
     45 }
     46 
     47 async function testSingleCustomStyleGroupCollapsed(consoleFront) {
     48  info("Testing console.groupCollapsed with a custom style");
     49  const packet = await consoleAPICall(
     50    consoleFront,
     51    () => top.console.groupCollapsed("%cfoobaz", "color:blue")
     52  );
     53 
     54  checkConsoleAPICall(packet.message, {
     55    arguments: ["foobaz"],
     56    styles: ["color:blue"]
     57  });
     58 }
     59 
     60 async function testMultipleCustomStyleGroup(consoleFront) {
     61  info("Testing console.group with multiple custom styles");
     62  const packet = await consoleAPICall(
     63    consoleFront,
     64    () => top.console.group("%cfoo%cbar", "color:red", "color:blue")
     65  );
     66 
     67  checkConsoleAPICall(packet.message, {
     68    arguments: ["foo", "bar"],
     69    styles: ["color:red", "color:blue"]
     70  });
     71 }
     72 
     73 async function testMultipleCustomStyleGroupCollapsed(consoleFront) {
     74  info("Testing console.groupCollapsed with multiple custom styles");
     75  const packet = await consoleAPICall(
     76    consoleFront,
     77    () => top.console.group("%cfoo%cbaz", "color:red", "color:green")
     78  );
     79 
     80  checkConsoleAPICall(packet.message, {
     81    arguments: ["foo", "baz"],
     82    styles: ["color:red", "color:green"]
     83  });
     84 }
     85 
     86 async function testFormatterWithNoStyleGroup(consoleFront) {
     87  info("Testing console.group with one formatter but no style");
     88  const packet = await consoleAPICall(
     89    consoleFront,
     90    () => top.console.group("%cfoobar")
     91  );
     92 
     93  checkConsoleAPICall(packet.message, {
     94    arguments: ["%cfoobar"],
     95  });
     96  is(packet.message.styles, undefined, "No 'styles' property");
     97 }
     98 
     99 async function testFormatterWithNoStyleGroupCollapsed(consoleFront) {
    100  info("Testing console.groupCollapsed with one formatter but no style");
    101  const packet = await consoleAPICall(
    102    consoleFront,
    103    () => top.console.groupCollapsed("%cfoobaz")
    104  );
    105 
    106  checkConsoleAPICall(packet.message, {
    107    arguments: ["%cfoobaz"],
    108  });
    109  is(packet.message.styles, undefined, "No 'styles' property");
    110 }
    111 
    112  </script>
    113 </head>
    114 <body>
    115  <p id="display"></p>
    116  <div id="content" style="display: none">
    117  </div>
    118  <pre id="test">
    119  </pre>
    120 </body>
    121 </html>