Skip to content

Commit c853ad4

Browse files
committed
Bug 1971094 - [devtools] Update search results when the selected source changes r=devtools-reviewers,nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D253015
1 parent e2fbaf5 commit c853ad4

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

devtools/client/debugger/src/components/Editor/SearchInFileBar.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
getIsCurrentThreadPaused,
1414
getSelectedSourceTextContent,
1515
getSearchOptions,
16-
getSelectedFrame,
1716
} from "../../selectors/index";
1817

1918
import { searchKeys } from "../../constants";
@@ -60,7 +59,6 @@ class SearchInFileBar extends Component {
6059
searchInFileEnabled: PropTypes.bool.isRequired,
6160
selectedSourceTextContent: PropTypes.object,
6261
selectedSource: PropTypes.object.isRequired,
63-
selectedFrame: PropTypes.object.isRequired,
6462
setActiveSearch: PropTypes.func.isRequired,
6563
querySearchWorker: PropTypes.func.isRequired,
6664
selectLocation: PropTypes.func.isRequired,
@@ -85,9 +83,8 @@ class SearchInFileBar extends Component {
8583
query &&
8684
this.props.selectedSource &&
8785
this.props.searchInFileEnabled &&
88-
nextProps.selectedFrame &&
8986
// If a new source is selected update the file search results
90-
nextProps.selectedFrame.location.source.id !== nextProps.selectedSource.id
87+
this.props.selectedSource.id !== nextProps.selectedSource.id
9188
) {
9289
// Do not scroll to the search location, if we just switched a new source
9390
// and debugger is already paused on a selelcted line.
@@ -400,7 +397,6 @@ const mapStateToProps = state => {
400397
selectedSource: getSelectedSource(state),
401398
isPaused: getIsCurrentThreadPaused(state),
402399
selectedSourceTextContent: getSelectedSourceTextContent(state),
403-
selectedFrame: getSelectedFrame(state),
404400
modifiers: getSearchOptions(state, "file-search"),
405401
};
406402
};

devtools/client/debugger/test/mochitest/browser_dbg-search-file-retains-query.js

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
44

5-
// Tests the search bar retains previous query on re-opening.
6-
75
"use strict";
86

9-
add_task(async function () {
7+
// Tests the search bar retains previous query on re-opening.
8+
add_task(async function testSearchRetainsPreviousQuery() {
109
const dbg = await initDebugger("doc-scripts.html", "simple1.js");
1110
const {
1211
selectors: { getActiveSearch },
@@ -36,3 +35,54 @@ add_task(async function () {
3635
// Test for the retained query
3736
is(findElement(dbg, "fileSearchInput").value, "con");
3837
});
38+
39+
// Tests that the search results are updated when switching between sources
40+
add_task(async function testSearchUpdatesResultsOnSourceChanges() {
41+
const dbg = await initDebugger("doc-scripts.html", "simple1.js", "long.js");
42+
const {
43+
selectors: { getActiveSearch },
44+
} = dbg;
45+
46+
await selectSource(dbg, "simple1.js");
47+
48+
// Open search bar
49+
pressKey(dbg, "fileSearch");
50+
await waitFor(() => getActiveSearch() === "file");
51+
is(getActiveSearch(), "file");
52+
53+
// Type a search query
54+
const searchQuery = "this";
55+
type(dbg, searchQuery);
56+
await waitForSearchState(dbg);
57+
58+
await waitUntil(
59+
() => findElement(dbg, "fileSearchSummary").innerText !== "No results found"
60+
);
61+
62+
is(
63+
findElement(dbg, "fileSearchSummary").innerText,
64+
"1 of 3 results",
65+
`There are 3 results found for search query "${searchQuery}" in simple1.js`
66+
);
67+
is(
68+
findElement(dbg, "fileSearchInput").value,
69+
searchQuery,
70+
`The search input value matches the search query "${searchQuery}"`
71+
);
72+
73+
info("Switch to long.js");
74+
await selectSource(dbg, "long.js");
75+
76+
await waitUntil(
77+
() => findElement(dbg, "fileSearchSummary").innerText == "1 of 23 results"
78+
);
79+
ok(
80+
true,
81+
`There are 23 results found for search query "${searchQuery}" in long.js`
82+
);
83+
is(
84+
findElement(dbg, "fileSearchInput").value,
85+
searchQuery,
86+
`The search input value still matches the search query "${searchQuery}"`
87+
);
88+
});

devtools/client/debugger/test/mochitest/shared-head.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,7 @@ const selectors = {
19401940
sourceTreeFolderNode: ".sources-panel .node .folder",
19411941
excludePatternsInput: ".project-text-search .exclude-patterns-field input",
19421942
fileSearchInput: ".search-bar input",
1943+
fileSearchSummary: ".search-bar .search-field-summary",
19431944
watchExpressionsHeader: ".watch-expressions-pane ._header .header-label",
19441945
watchExpressionsAddButton: ".watch-expressions-pane ._header .plus",
19451946
editorNotificationFooter: ".editor-notification-footer",

0 commit comments

Comments
 (0)