зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1184525 - Reset previous search results on markup-mutations to make sure we search again; r=pbrosset
This commit is contained in:
Родитель
b723623678
Коммит
857c47ebc1
|
@ -46,6 +46,7 @@ function SelectorSearch(aInspector, aInputNode) {
|
|||
this._onHTMLSearch = this._onHTMLSearch.bind(this);
|
||||
this._onSearchKeypress = this._onSearchKeypress.bind(this);
|
||||
this._onListBoxKeypress = this._onListBoxKeypress.bind(this);
|
||||
this._onMarkupMutation = this._onMarkupMutation.bind(this);
|
||||
|
||||
// Options for the AutocompletePopup.
|
||||
let options = {
|
||||
|
@ -63,6 +64,7 @@ function SelectorSearch(aInspector, aInputNode) {
|
|||
// event listeners.
|
||||
this.searchBox.addEventListener("command", this._onHTMLSearch, true);
|
||||
this.searchBox.addEventListener("keypress", this._onSearchKeypress, true);
|
||||
this.inspector.on("markupmutation", this._onMarkupMutation);
|
||||
|
||||
// For testing, we need to be able to wait for the most recent node request
|
||||
// to finish. Tests can watch this promise for that.
|
||||
|
@ -170,6 +172,7 @@ SelectorSearch.prototype = {
|
|||
// event listeners.
|
||||
this.searchBox.removeEventListener("command", this._onHTMLSearch, true);
|
||||
this.searchBox.removeEventListener("keypress", this._onSearchKeypress, true);
|
||||
this.inspector.off("markupmutation", this._onMarkupMutation);
|
||||
this.searchPopup.destroy();
|
||||
this.searchPopup = null;
|
||||
this.searchBox = null;
|
||||
|
@ -423,6 +426,15 @@ SelectorSearch.prototype = {
|
|||
this.emit("processing-done");
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset previous search results on markup-mutations to make sure we search
|
||||
* again after nodes have been added/removed/changed.
|
||||
*/
|
||||
_onMarkupMutation: function() {
|
||||
this._searchResults = null;
|
||||
this._lastSearched = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Populates the suggestions list and show the suggestion popup.
|
||||
*/
|
||||
|
|
|
@ -102,6 +102,7 @@ skip-if = e10s # Test synthesize scrolling events in content. Also, see bug 1035
|
|||
[browser_inspector_search-03.js]
|
||||
[browser_inspector_search-04.js]
|
||||
[browser_inspector_search-05.js]
|
||||
[browser_inspector_search-06.js]
|
||||
[browser_inspector_search-reserved.js]
|
||||
[browser_inspector_select-docshell.js]
|
||||
[browser_inspector_select-last-selected.js]
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Check that searching again for nodes after they are removed or added from the
|
||||
// DOM works correctly.
|
||||
|
||||
const TEST_URL = TEST_URL_ROOT + "doc_inspector_search.html";
|
||||
|
||||
add_task(function* () {
|
||||
let { inspector, testActor } = yield openInspectorForURL(TEST_URL);
|
||||
|
||||
info("Searching for test node #d1");
|
||||
yield focusSearchBoxUsingShortcut(inspector.panelWin);
|
||||
yield synthesizeKeys(["#", "d", "1"], inspector);
|
||||
|
||||
assertHasResult(inspector, true);
|
||||
|
||||
info("Removing node #d1");
|
||||
yield mutatePage(inspector, testActor,
|
||||
"document.getElementById(\"d1\").remove()");
|
||||
|
||||
info("Pressing return button to search again for node #d1.");
|
||||
yield synthesizeKeys("VK_RETURN", inspector);
|
||||
|
||||
assertHasResult(inspector, false);
|
||||
|
||||
info("Emptying the field and searching for a node that doesn't exist: #d3");
|
||||
let keys = ["VK_BACK_SPACE", "VK_BACK_SPACE", "VK_BACK_SPACE", "#", "d", "3"];
|
||||
yield synthesizeKeys(keys, inspector);
|
||||
|
||||
assertHasResult(inspector, false);
|
||||
|
||||
info("Create the #d3 node in the page");
|
||||
yield mutatePage(inspector, testActor,
|
||||
`document.getElementById("d2").insertAdjacentHTML(
|
||||
"afterend", "<div id=d3></div>")`);
|
||||
|
||||
info("Pressing return button to search again for node #d3.");
|
||||
yield synthesizeKeys("VK_RETURN", inspector);
|
||||
|
||||
assertHasResult(inspector, true);
|
||||
|
||||
// Catch-all event for remaining server requests when searching for the new
|
||||
// node.
|
||||
yield inspector.once("inspector-updated");
|
||||
});
|
||||
|
||||
function* synthesizeKeys(keys, inspector) {
|
||||
if (typeof keys === "string") {
|
||||
keys = [keys];
|
||||
}
|
||||
|
||||
for (let key of keys) {
|
||||
info("Synthesizing key " + key + " in the search box");
|
||||
let eventHandled = once(inspector.searchBox, "command", true);
|
||||
EventUtils.synthesizeKey(key, {}, inspector.panelWin);
|
||||
yield eventHandled;
|
||||
info("Waiting for the search query to complete");
|
||||
yield inspector.searchSuggestions._lastQuery;
|
||||
}
|
||||
}
|
||||
|
||||
function assertHasResult(inspector, expectResult) {
|
||||
is(inspector.searchBox.classList.contains("devtools-no-search-result"),
|
||||
!expectResult,
|
||||
"There are" + (expectResult ? "" : " no") + " search results");
|
||||
}
|
||||
|
||||
function* mutatePage(inspector, testActor, expression) {
|
||||
let onUpdated = inspector.once("inspector-updated");
|
||||
yield testActor.eval(expression);
|
||||
yield onUpdated;
|
||||
}
|
Загрузка…
Ссылка в новой задаче