browser_webconsole_console_table_post_alterations.js (1840B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Check that calling console.table on a variable which is modified after the 7 // console.table call only shows data for when the variable was logged. 8 9 const TEST_URI = `data:text/html,<!DOCTYPE html>Test console.table with modified variable`; 10 11 add_task(async function () { 12 const hud = await openNewTabAndConsole(TEST_URI); 13 14 await ContentTask.spawn(gBrowser.selectedBrowser, null, () => { 15 const x = ["a", "b"]; 16 content.wrappedJSObject.console.table(x); 17 x.push("c"); 18 content.wrappedJSObject.console.table(x); 19 x.sort((a, b) => { 20 if (a < b) { 21 return 1; 22 } 23 if (a > b) { 24 return -1; 25 } 26 return 0; 27 }); 28 content.wrappedJSObject.console.table(x); 29 }); 30 31 const [table1, table2, table3] = await waitFor(() => { 32 const res = hud.ui.outputNode.querySelectorAll(".message .consoletable"); 33 if (res.length === 3) { 34 return res; 35 } 36 return null; 37 }); 38 39 info("Check the rows of the first table"); 40 checkTable(table1, [ 41 [0, "a"], 42 [1, "b"], 43 ]); 44 45 info("Check the rows of the table after adding an element to the array"); 46 checkTable(table2, [ 47 [0, "a"], 48 [1, "b"], 49 [2, "c"], 50 ]); 51 52 info("Check the rows of the table after sorting the array"); 53 checkTable(table3, [ 54 [0, "c"], 55 [1, "b"], 56 [2, "a"], 57 ]); 58 }); 59 60 function checkTable(node, expectedRows) { 61 const rows = Array.from(node.querySelectorAll("tbody tr")); 62 is(rows.length, expectedRows.length, "table has the expected number of rows"); 63 64 expectedRows.forEach((expectedRow, rowIndex) => { 65 const rowCells = Array.from(rows[rowIndex].querySelectorAll("td")); 66 is(rowCells.map(x => x.textContent).join(" | "), expectedRow.join(" | ")); 67 }); 68 }