OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <script src="../http/tests/inspector/inspector-test.js"></script> |
| 4 <script type="text/javascript"> |
| 5 |
| 6 function test() |
| 7 { |
| 8 var suggestions = ["testTextPrompt"]; |
| 9 var waitingForAutocomplete = null; |
| 10 var completionsDone = function () { |
| 11 console.error("completionsDone called too early!"); |
| 12 InspectorTest.completeTest(); |
| 13 } |
| 14 var prompt = new WebInspector.TextPrompt(completions); |
| 15 var element = createElement("div"); |
| 16 document.body.appendChild(element); |
| 17 var proxy = prompt.attachAndStartEditing(element); |
| 18 prompt.setText("testT"); |
| 19 prompt.complete(); |
| 20 dumpTextPrompt(); |
| 21 completionsDone(); |
| 22 dumpTextPrompt(); |
| 23 |
| 24 typeCharacter("e"); |
| 25 dumpTextPrompt(); |
| 26 |
| 27 waitForAutocomplete(step2) |
| 28 function step2() |
| 29 { |
| 30 completionsDone(); |
| 31 dumpTextPrompt(); |
| 32 |
| 33 typeCharacter("z"); |
| 34 waitForAutocomplete(step3); |
| 35 } |
| 36 |
| 37 function step3() |
| 38 { |
| 39 completionsDone(); |
| 40 dumpTextPrompt(); |
| 41 typeCharacter(null); |
| 42 waitForAutocomplete(step4); |
| 43 } |
| 44 |
| 45 function step4() |
| 46 { |
| 47 completionsDone(); |
| 48 dumpTextPrompt(); |
| 49 typeCharacter(null); |
| 50 waitForAutocomplete(step5); |
| 51 } |
| 52 function step5() |
| 53 { |
| 54 completionsDone(); |
| 55 dumpTextPrompt(); |
| 56 InspectorTest.completeTest(); |
| 57 } |
| 58 |
| 59 function completions(element, range, force, callback) |
| 60 { |
| 61 InspectorTest.addResult("Requesting completions"); |
| 62 completionsDone = () => callback(suggestions.filter(s => s.startsWith(ra
nge.toString()))); |
| 63 var temp = waitingForAutocomplete; |
| 64 waitingForAutocomplete = null; |
| 65 if (temp) |
| 66 temp(); |
| 67 } |
| 68 |
| 69 function waitForAutocomplete(fn) |
| 70 { |
| 71 waitingForAutocomplete = fn; |
| 72 } |
| 73 |
| 74 function dumpTextPrompt() |
| 75 { |
| 76 InspectorTest.addResult(""); |
| 77 InspectorTest.addResult("Text:" + prompt.text()); |
| 78 InspectorTest.addResult("UserEnteredText:" + prompt.userEnteredText()); |
| 79 } |
| 80 |
| 81 function typeCharacter(character) |
| 82 { |
| 83 var keyboardEvent = new KeyboardEvent("keydown", { |
| 84 key: character || "Backspace", |
| 85 charCode: character ? character.charCodeAt(0) : "" |
| 86 }); |
| 87 element.dispatchEvent(keyboardEvent); |
| 88 |
| 89 var selection = element.getComponentSelection(); |
| 90 var range = selection.getRangeAt(0); |
| 91 var textNode = prompt.autoCompleteElement ? prompt.autoCompleteElement.p
reviousSibling : element.childTextNodes()[element.childTextNodes().length-1]; |
| 92 if (!character) |
| 93 textNode.textContent = textNode.textContent.substring(0,textNode.tex
tContent.length-1); |
| 94 else |
| 95 textNode.textContent += character; |
| 96 range.setStart(range.startContainer, range.startContainer.textContent.le
ngth); |
| 97 selection.removeAllRanges(); |
| 98 selection.addRange(range); |
| 99 var inputEvent = new InputEvent("input"); |
| 100 element.dispatchEvent(inputEvent); |
| 101 } |
| 102 } |
| 103 |
| 104 |
| 105 </script> |
| 106 </head> |
| 107 <body onload="runTest()"> |
| 108 <p>Tests that the hint displays properly on a WebInspector.TextPrompt with autoc
omplete.</p> |
| 109 </body> |
| 110 </html> |
OLD | NEW |