Bug 791323 - Need a mechanism to select a script programmatically in the debugger, r=rcampbell

This commit is contained in:
Victor Porof 2012-11-27 18:19:24 +02:00
parent ca9c710bb8
commit 226b110cfd
3 changed files with 94 additions and 0 deletions

View File

@ -370,6 +370,20 @@ create({ constructor: SourcesView, proto: MenuContainer.prototype }, {
this._container.removeEventListener("click", this._onClick, false);
},
/**
* Sets the preferred source url to be displayed in this container.
* @param string aValue
*/
set preferredSource(aValue) {
this._preferredValue = aValue;
// Selects the element with the specified value in this container,
// if already inserted.
if (this.containsValue(aValue)) {
this.selectedValue = aValue;
}
},
/**
* The select listener for the sources container.
*/

View File

@ -45,6 +45,7 @@ MOCHITEST_BROWSER_TESTS = \
browser_dbg_propertyview-filter-08.js \
browser_dbg_propertyview-reexpand.js \
browser_dbg_reload-same-script.js \
browser_dbg_reload-preferred-script.js \
browser_dbg_pane-collapse.js \
browser_dbg_panesize.js \
browser_dbg_panesize-inner.js \

View File

@ -0,0 +1,79 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests if the preferred script is shown when a page is loaded.
*/
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
let gPane = null;
let gTab = null;
let gDebuggee = null;
let gDebugger = null;
let gView = null;
requestLongerTimeout(2);
function test()
{
let expectedScript = "test-script-switching-02.js";
let expectedScriptShown = false;
let scriptShownUrl = null;
let resumed = false;
let testStarted = false;
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.contentWindow;
gView = gDebugger.DebuggerView;
resumed = true;
gView.Sources.preferredSource = EXAMPLE_URL + expectedScript;
startTest();
});
function onScriptShown(aEvent)
{
expectedScriptShown = aEvent.detail.url.indexOf(expectedScript) != -1;
scriptShownUrl = aEvent.detail.url;
startTest();
}
window.addEventListener("Debugger:SourceShown", onScriptShown);
function startTest()
{
if (expectedScriptShown && resumed && !testStarted) {
window.removeEventListener("Debugger:SourceShown", onScriptShown);
testStarted = true;
Services.tm.currentThread.dispatch({ run: performTest }, 0);
}
}
function performTest()
{
info("Currently preferred script: " + gView.Sources.preferredValue);
info("Currently selected script: " + gView.Sources.selectedValue);
isnot(gView.Sources.preferredValue.indexOf(expectedScript), -1,
"The preferred script url wasn't set correctly.");
isnot(gView.Sources.selectedValue.indexOf(expectedScript), -1,
"The selected script isn't the correct one.");
is(gView.Sources.selectedValue, scriptShownUrl,
"The shown script is not the the correct one.");
closeDebuggerAndFinish();
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gView = null;
});
}