michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: /* Bug 740948 */ michael@0: michael@0: let DEVTOOLS_CHROME_ENABLED = "devtools.chrome.enabled"; michael@0: let EDITOR_TEXT = [ michael@0: "var evt = new CustomEvent('foo', { bubbles: true });", michael@0: "document.body.innerHTML = 'Modified text';", michael@0: "window.dispatchEvent(evt);" michael@0: ].join("\n"); michael@0: michael@0: function test() michael@0: { michael@0: requestLongerTimeout(2); michael@0: waitForExplicitFinish(); michael@0: Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, true); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener("load", function onLoad() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); michael@0: openScratchpad(runTests); michael@0: }, true); michael@0: michael@0: content.location = "data:text/html,Scratchpad test for bug 740948"; michael@0: } michael@0: michael@0: function runTests() michael@0: { michael@0: let sp = gScratchpadWindow.Scratchpad; michael@0: ok(sp, "Scratchpad object exists in new window"); michael@0: michael@0: // Test that Reload And Run command is enabled in the content michael@0: // context and disabled in the browser context. michael@0: michael@0: let reloadAndRun = gScratchpadWindow.document. michael@0: getElementById("sp-cmd-reloadAndRun"); michael@0: ok(reloadAndRun, "Reload And Run command exists"); michael@0: ok(!reloadAndRun.hasAttribute("disabled"), michael@0: "Reload And Run command is enabled"); michael@0: michael@0: sp.setBrowserContext(); michael@0: ok(reloadAndRun.hasAttribute("disabled"), michael@0: "Reload And Run command is disabled in the browser context."); michael@0: michael@0: // Switch back to the content context and run our predefined michael@0: // code. This code modifies the body of our document and dispatches michael@0: // a custom event 'foo'. We listen to that event and check the michael@0: // body to make sure that the page has been reloaded and Scratchpad michael@0: // code has been executed. michael@0: michael@0: sp.setContentContext(); michael@0: sp.setText(EDITOR_TEXT); michael@0: michael@0: let browser = gBrowser.selectedBrowser; michael@0: michael@0: browser.addEventListener("DOMWindowCreated", function onWindowCreated() { michael@0: browser.removeEventListener("DOMWindowCreated", onWindowCreated, true); michael@0: michael@0: browser.contentWindow.addEventListener("foo", function onFoo() { michael@0: browser.contentWindow.removeEventListener("foo", onFoo, true); michael@0: michael@0: is(browser.contentWindow.document.body.innerHTML, "Modified text", michael@0: "After reloading, HTML is different."); michael@0: michael@0: Services.prefs.clearUserPref(DEVTOOLS_CHROME_ENABLED); michael@0: finish(); michael@0: }, true); michael@0: }, true); michael@0: michael@0: ok(browser.contentWindow.document.body.innerHTML !== "Modified text", michael@0: "Before reloading, HTML is intact."); michael@0: sp.reloadAndRun(); michael@0: } michael@0: