browser_webconsole_select_all.js (2123B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that the global Firefox "Select All" functionality (e.g. Edit > 7 // Select All) works properly in the Web Console. 8 9 const TEST_URI = "http://example.com/"; 10 11 add_task(async function testSelectAll() { 12 const hud = await openNewTabAndConsole(TEST_URI); 13 await testSelectionWhenMovingBetweenBoxes(hud); 14 testBrowserMenuSelectAll(hud); 15 }); 16 17 async function testSelectionWhenMovingBetweenBoxes(hud) { 18 // Fill the console with some output. 19 await clearOutput(hud); 20 await executeAndWaitForResultMessage(hud, "1 + 2", "3"); 21 await executeAndWaitForResultMessage(hud, "3 + 4", "7"); 22 await executeAndWaitForResultMessage(hud, "5 + 6", "11"); 23 } 24 25 function testBrowserMenuSelectAll(hud) { 26 const { ui } = hud; 27 const outputContainer = ui.outputNode.querySelector(".webconsole-output"); 28 29 is( 30 outputContainer.querySelectorAll(".message").length, 31 6, 32 "the output node contains the expected number of messages" 33 ); 34 35 // The focus is on the JsTerm, so we need to blur it for the copy comand to 36 // work. 37 outputContainer.ownerDocument.activeElement.blur(); 38 39 // Test that the global Firefox "Select All" functionality (e.g. Edit > 40 // Select All) works properly in the Web Console. 41 goDoCommand("cmd_selectAll"); 42 43 checkMessagesSelected(outputContainer); 44 hud.iframeWindow.getSelection().removeAllRanges(); 45 } 46 47 function checkMessagesSelected(outputContainer) { 48 const selection = outputContainer.ownerDocument.getSelection(); 49 const messages = outputContainer.querySelectorAll(".message"); 50 51 for (const message of messages) { 52 // Oddly, something about the top and bottom buffer having user-select be 53 // 'none' means that the messages themselves don't register as selected. 54 // However, all of their children will count as selected, which should be 55 // good enough for our purposes. 56 const selected = [...message.children].every(c => 57 selection.containsNode(c) 58 ); 59 ok(selected, `Node containing text "${message.textContent}" was selected`); 60 } 61 }