1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_autocomplete_in_debugger_stackframe.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,244 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 + 1.9 +// Test that makes sure web console autocomplete happens in the user-selected stackframe 1.10 +// from the js debugger. 1.11 + 1.12 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-autocomplete-in-stackframe.html"; 1.13 + 1.14 +let testDriver, gStackframes; 1.15 + 1.16 +function test() 1.17 +{ 1.18 + requestLongerTimeout(2); 1.19 + addTab(TEST_URI); 1.20 + browser.addEventListener("load", function onLoad() { 1.21 + browser.removeEventListener("load", onLoad, true); 1.22 + openConsole(null, function(hud) { 1.23 + testDriver = testCompletion(hud); 1.24 + testDriver.next(); 1.25 + }); 1.26 + }, true); 1.27 +} 1.28 + 1.29 +function testNext() { 1.30 + executeSoon(function() { 1.31 + testDriver.next(); 1.32 + }); 1.33 +} 1.34 + 1.35 +function testCompletion(hud) { 1.36 + let jsterm = hud.jsterm; 1.37 + let input = jsterm.inputNode; 1.38 + let popup = jsterm.autocompletePopup; 1.39 + 1.40 + // Test that document.title gives string methods. Native getters must execute. 1.41 + input.value = "document.title."; 1.42 + input.setSelectionRange(input.value.length, input.value.length); 1.43 + jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); 1.44 + yield undefined; 1.45 + 1.46 + let newItems = popup.getItems(); 1.47 + ok(newItems.length > 0, "'document.title.' gave a list of suggestions"); 1.48 + ok(newItems.some(function(item) { 1.49 + return item.label == "substr"; 1.50 + }), "autocomplete results do contain substr"); 1.51 + ok(newItems.some(function(item) { 1.52 + return item.label == "toLowerCase"; 1.53 + }), "autocomplete results do contain toLowerCase"); 1.54 + ok(newItems.some(function(item) { 1.55 + return item.label == "strike"; 1.56 + }), "autocomplete results do contain strike"); 1.57 + 1.58 + // Test if 'f' gives 'foo1' but not 'foo2' or 'foo3' 1.59 + input.value = "f"; 1.60 + input.setSelectionRange(1, 1); 1.61 + jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); 1.62 + yield undefined; 1.63 + 1.64 + newItems = popup.getItems(); 1.65 + ok(newItems.length > 0, "'f' gave a list of suggestions"); 1.66 + ok(!newItems.every(function(item) { 1.67 + return item.label != "foo1"; 1.68 + }), "autocomplete results do contain foo1"); 1.69 + ok(!newItems.every(function(item) { 1.70 + return item.label != "foo1Obj"; 1.71 + }), "autocomplete results do contain foo1Obj"); 1.72 + ok(newItems.every(function(item) { 1.73 + return item.label != "foo2"; 1.74 + }), "autocomplete results do not contain foo2"); 1.75 + ok(newItems.every(function(item) { 1.76 + return item.label != "foo2Obj"; 1.77 + }), "autocomplete results do not contain foo2Obj"); 1.78 + ok(newItems.every(function(item) { 1.79 + return item.label != "foo3"; 1.80 + }), "autocomplete results do not contain foo3"); 1.81 + ok(newItems.every(function(item) { 1.82 + return item.label != "foo3Obj"; 1.83 + }), "autocomplete results do not contain foo3Obj"); 1.84 + 1.85 + // Test if 'foo1Obj.' gives 'prop1' and 'prop2' 1.86 + input.value = "foo1Obj."; 1.87 + input.setSelectionRange(8, 8); 1.88 + jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); 1.89 + yield undefined; 1.90 + 1.91 + newItems = popup.getItems(); 1.92 + ok(!newItems.every(function(item) { 1.93 + return item.label != "prop1"; 1.94 + }), "autocomplete results do contain prop1"); 1.95 + ok(!newItems.every(function(item) { 1.96 + return item.label != "prop2"; 1.97 + }), "autocomplete results do contain prop2"); 1.98 + 1.99 + // Test if 'foo1Obj.prop2.' gives 'prop21' 1.100 + input.value = "foo1Obj.prop2."; 1.101 + input.setSelectionRange(14, 14); 1.102 + jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); 1.103 + yield undefined; 1.104 + 1.105 + newItems = popup.getItems(); 1.106 + ok(!newItems.every(function(item) { 1.107 + return item.label != "prop21"; 1.108 + }), "autocomplete results do contain prop21"); 1.109 + 1.110 + info("openDebugger"); 1.111 + executeSoon(() => openDebugger().then(debuggerOpened)); 1.112 + yield undefined; 1.113 + 1.114 + // From this point on the 1.115 + // Test if 'f' gives 'foo3' and 'foo1' but not 'foo2' 1.116 + input.value = "f"; 1.117 + input.setSelectionRange(1, 1); 1.118 + jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); 1.119 + yield undefined; 1.120 + 1.121 + newItems = popup.getItems(); 1.122 + ok(newItems.length > 0, "'f' gave a list of suggestions"); 1.123 + ok(!newItems.every(function(item) { 1.124 + return item.label != "foo3"; 1.125 + }), "autocomplete results do contain foo3"); 1.126 + ok(!newItems.every(function(item) { 1.127 + return item.label != "foo3Obj"; 1.128 + }), "autocomplete results do contain foo3Obj"); 1.129 + ok(!newItems.every(function(item) { 1.130 + return item.label != "foo1"; 1.131 + }), "autocomplete results do contain foo1"); 1.132 + ok(!newItems.every(function(item) { 1.133 + return item.label != "foo1Obj"; 1.134 + }), "autocomplete results do contain foo1Obj"); 1.135 + ok(newItems.every(function(item) { 1.136 + return item.label != "foo2"; 1.137 + }), "autocomplete results do not contain foo2"); 1.138 + ok(newItems.every(function(item) { 1.139 + return item.label != "foo2Obj"; 1.140 + }), "autocomplete results do not contain foo2Obj"); 1.141 + 1.142 + openDebugger().then(() => { 1.143 + gStackframes.selectFrame(1); 1.144 + 1.145 + info("openConsole"); 1.146 + executeSoon(() => openConsole(null, () => testDriver.next())); 1.147 + }); 1.148 + yield undefined; 1.149 + 1.150 + // Test if 'f' gives 'foo2' and 'foo1' but not 'foo3' 1.151 + input.value = "f"; 1.152 + input.setSelectionRange(1, 1); 1.153 + jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); 1.154 + yield undefined; 1.155 + 1.156 + newItems = popup.getItems(); 1.157 + ok(newItems.length > 0, "'f' gave a list of suggestions"); 1.158 + ok(!newItems.every(function(item) { 1.159 + return item.label != "foo2"; 1.160 + }), "autocomplete results do contain foo2"); 1.161 + ok(!newItems.every(function(item) { 1.162 + return item.label != "foo2Obj"; 1.163 + }), "autocomplete results do contain foo2Obj"); 1.164 + ok(!newItems.every(function(item) { 1.165 + return item.label != "foo1"; 1.166 + }), "autocomplete results do contain foo1"); 1.167 + ok(!newItems.every(function(item) { 1.168 + return item.label != "foo1Obj"; 1.169 + }), "autocomplete results do contain foo1Obj"); 1.170 + ok(newItems.every(function(item) { 1.171 + return item.label != "foo3"; 1.172 + }), "autocomplete results do not contain foo3"); 1.173 + ok(newItems.every(function(item) { 1.174 + return item.label != "foo3Obj"; 1.175 + }), "autocomplete results do not contain foo3Obj"); 1.176 + 1.177 + // Test if 'foo2Obj.' gives 'prop1' 1.178 + input.value = "foo2Obj."; 1.179 + input.setSelectionRange(8, 8); 1.180 + jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); 1.181 + yield undefined; 1.182 + 1.183 + newItems = popup.getItems(); 1.184 + ok(!newItems.every(function(item) { 1.185 + return item.label != "prop1"; 1.186 + }), "autocomplete results do contain prop1"); 1.187 + 1.188 + // Test if 'foo2Obj.prop1.' gives 'prop11' 1.189 + input.value = "foo2Obj.prop1."; 1.190 + input.setSelectionRange(14, 14); 1.191 + jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); 1.192 + yield undefined; 1.193 + 1.194 + newItems = popup.getItems(); 1.195 + ok(!newItems.every(function(item) { 1.196 + return item.label != "prop11"; 1.197 + }), "autocomplete results do contain prop11"); 1.198 + 1.199 + // Test if 'foo2Obj.prop1.prop11.' gives suggestions for a string i.e. 'length' 1.200 + input.value = "foo2Obj.prop1.prop11."; 1.201 + input.setSelectionRange(21, 21); 1.202 + jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); 1.203 + yield undefined; 1.204 + 1.205 + newItems = popup.getItems(); 1.206 + ok(!newItems.every(function(item) { 1.207 + return item.label != "length"; 1.208 + }), "autocomplete results do contain length"); 1.209 + 1.210 + // Test if 'foo1Obj[0].' throws no errors. 1.211 + input.value = "foo2Obj[0]."; 1.212 + input.setSelectionRange(11, 11); 1.213 + jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); 1.214 + yield undefined; 1.215 + 1.216 + newItems = popup.getItems(); 1.217 + is(newItems.length, 0, "no items for foo2Obj[0]"); 1.218 + 1.219 + testDriver = null; 1.220 + executeSoon(finishUp); 1.221 + yield undefined; 1.222 +} 1.223 + 1.224 +function debuggerOpened(aResult) 1.225 +{ 1.226 + let debuggerWin = aResult.panelWin; 1.227 + let debuggerController = debuggerWin.DebuggerController; 1.228 + let thread = debuggerController.activeThread; 1.229 + gStackframes = debuggerController.StackFrames; 1.230 + 1.231 + executeSoon(() => { 1.232 + thread.addOneTimeListener("framesadded", onFramesAdded); 1.233 + info("firstCall()"); 1.234 + content.wrappedJSObject.firstCall(); 1.235 + }); 1.236 +} 1.237 + 1.238 +function onFramesAdded() 1.239 +{ 1.240 + info("onFramesAdded, openConsole() now"); 1.241 + executeSoon(() => openConsole(null, testNext)); 1.242 +} 1.243 + 1.244 +function finishUp() { 1.245 + testDriver = gStackframes = null; 1.246 + finishTest(); 1.247 +}