Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/inspector-unit/text-prompt-hint.js

Issue 2513423003: DevTools: Convert inspector-unit tests to use reusable test harness (Closed)
Patch Set: Moved type definition out of externs Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/inspector-unit/text-prompt-hint.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector-unit/text-prompt-hint.js b/third_party/WebKit/LayoutTests/http/tests/inspector-unit/text-prompt-hint.js
new file mode 100644
index 0000000000000000000000000000000000000000..cb309dc7f7914e54272ba9ade5a60b34a07c30de
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/inspector-unit/text-prompt-hint.js
@@ -0,0 +1,108 @@
+TestRunner.addResult("Tests that the hint displays properly on a UI.TextPrompt with autocomplete.");
+
+var suggestions = [{title:"testTextPrompt"}];
+var waitingForAutocomplete = null;
+var completionsDone = function () {
+ console.error("completionsDone called too early!");
+ TestRunner.completeTest();
+}
+var prompt = new UI.TextPrompt();
+prompt.initialize(completions);
+var element = createElement("div");
+UI.inspectorView.element.appendChild(element);
+var proxy = prompt.attachAndStartEditing(element);
+prompt.setText("testT");
+waitForAutocomplete().then(step1);
+prompt.complete();
+dumpTextPrompt();
+
+function step1() {
+ dumpTextPrompt();
+
+ typeCharacter("e");
+ dumpTextPrompt();
+
+ waitForAutocomplete().then(step2);
+}
+function step2()
+{
+ dumpTextPrompt();
+
+ typeCharacter("z");
+ waitForAutocomplete().then(step3);
+}
+
+function step3()
+{
+ dumpTextPrompt();
+ typeCharacter(null);
+ waitForAutocomplete().then(step4);
+}
+
+function step4()
+{
+ dumpTextPrompt();
+ typeCharacter(null);
+ waitForAutocomplete().then(step5);
+}
+function step5()
+{
+ dumpTextPrompt();
+ prompt.setText("something_before test");
+ prompt.complete();
+ completionsDone().then(()=>{
+ dumpTextPrompt();
+ typeCharacter("T");
+ dumpTextPrompt();
+ TestRunner.completeTest();
+ });
+}
+
+function completions(expression, query)
+{
+ var callback;
+ var promise = new Promise(x => callback = x);
+ TestRunner.addResult("Requesting completions");
+ completionsDone = () => {
+ callback(suggestions.filter(s => s.title.startsWith(query.toString())))
+ return Promise.resolve();
+ };
+ var temp = waitingForAutocomplete;
+ waitingForAutocomplete = null;
+ if (temp)
+ temp();
+ return promise;
+}
+
+function waitForAutocomplete()
+{
+ return new Promise(x => waitingForAutocomplete = x).then(() => completionsDone());
+}
+
+function dumpTextPrompt()
+{
+ TestRunner.addResult("Text:" + prompt.text());
+ TestRunner.addResult("TextWithCurrentSuggestion:" + prompt.textWithCurrentSuggestion());
+ TestRunner.addResult("");
+}
+
+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._ghostTextElement.parentNode ? prompt._ghostTextElement.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);
+ element.dispatchEvent(new Event("input", {bubbles: true, cancelable: false}));
+}

Powered by Google App Engine
This is Rietveld 408576698