зеркало из https://github.com/mozilla/gecko-dev.git
Bug 740948 - Scratchpad should provide a quick way to reload the tab and re-run the code; r=harth
This commit is contained in:
Родитель
2267136e3c
Коммит
14f84b1dd8
|
@ -411,6 +411,34 @@ var Scratchpad = {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Reload the current page and execute the entire editor content when
|
||||
* the page finishes loading. Note that this operation should be available
|
||||
* only in the content context.
|
||||
*/
|
||||
reloadAndRun: function SP_reloadAndRun()
|
||||
{
|
||||
if (this.executionContext !== SCRATCHPAD_CONTEXT_CONTENT) {
|
||||
Cu.reportError(this.strings.
|
||||
GetStringFromName("scratchpadContext.invalid"));
|
||||
return;
|
||||
}
|
||||
|
||||
let browser = this.gBrowser.selectedBrowser;
|
||||
|
||||
this._reloadAndRunEvent = function onLoad(evt) {
|
||||
if (evt.target !== browser.contentDocument) {
|
||||
return;
|
||||
}
|
||||
|
||||
browser.removeEventListener("load", this._reloadAndRunEvent, true);
|
||||
this.run();
|
||||
}.bind(this);
|
||||
|
||||
browser.addEventListener("load", this._reloadAndRunEvent, true);
|
||||
browser.contentWindow.location.reload();
|
||||
},
|
||||
|
||||
/**
|
||||
* Execute the selected text (if any) or the entire editor content in the
|
||||
* current context. The evaluation result is inserted into the editor after
|
||||
|
@ -979,6 +1007,7 @@ var Scratchpad = {
|
|||
|
||||
let content = document.getElementById("sp-menu-content");
|
||||
document.getElementById("sp-menu-browser").removeAttribute("checked");
|
||||
document.getElementById("sp-cmd-reloadAndRun").removeAttribute("disabled");
|
||||
content.setAttribute("checked", true);
|
||||
this.executionContext = SCRATCHPAD_CONTEXT_CONTENT;
|
||||
this.notificationBox.removeAllNotifications(false);
|
||||
|
@ -995,8 +1024,12 @@ var Scratchpad = {
|
|||
}
|
||||
|
||||
let browser = document.getElementById("sp-menu-browser");
|
||||
let reloadAndRun = document.getElementById("sp-cmd-reloadAndRun");
|
||||
|
||||
document.getElementById("sp-menu-content").removeAttribute("checked");
|
||||
reloadAndRun.setAttribute("disabled", true);
|
||||
browser.setAttribute("checked", true);
|
||||
|
||||
this.executionContext = SCRATCHPAD_CONTEXT_BROWSER;
|
||||
this.notificationBox.appendNotification(
|
||||
this.strings.GetStringFromName("browserContext.notification"),
|
||||
|
@ -1173,6 +1206,8 @@ var Scratchpad = {
|
|||
}
|
||||
|
||||
this.resetContext();
|
||||
this.gBrowser.selectedBrowser.removeEventListener("load",
|
||||
this._reloadAndRunEvent, true);
|
||||
this.editor.removeEventListener(SourceEditor.EVENTS.DIRTY_CHANGED,
|
||||
this._onDirtyChanged);
|
||||
PreferenceObserver.uninit();
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
<command id="sp-cmd-display" oncommand="Scratchpad.display();"/>
|
||||
<command id="sp-cmd-contentContext" oncommand="Scratchpad.setContentContext();"/>
|
||||
<command id="sp-cmd-browserContext" oncommand="Scratchpad.setBrowserContext();" disabled="true"/>
|
||||
<command id="sp-cmd-reloadAndRun" oncommand="Scratchpad.reloadAndRun();"/>
|
||||
<command id="sp-cmd-resetContext" oncommand="Scratchpad.resetContext();"/>
|
||||
<command id="sp-cmd-errorConsole" oncommand="Scratchpad.openErrorConsole();" disabled="true"/>
|
||||
<command id="sp-cmd-webConsole" oncommand="Scratchpad.openWebConsole();"/>
|
||||
|
@ -90,6 +91,10 @@
|
|||
key="&display.key;"
|
||||
command="sp-cmd-display"
|
||||
modifiers="accel"/>
|
||||
<key id="sp-key-reloadAndRun"
|
||||
key="&reloadAndRun.key;"
|
||||
command="sp-cmd-reloadAndRun"
|
||||
modifiers="accel,shift"/>
|
||||
<key id="sp-key-errorConsole"
|
||||
key="&errorConsoleCmd.commandkey;"
|
||||
command="sp-cmd-errorConsole"
|
||||
|
@ -194,6 +199,11 @@
|
|||
key="sp-key-display"
|
||||
command="sp-cmd-display"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="sp-text-reloadAndRun"
|
||||
label="&reloadAndRun.label;"
|
||||
key="sp-key-reloadAndRun"
|
||||
accesskey="&reloadAndRun.accesskey;"
|
||||
command="sp-cmd-reloadAndRun"/>
|
||||
<menuitem id="sp-text-resetContext"
|
||||
label="&resetContext2.label;"
|
||||
accesskey="&resetContext2.accesskey;"
|
||||
|
|
|
@ -34,6 +34,7 @@ MOCHITEST_BROWSER_FILES = \
|
|||
browser_scratchpad_bug_651942_recent_files.js \
|
||||
browser_scratchpad_bug756681_display_non_error_exceptions.js \
|
||||
browser_scratchpad_bug_751744_revert_to_saved.js \
|
||||
browser_scratchpad_bug740948_reload_and_run.js \
|
||||
head.js \
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
let DEVTOOLS_CHROME_ENABLED = "devtools.chrome.enabled";
|
||||
let EDITOR_TEXT = [
|
||||
"var evt = new CustomEvent('foo', { bubbles: true });",
|
||||
"document.body.innerHTML = 'Modified text';",
|
||||
"window.dispatchEvent(evt);"
|
||||
].join("\n");
|
||||
|
||||
function test()
|
||||
{
|
||||
waitForExplicitFinish();
|
||||
Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, true);
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
|
||||
gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
|
||||
openScratchpad(runTests);
|
||||
}, true);
|
||||
|
||||
content.location = "data:text/html,Scratchpad test for bug 740948";
|
||||
}
|
||||
|
||||
function runTests()
|
||||
{
|
||||
let sp = gScratchpadWindow.Scratchpad;
|
||||
ok(sp, "Scratchpad object exists in new window");
|
||||
|
||||
// Test that Reload And Run command is enabled in the content
|
||||
// context and disabled in the browser context.
|
||||
|
||||
let reloadAndRun = gScratchpadWindow.document.
|
||||
getElementById("sp-cmd-reloadAndRun");
|
||||
ok(reloadAndRun, "Reload And Run command exists");
|
||||
ok(!reloadAndRun.hasAttribute("disabled"),
|
||||
"Reload And Run command is enabled");
|
||||
|
||||
sp.setBrowserContext();
|
||||
ok(reloadAndRun.hasAttribute("disabled"),
|
||||
"Reload And Run command is disabled in the browser context.");
|
||||
|
||||
// Switch back to the content context and run our predefined
|
||||
// code. This code modifies the body of our document and dispatches
|
||||
// a custom event 'foo'. We listen to that event and check the
|
||||
// body to make sure that the page has been reloaded and Scratchpad
|
||||
// code has been executed.
|
||||
|
||||
sp.setContentContext();
|
||||
sp.setText(EDITOR_TEXT);
|
||||
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
|
||||
browser.addEventListener("DOMWindowCreated", function onWindowCreated() {
|
||||
browser.removeEventListener("DOMWindowCreated", onWindowCreated, true);
|
||||
|
||||
browser.contentWindow.addEventListener("foo", function onFoo() {
|
||||
browser.contentWindow.removeEventListener("foo", onFoo, true);
|
||||
|
||||
is(browser.contentWindow.document.body.innerHTML, "Modified text",
|
||||
"After reloading, HTML is different.");
|
||||
|
||||
Services.prefs.clearUserPref(DEVTOOLS_CHROME_ENABLED);
|
||||
finish();
|
||||
}, true);
|
||||
}, true);
|
||||
|
||||
ok(browser.contentWindow.document.body.innerHTML !== "Modified text",
|
||||
"Before reloading, HTML is intact.");
|
||||
sp.reloadAndRun();
|
||||
}
|
||||
|
|
@ -105,6 +105,10 @@
|
|||
<!ENTITY resetContext2.label "Reset Variables">
|
||||
<!ENTITY resetContext2.accesskey "T">
|
||||
|
||||
<!ENTITY reloadAndRun.label "Reload And Run">
|
||||
<!ENTITY reloadAndRun.accesskey "E">
|
||||
<!ENTITY reloadAndRun.key "r">
|
||||
|
||||
<!ENTITY executeMenu.label "Execute">
|
||||
<!ENTITY executeMenu.accesskey "X">
|
||||
|
||||
|
|
|
@ -26,6 +26,10 @@ export.fileOverwriteConfirmation=File exists. Overwrite?
|
|||
# type.
|
||||
browserWindow.unavailable=Scratchpad cannot find any browser window to execute the code in.
|
||||
|
||||
# LOCALIZATION NOTE (scratchpadContext.invalid): This error message is shown
|
||||
# when user tries to run an operation in Scratchpad in an unsupported context.
|
||||
scratchpadContext.invalid=Scratchpad cannot run this operation in the current mode.
|
||||
|
||||
# LOCALIZATION NOTE (openFile.title): This is the file picker title, when you
|
||||
# open a file from Scratchpad.
|
||||
openFile.title=Open File
|
||||
|
|
Загрузка…
Ссылка в новой задаче