Bug 785650 - Make it easier to stop searching for scripts in the Debugger, r=past

This commit is contained in:
Victor Porof 2012-09-11 22:50:19 +03:00
Родитель 85335a7cff
Коммит cc0393d14b
11 изменённых файлов: 268 добавлений и 2 удалений

Просмотреть файл

@ -245,6 +245,7 @@ function GlobalSearchView() {
this._onLineClick = this._onLineClick.bind(this);
this._onMatchClick = this._onMatchClick.bind(this);
this._onResultsScroll = this._onResultsScroll.bind(this);
this._onFocusLost = this._onFocusLost.bind(this);
this._startSearch = this._startSearch.bind(this);
}
@ -259,6 +260,12 @@ GlobalSearchView.prototype = {
this._splitter.hidden = value;
},
/**
* True if the search results container is hidden.
* @return boolean
*/
get hidden() this._pane.hidden,
/**
* Removes all elements from the search results container, leaving it empty.
*/
@ -708,6 +715,13 @@ GlobalSearchView.prototype = {
editor.setSelection(offset + range.start, offset + range.start + range.length);
},
/**
* Listener handling the searchbox blur event.
*/
_onFocusLost: function DVGS__onFocusLost(e) {
this.hideAndEmpty();
},
/**
* Listener handling the global search container scroll event.
*/
@ -790,6 +804,7 @@ GlobalSearchView.prototype = {
*/
_pane: null,
_splitter: null,
_searchbox: null,
/**
* Initialization function, called when the debugger is initialized.
@ -797,8 +812,10 @@ GlobalSearchView.prototype = {
initialize: function DVS_initialize() {
this._pane = document.getElementById("globalsearch");
this._splitter = document.getElementById("globalsearch-splitter");
this._searchbox = document.getElementById("scripts-search");
this._pane.addEventListener("scroll", this._onResultsScroll, false);
this._searchbox.addEventListener("blur", this._onFocusLost, false);
},
/**
@ -806,10 +823,12 @@ GlobalSearchView.prototype = {
*/
destroy: function DVS_destroy() {
this._pane.removeEventListener("scroll", this._onResultsScroll, false);
this._searchbox.removeEventListener("blur", this._onFocusLost, false);
this.hideAndEmpty();
this._pane = null;
this._splitter = null;
this._searchbox = null;
this._scriptSources = null;
}
};
@ -1293,7 +1312,11 @@ ScriptsView.prototype = {
return;
}
if (isGlobal) {
DebuggerView.GlobalSearch.focusNextMatch();
if (DebuggerView.GlobalSearch.hidden) {
DebuggerView.GlobalSearch.scheduleSearch();
} else {
DebuggerView.GlobalSearch.focusNextMatch();
}
return;
}

Просмотреть файл

@ -103,7 +103,7 @@
#endif
</toolbar>
<vbox id="dbg-content" flex="1">
<vbox id="globalsearch" hidden="true" flex="1"/>
<vbox id="globalsearch" hidden="true"/>
<splitter id="globalsearch-splitter"
class="devtools-horizontal-splitter" hidden="true"/>
<hbox flex="1">

Просмотреть файл

@ -56,6 +56,7 @@ MOCHITEST_BROWSER_TESTS = \
browser_dbg_scripts-searching-05.js \
browser_dbg_scripts-searching-06.js \
browser_dbg_scripts-searching-07.js \
browser_dbg_scripts-searching-08.js \
browser_dbg_pause-resume.js \
browser_dbg_update-editor-mode.js \
$(warning browser_dbg_select-line.js temporarily disabled due to oranges, see bug 726609) \

Просмотреть файл

