browser_dbg-search-file-paused.js (2391B)
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( 11 "doc-scripts.html", 12 "simple1.js", 13 "simple2.js" 14 ); 15 16 info("Add a breakpoint, wait for pause"); 17 const source = findSource(dbg, "simple2.js"); 18 await selectSource(dbg, source); 19 await addBreakpoint(dbg, source, 5); 20 invokeInTab("main"); 21 await waitForPaused(dbg); 22 23 info("Starting a search for 'bar'"); 24 pressKey(dbg, "fileSearch"); 25 is(dbg.selectors.getActiveSearch(), "file"); 26 const el = getFocusedEl(dbg); 27 type(dbg, "bar"); 28 await waitForSearchState(dbg); 29 await waitFor(() => { 30 return getSearchQuery(dbg).includes("bar"); 31 }); 32 is(getSearchSelection(dbg).line, 1); 33 info("Ensuring 'bar' matches are highlighted"); 34 pressKey(dbg, "Enter"); 35 is(getSearchSelection(dbg).line, 4); 36 pressKey(dbg, "Enter"); 37 is(getSearchSelection(dbg).line, 1); 38 39 info("Switching files via frame click"); 40 const frames = findAllElements(dbg, "frames"); 41 pressMouseDown(dbg, frames[1]); 42 43 // Ensure that the debug line is in view, and not the first "bar" instance, 44 // which the user would have to scroll down for 45 ok(isScrolledPositionVisible(dbg, 1), "First search term is not in view"); 46 47 // Change the search term and go back to the first source in stack 48 info("Switching to paused file via frame click"); 49 pressKey(dbg, "fileSearch"); 50 el.value = ""; 51 type(dbg, "func"); 52 await waitForSearchState(dbg); 53 pressMouseDown(dbg, frames[0]); 54 await waitFor(() => { 55 return getSearchQuery(dbg).includes("func"); 56 }); 57 is(getSearchSelection(dbg).line, 0); 58 // Ensure there is a match for the new term and correct item is selected 59 pressKey(dbg, "Enter"); 60 await waitFor(() => getSearchSelection(dbg).line === 1); 61 pressKey(dbg, "Enter"); 62 // There are only two items in the search so pressing enter will cycle back to the first 63 await waitFor(() => getSearchSelection(dbg).line === 0); 64 }); 65 66 function getFocusedEl(dbg) { 67 const doc = dbg.win.document; 68 return doc.activeElement; 69 } 70 71 function pressMouseDown(dbg, node) { 72 EventUtils.sendMouseEvent({ type: "mousedown" }, node, dbg.win); 73 }