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.

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

mercurial