Bug 653108 - Scratchpad is tied to the tab it was first run in; r=mihai.sucan,sdwilsh

This commit is contained in:
Rob Campbell 2011-05-21 08:59:23 -03:00
Родитель df5074b693
Коммит 4c9d2b76eb
4 изменённых файлов: 127 добавлений и 7 удалений

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

@ -129,8 +129,9 @@ var Scratchpad = {
/** /**
* Get the Cu.Sandbox object for the active tab content window object. Note * Get the Cu.Sandbox object for the active tab content window object. Note
* that the returned object is cached for later reuse. The cached object is * that the returned object is cached for later reuse. The cached object is
* kept only for the current browser window and it is reset for each context * kept only for the current location in the current tab of the current
* switch or navigator:browser window switch. * browser window and it is reset for each context switch,
* navigator:browser window switch, tab switch or navigation.
*/ */
get contentSandbox() get contentSandbox()
{ {
@ -141,12 +142,16 @@ var Scratchpad = {
} }
if (!this._contentSandbox || if (!this._contentSandbox ||
this.browserWindow != this._previousBrowserWindow) { this.browserWindow != this._previousBrowserWindow ||
this._previousBrowser != this.gBrowser.selectedBrowser ||
this._previousLocation != this.gBrowser.contentWindow.location.href) {
let contentWindow = this.gBrowser.selectedBrowser.contentWindow; let contentWindow = this.gBrowser.selectedBrowser.contentWindow;
this._contentSandbox = new Cu.Sandbox(contentWindow, this._contentSandbox = new Cu.Sandbox(contentWindow,
{ sandboxPrototype: contentWindow, wantXrays: false }); { sandboxPrototype: contentWindow, wantXrays: false });
this._previousBrowserWindow = this.browserWindow; this._previousBrowserWindow = this.browserWindow;
this._previousBrowser = this.gBrowser.selectedBrowser;
this._previousLocation = contentWindow.location.href;
} }
return this._contentSandbox; return this._contentSandbox;
@ -558,8 +563,8 @@ var Scratchpad = {
let content = document.getElementById("sp-menu-content"); let content = document.getElementById("sp-menu-content");
document.getElementById("sp-menu-browser").removeAttribute("checked"); document.getElementById("sp-menu-browser").removeAttribute("checked");
content.setAttribute("checked", true); content.setAttribute("checked", true);
this.statusbarStatus.label = content.getAttribute("label");
this.executionContext = SCRATCHPAD_CONTEXT_CONTENT; this.executionContext = SCRATCHPAD_CONTEXT_CONTENT;
this.statusbarStatus.label = content.getAttribute("label");
this.resetContext(); this.resetContext();
}, },
@ -568,11 +573,11 @@ var Scratchpad = {
*/ */
setBrowserContext: function SP_setBrowserContext() setBrowserContext: function SP_setBrowserContext()
{ {
let chrome = document.getElementById("sp-menu-browser"); let browser = document.getElementById("sp-menu-browser");
document.getElementById("sp-menu-content").removeAttribute("checked"); document.getElementById("sp-menu-content").removeAttribute("checked");
chrome.setAttribute("checked", true); browser.setAttribute("checked", true);
this.statusbarStatus.label = chrome.getAttribute("label");
this.executionContext = SCRATCHPAD_CONTEXT_BROWSER; this.executionContext = SCRATCHPAD_CONTEXT_BROWSER;
this.statusbarStatus.label = browser.getAttribute("label");
this.resetContext(); this.resetContext();
}, },
@ -584,6 +589,8 @@ var Scratchpad = {
this._chromeSandbox = null; this._chromeSandbox = null;
this._contentSandbox = null; this._contentSandbox = null;
this._previousWindow = null; this._previousWindow = null;
this._previousBrowser = null;
this._previousLocation = null;
}, },
/** /**

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

@ -194,6 +194,7 @@ _BROWSER_FILES = \
browser_inspector_treePanel_result.html \ browser_inspector_treePanel_result.html \
browser_scratchpad_initialization.js \ browser_scratchpad_initialization.js \
browser_scratchpad_contexts.js \ browser_scratchpad_contexts.js \
browser_scratchpad_tab_switch.js \
browser_scratchpad_execute_print.js \ browser_scratchpad_execute_print.js \
browser_scratchpad_inspect.js \ browser_scratchpad_inspect.js \
browser_scratchpad_files.js \ browser_scratchpad_files.js \

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

@ -0,0 +1,111 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Reference to the Scratchpad chrome window object.
let gScratchpadWindow;
let tab1;
let tab2;
let sp;
function test()
{
waitForExplicitFinish();
tab1 = gBrowser.addTab();
gBrowser.selectedTab = tab1;
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
tab2 = gBrowser.addTab();
gBrowser.selectedTab = tab2;
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
gScratchpadWindow = Scratchpad.openScratchpad();
gScratchpadWindow.addEventListener("load", runTests, false);
}, true);
content.location = "data:text/html,test context switch in Scratchpad tab 2";
}, true);
content.location = "data:text/html,test context switch in Scratchpad tab 1";
}
function runTests()
{
gScratchpadWindow.removeEventListener("load", runTests, true);
sp = gScratchpadWindow.Scratchpad;
let contentMenu = gScratchpadWindow.document.getElementById("sp-menu-content");
let browserMenu = gScratchpadWindow.document.getElementById("sp-menu-browser");
let statusbar = sp.statusbarStatus;
ok(contentMenu, "found #sp-menu-content");
ok(browserMenu, "found #sp-menu-browser");
ok(statusbar, "found Scratchpad.statusbarStatus");
sp.setContentContext();
is(sp.executionContext, gScratchpadWindow.SCRATCHPAD_CONTEXT_CONTENT,
"executionContext is content");
is(contentMenu.getAttribute("checked"), "true",
"content menuitem is checked");
ok(!browserMenu.hasAttribute("checked"),
"chrome menuitem is not checked");
is(statusbar.getAttribute("label"), contentMenu.getAttribute("label"),
"statusbar label is correct");
ok(sp.textbox, "textbox exists");
sp.textbox.value = "window.foosbug653108 = 'aloha';";
ok(!content.wrappedJSObject.foosbug653108,
"no content.foosbug653108");
sp.run();
is(content.wrappedJSObject.foosbug653108, "aloha",
"content.foosbug653108 has been set");
gBrowser.tabContainer.addEventListener("TabSelect", runTests2, true);
gBrowser.selectedTab = tab1;
}
function runTests2() {
gBrowser.tabContainer.removeEventListener("TabSelect", runTests2, true);
ok(!window.foosbug653108, "no window.foosbug653108");
sp.textbox.value = "window.foosbug653108";
let result = sp.run();
isnot(result, "aloha", "window.foosbug653108 is not aloha");
sp.textbox.value = "window.foosbug653108 = 'ahoyhoy';";
sp.run();
is(content.wrappedJSObject.foosbug653108, "ahoyhoy",
"content.foosbug653108 has been set 2");
gBrowser.selectedBrowser.addEventListener("load", runTests3, true);
content.location = "data:text/html,test context switch in Scratchpad location 2";
}
function runTests3() {
gBrowser.selectedBrowser.removeEventListener("load", runTests3, true);
// Check that the sandbox is not cached.
sp.textbox.value = "typeof foosbug653108;";
is(sp.run()[1], "undefined", "global variable does not exist");
gScratchpadWindow.close();
gScratchpadWindow = null;
tab1 = null;
tab2 = null;
sp = null;
gBrowser.removeCurrentTab();
gBrowser.removeCurrentTab();
finish();
}

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

@ -28,3 +28,4 @@ saveFileAs=Save File As
# LOCALIZATION NOTE (saveFile.failed): This is the message displayed when file # LOCALIZATION NOTE (saveFile.failed): This is the message displayed when file
# save fails. # save fails.
saveFile.failed=The file save operation failed. saveFile.failed=The file save operation failed.