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 is correctly populated in 'with' frames. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_with-frame.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gVariables; michael@0: michael@0: function test() { 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: // The first 'with' scope should be expanded by default, but the michael@0: // variables haven't been fetched yet. This is how 'with' scopes work. michael@0: promise.all([ michael@0: waitForSourceAndCaret(gPanel, ".html", 22), michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES), michael@0: waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES) michael@0: ]).then(testFirstWithScope) michael@0: .then(expandSecondWithScope) michael@0: .then(testSecondWithScope) michael@0: .then(expandFunctionScope) michael@0: .then(testFunctionScope) 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 testFirstWithScope() { michael@0: let firstWithScope = gVariables.getScopeAtIndex(0); michael@0: is(firstWithScope.expanded, true, michael@0: "The first 'with' scope should be expanded by default."); michael@0: ok(firstWithScope.target.querySelector(".name").getAttribute("value").contains("[Object]"), michael@0: "The first 'with' scope should be properly identified."); michael@0: michael@0: let withEnums = firstWithScope._enum.childNodes; michael@0: let withNonEnums = firstWithScope._nonenum.childNodes; michael@0: michael@0: is(withEnums.length, 3, michael@0: "The first 'with' scope should contain all the created enumerable elements."); michael@0: is(withNonEnums.length, 1, michael@0: "The first 'with' scope should contain all the created non-enumerable elements."); michael@0: michael@0: is(withEnums[0].querySelector(".name").getAttribute("value"), "this", michael@0: "Should have the right property name for 'this'."); michael@0: is(withEnums[0].querySelector(".value").getAttribute("value"), michael@0: "Window \u2192 doc_with-frame.html", michael@0: "Should have the right property value for 'this'."); michael@0: ok(withEnums[0].querySelector(".value").className.contains("token-other"), michael@0: "Should have the right token class for 'this'."); michael@0: michael@0: is(withEnums[1].querySelector(".name").getAttribute("value"), "alpha", michael@0: "Should have the right property name for 'alpha'."); michael@0: is(withEnums[1].querySelector(".value").getAttribute("value"), "1", michael@0: "Should have the right property value for 'alpha'."); michael@0: ok(withEnums[1].querySelector(".value").className.contains("token-number"), michael@0: "Should have the right token class for 'alpha'."); michael@0: michael@0: is(withEnums[2].querySelector(".name").getAttribute("value"), "beta", michael@0: "Should have the right property name for 'beta'."); michael@0: is(withEnums[2].querySelector(".value").getAttribute("value"), "2", michael@0: "Should have the right property value for 'beta'."); michael@0: ok(withEnums[2].querySelector(".value").className.contains("token-number"), michael@0: "Should have the right token class for 'beta'."); michael@0: michael@0: is(withNonEnums[0].querySelector(".name").getAttribute("value"), "__proto__", michael@0: "Should have the right property name for '__proto__'."); michael@0: is(withNonEnums[0].querySelector(".value").getAttribute("value"), "Object", michael@0: "Should have the right property value for '__proto__'."); michael@0: ok(withNonEnums[0].querySelector(".value").className.contains("token-other"), michael@0: "Should have the right token class for '__proto__'."); michael@0: } michael@0: michael@0: function expandSecondWithScope() { michael@0: let deferred = promise.defer(); michael@0: michael@0: let secondWithScope = gVariables.getScopeAtIndex(1); michael@0: is(secondWithScope.expanded, false, michael@0: "The second 'with' 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: secondWithScope.target.querySelector(".name"), michael@0: gDebugger); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testSecondWithScope() { michael@0: let secondWithScope = gVariables.getScopeAtIndex(1); michael@0: is(secondWithScope.expanded, true, michael@0: "The second 'with' scope should now be expanded."); michael@0: ok(secondWithScope.target.querySelector(".name").getAttribute("value").contains("[Math]"), michael@0: "The second 'with' scope should be properly identified."); michael@0: michael@0: let withEnums = secondWithScope._enum.childNodes; michael@0: let withNonEnums = secondWithScope._nonenum.childNodes; michael@0: michael@0: is(withEnums.length, 0, michael@0: "The second 'with' scope should contain all the created enumerable elements."); michael@0: isnot(withNonEnums.length, 0, michael@0: "The second 'with' scope should contain all the created non-enumerable elements."); michael@0: michael@0: is(secondWithScope.get("E").target.querySelector(".name").getAttribute("value"), "E", michael@0: "Should have the right property name for 'E'."); michael@0: is(secondWithScope.get("E").target.querySelector(".value").getAttribute("value"), "2.718281828459045", michael@0: "Should have the right property value for 'E'."); michael@0: ok(secondWithScope.get("E").target.querySelector(".value").className.contains("token-number"), michael@0: "Should have the right token class for 'E'."); michael@0: michael@0: is(secondWithScope.get("PI").target.querySelector(".name").getAttribute("value"), "PI", michael@0: "Should have the right property name for 'PI'."); michael@0: is(secondWithScope.get("PI").target.querySelector(".value").getAttribute("value"), "3.141592653589793", michael@0: "Should have the right property value for 'PI'."); michael@0: ok(secondWithScope.get("PI").target.querySelector(".value").className.contains("token-number"), michael@0: "Should have the right token class for 'PI'."); michael@0: michael@0: is(secondWithScope.get("random").target.querySelector(".name").getAttribute("value"), "random", michael@0: "Should have the right property name for 'random'."); michael@0: is(secondWithScope.get("random").target.querySelector(".value").getAttribute("value"), "random()", michael@0: "Should have the right property value for 'random'."); michael@0: ok(secondWithScope.get("random").target.querySelector(".value").className.contains("token-other"), michael@0: "Should have the right token class for 'random'."); michael@0: michael@0: is(secondWithScope.get("__proto__").target.querySelector(".name").getAttribute("value"), "__proto__", michael@0: "Should have the right property name for '__proto__'."); michael@0: is(secondWithScope.get("__proto__").target.querySelector(".value").getAttribute("value"), "Object", michael@0: "Should have the right property value for '__proto__'."); michael@0: ok(secondWithScope.get("__proto__").target.querySelector(".value").className.contains("token-other"), michael@0: "Should have the right token class for '__proto__'."); michael@0: } michael@0: michael@0: function expandFunctionScope() { michael@0: let funcScope = gVariables.getScopeAtIndex(2); michael@0: is(funcScope.expanded, false, michael@0: "The function scope shouldn't be expanded by default, but the " + michael@0: "variables have been already fetched. This is how local scopes work."); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: funcScope.target.querySelector(".name"), michael@0: gDebugger); michael@0: michael@0: return promise.resolve(null); michael@0: } michael@0: michael@0: function testFunctionScope() { michael@0: let funcScope = gVariables.getScopeAtIndex(2); michael@0: is(funcScope.expanded, true, michael@0: "The function scope should now be expanded."); michael@0: ok(funcScope.target.querySelector(".name").getAttribute("value").contains("[test]"), michael@0: "The function scope should be properly identified."); michael@0: michael@0: let funcEnums = funcScope._enum.childNodes; michael@0: let funcNonEnums = funcScope._nonenum.childNodes; michael@0: michael@0: is(funcEnums.length, 6, michael@0: "The function scope should contain all the created enumerable elements."); michael@0: is(funcNonEnums.length, 0, michael@0: "The function scope should contain all the created non-enumerable elements."); michael@0: michael@0: is(funcScope.get("aNumber").target.querySelector(".name").getAttribute("value"), "aNumber", michael@0: "Should have the right property name for 'aNumber'."); michael@0: is(funcScope.get("aNumber").target.querySelector(".value").getAttribute("value"), "10", michael@0: "Should have the right property value for 'aNumber'."); michael@0: ok(funcScope.get("aNumber").target.querySelector(".value").className.contains("token-number"), michael@0: "Should have the right token class for 'aNumber'."); michael@0: michael@0: is(funcScope.get("a").target.querySelector(".name").getAttribute("value"), "a", michael@0: "Should have the right property name for 'a'."); michael@0: is(funcScope.get("a").target.querySelector(".value").getAttribute("value"), "314.1592653589793", michael@0: "Should have the right property value for 'a'."); michael@0: ok(funcScope.get("a").target.querySelector(".value").className.contains("token-number"), michael@0: "Should have the right token class for 'a'."); michael@0: michael@0: is(funcScope.get("r").target.querySelector(".name").getAttribute("value"), "r", michael@0: "Should have the right property name for 'r'."); michael@0: is(funcScope.get("r").target.querySelector(".value").getAttribute("value"), "10", michael@0: "Should have the right property value for 'r'."); michael@0: ok(funcScope.get("r").target.querySelector(".value").className.contains("token-number"), michael@0: "Should have the right token class for 'r'."); michael@0: michael@0: is(funcScope.get("foo").target.querySelector(".name").getAttribute("value"), "foo", michael@0: "Should have the right property name for 'foo'."); michael@0: is(funcScope.get("foo").target.querySelector(".value").getAttribute("value"), "6.283185307179586", michael@0: "Should have the right property value for 'foo'."); michael@0: ok(funcScope.get("foo").target.querySelector(".value").className.contains("token-number"), michael@0: "Should have the right token class for 'foo'."); 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: });