browser/devtools/netmonitor/test/browser_net_charts-01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/netmonitor/test/browser_net_charts-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,70 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Makes sure Pie Charts have the right internal structure.
     1.9 + */
    1.10 +
    1.11 +function test() {
    1.12 +  initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => {
    1.13 +    info("Starting test... ");
    1.14 +
    1.15 +    let { document, Chart } = aMonitor.panelWin;
    1.16 +    let container = document.createElement("box");
    1.17 +
    1.18 +    let pie = Chart.Pie(document, {
    1.19 +      width: 100,
    1.20 +      height: 100,
    1.21 +      data: [{
    1.22 +        size: 1,
    1.23 +        label: "foo"
    1.24 +      }, {
    1.25 +        size: 2,
    1.26 +        label: "bar"
    1.27 +      }, {
    1.28 +        size: 3,
    1.29 +        label: "baz"
    1.30 +      }]
    1.31 +    });
    1.32 +
    1.33 +    let node = pie.node;
    1.34 +    let slices = node.querySelectorAll(".pie-chart-slice.chart-colored-blob");
    1.35 +    let labels = node.querySelectorAll(".pie-chart-label");
    1.36 +
    1.37 +    ok(node.classList.contains("pie-chart-container") &&
    1.38 +       node.classList.contains("generic-chart-container"),
    1.39 +      "A pie chart container was created successfully.");
    1.40 +
    1.41 +    is(slices.length, 3,
    1.42 +      "There should be 3 pie chart slices created.");
    1.43 +    ok(slices[0].getAttribute("d").match(/\s*M 50,50 L 49\.\d+,97\.\d+ A 47\.5,47\.5 0 0 1 49\.\d+,2\.5\d* Z/),
    1.44 +      "The first slice has the correct data.");
    1.45 +    ok(slices[1].getAttribute("d").match(/\s*M 50,50 L 91\.\d+,26\.\d+ A 47\.5,47\.5 0 0 1 49\.\d+,97\.\d+ Z/),
    1.46 +      "The second slice has the correct data.");
    1.47 +    ok(slices[2].getAttribute("d").match(/\s*M 50,50 L 50\.\d+,2\.5\d* A 47\.5,47\.5 0 0 1 91\.\d+,26\.\d+ Z/),
    1.48 +      "The third slice has the correct data.");
    1.49 +
    1.50 +    ok(slices[0].hasAttribute("largest"),
    1.51 +      "The first slice should be the largest one.");
    1.52 +    ok(slices[2].hasAttribute("smallest"),
    1.53 +      "The third slice should be the smallest one.");
    1.54 +
    1.55 +    ok(slices[0].getAttribute("name"), "baz",
    1.56 +      "The first slice's name is correct.");
    1.57 +    ok(slices[1].getAttribute("name"), "bar",
    1.58 +      "The first slice's name is correct.");
    1.59 +    ok(slices[2].getAttribute("name"), "foo",
    1.60 +      "The first slice's name is correct.");
    1.61 +
    1.62 +    is(labels.length, 3,
    1.63 +      "There should be 3 pie chart labels created.");
    1.64 +    is(labels[0].textContent, "baz",
    1.65 +      "The first label's text is correct.");
    1.66 +    is(labels[1].textContent, "bar",
    1.67 +      "The first label's text is correct.");
    1.68 +    is(labels[2].textContent, "foo",
    1.69 +      "The first label's text is correct.");
    1.70 +
    1.71 +    teardown(aMonitor).then(finish);
    1.72 +  });
    1.73 +}

mercurial