browser_net_charts-02.js (1913B)
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 pie = Chart.Pie(document, { 29 data: null, 30 width: 100, 31 height: 100, 32 }); 33 34 const { node } = pie; 35 const slices = node.querySelectorAll(".pie-chart-slice"); 36 const labels = node.querySelectorAll(".pie-chart-label"); 37 38 ok( 39 node.classList.contains("pie-chart-container") && 40 node.classList.contains("generic-chart-container"), 41 "A pie chart container was created successfully." 42 ); 43 44 is(slices.length, 1, "There should be 1 pie chart slice created."); 45 ok( 46 slices[0] 47 .getAttribute("d") 48 .match( 49 /\s*M 50,50 L 50\.\d+,2\.5\d* A 47\.5,47\.5 0 1 1 49\.\d+,2\.5\d* Z/ 50 ), 51 "The first slice has the correct data." 52 ); 53 54 ok( 55 slices[0].hasAttribute("largest"), 56 "The first slice should be the largest one." 57 ); 58 ok( 59 slices[0].hasAttribute("smallest"), 60 "The first slice should also be the smallest one." 61 ); 62 is( 63 slices[0].getAttribute("data-statistic-name"), 64 L10N.getStr("pieChart.loading"), 65 "The first slice's name is correct." 66 ); 67 68 is(labels.length, 1, "There should be 1 pie chart label created."); 69 is(labels[0].textContent, "Loading", "The first label's text is correct."); 70 71 await teardown(monitor); 72 });