tor-browser

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

browser_net_charts-04.js (3135B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Makes sure Pie Charts have the right internal structure when
      8 * initialized with empty data.
      9 */
     10 
     11 add_task(async function () {
     12  const {
     13    L10N,
     14  } = require("resource://devtools/client/netmonitor/src/utils/l10n.js");
     15 
     16  const { monitor } = await initNetMonitor(HTTPS_SIMPLE_URL, {
     17    requestCount: 1,
     18  });
     19  info("Starting test... ");
     20 
     21  const { document, windowRequire } = monitor.panelWin;
     22  const { Chart } = windowRequire("devtools/client/shared/widgets/Chart");
     23 
     24  const wait = waitForNetworkEvents(monitor, 1);
     25  await navigateTo(HTTPS_SIMPLE_URL);
     26  await wait;
     27 
     28  const table = Chart.Table(document, {
     29    title: "Table title",
     30    data: null,
     31    totals: {
     32      label1: value => "Hello " + L10N.numberWithDecimals(value, 2),
     33      label2: value => "World " + L10N.numberWithDecimals(value, 2),
     34    },
     35    header: {
     36      label1: "",
     37      label2: "",
     38    },
     39  });
     40 
     41  const { node } = table;
     42  const title = node.querySelector(".table-chart-title");
     43  const grid = node.querySelector(".table-chart-grid");
     44  const totals = node.querySelector(".table-chart-totals");
     45  const rows = grid.querySelectorAll(".table-chart-row");
     46  const sums = node.querySelectorAll(".table-chart-summary-label");
     47 
     48  ok(
     49    node.classList.contains("table-chart-container") &&
     50      node.classList.contains("generic-chart-container"),
     51    "A table chart container was created successfully."
     52  );
     53 
     54  ok(title, "A title node was created successfully.");
     55  is(
     56    title.textContent,
     57    "Table title",
     58    "The title node displays the correct text."
     59  );
     60 
     61  is(
     62    rows.length,
     63    2,
     64    "There should be 1 table chart row and a 1 header created."
     65  );
     66 
     67  is(
     68    rows[1].querySelectorAll(".table-chart-row-label")[0].getAttribute("name"),
     69    "size",
     70    "The first column of the first row exists."
     71  );
     72  is(
     73    rows[1].querySelectorAll(".table-chart-row-label")[1].getAttribute("name"),
     74    "label",
     75    "The second column of the first row exists."
     76  );
     77  is(
     78    rows[1].querySelectorAll(".table-chart-row-label")[0].textContent,
     79    "",
     80    "The first column of the first row displays the correct text."
     81  );
     82  is(
     83    rows[1].querySelectorAll(".table-chart-row-label")[1].textContent,
     84    L10N.getStr("tableChart.loading"),
     85    "The second column of the first row displays the correct text."
     86  );
     87 
     88  is(sums.length, 2, "There should be 2 total summaries created.");
     89 
     90  is(
     91    totals
     92      .querySelectorAll(".table-chart-summary-label")[0]
     93      .getAttribute("name"),
     94    "label1",
     95    "The first sum's type is correct."
     96  );
     97  is(
     98    totals.querySelectorAll(".table-chart-summary-label")[0].textContent,
     99    "Hello 0",
    100    "The first sum's value is correct."
    101  );
    102 
    103  is(
    104    totals
    105      .querySelectorAll(".table-chart-summary-label")[1]
    106      .getAttribute("name"),
    107    "label2",
    108    "The second sum's type is correct."
    109  );
    110  is(
    111    totals.querySelectorAll(".table-chart-summary-label")[1].textContent,
    112    "World 0",
    113    "The second sum's value is correct."
    114  );
    115 
    116  await teardown(monitor);
    117 });