@ -11,6 +11,10 @@ var gScripts = null;
var gSearchBox = null;
var gMenulist = null;
/**
* Tests basic functionality of scripts filtering (token search and line jump).
*/
function test()
{
let scriptShown = false;

Просмотреть файл

@ -4,6 +4,10 @@
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests basic functionality of scripts filtering (file search).
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;

Просмотреть файл

@ -4,6 +4,11 @@
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests basic functionality of global search (lowercase + upper case, expected
* UI behavior, number of results found etc.)
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;

Просмотреть файл

@ -4,6 +4,11 @@
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests if the global search results switch back and forth, and wrap around
* when switching between them.
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;

Просмотреть файл

@ -4,6 +4,11 @@
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests if the global search results are cleared on location changes, and
* the expected UI behaviors are triggered.
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;

Просмотреть файл

@ -4,6 +4,11 @@
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests if the global search results trigger MatchFound and NoMatchFound events
* properly, and triggers the expected UI behavior.
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;

Просмотреть файл

@ -4,6 +4,12 @@
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests if the global search results are expanded on scroll or click, and
* clicking matches makes the source editor shows the correct script and
* makes a selection based on the match.
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;

Просмотреть файл

@ -0,0 +1,208 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests if the global search results are hidden when they're supposed to
* (after a focus lost, or when ESCAPE is pressed).
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;
var gDebugger = null;
var gEditor = null;
var gScripts = null;
var gSearchView = null;
var gSearchBox = null;
function test()
{
let scriptShown = false;
let framesAdded = false;
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.contentWindow;
gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
framesAdded = true;
runTest();
});
gDebuggee.firstCall();
});
window.addEventListener("Debugger:ScriptShown", function _onEvent(aEvent) {
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
scriptShown = true;
window.removeEventListener(aEvent.type, _onEvent);
runTest();
}
});
function runTest()
{
if (scriptShown && framesAdded) {
Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
}
}
}
function testScriptSearching() {
gDebugger.DebuggerController.activeThread.resume(function() {
gEditor = gDebugger.DebuggerView.editor;
gScripts = gDebugger.DebuggerView.Scripts;
gSearchView = gDebugger.DebuggerView.GlobalSearch;
gSearchBox = gScripts._searchbox;
doSearch();
});
}
function doSearch() {
is(gSearchView._pane.hidden, true,
"The global search pane shouldn't be visible yet.");
window.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
window.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gScripts.selected + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gScripts.selected;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
testFocusLost();
});
} else {
ok(false, "The current script shouldn't have changed after a global search.");
}
});
executeSoon(function() {
write("!a");
});
}
function testFocusLost()
{
is(gSearchView._pane.hidden, false,
"The global search pane should be visible after a search.");
window.addEventListener("Debugger:GlobalSearch:ViewCleared", function _onEvent(aEvent) {
window.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gScripts.selected + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gScripts.selected;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
reshowSearch();
});
} else {
ok(false, "The current script shouldn't have changed after the global search stopped.");
}
});
executeSoon(function() {
gDebugger.DebuggerView.editor.focus();
});
}
function reshowSearch() {
is(gSearchView._pane.hidden, true,
"The global search pane shouldn't be visible after the search was stopped.");
window.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
window.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gScripts.selected + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gScripts.selected;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
testEscape();
});
} else {
ok(false, "The current script shouldn't have changed after a global re-search.");
}
});
executeSoon(function() {
sendEnter();
});
}
function testEscape()
{
is(gSearchView._pane.hidden, false,
"The global search pane should be visible after a re-search.");
window.addEventListener("Debugger:GlobalSearch:ViewCleared", function _onEvent(aEvent) {
window.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gScripts.selected + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gScripts.selected;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
finalCheck();
});
} else {
ok(false, "The current script shouldn't have changed after the global search escaped.");
}
});
executeSoon(function() {
sendEscape();
});
}
function finalCheck()
{
is(gSearchView._pane.hidden, true,
"The global search pane shouldn't be visible after the search was escaped.");
closeDebuggerAndFinish();
}
function clear() {
gSearchBox.focus();
gSearchBox.value = "";
}
function write(text) {
clear();
append(text);
}
function sendEnter() {
gSearchBox.focus();
EventUtils.sendKey("ENTER");
}
function sendEscape() {
gSearchBox.focus();
EventUtils.sendKey("ESCAPE");
}
function append(text) {
gSearchBox.focus();
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i]);
}
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gEditor = null;
gScripts = null;
gSearchBox = null;
});