Wed, 31 Dec 2014 06:09:35 +0100
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 Table 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, L10N, Chart } = aMonitor.panelWin; |
michael@0 | 13 | let container = document.createElement("box"); |
michael@0 | 14 | |
michael@0 | 15 | let table = Chart.Table(document, { |
michael@0 | 16 | title: "Table title", |
michael@0 | 17 | data: [{ |
michael@0 | 18 | label1: 1, |
michael@0 | 19 | label2: 11.1 |
michael@0 | 20 | }, { |
michael@0 | 21 | label1: 2, |
michael@0 | 22 | label2: 12.2 |
michael@0 | 23 | }, { |
michael@0 | 24 | label1: 3, |
michael@0 | 25 | label2: 13.3 |
michael@0 | 26 | }], |
michael@0 | 27 | strings: { |
michael@0 | 28 | label2: (value, index) => value + ["foo", "bar", "baz"][index] |
michael@0 | 29 | }, |
michael@0 | 30 | totals: { |
michael@0 | 31 | label1: value => "Hello " + L10N.numberWithDecimals(value, 2), |
michael@0 | 32 | label2: value => "World " + L10N.numberWithDecimals(value, 2) |
michael@0 | 33 | } |
michael@0 | 34 | }); |
michael@0 | 35 | |
michael@0 | 36 | let node = table.node; |
michael@0 | 37 | let title = node.querySelector(".table-chart-title"); |
michael@0 | 38 | let grid = node.querySelector(".table-chart-grid"); |
michael@0 | 39 | let totals = node.querySelector(".table-chart-totals"); |
michael@0 | 40 | let rows = grid.querySelectorAll(".table-chart-row"); |
michael@0 | 41 | let sums = node.querySelectorAll(".table-chart-summary-label"); |
michael@0 | 42 | |
michael@0 | 43 | ok(node.classList.contains("table-chart-container") && |
michael@0 | 44 | node.classList.contains("generic-chart-container"), |
michael@0 | 45 | "A table chart container was created successfully."); |
michael@0 | 46 | |
michael@0 | 47 | ok(title, |
michael@0 | 48 | "A title node was created successfully."); |
michael@0 | 49 | is(title.getAttribute("value"), "Table title", |
michael@0 | 50 | "The title node displays the correct text."); |
michael@0 | 51 | |
michael@0 | 52 | is(rows.length, 3, |
michael@0 | 53 | "There should be 3 table chart rows created."); |
michael@0 | 54 | |
michael@0 | 55 | ok(rows[0].querySelector(".table-chart-row-box.chart-colored-blob"), |
michael@0 | 56 | "A colored blob exists for the firt row."); |
michael@0 | 57 | is(rows[0].querySelectorAll("label")[0].getAttribute("name"), "label1", |
michael@0 | 58 | "The first column of the first row exists."); |
michael@0 | 59 | is(rows[0].querySelectorAll("label")[1].getAttribute("name"), "label2", |
michael@0 | 60 | "The second column of the first row exists."); |
michael@0 | 61 | is(rows[0].querySelectorAll("label")[0].getAttribute("value"), "1", |
michael@0 | 62 | "The first column of the first row displays the correct text."); |
michael@0 | 63 | is(rows[0].querySelectorAll("label")[1].getAttribute("value"), "11.1foo", |
michael@0 | 64 | "The second column of the first row displays the correct text."); |
michael@0 | 65 | |
michael@0 | 66 | ok(rows[1].querySelector(".table-chart-row-box.chart-colored-blob"), |
michael@0 | 67 | "A colored blob exists for the second row."); |
michael@0 | 68 | is(rows[1].querySelectorAll("label")[0].getAttribute("name"), "label1", |
michael@0 | 69 | "The first column of the second row exists."); |
michael@0 | 70 | is(rows[1].querySelectorAll("label")[1].getAttribute("name"), "label2", |
michael@0 | 71 | "The second column of the second row exists."); |
michael@0 | 72 | is(rows[1].querySelectorAll("label")[0].getAttribute("value"), "2", |
michael@0 | 73 | "The first column of the second row displays the correct text."); |
michael@0 | 74 | is(rows[1].querySelectorAll("label")[1].getAttribute("value"), "12.2bar", |
michael@0 | 75 | "The second column of the first row displays the correct text."); |
michael@0 | 76 | |
michael@0 | 77 | ok(rows[2].querySelector(".table-chart-row-box.chart-colored-blob"), |
michael@0 | 78 | "A colored blob exists for the third row."); |
michael@0 | 79 | is(rows[2].querySelectorAll("label")[0].getAttribute("name"), "label1", |
michael@0 | 80 | "The first column of the third row exists."); |
michael@0 | 81 | is(rows[2].querySelectorAll("label")[1].getAttribute("name"), "label2", |
michael@0 | 82 | "The second column of the third row exists."); |
michael@0 | 83 | is(rows[2].querySelectorAll("label")[0].getAttribute("value"), "3", |
michael@0 | 84 | "The first column of the third row displays the correct text."); |
michael@0 | 85 | is(rows[2].querySelectorAll("label")[1].getAttribute("value"), "13.3baz", |
michael@0 | 86 | "The second column of the third row displays the correct text."); |
michael@0 | 87 | |
michael@0 | 88 | is(sums.length, 2, |
michael@0 | 89 | "There should be 2 total summaries created."); |
michael@0 | 90 | |
michael@0 | 91 | is(totals.querySelectorAll(".table-chart-summary-label")[0].getAttribute("name"), "label1", |
michael@0 | 92 | "The first sum's type is correct."); |
michael@0 | 93 | is(totals.querySelectorAll(".table-chart-summary-label")[0].getAttribute("value"), "Hello 6", |
michael@0 | 94 | "The first sum's value is correct."); |
michael@0 | 95 | |
michael@0 | 96 | is(totals.querySelectorAll(".table-chart-summary-label")[1].getAttribute("name"), "label2", |
michael@0 | 97 | "The second sum's type is correct."); |
michael@0 | 98 | is(totals.querySelectorAll(".table-chart-summary-label")[1].getAttribute("value"), "World 36.60", |
michael@0 | 99 | "The second sum's value is correct."); |
michael@0 | 100 | |
michael@0 | 101 | teardown(aMonitor).then(finish); |
michael@0 | 102 | }); |
michael@0 | 103 | } |