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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/inspector-unit/text-prompt-hint.html

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 <html>
2 <head>
3 <base href="/inspector-debug/"></base>
4 <script src="/inspector-debug/Runtime.js"></script>
5 <script src="/inspector-unit/inspector-unit-test.js"></script>
6 <script type="text/javascript">
7
8 function test()
9 {
10 var suggestions = [{title:"testTextPrompt"}];
11 var waitingForAutocomplete = null;
12 var completionsDone = function () {
13 console.error("completionsDone called too early!");
14 UnitTest.completeTest();
15 }
16 var prompt = new UI.TextPrompt();
17 prompt.initialize(completions);
18 var element = createElement("div");
19 UI.inspectorView.element.appendChild(element);
20 var proxy = prompt.attachAndStartEditing(element);
21 prompt.setText("testT");
22 waitForAutocomplete().then(step1);
23 prompt.complete();
24 dumpTextPrompt();
25
26 function step1() {
27 dumpTextPrompt();
28
29 typeCharacter("e");
30 dumpTextPrompt();
31
32 waitForAutocomplete().then(step2);
33 }
34 function step2()
35 {
36 dumpTextPrompt();
37
38 typeCharacter("z");
39 waitForAutocomplete().then(step3);
40 }
41
42 function step3()
43 {
44 dumpTextPrompt();
45 typeCharacter(null);
46 waitForAutocomplete().then(step4);
47 }
48
49 function step4()
50 {
51 dumpTextPrompt();
52 typeCharacter(null);
53 waitForAutocomplete().then(step5);
54 }
55 function step5()
56 {
57 dumpTextPrompt();
58 prompt.setText("something_before test");
59 prompt.complete();
60 completionsDone().then(()=>{
61 dumpTextPrompt();
62 typeCharacter("T");
63 dumpTextPrompt();
64 UnitTest.completeTest();
65 });
66 }
67
68 function completions(expression, query)
69 {
70 var callback;
71 var promise = new Promise(x => callback = x);
72 UnitTest.addResult("Requesting completions");
73 completionsDone = () => {
74 callback(suggestions.filter(s => s.title.startsWith(query.toString() )))
75 return Promise.resolve();
76 };
77 var temp = waitingForAutocomplete;
78 waitingForAutocomplete = null;
79 if (temp)
80 temp();
81 return promise;
82 }
83
84 function waitForAutocomplete()
85 {
86 return new Promise(x => waitingForAutocomplete = x).then(() => completio nsDone());
87 }
88
89 function dumpTextPrompt()
90 {
91 UnitTest.addResult("Text:" + prompt.text());
92 UnitTest.addResult("TextWithCurrentSuggestion:" + prompt.textWithCurrent Suggestion());
93 UnitTest.addResult("");
94 }
95
96 function typeCharacter(character)
97 {
98 var keyboardEvent = new KeyboardEvent("keydown", {
99 key: character || "Backspace",
100 charCode: character ? character.charCodeAt(0) : ""
101 });
102 element.dispatchEvent(keyboardEvent);
103
104 var selection = element.getComponentSelection();
105 var range = selection.getRangeAt(0);
106 var textNode = prompt._ghostTextElement.parentNode ? prompt._ghostTextEl ement.previousSibling : element.childTextNodes()[element.childTextNodes().length - 1];
107 if (!character)
108 textNode.textContent = textNode.textContent.substring(0,textNode.tex tContent.length-1);
109 else
110 textNode.textContent += character;
111 range.setStart(range.startContainer, range.startContainer.textContent.le ngth);
112 selection.removeAllRanges();
113 selection.addRange(range);
114 element.dispatchEvent(new Event("input", {bubbles: true, cancelable: fal se}));
115 }
116 }
117
118
119 </script>
120 </head>
121 <body>
122 <p>Tests that the hint displays properly on a UI.TextPrompt with autocomplete.</ p>
123 </body>
124 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698