mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Bug 1246692 - Test that the browser toolbox has a working console. r=jryans
This commit is contained in:
parent
0e31ff0cab
commit
251624825f
@ -198,6 +198,8 @@ BrowserToolboxProcess.prototype = {
|
||||
|
||||
if (this._options.addonID) {
|
||||
xulURI += "?addonID=" + this._options.addonID;
|
||||
} else if (this._options.testScript) {
|
||||
xulURI += "?testScript=" + encodeURIComponent(this._options.testScript);
|
||||
}
|
||||
|
||||
dumpn("Running chrome debugging process.");
|
||||
|
@ -17,6 +17,7 @@ support-files =
|
||||
browser_toolbox_options_enable_serviceworkers_testing.html
|
||||
serviceworker.js
|
||||
|
||||
[browser_browser_toolbox.js]
|
||||
[browser_devtools_api.js]
|
||||
[browser_devtools_api_destroy.js]
|
||||
[browser_dynamic_tool_enabling.js]
|
||||
|
63
devtools/client/framework/test/browser_browser_toolbox.js
Normal file
63
devtools/client/framework/test/browser_browser_toolbox.js
Normal file
@ -0,0 +1,63 @@
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// On debug test slave, it takes about 50s to run the test.
|
||||
requestLongerTimeout(4);
|
||||
|
||||
add_task(function* runTest() {
|
||||
yield new Promise(done => {
|
||||
let options = {"set": [
|
||||
["devtools.debugger.prompt-connection", false],
|
||||
["devtools.debugger.remote-enabled", true],
|
||||
["devtools.chrome.enabled", true],
|
||||
// Test-only pref to allow passing `testScript` argument to the browser
|
||||
// toolbox
|
||||
["devtools.browser-toolbox.allow-unsafe-script", true],
|
||||
// On debug test slave, it takes more than the default time (20s)
|
||||
// to get a initialized console
|
||||
["devtools.debugger.remote-timeout", 120000]
|
||||
]};
|
||||
SpecialPowers.pushPrefEnv(options, done);
|
||||
});
|
||||
|
||||
// Wait for a notification sent by a script evaluated in the webconsole
|
||||
// of the browser toolbox.
|
||||
let onCustomMessage = new Promise(done => {
|
||||
Services.obs.addObserver(function listener() {
|
||||
Services.obs.removeObserver(listener, "browser-toolbox-console-works");
|
||||
done();
|
||||
}, "browser-toolbox-console-works", false);
|
||||
});
|
||||
|
||||
let { BrowserToolboxProcess } = Cu.import("resource://devtools/client/framework/ToolboxProcess.jsm", {});
|
||||
let closePromise;
|
||||
yield new Promise(onRun => {
|
||||
let options = {
|
||||
// Pass a test script evaluated in the browser toolbox window
|
||||
// living in a distinct process. It has access to `toolbox` object
|
||||
// in its global scope.
|
||||
testScript: "new " + function () {
|
||||
toolbox.selectTool("webconsole")
|
||||
.then(() => toolbox.getPanel("webconsole"))
|
||||
.then(() => {
|
||||
let { jsterm } = toolbox.getPanel("webconsole").hud;
|
||||
let js = "Services.obs.notifyObservers(null, 'browser-toolbox-console-works', null);";
|
||||
return jsterm.execute(js);
|
||||
})
|
||||
.then(() => toolbox.destroy());
|
||||
}
|
||||
};
|
||||
closePromise = new Promise(onClose => {
|
||||
info("Opening the browser toolbox\n");
|
||||
BrowserToolboxProcess.init(onClose, onRun, options);
|
||||
});
|
||||
});
|
||||
ok(true, "Browser toolbox started\n");
|
||||
|
||||
yield onCustomMessage;
|
||||
ok(true, "Received the custom message");
|
||||
|
||||
yield closePromise;
|
||||
ok(true, "Browser toolbox process just closed");
|
||||
});
|
@ -111,9 +111,26 @@ function openToolbox({ form, chrome, isTabActor }) {
|
||||
}
|
||||
|
||||
function onNewToolbox(toolbox) {
|
||||
gToolbox = toolbox;
|
||||
bindToolboxHandlers();
|
||||
raise();
|
||||
gToolbox = toolbox;
|
||||
bindToolboxHandlers();
|
||||
raise();
|
||||
let testScript = getParameterByName("testScript");
|
||||
if (testScript) {
|
||||
// Only allow executing random chrome scripts when a special
|
||||
// test-only pref is set
|
||||
let prefName = "devtools.browser-toolbox.allow-unsafe-script";
|
||||
if (Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
|
||||
Services.prefs.getBoolPref(prefName) === true) {
|
||||
evaluateTestScript(testScript, toolbox);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function evaluateTestScript(script, toolbox) {
|
||||
let sandbox = Cu.Sandbox(window);
|
||||
sandbox.window = window;
|
||||
sandbox.toolbox = toolbox;
|
||||
Cu.evalInSandbox(script, sandbox);
|
||||
}
|
||||
|
||||
function bindToolboxHandlers() {
|
||||
|
Loading…
Reference in New Issue
Block a user