Index: third_party/WebKit/LayoutTests/inspector/text-prompt-hint.html |
diff --git a/third_party/WebKit/LayoutTests/inspector/text-prompt-hint.html b/third_party/WebKit/LayoutTests/inspector/text-prompt-hint.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..af1e1258e602cf83f906b06443042cd2947560b4 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/inspector/text-prompt-hint.html |
@@ -0,0 +1,110 @@ |
+<html> |
+<head> |
+<script src="../http/tests/inspector/inspector-test.js"></script> |
+<script type="text/javascript"> |
+ |
+function test() |
+{ |
+ var suggestions = ["testTextPrompt"]; |
+ var waitingForAutocomplete = null; |
+ var completionsDone = function () { |
+ console.error("completionsDone called too early!"); |
+ InspectorTest.completeTest(); |
+ } |
+ var prompt = new WebInspector.TextPrompt(completions); |
+ var element = createElement("div"); |
+ document.body.appendChild(element); |
+ var proxy = prompt.attachAndStartEditing(element); |
+ prompt.setText("testT"); |
+ prompt.complete(); |
+ dumpTextPrompt(); |
+ completionsDone(); |
+ dumpTextPrompt(); |
+ |
+ typeCharacter("e"); |
+ dumpTextPrompt(); |
+ |
+ waitForAutocomplete(step2) |
+ function step2() |
+ { |
+ completionsDone(); |
+ dumpTextPrompt(); |
+ |
+ typeCharacter("z"); |
+ waitForAutocomplete(step3); |
+ } |
+ |
+ function step3() |
+ { |
+ completionsDone(); |
+ dumpTextPrompt(); |
+ typeCharacter(null); |
+ waitForAutocomplete(step4); |
+ } |
+ |
+ function step4() |
+ { |
+ completionsDone(); |
+ dumpTextPrompt(); |
+ typeCharacter(null); |
+ waitForAutocomplete(step5); |
+ } |
+ function step5() |
+ { |
+ completionsDone(); |
+ dumpTextPrompt(); |
+ InspectorTest.completeTest(); |
+ } |
+ |
+ function completions(element, range, force, callback) |
+ { |
+ InspectorTest.addResult("Requesting completions"); |
+ completionsDone = () => callback(suggestions.filter(s => s.startsWith(range.toString()))); |
+ var temp = waitingForAutocomplete; |
+ waitingForAutocomplete = null; |
+ if (temp) |
+ temp(); |
+ } |
+ |
+ function waitForAutocomplete(fn) |
+ { |
+ waitingForAutocomplete = fn; |
+ } |
+ |
+ function dumpTextPrompt() |
+ { |
+ InspectorTest.addResult(""); |
+ InspectorTest.addResult("Text:" + prompt.text()); |
+ InspectorTest.addResult("UserEnteredText:" + prompt.userEnteredText()); |
+ } |
+ |
+ function typeCharacter(character) |
+ { |
+ var keyboardEvent = new KeyboardEvent("keydown", { |
+ key: character || "Backspace", |
+ charCode: character ? character.charCodeAt(0) : "" |
+ }); |
+ element.dispatchEvent(keyboardEvent); |
+ |
+ var selection = element.getComponentSelection(); |
+ var range = selection.getRangeAt(0); |
+ var textNode = prompt.autoCompleteElement ? prompt.autoCompleteElement.previousSibling : element.childTextNodes()[element.childTextNodes().length-1]; |
+ if (!character) |
+ textNode.textContent = textNode.textContent.substring(0,textNode.textContent.length-1); |
+ else |
+ textNode.textContent += character; |
+ range.setStart(range.startContainer, range.startContainer.textContent.length); |
+ selection.removeAllRanges(); |
+ selection.addRange(range); |
+ var inputEvent = new InputEvent("input"); |
+ element.dispatchEvent(inputEvent); |
+ } |
+} |
+ |
+ |
+</script> |
+</head> |
+<body onload="runTest()"> |
+<p>Tests that the hint displays properly on a WebInspector.TextPrompt with autocomplete.</p> |
+</body> |
+</html> |