browser/devtools/debugger/test/browser_dbg_on-pause-raise.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 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Tests that the toolbox is raised when the debugger gets paused.
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
michael@0 9
michael@0 10 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 11 let gNewTab, gFocusedWindow, gToolbox, gToolboxTab;
michael@0 12
michael@0 13 function test() {
michael@0 14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 15 gTab = aTab;
michael@0 16 gDebuggee = aDebuggee;
michael@0 17 gPanel = aPanel;
michael@0 18 gDebugger = gPanel.panelWin;
michael@0 19 gToolbox = gPanel._toolbox;
michael@0 20 gToolboxTab = gToolbox.doc.getElementById("toolbox-tab-jsdebugger");
michael@0 21
michael@0 22 waitForSourceShown(gPanel, ".html").then(performTest);
michael@0 23 });
michael@0 24 }
michael@0 25
michael@0 26 function performTest() {
michael@0 27 addTab(TAB_URL).then(aTab => {
michael@0 28 isnot(aTab, gTab,
michael@0 29 "The newly added tab is different from the debugger's tab.");
michael@0 30 is(gBrowser.selectedTab, aTab,
michael@0 31 "Debugger's tab is not the selected tab.");
michael@0 32
michael@0 33 gNewTab = aTab;
michael@0 34 gFocusedWindow = window;
michael@0 35 testPause();
michael@0 36 });
michael@0 37 }
michael@0 38
michael@0 39 function focusMainWindow() {
michael@0 40 // Make sure toolbox is not focused.
michael@0 41 window.addEventListener("focus", onFocus, true);
michael@0 42 info("Focusing main window.")
michael@0 43
michael@0 44 // Execute soon to avoid any race conditions between toolbox and main window
michael@0 45 // getting focused.
michael@0 46 executeSoon(() => {
michael@0 47 window.focus();
michael@0 48 });
michael@0 49 }
michael@0 50
michael@0 51 function onFocus() {
michael@0 52 window.removeEventListener("focus", onFocus, true);
michael@0 53 info("Main window focused.")
michael@0 54
michael@0 55 gFocusedWindow = window;
michael@0 56 testPause();
michael@0 57 }
michael@0 58
michael@0 59 function testPause() {
michael@0 60 is(gDebugger.gThreadClient.paused, false,
michael@0 61 "Should be running after starting the test.");
michael@0 62
michael@0 63 is(gFocusedWindow, window,
michael@0 64 "Main window is the top level window before pause.");
michael@0 65
michael@0 66 if (gToolbox.hostType == devtools.Toolbox.HostType.WINDOW) {
michael@0 67 gToolbox._host._window.onfocus = () => {
michael@0 68 gFocusedWindow = gToolbox._host._window;
michael@0 69 };
michael@0 70 }
michael@0 71
michael@0 72 gDebugger.gThreadClient.addOneTimeListener("paused", () => {
michael@0 73 if (gToolbox.hostType == devtools.Toolbox.HostType.WINDOW) {
michael@0 74 is(gFocusedWindow, gToolbox._host._window,
michael@0 75 "Toolbox window is the top level window on pause.");
michael@0 76 } else {
michael@0 77 is(gBrowser.selectedTab, gTab,
michael@0 78 "Debugger's tab got selected.");
michael@0 79 }
michael@0 80 gToolbox.selectTool("webconsole").then(() => {
michael@0 81 ok(gToolboxTab.hasAttribute("highlighted") &&
michael@0 82 gToolboxTab.getAttribute("highlighted") == "true",
michael@0 83 "The highlighted class is present");
michael@0 84 ok(!gToolboxTab.hasAttribute("selected") ||
michael@0 85 gToolboxTab.getAttribute("selected") != "true",
michael@0 86 "The tab is not selected");
michael@0 87 }).then(() => gToolbox.selectTool("jsdebugger")).then(() => {
michael@0 88 ok(gToolboxTab.hasAttribute("highlighted") &&
michael@0 89 gToolboxTab.getAttribute("highlighted") == "true",
michael@0 90 "The highlighted class is present");
michael@0 91 ok(gToolboxTab.hasAttribute("selected") &&
michael@0 92 gToolboxTab.getAttribute("selected") == "true",
michael@0 93 "...and the tab is selected, so the glow will not be present.");
michael@0 94 }).then(testResume);
michael@0 95 });
michael@0 96
michael@0 97 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 98 gDebugger.document.getElementById("resume"),
michael@0 99 gDebugger);
michael@0 100 }
michael@0 101
michael@0 102 function testResume() {
michael@0 103 gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
michael@0 104 gToolbox.selectTool("webconsole").then(() => {
michael@0 105 ok(!gToolboxTab.hasAttribute("highlighted") ||
michael@0 106 gToolboxTab.getAttribute("highlighted") != "true",
michael@0 107 "The highlighted class is not present now after the resume");
michael@0 108 ok(!gToolboxTab.hasAttribute("selected") ||
michael@0 109 gToolboxTab.getAttribute("selected") != "true",
michael@0 110 "The tab is not selected");
michael@0 111 }).then(maybeEndTest);
michael@0 112 });
michael@0 113
michael@0 114 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 115 gDebugger.document.getElementById("resume"),
michael@0 116 gDebugger);
michael@0 117 }
michael@0 118
michael@0 119 function maybeEndTest() {
michael@0 120 if (gToolbox.hostType == devtools.Toolbox.HostType.BOTTOM) {
michael@0 121 info("Switching to a toolbox window host.");
michael@0 122 gToolbox.switchHost(devtools.Toolbox.HostType.WINDOW).then(focusMainWindow);
michael@0 123 } else {
michael@0 124 info("Switching to main window host.");
michael@0 125 gToolbox.switchHost(devtools.Toolbox.HostType.BOTTOM).then(() => closeDebuggerAndFinish(gPanel));
michael@0 126 }
michael@0 127 }
michael@0 128
michael@0 129 registerCleanupFunction(function() {
michael@0 130 // Revert to the default toolbox host, so that the following tests proceed
michael@0 131 // normally and not inside a non-default host.
michael@0 132 Services.prefs.setCharPref("devtools.toolbox.host", devtools.Toolbox.HostType.BOTTOM);
michael@0 133
michael@0 134 gTab = null;
michael@0 135 gDebuggee = null;
michael@0 136 gPanel = null;
michael@0 137 gDebugger = null;
michael@0 138
michael@0 139 removeTab(gNewTab);
michael@0 140 gNewTab = null;
michael@0 141 gFocusedWindow = null;
michael@0 142 gToolbox = null;
michael@0 143 gToolboxTab = null;
michael@0 144 });

mercurial