browser/devtools/webconsole/test/browser_webconsole_scratchpad_panel_link.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
michael@0 5 const TEST_URI = "data:text/html;charset=utf8,<p>test Scratchpad panel linking</p>";
michael@0 6
michael@0 7 let { Task } = Cu.import("resource://gre/modules/Task.jsm", {});
michael@0 8 let { Tools } = require("main");
michael@0 9 let { isTargetSupported } = Tools.scratchpad;
michael@0 10
michael@0 11 Tools.scratchpad.isTargetSupported = () => true;
michael@0 12
michael@0 13
michael@0 14 function test()
michael@0 15 {
michael@0 16 waitForExplicitFinish();
michael@0 17
michael@0 18 addTab(TEST_URI);
michael@0 19 gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() {
michael@0 20 gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true);
michael@0 21 info("Opening toolbox with Scratchpad panel");
michael@0 22
michael@0 23 let target = TargetFactory.forTab(gBrowser.selectedTab);
michael@0 24 gDevTools.showToolbox(target, "scratchpad", "window").then(runTests);
michael@0 25 }, true);
michael@0 26 }
michael@0 27
michael@0 28 function runTests(aToolbox)
michael@0 29 {
michael@0 30 Task.spawn(function*() {
michael@0 31 let scratchpadPanel = aToolbox.getPanel("scratchpad");
michael@0 32 let { scratchpad } = scratchpadPanel;
michael@0 33 is(aToolbox.getCurrentPanel(), scratchpadPanel,
michael@0 34 "Scratchpad is currently selected panel");
michael@0 35
michael@0 36 info("Switching to webconsole panel");
michael@0 37
michael@0 38 let webconsolePanel = yield aToolbox.selectTool("webconsole");
michael@0 39 let { hud } = webconsolePanel;
michael@0 40 is(aToolbox.getCurrentPanel(), webconsolePanel,
michael@0 41 "Webconsole is currently selected panel");
michael@0 42
michael@0 43 info("console.log()ing from Scratchpad");
michael@0 44
michael@0 45 scratchpad.setText("console.log('foobar-from-scratchpad')");
michael@0 46 scratchpad.run();
michael@0 47 let messages = yield waitForMessages({
michael@0 48 webconsole: hud,
michael@0 49 messages: [{ text: "foobar-from-scratchpad" }]
michael@0 50 });
michael@0 51
michael@0 52 info("Clicking link to switch to and focus Scratchpad");
michael@0 53
michael@0 54 let [matched] = [...messages[0].matched];
michael@0 55 ok(matched, "Found logged message from Scratchpad");
michael@0 56 let anchor = matched.querySelector("a.message-location");
michael@0 57
michael@0 58 aToolbox.on("scratchpad-selected", function selected() {
michael@0 59 aToolbox.off("scratchpad-selected", selected);
michael@0 60
michael@0 61 is(aToolbox.getCurrentPanel(), scratchpadPanel,
michael@0 62 "Clicking link switches to Scratchpad panel");
michael@0 63
michael@0 64 is(Services.ww.activeWindow, aToolbox.frame.ownerGlobal,
michael@0 65 "Scratchpad's toolbox is focused");
michael@0 66
michael@0 67 Tools.scratchpad.isTargetSupported = isTargetSupported;
michael@0 68 finish();
michael@0 69 });
michael@0 70
michael@0 71 EventUtils.synthesizeMouse(anchor, 2, 2, {}, hud.iframeWindow);
michael@0 72 });
michael@0 73 }

mercurial