tor-browser

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

browser_net_charts-06.js (1658B)


      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 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 pie = Chart.Pie(document, {
     28    data: [],
     29    width: 100,
     30    height: 100,
     31  });
     32 
     33  const { node } = pie;
     34  const slices = node.querySelectorAll(".pie-chart-slice");
     35  const labels = node.querySelectorAll(".pie-chart-label");
     36 
     37  is(slices.length, 1, "There should be 1 pie chart slice created.");
     38  ok(
     39    slices[0]
     40      .getAttribute("d")
     41      .match(
     42        /\s*M 50,50 L 50\.\d+,2\.5\d* A 47\.5,47\.5 0 1 1 49\.\d+,2\.5\d* Z/
     43      ),
     44    "The slice has the correct data."
     45  );
     46 
     47  ok(slices[0].hasAttribute("largest"), "The slice should be the largest one.");
     48  ok(
     49    slices[0].hasAttribute("smallest"),
     50    "The slice should also be the smallest one."
     51  );
     52  is(
     53    slices[0].getAttribute("data-statistic-name"),
     54    L10N.getStr("pieChart.unavailable"),
     55    "The slice's name is correct."
     56  );
     57 
     58  is(labels.length, 1, "There should be 1 pie chart label created.");
     59  is(labels[0].textContent, "Empty", "The label's text is correct.");
     60 
     61  await teardown(monitor);
     62 });