Bug 851349 - Fix intermittent failures in disabled test browser_inspector_search-navigation.js and re-enable it. r=pbrosset

This commit is contained in:
Sami Jaktholm 2014-07-10 22:00:00 +02:00
parent 39e4605c54
commit 35873cd632
3 changed files with 78 additions and 157 deletions

@ -5,7 +5,7 @@
"use strict";
const promise = require("devtools/toolkit/deprecated-sync-thenables");
loader.lazyGetter(this, "EventEmitter", () => require("devtools/toolkit/event-emitter"));
loader.lazyGetter(this, "AutocompletePopup", () => require("devtools/shared/autocomplete-popup").AutocompletePopup);
// Maximum number of selector suggestions shown in the panel.
@ -14,6 +14,10 @@ const MAX_SUGGESTIONS = 15;
/**
* Converts any input box on a page to a CSS selector search and suggestion box.
*
* Emits 'processing-done' event when it is done processing the current
* keypress, search request or selection from the list, whether that led to a
* search or not.
*
* @constructor
* @param InspectorPanel aInspector
* The InspectorPanel whose `walker` attribute should be used for
@ -61,6 +65,7 @@ function SelectorSearch(aInspector, aInputNode) {
// For testing, we need to be able to wait for the most recent node request
// to finish. Tests can watch this promise for that.
this._lastQuery = promise.resolve(null);
EventEmitter.decorate(this);
}
exports.SelectorSearch = SelectorSearch;
@ -183,6 +188,7 @@ SelectorSearch.prototype = {
_onHTMLSearch: function() {
let query = this.searchBox.value;
if (query == this._lastSearched) {
this.emit("processing-done");
return;
}
this._lastSearched = query;
@ -196,6 +202,7 @@ SelectorSearch.prototype = {
if (this.searchPopup.isOpen) {
this.searchPopup.hidePopup();
}
this.emit("processing-done");
return;
}
@ -258,7 +265,7 @@ SelectorSearch.prototype = {
}
this.searchBox.classList.add("devtools-no-search-result");
return this.showSuggestions();
});
}).then(() => this.emit("processing-done"));
},
/**
@ -332,7 +339,10 @@ SelectorSearch.prototype = {
aEvent.preventDefault();
aEvent.stopPropagation();
if (this._searchResults && this._searchResults.length > 0) {
this._lastQuery = this._selectResult(this._searchIndex);
this._lastQuery = this._selectResult(this._searchIndex).then(() => this.emit("processing-done"));
}
else {
this.emit("processing-done");
}
},
@ -393,6 +403,7 @@ SelectorSearch.prototype = {
this._onHTMLSearch();
break;
}
this.emit("processing-done");
},
/**

@ -48,8 +48,7 @@ skip-if = true # Bug 1028609
[browser_inspector_search-02.js]
[browser_inspector_search-03.js]
[browser_inspector_select-last-selected.js]
# [browser_inspector_search-navigation.js]
# Disabled for too many intermittent failures (bug 851349)
[browser_inspector_search-navigation.js]
[browser_inspector_sidebarstate.js]
[browser_inspector_switch-to-inspector-on-pick.js]
[browser_inspector_update-on-navigation.js]

@ -1,162 +1,73 @@
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
function test()
{
requestLongerTimeout(2);
// Check that searchbox value is correct when suggestions popup is navigated
// with keyboard.
let inspector, searchBox, state, panel;
let panelOpeningStates = [0, 3, 9, 14, 17];
let panelClosingStates = [2, 8, 13, 16];
// Test data as pairs of [key to press, expected content of searchbox].
const KEY_STATES = [
["d", "d"],
["i", "di"],
["v", "div"],
[".", "div."],
["VK_UP", "div.c1"],
["VK_DOWN", "div.l1"],
["VK_DOWN", "div.l1"],
["VK_BACK_SPACE", "div.l"],
["VK_TAB", "div.l1"],
[" ", "div.l1 "],
["VK_UP", "div.l1 div"],
["VK_UP", "div.l1 div"],
[".", "div.l1 div."],
["VK_TAB", "div.l1 div.c1"],
["VK_BACK_SPACE", "div.l1 div.c"],
["VK_BACK_SPACE", "div.l1 div."],
["VK_BACK_SPACE", "div.l1 div"],
["VK_BACK_SPACE", "div.l1 di"],
["VK_BACK_SPACE", "div.l1 d"],
["VK_BACK_SPACE", "div.l1 "],
["VK_UP", "div.l1 div"],
["VK_BACK_SPACE", "div.l1 di"],
["VK_BACK_SPACE", "div.l1 d"],
["VK_BACK_SPACE", "div.l1 "],
["VK_UP", "div.l1 div"],
["VK_UP", "div.l1 div"],
["VK_TAB", "div.l1 div"],
["VK_BACK_SPACE", "div.l1 di"],
["VK_BACK_SPACE", "div.l1 d"],
["VK_BACK_SPACE", "div.l1 "],
["VK_DOWN", "div.l1 div"],
["VK_DOWN", "div.l1 span"],
["VK_DOWN", "div.l1 span"],
["VK_BACK_SPACE", "div.l1 spa"],
["VK_BACK_SPACE", "div.l1 sp"],
["VK_BACK_SPACE", "div.l1 s"],
["VK_BACK_SPACE", "div.l1 "],
["VK_BACK_SPACE", "div.l1"],
["VK_BACK_SPACE", "div.l"],
["VK_BACK_SPACE", "div."],
["VK_BACK_SPACE", "div"],
["VK_BACK_SPACE", "di"],
["VK_BACK_SPACE", "d"],
["VK_BACK_SPACE", ""],
];
// The various states of the inspector: [key, query]
// [
// what key to press,
// what should be the text in the searchbox
// ]
let keyStates = [
["d", "d"],
["i", "di"],
["v", "div"],
[".", "div."],
["VK_UP", "div.c1"],
["VK_DOWN", "div.l1"],
["VK_DOWN", "div.l1"],
["VK_BACK_SPACE", "div.l"],
["VK_TAB", "div.l1"],
[" ", "div.l1 "],
["VK_UP", "div.l1 DIV"],
["VK_UP", "div.l1 DIV"],
[".", "div.l1 DIV."],
["VK_TAB", "div.l1 DIV.c1"],
["VK_BACK_SPACE", "div.l1 DIV.c"],
["VK_BACK_SPACE", "div.l1 DIV."],
["VK_BACK_SPACE", "div.l1 DIV"],
["VK_BACK_SPACE", "div.l1 DI"],
["VK_BACK_SPACE", "div.l1 D"],
["VK_BACK_SPACE", "div.l1 "],
["VK_UP", "div.l1 DIV"],
["VK_BACK_SPACE", "div.l1 DI"],
["VK_BACK_SPACE", "div.l1 D"],
["VK_BACK_SPACE", "div.l1 "],
["VK_UP", "div.l1 DIV"],
["VK_UP", "div.l1 DIV"],
["VK_TAB", "div.l1 DIV"],
["VK_BACK_SPACE", "div.l1 DI"],
["VK_BACK_SPACE", "div.l1 D"],
["VK_BACK_SPACE", "div.l1 "],
["VK_DOWN", "div.l1 DIV"],
["VK_DOWN", "div.l1 SPAN"],
["VK_DOWN", "div.l1 SPAN"],
["VK_BACK_SPACE", "div.l1 SPA"],
["VK_BACK_SPACE", "div.l1 SP"],
["VK_BACK_SPACE", "div.l1 S"],
["VK_BACK_SPACE", "div.l1 "],
["VK_BACK_SPACE", "div.l1"],
["VK_BACK_SPACE", "div.l"],
["VK_BACK_SPACE", "div."],
["VK_BACK_SPACE", "div"],
["VK_BACK_SPACE", "di"],
["VK_BACK_SPACE", "d"],
["VK_BACK_SPACE", ""],
];
const TEST_URL = TEST_URL_ROOT +
"doc_inspector_search-suggestions.html";
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function onload() {
gBrowser.selectedBrowser.removeEventListener("load", onload, true);
waitForFocus(setupTest, content);
}, true);
let test = asyncTest(function* () {
let { inspector } = yield openInspectorForURL(TEST_URL);
yield focusSearchBoxUsingShortcut(inspector.panelWin);
content.location = "http://mochi.test:8888/browser/browser/devtools/inspector/test/doc_inspector_search-suggestions.html";
for (let [key, query] of KEY_STATES) {
info("Pressing key " + key + " to get searchbox value as " + query);
function $(id) {
if (id == null) return null;
return content.document.getElementById(id);
}
function setupTest()
{
openInspector(startTest);
}
function startTest(aInspector)
{
inspector = aInspector;
searchBox =
inspector.panelWin.document.getElementById("inspector-searchbox");
panel = inspector.searchSuggestions.searchPopup._list;
focusSearchBoxUsingShortcut(inspector.panelWin, function() {
searchBox.addEventListener("keypress", checkState, true);
panel.addEventListener("keypress", checkState, true);
checkStateAndMoveOn(0);
});
}
function checkStateAndMoveOn(index) {
if (index == keyStates.length) {
finishUp();
return;
}
let [key, query] = keyStates[index];
state = index;
info("pressing key " + key + " to get searchbox value as " + query);
let done = inspector.searchSuggestions.once("processing-done");
EventUtils.synthesizeKey(key, {}, inspector.panelWin);
yield done;
is(inspector.searchBox.value, query, "The searchbox value is correct.");
}
function checkState(event) {
if (event && event.keyCode != event.DOM_VK_UP &&
event.keyCode != event.DOM_VK_DOWN) {
info("Should wait before server sends the qSA response.");
inspector.searchSuggestions._lastQuery
.then(() => checkState(), () => checkState());
return;
}
if (panelOpeningStates.indexOf(state) != -1 &&
!inspector.searchSuggestions.searchPopup.isOpen) {
info("Panel is not open, should wait before it shows up.");
panel.parentNode.addEventListener("popupshown", function retry() {
panel.parentNode.removeEventListener("popupshown", retry, false);
info("Panel is visible now");
executeSoon(checkState);
}, false);
return;
}
else if (panelClosingStates.indexOf(state) != -1 &&
panel.parentNode.state != "closed") {
info("Panel is open, should wait for it to close.");
panel.parentNode.addEventListener("popuphidden", function retry() {
panel.parentNode.removeEventListener("popuphidden", retry, false);
info("Panel is hidden now");
executeSoon(checkState);
}, false);
return;
}
// Using setTimout as the "command" event fires at delay after keypress
window.setTimeout(function() {
let [key, query] = keyStates[state];
if (searchBox.value == query) {
ok(true, "The suggestion at " + state + "th step on " +
"pressing " + key + " key is correct.");
}
else {
info("value is not correct, waiting longer for state " + state +
" with panel " + panel.parentNode.state);
checkState();
return;
}
checkStateAndMoveOn(state + 1);
}, 200);
}
function finishUp() {
searchBox = null;
panel = null;
gBrowser.removeCurrentTab();
finish();
}
}
});