Remove closed connection targets from scratchpad and request a new one on evaluation (bug 949262). r=fitzgen

--HG--
extra : rebase_source : e507386dca54759499fdf7c8c70ec23732d261fc
This commit is contained in:
Panos Astithas 2014-06-17 19:49:23 +03:00
Родитель bf6636a318
Коммит ca81c6224e
3 изменённых файлов: 52 добавлений и 4 удалений

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

@ -1958,7 +1958,7 @@ ScratchpadTab.consoleFor = function consoleFor(aSubject)
if (!scratchpadTargets.has(aSubject)) {
scratchpadTargets.set(aSubject, new this(aSubject));
}
return scratchpadTargets.get(aSubject).connect();
return scratchpadTargets.get(aSubject).connect(aSubject);
};
@ -1971,10 +1971,12 @@ ScratchpadTab.prototype = {
/**
* Initialize a debugger client and connect it to the debugger server.
*
* @param object aSubject
* The tab or window to obtain the connection for.
* @return Promise
* The promise for the result of connecting to this tab or window.
*/
connect: function ST_connect()
connect: function ST_connect(aSubject)
{
if (this._connector) {
return this._connector;
@ -1992,7 +1994,7 @@ ScratchpadTab.prototype = {
deferred.promise.then(() => clearTimeout(connectTimer));
this._attach().then(aTarget => {
this._attach(aSubject).then(aTarget => {
let consoleActor = aTarget.form.consoleActor;
let client = aTarget.client;
client.attachConsole(consoleActor, [], (aResponse, aWebConsoleClient) => {
@ -2015,12 +2017,19 @@ ScratchpadTab.prototype = {
/**
* Attach to this tab.
*
* @param object aSubject
* The tab or window to obtain the connection for.
* @return Promise
* The promise for the TabTarget for this tab.
*/
_attach: function ST__attach()
_attach: function ST__attach(aSubject)
{
let target = TargetFactory.forTab(this._tab);
target.once("close", () => {
if (scratchpadTargets) {
scratchpadTargets.delete(aSubject);
}
});
return target.makeRemote().then(() => target);
},
};

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

@ -39,3 +39,4 @@ support-files = head.js
[browser_scratchpad_restore.js]
[browser_scratchpad_tab_switch.js]
[browser_scratchpad_ui.js]
[browser_scratchpad_close_toolbox.js]

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

@ -0,0 +1,38 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that closing the toolbox after having opened a scratchpad leaves the
// latter in a functioning state.
let {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
function test() {
const options = {
tabContent: "test closing toolbox and then reusing scratchpad"
};
openTabAndScratchpad(options)
.then(Task.async(runTests))
.then(finish, console.error);
}
function* runTests([win, sp]) {
// Use the scratchpad before opening the toolbox.
const source = "window.foobar = 7;";
sp.setText(source);
let [,,result] = yield sp.display();
is(result, 7, "Display produced the expected output.");
// Now open the toolbox and close it again.
let target = devtools.TargetFactory.forTab(gBrowser.selectedTab);
let toolbox = yield gDevTools.showToolbox(target, "webconsole");
ok(toolbox, "Toolbox was opened.");
let closed = yield gDevTools.closeToolbox(target);
is(closed, true, "Toolbox was closed.");
// Now see if using the scratcphad works as expected.
sp.setText(source);
let [,,result2] = yield sp.display();
is(result2, 7,
"Display produced the expected output after the toolbox was gone.");
}