browser_jsterm_eager_evaluation_element_highlight.js (2977B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const TEST_URI = `data:text/html;charset=utf8,<!DOCTYPE html> 8 <h1 class="title">hello</h1> 9 <div id="mydiv">mydivtext</div> 10 <script> 11 x = Object.create(null, Object.getOwnPropertyDescriptors({ 12 a: document.querySelector("h1"), 13 b: document.querySelector("div"), 14 c: document.createElement("hr") 15 })); 16 </script>`; 17 18 // Test that when the eager evaluation result is an element, it gets highlighted. 19 add_task(async function () { 20 const hud = await openNewTabAndConsole(TEST_URI); 21 const { jsterm, toolbox } = hud; 22 const { autocompletePopup } = jsterm; 23 24 const highlighterTestFront = await getHighlighterTestFront(toolbox); 25 const highlighter = toolbox.getHighlighter(); 26 let onHighlighterShown; 27 let onHighlighterHidden; 28 let data; 29 30 ok(!autocompletePopup.isOpen, "popup is not open"); 31 const onPopupOpen = autocompletePopup.once("popup-opened"); 32 onHighlighterShown = highlighter.waitForHighlighterShown(); 33 EventUtils.sendString("x."); 34 await onPopupOpen; 35 36 await waitForEagerEvaluationResult(hud, `<h1 class="title">`); 37 data = await onHighlighterShown; 38 is(data.nodeFront.displayName, "h1", "The correct node was highlighted"); 39 isVisible = await highlighterTestFront.isHighlighting(); 40 is(isVisible, true, "Highlighter is displayed"); 41 42 onHighlighterShown = highlighter.waitForHighlighterShown(); 43 EventUtils.synthesizeKey("KEY_ArrowDown"); 44 await waitForEagerEvaluationResult(hud, `<div id="mydiv">`); 45 data = await onHighlighterShown; 46 is(data.nodeFront.displayName, "div", "The correct node was highlighted"); 47 isVisible = await highlighterTestFront.isHighlighting(); 48 is(isVisible, true, "Highlighter is displayed"); 49 50 onHighlighterHidden = highlighter.waitForHighlighterHidden(); 51 EventUtils.synthesizeKey("KEY_ArrowDown"); 52 await waitForEagerEvaluationResult(hud, `<hr>`); 53 await onHighlighterHidden; 54 ok(true, "The highlighter isn't displayed on a non-connected element"); 55 56 info("Test that text nodes are highlighted"); 57 onHighlighterShown = highlighter.waitForHighlighterShown(); 58 EventUtils.sendString("b.firstChild"); 59 await waitForEagerEvaluationResult(hud, `#text "mydivtext"`); 60 data = await onHighlighterShown; 61 is( 62 data.nodeFront.displayName, 63 "#text", 64 "The correct text node was highlighted" 65 ); 66 isVisible = await highlighterTestFront.isHighlighting(); 67 is(isVisible, true, "Highlighter is displayed"); 68 69 onHighlighterHidden = highlighter.waitForHighlighterHidden(); 70 EventUtils.synthesizeKey("KEY_Enter"); 71 await waitFor(() => findEvaluationResultMessage(hud, `#text "mydivtext"`)); 72 await waitForNoEagerEvaluationResult(hud); 73 isVisible = await highlighterTestFront.isHighlighting(); 74 is(isVisible, false, "Highlighter is closed after evaluating the expression"); 75 });