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.

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

mercurial