| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script src="../../http/tests/inspector/inspector-test.js"></script> | 3 <script src="../../http/tests/inspector/inspector-test.js"></script> |
| 4 <script src="../../http/tests/inspector/console-test.js"></script> | 4 <script src="../../http/tests/inspector/console-test.js"></script> |
| 5 <script> | 5 <script> |
| 6 function templateString() | 6 function templateString() |
| 7 { | 7 { |
| 8 console.log("The template string should not run and you should not see this
log"); | 8 console.log("The template string should not run and you should not see this
log"); |
| 9 return { | 9 return { |
| 10 shouldNotFindThis:56 | 10 shouldNotFindThis:56 |
| 11 }; | 11 }; |
| 12 } | 12 } |
| 13 | 13 |
| 14 function test() | 14 function test() |
| 15 { | 15 { |
| 16 function testCompletions(base, prefix, expected) | 16 var consoleEditor; |
| 17 function testCompletions(text, expected, force) |
| 17 { | 18 { |
| 18 var callback; | 19 consoleEditor.setText(text); |
| 19 var promise = new Promise(fulfill => callback = fulfill); | 20 consoleEditor.setSelection(WebInspector.TextRange.createFromLocation(Inf
inity, Infinity)); |
| 20 WebInspector.JavaScriptAutocomplete.completionsForTextInCurrentContext(b
ase, prefix).then(checkExpected); | 21 consoleEditor._autocompleteController.autocomplete(force); |
| 21 return promise; | 22 return InspectorTest.addSnifferPromise(consoleEditor._autocompleteContro
ller, "_onSuggestionsShownForTest").then(checkExpected); |
| 22 | 23 |
| 23 function checkExpected(completions) | 24 function checkExpected(suggestions) |
| 24 { | 25 { |
| 25 InspectorTest.addResult("Checking '" + base + prefix + "'"); | 26 var completions = new Set(suggestions.map(suggestion => suggestion.t
itle)); |
| 27 var message = "Checking '" + text + "'"; |
| 28 if (force) |
| 29 message += " forcefully"; |
| 30 InspectorTest.addResult(message); |
| 26 for (var i = 0; i < expected.length; i++) | 31 for (var i = 0; i < expected.length; i++) |
| 27 InspectorTest.addResult(((completions.indexOf(expected[i]) !== -
1) ? "Found" : "Not Found") + ": " + expected[i]); | 32 InspectorTest.addResult((completions.has(expected[i]) ? "Found"
: "Not Found") + ": " + expected[i]); |
| 28 InspectorTest.addResult(""); | 33 InspectorTest.addResult(""); |
| 29 callback(); | |
| 30 } | 34 } |
| 31 } | 35 } |
| 32 function sequential(tests) | 36 function sequential(tests) |
| 33 { | 37 { |
| 34 var promise = Promise.resolve(); | 38 var promise = Promise.resolve(); |
| 35 for (var i = 0; i < tests.length; i++) | 39 for (var i = 0; i < tests.length; i++) |
| 36 promise = promise.then(tests[i]); | 40 promise = promise.then(tests[i]); |
| 37 return promise; | 41 return promise; |
| 38 } | 42 } |
| 39 | 43 |
| 40 sequential([ | 44 sequential([ |
| 41 () => testCompletions("window.", "do", ["document"]), | 45 InspectorTest.waitUntilConsoleEditorLoaded().then(e => consoleEditor = e
), |
| 42 () => testCompletions("", "win", ["window"]), | 46 () => testCompletions("window.do", ["document"]), |
| 43 () => testCompletions("window[", '"doc', ['"document"]']), | 47 () => testCompletions("win", ["window"]), |
| 44 () => testCompletions('window["document"].', "bo", ["body"]), | 48 () => testCompletions('window["doc', ['"document"]']), |
| 45 () => testCompletions('window["document"]["body"].', "textC", ["textCont
ent"]), | 49 () => testCompletions('window["document"].bo', ["body"]), |
| 46 () => testCompletions('document.body.', "inner", ["innerText", "innerHTM
L"]), | 50 () => testCompletions('window["document"]["body"].textC', ["textContent"
]), |
| 47 () => testCompletions('document["body"][window.', "do", ["document"]), | 51 () => testCompletions('document.body.inner', ["innerText", "innerHTML"])
, |
| 48 () => testCompletions('document["body"][window["document"].body.childNod
es[0].', "text", ["textContent"]), | 52 () => testCompletions('document["body"][window.do', ["document"]), |
| 49 () => testCompletions("templateString`asdf`", "should", ["shouldNotFindT
his"]), | 53 () => testCompletions('document["body"][window["document"].body.childNod
es[0].text', ["textContent"]), |
| 50 () => testCompletions("window.document.", "BODY", ["body"]), | 54 () => testCompletions("templateString`asdf`should", ["shouldNotFindThis"
]), |
| 51 () => testCompletions("window.", "dOcUmE", ["document"]), | 55 () => testCompletions("window.document.BODY", ["body"]), |
| 52 () => testCompletions("window.", "node", ["NodeList", "AudioNode", "Gain
Node"]), | 56 () => testCompletions("window.dOcUmE", ["document"]), |
| 53 () => testCompletions("", "32", ["Float32Array", "Int32Array"]), | 57 () => testCompletions("window.node", ["NodeList", "AudioNode", "GainNode
"]), |
| 54 () => testCompletions("window.", "32", ["Float32Array", "Int32Array"]) | 58 () => testCompletions("32", ["Float32Array", "Int32Array"]), |
| 59 () => testCompletions("window.32", ["Float32Array", "Int32Array"]), |
| 60 () => testCompletions("", ["window"], false), |
| 61 () => testCompletions("", ["window"], true), |
| 62 () => testCompletions('"string g', ["getComputedStyle"], false), |
| 63 () => testCompletions("`template string docu", ["document"], false), |
| 64 () => testCompletions("`${do", ["document"], false), |
| 65 () => testCompletions("// do", ["document"], false) |
| 55 ]).then(InspectorTest.completeTest); | 66 ]).then(InspectorTest.completeTest); |
| 56 | 67 |
| 57 } | 68 } |
| 58 </script> | 69 </script> |
| 59 </head> | 70 </head> |
| 60 <body onload="runTest()"> | 71 <body onload="runTest()"> |
| 61 <p>Tests that console correctly finds suggestions in complicated cases.</p> | 72 <p>Tests that console correctly finds suggestions in complicated cases.</p> |
| 62 </body> | 73 </body> |
| 63 </html> | 74 </html> |
| OLD | NEW |