michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Make sure that the variables view displays the right variables and michael@0: * properties in the global scope when debugger is paused. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_frame-parameters.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gVariables; michael@0: michael@0: function test() { michael@0: // Debug test slaves are a bit slow at this test. michael@0: requestLongerTimeout(2); michael@0: michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gVariables = gDebugger.DebuggerView.Variables; michael@0: michael@0: waitForSourceAndCaretAndScopes(gPanel, ".html", 24) michael@0: .then(expandGlobalScope) michael@0: .then(testGlobalScope) michael@0: .then(expandWindowVariable) michael@0: .then(testWindowVariable) michael@0: .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + aError.message + "\n" + aError.stack); michael@0: }); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "click" }, michael@0: gDebuggee.document.querySelector("button"), michael@0: gDebuggee); michael@0: }); michael@0: } michael@0: michael@0: function expandGlobalScope() { michael@0: let deferred = promise.defer(); michael@0: michael@0: let globalScope = gVariables.getScopeAtIndex(1); michael@0: is(globalScope.expanded, false, michael@0: "The global scope should not be expanded by default."); michael@0: michael@0: gDebugger.once(gDebugger.EVENTS.FETCHED_VARIABLES, deferred.resolve); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: globalScope.target.querySelector(".name"), michael@0: gDebugger); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testGlobalScope() { michael@0: let globalScope = gVariables.getScopeAtIndex(1); michael@0: is(globalScope.expanded, true, michael@0: "The global scope should now be expanded."); michael@0: michael@0: is(globalScope.get("InstallTrigger").target.querySelector(".name").getAttribute("value"), "InstallTrigger", michael@0: "Should have the right property name for 'InstallTrigger'."); michael@0: is(globalScope.get("InstallTrigger").target.querySelector(".value").getAttribute("value"), "InstallTriggerImpl", michael@0: "Should have the right property value for 'InstallTrigger'."); michael@0: michael@0: is(globalScope.get("SpecialPowers").target.querySelector(".name").getAttribute("value"), "SpecialPowers", michael@0: "Should have the right property name for 'SpecialPowers'."); michael@0: is(globalScope.get("SpecialPowers").target.querySelector(".value").getAttribute("value"), "Object", michael@0: "Should have the right property value for 'SpecialPowers'."); michael@0: michael@0: is(globalScope.get("window").target.querySelector(".name").getAttribute("value"), "window", michael@0: "Should have the right property name for 'window'."); michael@0: is(globalScope.get("window").target.querySelector(".value").getAttribute("value"), michael@0: "Window \u2192 doc_frame-parameters.html", michael@0: "Should have the right property value for 'window'."); michael@0: michael@0: is(globalScope.get("document").target.querySelector(".name").getAttribute("value"), "document", michael@0: "Should have the right property name for 'document'."); michael@0: is(globalScope.get("document").target.querySelector(".value").getAttribute("value"), michael@0: "HTMLDocument \u2192 doc_frame-parameters.html", michael@0: "Should have the right property value for 'document'."); michael@0: michael@0: is(globalScope.get("undefined").target.querySelector(".name").getAttribute("value"), "undefined", michael@0: "Should have the right property name for 'undefined'."); michael@0: is(globalScope.get("undefined").target.querySelector(".value").getAttribute("value"), "undefined", michael@0: "Should have the right property value for 'undefined'."); michael@0: michael@0: is(globalScope.get("undefined").target.querySelector(".enum").childNodes.length, 0, michael@0: "Should have no child enumerable properties for 'undefined'."); michael@0: is(globalScope.get("undefined").target.querySelector(".nonenum").childNodes.length, 0, michael@0: "Should have no child non-enumerable properties for 'undefined'."); michael@0: } michael@0: michael@0: function expandWindowVariable() { michael@0: let deferred = promise.defer(); michael@0: michael@0: let windowVar = gVariables.getScopeAtIndex(1).get("window"); michael@0: is(windowVar.expanded, false, michael@0: "The window variable should not be expanded by default."); michael@0: michael@0: gDebugger.once(gDebugger.EVENTS.FETCHED_PROPERTIES, deferred.resolve); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: windowVar.target.querySelector(".name"), michael@0: gDebugger); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testWindowVariable() { michael@0: let windowVar = gVariables.getScopeAtIndex(1).get("window"); michael@0: is(windowVar.expanded, true, michael@0: "The window variable should now be expanded."); michael@0: michael@0: is(windowVar.get("InstallTrigger").target.querySelector(".name").getAttribute("value"), "InstallTrigger", michael@0: "Should have the right property name for 'InstallTrigger'."); michael@0: is(windowVar.get("InstallTrigger").target.querySelector(".value").getAttribute("value"), "InstallTriggerImpl", michael@0: "Should have the right property value for 'InstallTrigger'."); michael@0: michael@0: is(windowVar.get("SpecialPowers").target.querySelector(".name").getAttribute("value"), "SpecialPowers", michael@0: "Should have the right property name for 'SpecialPowers'."); michael@0: is(windowVar.get("SpecialPowers").target.querySelector(".value").getAttribute("value"), "Object", michael@0: "Should have the right property value for 'SpecialPowers'."); michael@0: michael@0: is(windowVar.get("window").target.querySelector(".name").getAttribute("value"), "window", michael@0: "Should have the right property name for 'window'."); michael@0: is(windowVar.get("window").target.querySelector(".value").getAttribute("value"), michael@0: "Window \u2192 doc_frame-parameters.html", michael@0: "Should have the right property value for 'window'."); michael@0: michael@0: is(windowVar.get("document").target.querySelector(".name").getAttribute("value"), "document", michael@0: "Should have the right property name for 'document'."); michael@0: is(windowVar.get("document").target.querySelector(".value").getAttribute("value"), michael@0: "HTMLDocument \u2192 doc_frame-parameters.html", michael@0: "Should have the right property value for 'document'."); michael@0: michael@0: is(windowVar.get("undefined").target.querySelector(".name").getAttribute("value"), "undefined", michael@0: "Should have the right property name for 'undefined'."); michael@0: is(windowVar.get("undefined").target.querySelector(".value").getAttribute("value"), "undefined", michael@0: "Should have the right property value for 'undefined'."); michael@0: michael@0: is(windowVar.get("undefined").target.querySelector(".enum").childNodes.length, 0, michael@0: "Should have no child enumerable properties for 'undefined'."); michael@0: is(windowVar.get("undefined").target.querySelector(".nonenum").childNodes.length, 0, michael@0: "Should have no child non-enumerable properties for 'undefined'."); michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gTab = null; michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: gVariables = null; michael@0: });