browser/devtools/scratchpad/test/browser_scratchpad_wrong_window_focus.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 sw=2 sts=2 et: */
     2 /* Any copyright is dedicated to the Public Domain.
     3    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /* Bug 661762 */
     7 function test()
     8 {
     9   waitForExplicitFinish();
    11   // To test for this bug we open a Scratchpad window, save its
    12   // reference and then open another one. This way the first window
    13   // loses its focus.
    14   //
    15   // Then we open a web console and execute a console.log statement
    16   // from the first Scratch window (that's why we needed to save its
    17   // reference).
    18   //
    19   // Then we wait for our message to appear in the console and click
    20   // on the location link. After that we check which Scratchpad window
    21   // is currently active (it should be the older one).
    23   gBrowser.selectedTab = gBrowser.addTab();
    24   gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
    25     gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
    27     openScratchpad(function () {
    28       let sw = gScratchpadWindow;
    29       let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
    31       openScratchpad(function () {
    32         let target = devtools.TargetFactory.forTab(gBrowser.selectedTab);
    33         gDevTools.showToolbox(target, "webconsole").then((toolbox) => {
    34           let hud = toolbox.getCurrentPanel().hud;
    35           hud.jsterm.clearOutput(true);
    36           testFocus(sw, hud);
    37         });
    38       });
    39     });
    40   }, true);
    42   content.location = "data:text/html;charset=utf8,<p>test window focus for Scratchpad.";
    43 }
    45 function testFocus(sw, hud) {
    46   let sp = sw.Scratchpad;
    48   function onMessage(event, messages) {
    49     let msg = [...messages][0];
    51     var loc = msg.querySelector(".message-location");
    52     ok(loc, "location element exists");
    53     is(loc.textContent.trim(), sw.Scratchpad.uniqueName + ":1",
    54         "location value is correct");
    56     sw.addEventListener("focus", function onFocus() {
    57       sw.removeEventListener("focus", onFocus, true);
    59       let win = Services.wm.getMostRecentWindow("devtools:scratchpad");
    61       ok(win, "there are active Scratchpad windows");
    62       is(win.Scratchpad.uniqueName, sw.Scratchpad.uniqueName,
    63           "correct window is in focus");
    65       // gScratchpadWindow will be closed automatically but we need to
    66       // close the second window ourselves.
    67       sw.close();
    68       finish();
    69     }, true);
    71     // Simulate a click on the "Scratchpad/N:1" link.
    72     EventUtils.synthesizeMouse(loc, 2, 2, {}, hud.iframeWindow);
    73   }
    75   // Sending messages to web console is an asynchronous operation. That's
    76   // why we have to setup an observer here.
    77   hud.ui.once("messages-added", onMessage);
    79   sp.setText("console.log('foo');");
    80   sp.run().then(function ([selection, error, result]) {
    81     is(selection, "console.log('foo');", "selection is correct");
    82     is(error, undefined, "error is correct");
    83     is(result.type, "undefined", "result is correct");
    84   });
    85 }

mercurial