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: michael@0: const TEST_URI = "data:text/html;charset=utf8,

test Scratchpad panel linking

"; michael@0: michael@0: let { Task } = Cu.import("resource://gre/modules/Task.jsm", {}); michael@0: let { Tools } = require("main"); michael@0: let { isTargetSupported } = Tools.scratchpad; michael@0: michael@0: Tools.scratchpad.isTargetSupported = () => true; michael@0: michael@0: michael@0: function test() michael@0: { michael@0: waitForExplicitFinish(); michael@0: michael@0: addTab(TEST_URI); michael@0: gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true); michael@0: info("Opening toolbox with Scratchpad panel"); michael@0: michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: gDevTools.showToolbox(target, "scratchpad", "window").then(runTests); michael@0: }, true); michael@0: } michael@0: michael@0: function runTests(aToolbox) michael@0: { michael@0: Task.spawn(function*() { michael@0: let scratchpadPanel = aToolbox.getPanel("scratchpad"); michael@0: let { scratchpad } = scratchpadPanel; michael@0: is(aToolbox.getCurrentPanel(), scratchpadPanel, michael@0: "Scratchpad is currently selected panel"); michael@0: michael@0: info("Switching to webconsole panel"); michael@0: michael@0: let webconsolePanel = yield aToolbox.selectTool("webconsole"); michael@0: let { hud } = webconsolePanel; michael@0: is(aToolbox.getCurrentPanel(), webconsolePanel, michael@0: "Webconsole is currently selected panel"); michael@0: michael@0: info("console.log()ing from Scratchpad"); michael@0: michael@0: scratchpad.setText("console.log('foobar-from-scratchpad')"); michael@0: scratchpad.run(); michael@0: let messages = yield waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ text: "foobar-from-scratchpad" }] michael@0: }); michael@0: michael@0: info("Clicking link to switch to and focus Scratchpad"); michael@0: michael@0: let [matched] = [...messages[0].matched]; michael@0: ok(matched, "Found logged message from Scratchpad"); michael@0: let anchor = matched.querySelector("a.message-location"); michael@0: michael@0: aToolbox.on("scratchpad-selected", function selected() { michael@0: aToolbox.off("scratchpad-selected", selected); michael@0: michael@0: is(aToolbox.getCurrentPanel(), scratchpadPanel, michael@0: "Clicking link switches to Scratchpad panel"); michael@0: michael@0: is(Services.ww.activeWindow, aToolbox.frame.ownerGlobal, michael@0: "Scratchpad's toolbox is focused"); michael@0: michael@0: Tools.scratchpad.isTargetSupported = isTargetSupported; michael@0: finish(); michael@0: }); michael@0: michael@0: EventUtils.synthesizeMouse(anchor, 2, 2, {}, hud.iframeWindow); michael@0: }); michael@0: }