browser_dbg-search-file.js (3347B)
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 the search bar correctly responds to queries, enter, shift enter 6 7 "use strict"; 8 9 add_task(async function () { 10 const dbg = await initDebugger("doc-scripts.html", "simple1.js"); 11 await selectSource(dbg, "simple1.js"); 12 13 pressKey(dbg, "fileSearch"); 14 is(dbg.selectors.getActiveSearch(), "file", "The search UI was opened"); 15 16 info("Test closing and re-opening the search UI"); 17 pressKey(dbg, "Escape"); 18 is( 19 dbg.selectors.getActiveSearch(), 20 null, 21 "The search UI was closed when hitting Escape" 22 ); 23 24 pressKey(dbg, "fileSearch"); 25 is(dbg.selectors.getActiveSearch(), "file", "The search UI was opened again"); 26 27 info("Search for `con` in the script"); 28 type(dbg, "con"); 29 await waitForSearchState(dbg); 30 31 // All the lines in the script that include `con` 32 const linesWithResults = [ 33 // const func 34 4, 35 // const result 36 5, 37 // constructor (in MyClass) 38 42, 39 // constructor (in Klass) 40 55, 41 // const bla 42 78, 43 ]; 44 45 await waitForCursorPosition(dbg, linesWithResults[0]); 46 assertCursorPosition( 47 dbg, 48 linesWithResults[0], 49 6, 50 "typing in the search input moves the cursor in the source content" 51 ); 52 53 info("Check that pressing Enter navigates forward through the results"); 54 await navigateWithKey( 55 dbg, 56 "Enter", 57 linesWithResults[1], 58 "Enter moves forward in the search results" 59 ); 60 61 await navigateWithKey( 62 dbg, 63 "Enter", 64 linesWithResults[2], 65 "Enter moves forward in the search results" 66 ); 67 68 info( 69 "Check that pressing Shift+Enter navigates backward through the results" 70 ); 71 await navigateWithKey( 72 dbg, 73 "ShiftEnter", 74 linesWithResults[1], 75 "Shift+Enter moves backward in the search results" 76 ); 77 78 await navigateWithKey( 79 dbg, 80 "ShiftEnter", 81 linesWithResults[0], 82 "Shift+Enter moves backward in the search results" 83 ); 84 85 info( 86 "Check that navigating backward goes to the last result when we were at the first one" 87 ); 88 await navigateWithKey( 89 dbg, 90 "ShiftEnter", 91 linesWithResults.at(-1), 92 "Shift+Enter cycles back through the results" 93 ); 94 95 info( 96 "Check that navigating forward goes to the first result when we were at the last one" 97 ); 98 await navigateWithKey( 99 dbg, 100 "Enter", 101 linesWithResults[0], 102 "Enter cycles forward through the results" 103 ); 104 105 info("Check that changing the search term works"); 106 pressKey(dbg, "fileSearch"); 107 type(dbg, "doEval"); 108 109 await waitForCursorPosition(dbg, 9); 110 assertCursorPosition( 111 dbg, 112 9, 113 16, 114 "The UI navigates to the new search results" 115 ); 116 117 // selecting another source keeps search open 118 await selectSource(dbg, "simple2.js"); 119 ok(findElement(dbg, "searchField"), "Search field is still visible"); 120 121 // search is always focused regardless of when or how it was opened 122 pressKey(dbg, "fileSearch"); 123 await clickElement(dbg, "codeMirror"); 124 pressKey(dbg, "fileSearch"); 125 is(dbg.win.document.activeElement.tagName, "INPUT", "Search field focused"); 126 }); 127 128 async function navigateWithKey(dbg, key, expectedLine) { 129 pressKey(dbg, key); 130 await waitForCursorPosition(dbg, expectedLine); 131 }