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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Makes sure Pie Charts have the right internal structure.
michael@0 6 */
michael@0 7
michael@0 8 function test() {
michael@0 9 initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => {
michael@0 10 info("Starting test... ");
michael@0 11
michael@0 12 let { document, Chart } = aMonitor.panelWin;
michael@0 13 let container = document.createElement("box");
michael@0 14
michael@0 15 let pie = Chart.Pie(document, {
michael@0 16 width: 100,
michael@0 17 height: 100,
michael@0 18 data: [{
michael@0 19 size: 1,
michael@0 20 label: "foo"
michael@0 21 }, {
michael@0 22 size: 2,
michael@0 23 label: "bar"
michael@0 24 }, {
michael@0 25 size: 3,
michael@0 26 label: "baz"
michael@0 27 }]
michael@0 28 });
michael@0 29
michael@0 30 let node = pie.node;
michael@0 31 let slices = node.querySelectorAll(".pie-chart-slice.chart-colored-blob");
michael@0 32 let labels = node.querySelectorAll(".pie-chart-label");
michael@0 33
michael@0 34 ok(node.classList.contains("pie-chart-container") &&
michael@0 35 node.classList.contains("generic-chart-container"),
michael@0 36 "A pie chart container was created successfully.");
michael@0 37
michael@0 38 is(slices.length, 3,
michael@0 39 "There should be 3 pie chart slices created.");
michael@0 40 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/),
michael@0 41 "The first slice has the correct data.");
michael@0 42 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/),
michael@0 43 "The second slice has the correct data.");
michael@0 44 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/),
michael@0 45 "The third slice has the correct data.");
michael@0 46
michael@0 47 ok(slices[0].hasAttribute("largest"),
michael@0 48 "The first slice should be the largest one.");
michael@0 49 ok(slices[2].hasAttribute("smallest"),
michael@0 50 "The third slice should be the smallest one.");
michael@0 51
michael@0 52 ok(slices[0].getAttribute("name"), "baz",
michael@0 53 "The first slice's name is correct.");
michael@0 54 ok(slices[1].getAttribute("name"), "bar",
michael@0 55 "The first slice's name is correct.");
michael@0 56 ok(slices[2].getAttribute("name"), "foo",
michael@0 57 "The first slice's name is correct.");
michael@0 58
michael@0 59 is(labels.length, 3,
michael@0 60 "There should be 3 pie chart labels created.");
michael@0 61 is(labels[0].textContent, "baz",
michael@0 62 "The first label's text is correct.");
michael@0 63 is(labels[1].textContent, "bar",
michael@0 64 "The first label's text is correct.");
michael@0 65 is(labels[2].textContent, "foo",
michael@0 66 "The first label's text is correct.");
michael@0 67
michael@0 68 teardown(aMonitor).then(finish);
michael@0 69 });
michael@0 70 }

mercurial