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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 TestRunner.addResult("Tests that the hint displays properly on a UI.TextPrompt w ith autocomplete.");
2
3 var suggestions = [{title:"testTextPrompt"}];
4 var waitingForAutocomplete = null;
5 var completionsDone = function () {
6 console.error("completionsDone called too early!");
7 TestRunner.completeTest();
8 }
9 var prompt = new UI.TextPrompt();
10 prompt.initialize(completions);
11 var element = createElement("div");
12 UI.inspectorView.element.appendChild(element);
13 var proxy = prompt.attachAndStartEditing(element);
14 prompt.setText("testT");
15 waitForAutocomplete().then(step1);
16 prompt.complete();
17 dumpTextPrompt();
18
19 function step1() {
20 dumpTextPrompt();
21
22 typeCharacter("e");
23 dumpTextPrompt();
24
25 waitForAutocomplete().then(step2);
26 }
27 function step2()
28 {
29 dumpTextPrompt();
30
31 typeCharacter("z");
32 waitForAutocomplete().then(step3);
33 }
34
35 function step3()
36 {
37 dumpTextPrompt();
38 typeCharacter(null);
39 waitForAutocomplete().then(step4);
40 }
41
42 function step4()
43 {
44 dumpTextPrompt();
45 typeCharacter(null);
46 waitForAutocomplete().then(step5);
47 }
48 function step5()
49 {
50 dumpTextPrompt();
51 prompt.setText("something_before test");
52 prompt.complete();
53 completionsDone().then(()=>{
54 dumpTextPrompt();
55 typeCharacter("T");
56 dumpTextPrompt();
57 TestRunner.completeTest();
58 });
59 }
60
61 function completions(expression, query)
62 {
63 var callback;
64 var promise = new Promise(x => callback = x);
65 TestRunner.addResult("Requesting completions");
66 completionsDone = () => {
67 callback(suggestions.filter(s => s.title.startsWith(query.toString())))
68 return Promise.resolve();
69 };
70 var temp = waitingForAutocomplete;
71 waitingForAutocomplete = null;
72 if (temp)
73 temp();
74 return promise;
75 }
76
77 function waitForAutocomplete()
78 {
79 return new Promise(x => waitingForAutocomplete = x).then(() => completionsDo ne());
80 }
81
82 function dumpTextPrompt()
83 {
84 TestRunner.addResult("Text:" + prompt.text());
85 TestRunner.addResult("TextWithCurrentSuggestion:" + prompt.textWithCurrentSu ggestion());
86 TestRunner.addResult("");
87 }
88
89 function typeCharacter(character)
90 {
91 var keyboardEvent = new KeyboardEvent("keydown", {
92 key: character || "Backspace",
93 charCode: character ? character.charCodeAt(0) : ""
94 });
95 element.dispatchEvent(keyboardEvent);
96
97 var selection = element.getComponentSelection();
98 var range = selection.getRangeAt(0);
99 var textNode = prompt._ghostTextElement.parentNode ? prompt._ghostTextElemen t.previousSibling : element.childTextNodes()[element.childTextNodes().length - 1 ];
100 if (!character)
101 textNode.textContent = textNode.textContent.substring(0,textNode.textCon tent.length-1);
102 else
103 textNode.textContent += character;
104 range.setStart(range.startContainer, range.startContainer.textContent.length );
105 selection.removeAllRanges();
106 selection.addRange(range);
107 element.dispatchEvent(new Event("input", {bubbles: true, cancelable: false}) );
108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698