michael@0: /* 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: // Test that makes sure web console autocomplete happens in the user-selected stackframe michael@0: // from the js debugger. michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-autocomplete-in-stackframe.html"; michael@0: michael@0: let testDriver, gStackframes; michael@0: michael@0: function test() michael@0: { michael@0: requestLongerTimeout(2); michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: openConsole(null, function(hud) { michael@0: testDriver = testCompletion(hud); michael@0: testDriver.next(); michael@0: }); michael@0: }, true); michael@0: } michael@0: michael@0: function testNext() { michael@0: executeSoon(function() { michael@0: testDriver.next(); michael@0: }); michael@0: } michael@0: michael@0: function testCompletion(hud) { michael@0: let jsterm = hud.jsterm; michael@0: let input = jsterm.inputNode; michael@0: let popup = jsterm.autocompletePopup; michael@0: michael@0: // Test that document.title gives string methods. Native getters must execute. michael@0: input.value = "document.title."; michael@0: input.setSelectionRange(input.value.length, input.value.length); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: let newItems = popup.getItems(); michael@0: ok(newItems.length > 0, "'document.title.' gave a list of suggestions"); michael@0: ok(newItems.some(function(item) { michael@0: return item.label == "substr"; michael@0: }), "autocomplete results do contain substr"); michael@0: ok(newItems.some(function(item) { michael@0: return item.label == "toLowerCase"; michael@0: }), "autocomplete results do contain toLowerCase"); michael@0: ok(newItems.some(function(item) { michael@0: return item.label == "strike"; michael@0: }), "autocomplete results do contain strike"); michael@0: michael@0: // Test if 'f' gives 'foo1' but not 'foo2' or 'foo3' michael@0: input.value = "f"; michael@0: input.setSelectionRange(1, 1); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: newItems = popup.getItems(); michael@0: ok(newItems.length > 0, "'f' gave a list of suggestions"); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "foo1"; michael@0: }), "autocomplete results do contain foo1"); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "foo1Obj"; michael@0: }), "autocomplete results do contain foo1Obj"); michael@0: ok(newItems.every(function(item) { michael@0: return item.label != "foo2"; michael@0: }), "autocomplete results do not contain foo2"); michael@0: ok(newItems.every(function(item) { michael@0: return item.label != "foo2Obj"; michael@0: }), "autocomplete results do not contain foo2Obj"); michael@0: ok(newItems.every(function(item) { michael@0: return item.label != "foo3"; michael@0: }), "autocomplete results do not contain foo3"); michael@0: ok(newItems.every(function(item) { michael@0: return item.label != "foo3Obj"; michael@0: }), "autocomplete results do not contain foo3Obj"); michael@0: michael@0: // Test if 'foo1Obj.' gives 'prop1' and 'prop2' michael@0: input.value = "foo1Obj."; michael@0: input.setSelectionRange(8, 8); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: newItems = popup.getItems(); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "prop1"; michael@0: }), "autocomplete results do contain prop1"); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "prop2"; michael@0: }), "autocomplete results do contain prop2"); michael@0: michael@0: // Test if 'foo1Obj.prop2.' gives 'prop21' michael@0: input.value = "foo1Obj.prop2."; michael@0: input.setSelectionRange(14, 14); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: newItems = popup.getItems(); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "prop21"; michael@0: }), "autocomplete results do contain prop21"); michael@0: michael@0: info("openDebugger"); michael@0: executeSoon(() => openDebugger().then(debuggerOpened)); michael@0: yield undefined; michael@0: michael@0: // From this point on the michael@0: // Test if 'f' gives 'foo3' and 'foo1' but not 'foo2' michael@0: input.value = "f"; michael@0: input.setSelectionRange(1, 1); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: newItems = popup.getItems(); michael@0: ok(newItems.length > 0, "'f' gave a list of suggestions"); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "foo3"; michael@0: }), "autocomplete results do contain foo3"); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "foo3Obj"; michael@0: }), "autocomplete results do contain foo3Obj"); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "foo1"; michael@0: }), "autocomplete results do contain foo1"); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "foo1Obj"; michael@0: }), "autocomplete results do contain foo1Obj"); michael@0: ok(newItems.every(function(item) { michael@0: return item.label != "foo2"; michael@0: }), "autocomplete results do not contain foo2"); michael@0: ok(newItems.every(function(item) { michael@0: return item.label != "foo2Obj"; michael@0: }), "autocomplete results do not contain foo2Obj"); michael@0: michael@0: openDebugger().then(() => { michael@0: gStackframes.selectFrame(1); michael@0: michael@0: info("openConsole"); michael@0: executeSoon(() => openConsole(null, () => testDriver.next())); michael@0: }); michael@0: yield undefined; michael@0: michael@0: // Test if 'f' gives 'foo2' and 'foo1' but not 'foo3' michael@0: input.value = "f"; michael@0: input.setSelectionRange(1, 1); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: newItems = popup.getItems(); michael@0: ok(newItems.length > 0, "'f' gave a list of suggestions"); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "foo2"; michael@0: }), "autocomplete results do contain foo2"); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "foo2Obj"; michael@0: }), "autocomplete results do contain foo2Obj"); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "foo1"; michael@0: }), "autocomplete results do contain foo1"); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "foo1Obj"; michael@0: }), "autocomplete results do contain foo1Obj"); michael@0: ok(newItems.every(function(item) { michael@0: return item.label != "foo3"; michael@0: }), "autocomplete results do not contain foo3"); michael@0: ok(newItems.every(function(item) { michael@0: return item.label != "foo3Obj"; michael@0: }), "autocomplete results do not contain foo3Obj"); michael@0: michael@0: // Test if 'foo2Obj.' gives 'prop1' michael@0: input.value = "foo2Obj."; michael@0: input.setSelectionRange(8, 8); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: newItems = popup.getItems(); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "prop1"; michael@0: }), "autocomplete results do contain prop1"); michael@0: michael@0: // Test if 'foo2Obj.prop1.' gives 'prop11' michael@0: input.value = "foo2Obj.prop1."; michael@0: input.setSelectionRange(14, 14); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: newItems = popup.getItems(); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "prop11"; michael@0: }), "autocomplete results do contain prop11"); michael@0: michael@0: // Test if 'foo2Obj.prop1.prop11.' gives suggestions for a string i.e. 'length' michael@0: input.value = "foo2Obj.prop1.prop11."; michael@0: input.setSelectionRange(21, 21); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: newItems = popup.getItems(); michael@0: ok(!newItems.every(function(item) { michael@0: return item.label != "length"; michael@0: }), "autocomplete results do contain length"); michael@0: michael@0: // Test if 'foo1Obj[0].' throws no errors. michael@0: input.value = "foo2Obj[0]."; michael@0: input.setSelectionRange(11, 11); michael@0: jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); michael@0: yield undefined; michael@0: michael@0: newItems = popup.getItems(); michael@0: is(newItems.length, 0, "no items for foo2Obj[0]"); michael@0: michael@0: testDriver = null; michael@0: executeSoon(finishUp); michael@0: yield undefined; michael@0: } michael@0: michael@0: function debuggerOpened(aResult) michael@0: { michael@0: let debuggerWin = aResult.panelWin; michael@0: let debuggerController = debuggerWin.DebuggerController; michael@0: let thread = debuggerController.activeThread; michael@0: gStackframes = debuggerController.StackFrames; michael@0: michael@0: executeSoon(() => { michael@0: thread.addOneTimeListener("framesadded", onFramesAdded); michael@0: info("firstCall()"); michael@0: content.wrappedJSObject.firstCall(); michael@0: }); michael@0: } michael@0: michael@0: function onFramesAdded() michael@0: { michael@0: info("onFramesAdded, openConsole() now"); michael@0: executeSoon(() => openConsole(null, testNext)); michael@0: } michael@0: michael@0: function finishUp() { michael@0: testDriver = gStackframes = null; michael@0: finishTest(); michael@0: }