tor-browser

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

browser_net_charts-07.js (2663B)


      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 Table Charts correctly handle empty source data.
      8 */
      9 
     10 add_task(async function () {
     11  const {
     12    L10N,
     13  } = require("resource://devtools/client/netmonitor/src/utils/l10n.js");
     14 
     15  const { monitor } = await initNetMonitor(HTTPS_SIMPLE_URL, {
     16    requestCount: 1,
     17  });
     18  info("Starting test... ");
     19 
     20  const { document, windowRequire } = monitor.panelWin;
     21  const { Chart } = windowRequire("devtools/client/shared/widgets/Chart");
     22 
     23  const wait = waitForNetworkEvents(monitor, 1);
     24  await navigateTo(HTTPS_SIMPLE_URL);
     25  await wait;
     26 
     27  const table = Chart.Table(document, {
     28    data: [],
     29    totals: {
     30      label1: value => "Hello " + L10N.numberWithDecimals(value, 2),
     31      label2: value => "World " + L10N.numberWithDecimals(value, 2),
     32    },
     33    header: {
     34      label1: "",
     35      label2: "",
     36    },
     37  });
     38 
     39  const { node } = table;
     40  const grid = node.querySelector(".table-chart-grid");
     41  const totals = node.querySelector(".table-chart-totals");
     42  const rows = grid.querySelectorAll(".table-chart-row");
     43  const sums = node.querySelectorAll(".table-chart-summary-label");
     44 
     45  is(rows.length, 2, "There should be 1 table chart row and 1 header created.");
     46 
     47  is(
     48    rows[1].querySelectorAll(".table-chart-row-label")[0].getAttribute("name"),
     49    "size",
     50    "The first column of the first row exists."
     51  );
     52  is(
     53    rows[1].querySelectorAll(".table-chart-row-label")[1].getAttribute("name"),
     54    "label",
     55    "The second column of the first row exists."
     56  );
     57  is(
     58    rows[1].querySelectorAll(".table-chart-row-label")[0].textContent,
     59    "",
     60    "The first column of the first row displays the correct text."
     61  );
     62  is(
     63    rows[1].querySelectorAll(".table-chart-row-label")[1].textContent,
     64    L10N.getStr("tableChart.unavailable"),
     65    "The second column of the first row displays the correct text."
     66  );
     67 
     68  is(sums.length, 2, "There should be 2 total summaries created.");
     69 
     70  is(
     71    totals
     72      .querySelectorAll(".table-chart-summary-label")[0]
     73      .getAttribute("name"),
     74    "label1",
     75    "The first sum's type is correct."
     76  );
     77  is(
     78    totals.querySelectorAll(".table-chart-summary-label")[0].textContent,
     79    "Hello 0",
     80    "The first sum's value is correct."
     81  );
     82 
     83  is(
     84    totals
     85      .querySelectorAll(".table-chart-summary-label")[1]
     86      .getAttribute("name"),
     87    "label2",
     88    "The second sum's type is correct."
     89  );
     90  is(
     91    totals.querySelectorAll(".table-chart-summary-label")[1].textContent,
     92    "World 0",
     93    "The second sum's value is correct."
     94  );
     95 
     96  await teardown(monitor);
     97 });