browser/devtools/scratchpad/test/browser_scratchpad_reload_and_run.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 2 /* Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 4 /* Bug 740948 */
michael@0 5
michael@0 6 let DEVTOOLS_CHROME_ENABLED = "devtools.chrome.enabled";
michael@0 7 let EDITOR_TEXT = [
michael@0 8 "var evt = new CustomEvent('foo', { bubbles: true });",
michael@0 9 "document.body.innerHTML = 'Modified text';",
michael@0 10 "window.dispatchEvent(evt);"
michael@0 11 ].join("\n");
michael@0 12
michael@0 13 function test()
michael@0 14 {
michael@0 15 requestLongerTimeout(2);
michael@0 16 waitForExplicitFinish();
michael@0 17 Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, true);
michael@0 18
michael@0 19 gBrowser.selectedTab = gBrowser.addTab();
michael@0 20 gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
michael@0 21 gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
michael@0 22 openScratchpad(runTests);
michael@0 23 }, true);
michael@0 24
michael@0 25 content.location = "data:text/html,Scratchpad test for bug 740948";
michael@0 26 }
michael@0 27
michael@0 28 function runTests()
michael@0 29 {
michael@0 30 let sp = gScratchpadWindow.Scratchpad;
michael@0 31 ok(sp, "Scratchpad object exists in new window");
michael@0 32
michael@0 33 // Test that Reload And Run command is enabled in the content
michael@0 34 // context and disabled in the browser context.
michael@0 35
michael@0 36 let reloadAndRun = gScratchpadWindow.document.
michael@0 37 getElementById("sp-cmd-reloadAndRun");
michael@0 38 ok(reloadAndRun, "Reload And Run command exists");
michael@0 39 ok(!reloadAndRun.hasAttribute("disabled"),
michael@0 40 "Reload And Run command is enabled");
michael@0 41
michael@0 42 sp.setBrowserContext();
michael@0 43 ok(reloadAndRun.hasAttribute("disabled"),
michael@0 44 "Reload And Run command is disabled in the browser context.");
michael@0 45
michael@0 46 // Switch back to the content context and run our predefined
michael@0 47 // code. This code modifies the body of our document and dispatches
michael@0 48 // a custom event 'foo'. We listen to that event and check the
michael@0 49 // body to make sure that the page has been reloaded and Scratchpad
michael@0 50 // code has been executed.
michael@0 51
michael@0 52 sp.setContentContext();
michael@0 53 sp.setText(EDITOR_TEXT);
michael@0 54
michael@0 55 let browser = gBrowser.selectedBrowser;
michael@0 56
michael@0 57 browser.addEventListener("DOMWindowCreated", function onWindowCreated() {
michael@0 58 browser.removeEventListener("DOMWindowCreated", onWindowCreated, true);
michael@0 59
michael@0 60 browser.contentWindow.addEventListener("foo", function onFoo() {
michael@0 61 browser.contentWindow.removeEventListener("foo", onFoo, true);
michael@0 62
michael@0 63 is(browser.contentWindow.document.body.innerHTML, "Modified text",
michael@0 64 "After reloading, HTML is different.");
michael@0 65
michael@0 66 Services.prefs.clearUserPref(DEVTOOLS_CHROME_ENABLED);
michael@0 67 finish();
michael@0 68 }, true);
michael@0 69 }, true);
michael@0 70
michael@0 71 ok(browser.contentWindow.document.body.innerHTML !== "Modified text",
michael@0 72 "Before reloading, HTML is intact.");
michael@0 73 sp.reloadAndRun();
michael@0 74 }
michael@0 75

mercurial