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 correctly displays the properties michael@0: * of objects 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(initialChecks) michael@0: .then(testExpandVariables) 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 initialChecks() { michael@0: let scopeNodes = gDebugger.document.querySelectorAll(".variables-view-scope"); michael@0: is(scopeNodes.length, 2, michael@0: "There should be 2 scopes available."); michael@0: michael@0: ok(scopeNodes[0].querySelector(".name").getAttribute("value").contains("[test]"), michael@0: "The local scope should be properly identified."); michael@0: ok(scopeNodes[1].querySelector(".name").getAttribute("value").contains("[Window]"), michael@0: "The global scope should be properly identified."); michael@0: michael@0: is(gVariables.getScopeAtIndex(0).target, scopeNodes[0], michael@0: "getScopeAtIndex(0) didn't return the expected scope."); michael@0: is(gVariables.getScopeAtIndex(1).target, scopeNodes[1], michael@0: "getScopeAtIndex(1) didn't return the expected scope."); michael@0: michael@0: is(gVariables.getItemForNode(scopeNodes[0]).target, scopeNodes[0], michael@0: "getItemForNode([0]) didn't return the expected scope."); michael@0: is(gVariables.getItemForNode(scopeNodes[1]).target, scopeNodes[1], michael@0: "getItemForNode([1]) didn't return the expected scope."); michael@0: michael@0: is(gVariables.getItemForNode(scopeNodes[0]).expanded, true, michael@0: "The local scope should be expanded by default."); michael@0: is(gVariables.getItemForNode(scopeNodes[1]).expanded, false, michael@0: "The global scope should not be collapsed by default."); michael@0: } michael@0: michael@0: function testExpandVariables() { michael@0: let deferred = promise.defer(); michael@0: michael@0: let localScope = gVariables.getScopeAtIndex(0); michael@0: let localEnums = localScope.target.querySelector(".variables-view-element-details.enum").childNodes; michael@0: michael@0: let thisVar = gVariables.getItemForNode(localEnums[0]); michael@0: let argsVar = gVariables.getItemForNode(localEnums[8]); michael@0: let cVar = gVariables.getItemForNode(localEnums[10]); michael@0: michael@0: is(thisVar.target.querySelector(".name").getAttribute("value"), "this", michael@0: "Should have the right property name for 'this'."); michael@0: is(argsVar.target.querySelector(".name").getAttribute("value"), "arguments", michael@0: "Should have the right property name for 'arguments'."); michael@0: is(cVar.target.querySelector(".name").getAttribute("value"), "c", michael@0: "Should have the right property name for 'c'."); michael@0: michael@0: is(thisVar.expanded, false, michael@0: "The thisVar should not be expanded at this point."); michael@0: is(argsVar.expanded, false, michael@0: "The argsVar should not be expanded at this point."); michael@0: is(cVar.expanded, false, michael@0: "The cVar should not be expanded at this point."); michael@0: michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 3).then(() => { michael@0: is(thisVar.get("window").target.querySelector(".name").getAttribute("value"), "window", michael@0: "Should have the right property name for 'window'."); michael@0: is(thisVar.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: ok(thisVar.get("window").target.querySelector(".value").className.contains("token-other"), michael@0: "Should have the right token class for 'window'."); michael@0: michael@0: is(thisVar.get("document").target.querySelector(".name").getAttribute("value"), "document", michael@0: "Should have the right property name for 'document'."); michael@0: is(thisVar.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: ok(thisVar.get("document").target.querySelector(".value").className.contains("token-domnode"), michael@0: "Should have the right token class for 'document'."); michael@0: michael@0: let argsProps = argsVar.target.querySelectorAll(".variables-view-property"); michael@0: is(argsProps.length, 8, michael@0: "The 'arguments' variable should contain 5 enumerable and 3 non-enumerable properties"); michael@0: michael@0: is(argsProps[0].querySelector(".name").getAttribute("value"), "0", michael@0: "Should have the right property name for '0'."); michael@0: is(argsProps[0].querySelector(".value").getAttribute("value"), "Object", michael@0: "Should have the right property value for '0'."); michael@0: ok(argsProps[0].querySelector(".value").className.contains("token-other"), michael@0: "Should have the right token class for '0'."); michael@0: michael@0: is(argsProps[1].querySelector(".name").getAttribute("value"), "1", michael@0: "Should have the right property name for '1'."); michael@0: is(argsProps[1].querySelector(".value").getAttribute("value"), "\"beta\"", michael@0: "Should have the right property value for '1'."); michael@0: ok(argsProps[1].querySelector(".value").className.contains("token-string"), michael@0: "Should have the right token class for '1'."); michael@0: michael@0: is(argsProps[2].querySelector(".name").getAttribute("value"), "2", michael@0: "Should have the right property name for '2'."); michael@0: is(argsProps[2].querySelector(".value").getAttribute("value"), "3", michael@0: "Should have the right property name for '2'."); michael@0: ok(argsProps[2].querySelector(".value").className.contains("token-number"), michael@0: "Should have the right token class for '2'."); michael@0: michael@0: is(argsProps[3].querySelector(".name").getAttribute("value"), "3", michael@0: "Should have the right property name for '3'."); michael@0: is(argsProps[3].querySelector(".value").getAttribute("value"), "false", michael@0: "Should have the right property value for '3'."); michael@0: ok(argsProps[3].querySelector(".value").className.contains("token-boolean"), michael@0: "Should have the right token class for '3'."); michael@0: michael@0: is(argsProps[4].querySelector(".name").getAttribute("value"), "4", michael@0: "Should have the right property name for '4'."); michael@0: is(argsProps[4].querySelector(".value").getAttribute("value"), "null", michael@0: "Should have the right property name for '4'."); michael@0: ok(argsProps[4].querySelector(".value").className.contains("token-null"), michael@0: "Should have the right token class for '4'."); michael@0: michael@0: is(gVariables.getItemForNode(argsProps[0]).target, michael@0: argsVar.target.querySelectorAll(".variables-view-property")[0], michael@0: "getItemForNode([0]) didn't return the expected property."); michael@0: michael@0: is(gVariables.getItemForNode(argsProps[1]).target, michael@0: argsVar.target.querySelectorAll(".variables-view-property")[1], michael@0: "getItemForNode([1]) didn't return the expected property."); michael@0: michael@0: is(gVariables.getItemForNode(argsProps[2]).target, michael@0: argsVar.target.querySelectorAll(".variables-view-property")[2], michael@0: "getItemForNode([2]) didn't return the expected property."); michael@0: michael@0: is(argsVar.find(argsProps[0]).target, michael@0: argsVar.target.querySelectorAll(".variables-view-property")[0], michael@0: "find([0]) didn't return the expected property."); michael@0: michael@0: is(argsVar.find(argsProps[1]).target, michael@0: argsVar.target.querySelectorAll(".variables-view-property")[1], michael@0: "find([1]) didn't return the expected property."); michael@0: michael@0: is(argsVar.find(argsProps[2]).target, michael@0: argsVar.target.querySelectorAll(".variables-view-property")[2], michael@0: "find([2]) didn't return the expected property."); michael@0: michael@0: let cProps = cVar.target.querySelectorAll(".variables-view-property"); michael@0: is(cProps.length, 7, michael@0: "The 'c' variable should contain 6 enumerable and 1 non-enumerable properties"); michael@0: michael@0: is(cProps[0].querySelector(".name").getAttribute("value"), "a", michael@0: "Should have the right property name for 'a'."); michael@0: is(cProps[0].querySelector(".value").getAttribute("value"), "1", michael@0: "Should have the right property value for 'a'."); michael@0: ok(cProps[0].querySelector(".value").className.contains("token-number"), michael@0: "Should have the right token class for 'a'."); michael@0: michael@0: is(cProps[1].querySelector(".name").getAttribute("value"), "b", michael@0: "Should have the right property name for 'b'."); michael@0: is(cProps[1].querySelector(".value").getAttribute("value"), "\"beta\"", michael@0: "Should have the right property value for 'b'."); michael@0: ok(cProps[1].querySelector(".value").className.contains("token-string"), michael@0: "Should have the right token class for 'b'."); michael@0: michael@0: is(cProps[2].querySelector(".name").getAttribute("value"), "c", michael@0: "Should have the right property name for 'c'."); michael@0: is(cProps[2].querySelector(".value").getAttribute("value"), "3", michael@0: "Should have the right property value for 'c'."); michael@0: ok(cProps[2].querySelector(".value").className.contains("token-number"), michael@0: "Should have the right token class for 'c'."); michael@0: michael@0: is(cProps[3].querySelector(".name").getAttribute("value"), "d", michael@0: "Should have the right property name for 'd'."); michael@0: is(cProps[3].querySelector(".value").getAttribute("value"), "false", michael@0: "Should have the right property value for 'd'."); michael@0: ok(cProps[3].querySelector(".value").className.contains("token-boolean"), michael@0: "Should have the right token class for 'd'."); michael@0: michael@0: is(cProps[4].querySelector(".name").getAttribute("value"), "e", michael@0: "Should have the right property name for 'e'."); michael@0: is(cProps[4].querySelector(".value").getAttribute("value"), "null", michael@0: "Should have the right property value for 'e'."); michael@0: ok(cProps[4].querySelector(".value").className.contains("token-null"), michael@0: "Should have the right token class for 'e'."); michael@0: michael@0: is(cProps[5].querySelector(".name").getAttribute("value"), "f", michael@0: "Should have the right property name for 'f'."); michael@0: is(cProps[5].querySelector(".value").getAttribute("value"), "undefined", michael@0: "Should have the right property value for 'f'."); michael@0: ok(cProps[5].querySelector(".value").className.contains("token-undefined"), michael@0: "Should have the right token class for 'f'."); michael@0: michael@0: is(gVariables.getItemForNode(cProps[0]).target, michael@0: cVar.target.querySelectorAll(".variables-view-property")[0], michael@0: "getItemForNode([0]) didn't return the expected property."); michael@0: michael@0: is(gVariables.getItemForNode(cProps[1]).target, michael@0: cVar.target.querySelectorAll(".variables-view-property")[1], michael@0: "getItemForNode([1]) didn't return the expected property."); michael@0: michael@0: is(gVariables.getItemForNode(cProps[2]).target, michael@0: cVar.target.querySelectorAll(".variables-view-property")[2], michael@0: "getItemForNode([2]) didn't return the expected property."); michael@0: michael@0: is(cVar.find(cProps[0]).target, michael@0: cVar.target.querySelectorAll(".variables-view-property")[0], michael@0: "find([0]) didn't return the expected property."); michael@0: michael@0: is(cVar.find(cProps[1]).target, michael@0: cVar.target.querySelectorAll(".variables-view-property")[1], michael@0: "find([1]) didn't return the expected property."); michael@0: michael@0: is(cVar.find(cProps[2]).target, michael@0: cVar.target.querySelectorAll(".variables-view-property")[2], michael@0: "find([2]) didn't return the expected property."); michael@0: }); michael@0: michael@0: // Expand the 'this', 'arguments' and 'c' variables view nodes. This causes michael@0: // their properties to be retrieved and displayed. michael@0: thisVar.expand(); michael@0: argsVar.expand(); michael@0: cVar.expand(); michael@0: michael@0: is(thisVar.expanded, true, michael@0: "The thisVar should be immediately marked as expanded."); michael@0: is(argsVar.expanded, true, michael@0: "The argsVar should be immediately marked as expanded."); michael@0: is(cVar.expanded, true, michael@0: "The cVar should be immediately marked as expanded."); 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: });