Chromium Code Reviews| 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 function testCompletions(base, prefix, expected, force, token) |
| 17 { | 17 { |
| 18 var callback; | 18 var callback; |
| 19 var promise = new Promise(fulfill => callback = fulfill); | 19 var promise = new Promise(fulfill => callback = fulfill); |
| 20 WebInspector.JavaScriptAutocomplete.completionsForTextInCurrentContext(b ase, prefix).then(checkExpected); | 20 WebInspector.JavaScriptAutocomplete.completionsForTextInCurrentContext(b ase, prefix, force, token).then(checkExpected); |
| 21 return promise; | 21 return promise; |
| 22 | 22 |
| 23 function checkExpected(completions) | 23 function checkExpected(completions) |
| 24 { | 24 { |
| 25 InspectorTest.addResult("Checking '" + base + prefix + "'"); | 25 var message = "Checking '" + base + prefix + "'"; |
| 26 if (force) | |
| 27 message += " forcefully"; | |
| 28 if (token) | |
| 29 message += " with token " + token; | |
| 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.indexOf(expected[i]) !== - 1) ? "Found" : "Not Found") + ": " + expected[i]); |
| 28 InspectorTest.addResult(""); | 33 InspectorTest.addResult(""); |
| 29 callback(); | 34 callback(); |
| 30 } | 35 } |
| 31 } | 36 } |
| 32 function sequential(tests) | 37 function sequential(tests) |
| 33 { | 38 { |
| 34 var promise = Promise.resolve(); | 39 var promise = Promise.resolve(); |
| 35 for (var i = 0; i < tests.length; i++) | 40 for (var i = 0; i < tests.length; i++) |
| 36 promise = promise.then(tests[i]); | 41 promise = promise.then(tests[i]); |
| 37 return promise; | 42 return promise; |
| 38 } | 43 } |
| 39 | 44 |
| 40 sequential([ | 45 sequential([ |
| 41 () => testCompletions("window.", "do", ["document"]), | 46 () => testCompletions("window.", "do", ["document"]), |
| 42 () => testCompletions("", "win", ["window"]), | 47 () => testCompletions("", "win", ["window"]), |
| 43 () => testCompletions("window[", '"doc', ['"document"]']), | 48 () => testCompletions("window[", '"doc', ['"document"]']), |
| 44 () => testCompletions('window["document"].', "bo", ["body"]), | 49 () => testCompletions('window["document"].', "bo", ["body"]), |
| 45 () => testCompletions('window["document"]["body"].', "textC", ["textCont ent"]), | 50 () => testCompletions('window["document"]["body"].', "textC", ["textCont ent"]), |
| 46 () => testCompletions('document.body.', "inner", ["innerText", "innerHTM L"]), | 51 () => testCompletions('document.body.', "inner", ["innerText", "innerHTM L"]), |
| 47 () => testCompletions('document["body"][window.', "do", ["document"]), | 52 () => testCompletions('document["body"][window.', "do", ["document"]), |
| 48 () => testCompletions('document["body"][window["document"].body.childNod es[0].', "text", ["textContent"]), | 53 () => testCompletions('document["body"][window["document"].body.childNod es[0].', "text", ["textContent"]), |
| 49 () => testCompletions("templateString`asdf`", "should", ["shouldNotFindT his"]), | 54 () => testCompletions("templateString`asdf`", "should", ["shouldNotFindT his"]), |
| 50 () => testCompletions("window.document.", "BODY", ["body"]), | 55 () => testCompletions("window.document.", "BODY", ["body"]), |
| 51 () => testCompletions("window.", "dOcUmE", ["document"]), | 56 () => testCompletions("window.", "dOcUmE", ["document"]), |
| 52 () => testCompletions("window.", "node", ["NodeList", "AudioNode", "Gain Node"]), | 57 () => testCompletions("window.", "node", ["NodeList", "AudioNode", "Gain Node"]), |
| 53 () => testCompletions("", "32", ["Float32Array", "Int32Array"]), | 58 () => testCompletions("", "32", ["Float32Array", "Int32Array"]), |
| 54 () => testCompletions("window.", "32", ["Float32Array", "Int32Array"]) | 59 () => testCompletions("window.", "32", ["Float32Array", "Int32Array"]), |
| 60 () => testCompletions("", "", ["window"], false), | |
| 61 () => testCompletions("", "", ["window"], true), | |
|
einbinder
2016/11/07 23:06:06
Bonus test of forced/unforced completions.
| |
| 62 () => testCompletions("", "g", ["getComputedStyle"], false, "js-string") , | |
| 63 () => testCompletions("window.", "docu", ["document"], false, "js-string -2"), | |
| 64 () => testCompletions("window[", '"docu', ['"document"]'], false, "js-st ring") | |
| 55 ]).then(InspectorTest.completeTest); | 65 ]).then(InspectorTest.completeTest); |
| 56 | 66 |
| 57 } | 67 } |
| 58 </script> | 68 </script> |
| 59 </head> | 69 </head> |
| 60 <body onload="runTest()"> | 70 <body onload="runTest()"> |
| 61 <p>Tests that console correctly finds suggestions in complicated cases.</p> | 71 <p>Tests that console correctly finds suggestions in complicated cases.</p> |
| 62 </body> | 72 </body> |
| 63 </html> | 73 </html> |
| OLD | NEW |