browser_webconsole_reverse_search_initial_value.js (3027B)
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 // Tests reverse search features. 6 7 "use strict"; 8 9 const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8>Test reverse search initial value`; 10 11 add_task(async function () { 12 const hud = await openNewTabAndConsole(TEST_URI); 13 const { jsterm } = hud; 14 15 const jstermHistory = [ 16 `Dog = "Snoopy"`, 17 `document 18 .querySelectorAll("*") 19 .forEach(() => {})`, 20 `document`, 21 `"😎"`, 22 ]; 23 24 const onLastMessage = waitForMessageByType(hud, `"😎"`, ".result"); 25 for (const input of jstermHistory) { 26 execute(hud, input); 27 } 28 await onLastMessage; 29 30 setInputValue(hud, "ado"); 31 32 info(`Select 2 chars ("do") from the input`); 33 jsterm.editor.setSelection({ line: 0, ch: 1 }, { line: 0, ch: 3 }); 34 35 info("Check that the reverse search toolbar as the expected initial state"); 36 let reverseSearchElement = await openReverseSearch(hud); 37 is( 38 reverseSearchElement.querySelector("input").value, 39 "do", 40 `Reverse search input has expected "do" value` 41 ); 42 is(isReverseSearchInputFocused(hud), true, "reverse search input is focused"); 43 ok( 44 reverseSearchElement, 45 "Reverse search is displayed with a keyboard shortcut" 46 ); 47 const infoElement = getReverseSearchInfoElement(hud); 48 is( 49 infoElement.textContent, 50 "3 of 3 results", 51 "The reverse info has the expected text" 52 ); 53 54 const previousButton = reverseSearchElement.querySelector( 55 ".search-result-button-prev" 56 ); 57 const nextButton = reverseSearchElement.querySelector( 58 ".search-result-button-next" 59 ); 60 ok(previousButton, "Previous navigation button is displayed"); 61 ok(nextButton, "Next navigation button is displayed"); 62 63 is(getInputValue(hud), "document", "JsTerm has the expected input"); 64 is( 65 jsterm.autocompletePopup.isOpen, 66 false, 67 "Setting the input value did not trigger the autocompletion" 68 ); 69 70 const onJsTermValueChanged = jsterm.once("set-input-value"); 71 EventUtils.sendString("g"); 72 await onJsTermValueChanged; 73 is(getInputValue(hud), `Dog = "Snoopy"`, "JsTerm input was updated"); 74 is( 75 infoElement.textContent, 76 "1 result", 77 "The reverse info has the expected text" 78 ); 79 ok( 80 !reverseSearchElement.querySelector(".search-result-button-prev") && 81 !reverseSearchElement.querySelector(".search-result-button-next"), 82 "The results navigation buttons are not displayed when there's only one result" 83 ); 84 85 info("Check that there's no initial value when no text is selected"); 86 EventUtils.synthesizeKey("KEY_Escape"); 87 await waitFor(() => !getReverseSearchElement(hud)); 88 89 info( 90 "Check that opening the reverse search input is empty after opening it again" 91 ); 92 reverseSearchElement = await openReverseSearch(hud); 93 is( 94 reverseSearchElement.querySelector("input").value, 95 "", 96 "Reverse search input is empty" 97 ); 98 });