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

Side by Side Diff: third_party/WebKit/LayoutTests/inspector/console/console-copy-truncated-text.html

Issue 2866363003: DevTools: format keys in object previews using sans serif. (Closed)
Patch Set: removed the test Created 3 years, 7 months 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 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/console-test.js"></script>
5 <script>
6
7 function test()
8 {
9 var longUrl = "www." + "z123456789".repeat(15) + ".com";
10 var shortUrl = "www.bar.com";
11 var mixedUrl = longUrl + " " + shortUrl + " " + longUrl;
12 var shortUrlWithHashes = "www." + "0123456789".repeat(2) + "zfoobarz" + "012 3456789".repeat(2);
13 var urlWithHashes = "www." + "0123456789".repeat(2) + "z".repeat(150) + "012 3456789".repeat(2);
14 var highlightedUrl = "www." + "z".repeat(200) + ".com";
15 var longUrlInMessageWithNonTextNodePrefix = "www." + "z123456789".repeat(15) + ".com";
16 var prepareCode = `
17 // Keep this as the first url logged to record the max truncated length.
18 console.log("${longUrl}");
19
20 console.log("${shortUrl}");
21 console.log("${longUrl}");
22 console.log("${mixedUrl}");
23 console.log("${shortUrlWithHashes}");
24 console.log("${urlWithHashes}");
25 console.log("${highlightedUrl}");
26 console.log("${longUrlInMessageWithNonTextNodePrefix}");
27 `;
28
29 var expectedMessageCount = 8;
30 var consoleView = Console.ConsoleView.instance();
31 var viewport = Console.ConsoleView.instance()._viewport;
32 var maxLength;
33 var halfMaxLength;
34 var secondLongUrlIndexInMixedUrl;
35
36 var tests = [
37 function testSelectWithinTruncatedUrl(next)
38 {
39 makeSelectionAndDump(0, 0, 0, halfMaxLength);
40 makeSelectionAndDump(0, 0, 0, halfMaxLength + 1);
41 makeSelectionAndDump(0, 0, 0, maxLength);
42 makeSelectionAndDump(0, halfMaxLength, 0, halfMaxLength + 1);
43 makeSelectionAndDump(0, halfMaxLength, 0, maxLength);
44 makeSelectionAndDump(0, halfMaxLength + 1, 0, maxLength);
45 next();
46 },
47
48 function testSelectAcrossMultipleMessages(next) {
49 makeSelectionAndDump(0, 0, 1, shortUrl.length);
50 makeSelectionAndDump(0, halfMaxLength, 1, shortUrl.length);
51 makeSelectionAndDump(0, halfMaxLength + 1, 1, shortUrl.length);
52 next()
53 },
54
55 function testSelectAcrossMultipleMessagesWithTruncatedUrls(next) {
56 makeSelectionAndDump(0, 0, 2, halfMaxLength);
57 makeSelectionAndDump(0, 0, 2, halfMaxLength + 1);
58 makeSelectionAndDump(0, 0, 2, maxLength);
59 next()
60 },
61
62 function testSelectWithinMessageWithMultipleTruncatedUrls(next) {
63 makeSelectionAndDump(3, 0, 3, halfMaxLength);
64 makeSelectionAndDump(3, 0, 3, halfMaxLength + 1);
65 makeSelectionAndDump(3, 0, 3, secondLongUrlIndexInMixedUrl);
66 makeSelectionAndDump(3, 0, 3, secondLongUrlIndexInMixedUrl + halfMax Length);
67 makeSelectionAndDump(3, 0, 3, secondLongUrlIndexInMixedUrl + halfMax Length + 1);
68 makeSelectionAndDump(3, 0, 3, secondLongUrlIndexInMixedUrl + maxLeng th);
69
70 makeSelectionAndDump(3, halfMaxLength, 3, halfMaxLength + 1);
71 makeSelectionAndDump(3, halfMaxLength, 3, secondLongUrlIndexInMixedU rl);
72 makeSelectionAndDump(3, halfMaxLength, 3, secondLongUrlIndexInMixedU rl + halfMaxLength);
73 makeSelectionAndDump(3, halfMaxLength, 3, secondLongUrlIndexInMixedU rl + halfMaxLength + 1);
74 makeSelectionAndDump(3, halfMaxLength, 3, secondLongUrlIndexInMixedU rl + maxLength);
75
76 makeSelectionAndDump(3, halfMaxLength + 1, 3, secondLongUrlIndexInMi xedUrl);
77 makeSelectionAndDump(3, halfMaxLength + 1, 3, secondLongUrlIndexInMi xedUrl + halfMaxLength);
78 makeSelectionAndDump(3, halfMaxLength + 1, 3, secondLongUrlIndexInMi xedUrl + halfMaxLength + 1);
79 makeSelectionAndDump(3, halfMaxLength + 1, 3, secondLongUrlIndexInMi xedUrl + maxLength);
80
81 makeSelectionAndDump(3, secondLongUrlIndexInMixedUrl, 3, secondLongU rlIndexInMixedUrl + halfMaxLength);
82 makeSelectionAndDump(3, secondLongUrlIndexInMixedUrl, 3, secondLongU rlIndexInMixedUrl + halfMaxLength + 1);
83 makeSelectionAndDump(3, secondLongUrlIndexInMixedUrl, 3, secondLongU rlIndexInMixedUrl + maxLength);
84
85 makeSelectionAndDump(3, secondLongUrlIndexInMixedUrl + halfMaxLength , 3, secondLongUrlIndexInMixedUrl + halfMaxLength + 1);
86 makeSelectionAndDump(3, secondLongUrlIndexInMixedUrl + halfMaxLength , 3, secondLongUrlIndexInMixedUrl + maxLength);
87
88 makeSelectionAndDump(3, secondLongUrlIndexInMixedUrl + halfMaxLength + 1, 3, secondLongUrlIndexInMixedUrl + maxLength);
89 next()
90 },
91
92 function testSelectWithinShortUrlWithHashes(next)
93 {
94 var hashedUrlMaxLength = consoleMessageText(4).length;
95 var hashedUrlHalfMaxLength = Math.ceil(hashedUrlMaxLength / 2);
96 makeSelectionAndDump(4, 0, 4, hashedUrlHalfMaxLength);
97 makeSelectionAndDump(4, 0, 4, hashedUrlMaxLength);
98 makeSelectionAndDump(4, hashedUrlHalfMaxLength, 4, hashedUrlMaxLengt h);
99 next();
100 },
101
102 function testSelectWithinUrlWithHashes(next)
103 {
104 var hashedUrlMaxLength = consoleMessageText(5).length;
105 var hashedUrlHalfMaxLength = Math.ceil(hashedUrlMaxLength / 2);
106 makeSelectionAndDump(5, 0, 5, hashedUrlHalfMaxLength);
107 makeSelectionAndDump(5, 0, 5, hashedUrlHalfMaxLength + 1);
108 makeSelectionAndDump(5, 0, 5, hashedUrlMaxLength);
109 makeSelectionAndDump(5, hashedUrlHalfMaxLength, 5, hashedUrlHalfMaxL ength + 1);
110 makeSelectionAndDump(5, hashedUrlHalfMaxLength, 5, hashedUrlMaxLengt h);
111 makeSelectionAndDump(5, hashedUrlHalfMaxLength + 1, 5, hashedUrlMaxL ength);
112 next();
113 },
114
115 function testSelectWithinHighlightedUrlBeginning(next) {
116 testHighlightedUrlWithSearchQuery("www.", next);
117 },
118
119 function testSelectWithinHighlightedUrlMiddle(next) {
120 testHighlightedUrlWithSearchQuery("zzzzz", next);
121 },
122
123 function testSelectWithinHighlightedUrlEnd(next) {
124 testHighlightedUrlWithSearchQuery(".com", next);
125 },
126
127 function testSelectionStartingInNonTextNode(next) {
128 var messageElement = consoleView.itemElement(7).element();
129
130 // Artificially insert an empty non-text node element in the beginni ng.
131 var artificialEmptyPrefixElement = createElementWithClass('div', 'ar tificialEmptyPrefixElement');
132 messageElement.insertBefore(artificialEmptyPrefixElement, messageEle ment.firstChild);
133
134 // Use .childNodes to ensure we get all nodes.
135 InspectorTest.addResult("\nMaking selection from empty prefix to end ");
136 window.getSelection().setBaseAndExtent(artificialEmptyPrefixElement, 0, messageElement.lastChild, messageElement.childNodes.length - 1);
137
138 var selectedText = viewport._selectedText();
139 if (selectedText)
140 InspectorTest.addResult("Selection length: " + selectedText.leng th + ", " + "text: " + selectedText.replace(/\bVM\d+/g, "VM"));
141 else
142 InspectorTest.addResult("No selection");
143 next();
144 }
145 ];
146
147 InspectorTest.waitForConsoleMessages(expectedMessageCount, () => {
148 viewport.invalidate();
149
150 // Get the max truncated length from the first longUrl logged.
151 try {
152 var longUrlMessageText = consoleMessageText(0);
153 maxLength = longUrlMessageText.length;
154 halfMaxLength = Math.ceil(maxLength / 2);
155 secondLongUrlIndexInMixedUrl = maxLength + 1 + shortUrl.length + 1;
156 InspectorTest.addResult("Long url has max length: " + maxLength + ", text: " + longUrlMessageText);
157 } catch (e) {
158 InspectorTest.addResult("FAIL: Could not get max truncation length f rom first longUrl message.");
159 InspectorTest.completeTest();
160 return;
161 }
162 InspectorTest.runTestSuite(tests);
163 });
164 InspectorTest.evaluateInPage(prepareCode);
165
166 function consoleMessageText(index) {
167 var messageElement = consoleView._visibleViewMessages[index].element();
168 return messageElement.querySelector('.console-message-text').deepTextCon tent();
169 }
170
171 function makeSelectionAndDump(fromMessage, fromTextOffset, toMessage, toText Offset, includeAnchor, useTextContainer) {
172 InspectorTest.addResult("\nMaking selection: " + fromMessage + ", " + fr omTextOffset + ", " + toMessage + ", " + toTextOffset);
173
174 // Ignore the anchor text on the start/end message, just use their conte nts.
175 if (!includeAnchor) {
176 var fromAnchor = consoleView.itemElement(fromMessage).element().quer ySelector('.console-message-anchor');
177 var toAnchor = consoleView.itemElement(toMessage).element().querySel ector('.console-message-anchor');
178 fromTextOffset += fromAnchor ? fromAnchor.deepTextContent().length : 0;
179 toTextOffset += toAnchor ? toAnchor.deepTextContent().length : 0;
180 }
181 InspectorTest.selectConsoleMessages(fromMessage, fromTextOffset, toMessa ge, toTextOffset, useTextContainer);
182 var selectedText = viewport._selectedText();
183 if (selectedText)
184 InspectorTest.addResult("Selection length: " + selectedText.length + ", " + "text: " + selectedText.replace(/\bVM\d+/g, "VM"));
185 else
186 InspectorTest.addResult("No selection");
187 }
188
189 function testHighlightedUrlWithSearchQuery(query, next) {
190 // Clear any existing ranges to avoid using them as the query.
191 window.getSelection().removeAllRanges();
192 InspectorTest.addSniffer(consoleView, "_searchFinishedForTests", onSearc h);
193 consoleView._searchableView._searchInputElement.value = query;
194 consoleView._searchableView._regexButton.setToggled(false);
195 consoleView._searchableView._caseSensitiveButton.setToggled(false);
196 consoleView._searchableView.showSearchField();
197 InspectorTest.addResult("Searching for text: " + query);
198
199 function onSearch() {
200 var matches = consoleView.element.childTextNodes().filter(node => no de.parentElement.classList.contains("highlighted-search-result")).map(node => no de.parentElement);
201 InspectorTest.addResult("Highlighted " + matches.length + " matches" );
202
203 // Use TextNodes for containers to get inside the highlighted match element.
204 makeSelectionAndDump(6, 0, 6, halfMaxLength, false, true);
205 makeSelectionAndDump(6, 0, 6, halfMaxLength + 1, false, true);
206 makeSelectionAndDump(6, 0, 6, maxLength, false, true);
207 makeSelectionAndDump(6, halfMaxLength, 6, halfMaxLength + 1);
208 makeSelectionAndDump(6, halfMaxLength, 6, maxLength);
209 makeSelectionAndDump(6, halfMaxLength + 1, 6, maxLength);
210 next();
211 }
212 }
213 }
214 </script>
215 </head>
216 <body onload="runTest()">
217 <p>Tests that console copies tree outline messages properly.</p>
218 </body>
219 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698