1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/netmonitor/test/browser_net_charts-03.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 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 Table 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, L10N, Chart } = aMonitor.panelWin; 1.16 + let container = document.createElement("box"); 1.17 + 1.18 + let table = Chart.Table(document, { 1.19 + title: "Table title", 1.20 + data: [{ 1.21 + label1: 1, 1.22 + label2: 11.1 1.23 + }, { 1.24 + label1: 2, 1.25 + label2: 12.2 1.26 + }, { 1.27 + label1: 3, 1.28 + label2: 13.3 1.29 + }], 1.30 + strings: { 1.31 + label2: (value, index) => value + ["foo", "bar", "baz"][index] 1.32 + }, 1.33 + totals: { 1.34 + label1: value => "Hello " + L10N.numberWithDecimals(value, 2), 1.35 + label2: value => "World " + L10N.numberWithDecimals(value, 2) 1.36 + } 1.37 + }); 1.38 + 1.39 + let node = table.node; 1.40 + let title = node.querySelector(".table-chart-title"); 1.41 + let grid = node.querySelector(".table-chart-grid"); 1.42 + let totals = node.querySelector(".table-chart-totals"); 1.43 + let rows = grid.querySelectorAll(".table-chart-row"); 1.44 + let sums = node.querySelectorAll(".table-chart-summary-label"); 1.45 + 1.46 + ok(node.classList.contains("table-chart-container") && 1.47 + node.classList.contains("generic-chart-container"), 1.48 + "A table chart container was created successfully."); 1.49 + 1.50 + ok(title, 1.51 + "A title node was created successfully."); 1.52 + is(title.getAttribute("value"), "Table title", 1.53 + "The title node displays the correct text."); 1.54 + 1.55 + is(rows.length, 3, 1.56 + "There should be 3 table chart rows created."); 1.57 + 1.58 + ok(rows[0].querySelector(".table-chart-row-box.chart-colored-blob"), 1.59 + "A colored blob exists for the firt row."); 1.60 + is(rows[0].querySelectorAll("label")[0].getAttribute("name"), "label1", 1.61 + "The first column of the first row exists."); 1.62 + is(rows[0].querySelectorAll("label")[1].getAttribute("name"), "label2", 1.63 + "The second column of the first row exists."); 1.64 + is(rows[0].querySelectorAll("label")[0].getAttribute("value"), "1", 1.65 + "The first column of the first row displays the correct text."); 1.66 + is(rows[0].querySelectorAll("label")[1].getAttribute("value"), "11.1foo", 1.67 + "The second column of the first row displays the correct text."); 1.68 + 1.69 + ok(rows[1].querySelector(".table-chart-row-box.chart-colored-blob"), 1.70 + "A colored blob exists for the second row."); 1.71 + is(rows[1].querySelectorAll("label")[0].getAttribute("name"), "label1", 1.72 + "The first column of the second row exists."); 1.73 + is(rows[1].querySelectorAll("label")[1].getAttribute("name"), "label2", 1.74 + "The second column of the second row exists."); 1.75 + is(rows[1].querySelectorAll("label")[0].getAttribute("value"), "2", 1.76 + "The first column of the second row displays the correct text."); 1.77 + is(rows[1].querySelectorAll("label")[1].getAttribute("value"), "12.2bar", 1.78 + "The second column of the first row displays the correct text."); 1.79 + 1.80 + ok(rows[2].querySelector(".table-chart-row-box.chart-colored-blob"), 1.81 + "A colored blob exists for the third row."); 1.82 + is(rows[2].querySelectorAll("label")[0].getAttribute("name"), "label1", 1.83 + "The first column of the third row exists."); 1.84 + is(rows[2].querySelectorAll("label")[1].getAttribute("name"), "label2", 1.85 + "The second column of the third row exists."); 1.86 + is(rows[2].querySelectorAll("label")[0].getAttribute("value"), "3", 1.87 + "The first column of the third row displays the correct text."); 1.88 + is(rows[2].querySelectorAll("label")[1].getAttribute("value"), "13.3baz", 1.89 + "The second column of the third row displays the correct text."); 1.90 + 1.91 + is(sums.length, 2, 1.92 + "There should be 2 total summaries created."); 1.93 + 1.94 + is(totals.querySelectorAll(".table-chart-summary-label")[0].getAttribute("name"), "label1", 1.95 + "The first sum's type is correct."); 1.96 + is(totals.querySelectorAll(".table-chart-summary-label")[0].getAttribute("value"), "Hello 6", 1.97 + "The first sum's value is correct."); 1.98 + 1.99 + is(totals.querySelectorAll(".table-chart-summary-label")[1].getAttribute("name"), "label2", 1.100 + "The second sum's type is correct."); 1.101 + is(totals.querySelectorAll(".table-chart-summary-label")[1].getAttribute("value"), "World 36.60", 1.102 + "The second sum's value is correct."); 1.103 + 1.104 + teardown(aMonitor).then(finish); 1.105 + }); 1.106 +}