Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | // Test that makes sure web console autocomplete happens in the user-selected stackframe |
michael@0 | 7 | // from the js debugger. |
michael@0 | 8 | |
michael@0 | 9 | const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-autocomplete-in-stackframe.html"; |
michael@0 | 10 | |
michael@0 | 11 | let testDriver, gStackframes; |
michael@0 | 12 | |
michael@0 | 13 | function test() |
michael@0 | 14 | { |
michael@0 | 15 | requestLongerTimeout(2); |
michael@0 | 16 | addTab(TEST_URI); |
michael@0 | 17 | browser.addEventListener("load", function onLoad() { |
michael@0 | 18 | browser.removeEventListener("load", onLoad, true); |
michael@0 | 19 | openConsole(null, function(hud) { |
michael@0 | 20 | testDriver = testCompletion(hud); |
michael@0 | 21 | testDriver.next(); |
michael@0 | 22 | }); |
michael@0 | 23 | }, true); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | function testNext() { |
michael@0 | 27 | executeSoon(function() { |
michael@0 | 28 | testDriver.next(); |
michael@0 | 29 | }); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function testCompletion(hud) { |
michael@0 | 33 | let jsterm = hud.jsterm; |
michael@0 | 34 | let input = jsterm.inputNode; |
michael@0 | 35 | let popup = jsterm.autocompletePopup; |
michael@0 | 36 | |
michael@0 | 37 | // Test that document.title gives string methods. Native getters must execute. |
michael@0 | 38 | input.value = "document.title."; |
michael@0 | 39 | input.setSelectionRange(input.value.length, input.value.length); |
michael@0 | 40 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 41 | yield undefined; |
michael@0 | 42 | |
michael@0 | 43 | let newItems = popup.getItems(); |
michael@0 | 44 | ok(newItems.length > 0, "'document.title.' gave a list of suggestions"); |
michael@0 | 45 | ok(newItems.some(function(item) { |
michael@0 | 46 | return item.label == "substr"; |
michael@0 | 47 | }), "autocomplete results do contain substr"); |
michael@0 | 48 | ok(newItems.some(function(item) { |
michael@0 | 49 | return item.label == "toLowerCase"; |
michael@0 | 50 | }), "autocomplete results do contain toLowerCase"); |
michael@0 | 51 | ok(newItems.some(function(item) { |
michael@0 | 52 | return item.label == "strike"; |
michael@0 | 53 | }), "autocomplete results do contain strike"); |
michael@0 | 54 | |
michael@0 | 55 | // Test if 'f' gives 'foo1' but not 'foo2' or 'foo3' |
michael@0 | 56 | input.value = "f"; |
michael@0 | 57 | input.setSelectionRange(1, 1); |
michael@0 | 58 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 59 | yield undefined; |
michael@0 | 60 | |
michael@0 | 61 | newItems = popup.getItems(); |
michael@0 | 62 | ok(newItems.length > 0, "'f' gave a list of suggestions"); |
michael@0 | 63 | ok(!newItems.every(function(item) { |
michael@0 | 64 | return item.label != "foo1"; |
michael@0 | 65 | }), "autocomplete results do contain foo1"); |
michael@0 | 66 | ok(!newItems.every(function(item) { |
michael@0 | 67 | return item.label != "foo1Obj"; |
michael@0 | 68 | }), "autocomplete results do contain foo1Obj"); |
michael@0 | 69 | ok(newItems.every(function(item) { |
michael@0 | 70 | return item.label != "foo2"; |
michael@0 | 71 | }), "autocomplete results do not contain foo2"); |
michael@0 | 72 | ok(newItems.every(function(item) { |
michael@0 | 73 | return item.label != "foo2Obj"; |
michael@0 | 74 | }), "autocomplete results do not contain foo2Obj"); |
michael@0 | 75 | ok(newItems.every(function(item) { |
michael@0 | 76 | return item.label != "foo3"; |
michael@0 | 77 | }), "autocomplete results do not contain foo3"); |
michael@0 | 78 | ok(newItems.every(function(item) { |
michael@0 | 79 | return item.label != "foo3Obj"; |
michael@0 | 80 | }), "autocomplete results do not contain foo3Obj"); |
michael@0 | 81 | |
michael@0 | 82 | // Test if 'foo1Obj.' gives 'prop1' and 'prop2' |
michael@0 | 83 | input.value = "foo1Obj."; |
michael@0 | 84 | input.setSelectionRange(8, 8); |
michael@0 | 85 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 86 | yield undefined; |
michael@0 | 87 | |
michael@0 | 88 | newItems = popup.getItems(); |
michael@0 | 89 | ok(!newItems.every(function(item) { |
michael@0 | 90 | return item.label != "prop1"; |
michael@0 | 91 | }), "autocomplete results do contain prop1"); |
michael@0 | 92 | ok(!newItems.every(function(item) { |
michael@0 | 93 | return item.label != "prop2"; |
michael@0 | 94 | }), "autocomplete results do contain prop2"); |
michael@0 | 95 | |
michael@0 | 96 | // Test if 'foo1Obj.prop2.' gives 'prop21' |
michael@0 | 97 | input.value = "foo1Obj.prop2."; |
michael@0 | 98 | input.setSelectionRange(14, 14); |
michael@0 | 99 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 100 | yield undefined; |
michael@0 | 101 | |
michael@0 | 102 | newItems = popup.getItems(); |
michael@0 | 103 | ok(!newItems.every(function(item) { |
michael@0 | 104 | return item.label != "prop21"; |
michael@0 | 105 | }), "autocomplete results do contain prop21"); |
michael@0 | 106 | |
michael@0 | 107 | info("openDebugger"); |
michael@0 | 108 | executeSoon(() => openDebugger().then(debuggerOpened)); |
michael@0 | 109 | yield undefined; |
michael@0 | 110 | |
michael@0 | 111 | // From this point on the |
michael@0 | 112 | // Test if 'f' gives 'foo3' and 'foo1' but not 'foo2' |
michael@0 | 113 | input.value = "f"; |
michael@0 | 114 | input.setSelectionRange(1, 1); |
michael@0 | 115 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 116 | yield undefined; |
michael@0 | 117 | |
michael@0 | 118 | newItems = popup.getItems(); |
michael@0 | 119 | ok(newItems.length > 0, "'f' gave a list of suggestions"); |
michael@0 | 120 | ok(!newItems.every(function(item) { |
michael@0 | 121 | return item.label != "foo3"; |
michael@0 | 122 | }), "autocomplete results do contain foo3"); |
michael@0 | 123 | ok(!newItems.every(function(item) { |
michael@0 | 124 | return item.label != "foo3Obj"; |
michael@0 | 125 | }), "autocomplete results do contain foo3Obj"); |
michael@0 | 126 | ok(!newItems.every(function(item) { |
michael@0 | 127 | return item.label != "foo1"; |
michael@0 | 128 | }), "autocomplete results do contain foo1"); |
michael@0 | 129 | ok(!newItems.every(function(item) { |
michael@0 | 130 | return item.label != "foo1Obj"; |
michael@0 | 131 | }), "autocomplete results do contain foo1Obj"); |
michael@0 | 132 | ok(newItems.every(function(item) { |
michael@0 | 133 | return item.label != "foo2"; |
michael@0 | 134 | }), "autocomplete results do not contain foo2"); |
michael@0 | 135 | ok(newItems.every(function(item) { |
michael@0 | 136 | return item.label != "foo2Obj"; |
michael@0 | 137 | }), "autocomplete results do not contain foo2Obj"); |
michael@0 | 138 | |
michael@0 | 139 | openDebugger().then(() => { |
michael@0 | 140 | gStackframes.selectFrame(1); |
michael@0 | 141 | |
michael@0 | 142 | info("openConsole"); |
michael@0 | 143 | executeSoon(() => openConsole(null, () => testDriver.next())); |
michael@0 | 144 | }); |
michael@0 | 145 | yield undefined; |
michael@0 | 146 | |
michael@0 | 147 | // Test if 'f' gives 'foo2' and 'foo1' but not 'foo3' |
michael@0 | 148 | input.value = "f"; |
michael@0 | 149 | input.setSelectionRange(1, 1); |
michael@0 | 150 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 151 | yield undefined; |
michael@0 | 152 | |
michael@0 | 153 | newItems = popup.getItems(); |
michael@0 | 154 | ok(newItems.length > 0, "'f' gave a list of suggestions"); |
michael@0 | 155 | ok(!newItems.every(function(item) { |
michael@0 | 156 | return item.label != "foo2"; |
michael@0 | 157 | }), "autocomplete results do contain foo2"); |
michael@0 | 158 | ok(!newItems.every(function(item) { |
michael@0 | 159 | return item.label != "foo2Obj"; |
michael@0 | 160 | }), "autocomplete results do contain foo2Obj"); |
michael@0 | 161 | ok(!newItems.every(function(item) { |
michael@0 | 162 | return item.label != "foo1"; |
michael@0 | 163 | }), "autocomplete results do contain foo1"); |
michael@0 | 164 | ok(!newItems.every(function(item) { |
michael@0 | 165 | return item.label != "foo1Obj"; |
michael@0 | 166 | }), "autocomplete results do contain foo1Obj"); |
michael@0 | 167 | ok(newItems.every(function(item) { |
michael@0 | 168 | return item.label != "foo3"; |
michael@0 | 169 | }), "autocomplete results do not contain foo3"); |
michael@0 | 170 | ok(newItems.every(function(item) { |
michael@0 | 171 | return item.label != "foo3Obj"; |
michael@0 | 172 | }), "autocomplete results do not contain foo3Obj"); |
michael@0 | 173 | |
michael@0 | 174 | // Test if 'foo2Obj.' gives 'prop1' |
michael@0 | 175 | input.value = "foo2Obj."; |
michael@0 | 176 | input.setSelectionRange(8, 8); |
michael@0 | 177 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 178 | yield undefined; |
michael@0 | 179 | |
michael@0 | 180 | newItems = popup.getItems(); |
michael@0 | 181 | ok(!newItems.every(function(item) { |
michael@0 | 182 | return item.label != "prop1"; |
michael@0 | 183 | }), "autocomplete results do contain prop1"); |
michael@0 | 184 | |
michael@0 | 185 | // Test if 'foo2Obj.prop1.' gives 'prop11' |
michael@0 | 186 | input.value = "foo2Obj.prop1."; |
michael@0 | 187 | input.setSelectionRange(14, 14); |
michael@0 | 188 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 189 | yield undefined; |
michael@0 | 190 | |
michael@0 | 191 | newItems = popup.getItems(); |
michael@0 | 192 | ok(!newItems.every(function(item) { |
michael@0 | 193 | return item.label != "prop11"; |
michael@0 | 194 | }), "autocomplete results do contain prop11"); |
michael@0 | 195 | |
michael@0 | 196 | // Test if 'foo2Obj.prop1.prop11.' gives suggestions for a string i.e. 'length' |
michael@0 | 197 | input.value = "foo2Obj.prop1.prop11."; |
michael@0 | 198 | input.setSelectionRange(21, 21); |
michael@0 | 199 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 200 | yield undefined; |
michael@0 | 201 | |
michael@0 | 202 | newItems = popup.getItems(); |
michael@0 | 203 | ok(!newItems.every(function(item) { |
michael@0 | 204 | return item.label != "length"; |
michael@0 | 205 | }), "autocomplete results do contain length"); |
michael@0 | 206 | |
michael@0 | 207 | // Test if 'foo1Obj[0].' throws no errors. |
michael@0 | 208 | input.value = "foo2Obj[0]."; |
michael@0 | 209 | input.setSelectionRange(11, 11); |
michael@0 | 210 | jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext); |
michael@0 | 211 | yield undefined; |
michael@0 | 212 | |
michael@0 | 213 | newItems = popup.getItems(); |
michael@0 | 214 | is(newItems.length, 0, "no items for foo2Obj[0]"); |
michael@0 | 215 | |
michael@0 | 216 | testDriver = null; |
michael@0 | 217 | executeSoon(finishUp); |
michael@0 | 218 | yield undefined; |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | function debuggerOpened(aResult) |
michael@0 | 222 | { |
michael@0 | 223 | let debuggerWin = aResult.panelWin; |
michael@0 | 224 | let debuggerController = debuggerWin.DebuggerController; |
michael@0 | 225 | let thread = debuggerController.activeThread; |
michael@0 | 226 | gStackframes = debuggerController.StackFrames; |
michael@0 | 227 | |
michael@0 | 228 | executeSoon(() => { |
michael@0 | 229 | thread.addOneTimeListener("framesadded", onFramesAdded); |
michael@0 | 230 | info("firstCall()"); |
michael@0 | 231 | content.wrappedJSObject.firstCall(); |
michael@0 | 232 | }); |
michael@0 | 233 | } |
michael@0 | 234 | |
michael@0 | 235 | function onFramesAdded() |
michael@0 | 236 | { |
michael@0 | 237 | info("onFramesAdded, openConsole() now"); |
michael@0 | 238 | executeSoon(() => openConsole(null, testNext)); |
michael@0 | 239 | } |
michael@0 | 240 | |
michael@0 | 241 | function finishUp() { |
michael@0 | 242 | testDriver = gStackframes = null; |
michael@0 | 243 | finishTest(); |
michael@0 | 244 | } |