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

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

Issue 2644753002: DevTools: untruncate links on copy (Closed)
Patch Set: undo zero-width space, back to ellipsis 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 = 9;
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(1, 0, 1, halfMaxLength);
40 makeSelectionAndDump(1, 0, 1, halfMaxLength + 1);
41 makeSelectionAndDump(1, 0, 1, maxLength);
42 makeSelectionAndDump(1, halfMaxLength, 1, halfMaxLength + 1);
43 makeSelectionAndDump(1, halfMaxLength, 1, maxLength);
44 makeSelectionAndDump(1, halfMaxLength + 1, 1, maxLength);
45 next();
46 },
47
48 function testSelectAcrossMultipleMessages(next) {
49 makeSelectionAndDump(1, 0, 2, shortUrl.length);
50 makeSelectionAndDump(1, halfMaxLength, 2, shortUrl.length);
51 makeSelectionAndDump(1, halfMaxLength + 1, 2, shortUrl.length);
52 next()
53 },
54
55 function testSelectAcrossMultipleMessagesWithTruncatedUrls(next) {
56 makeSelectionAndDump(1, 0, 3, halfMaxLength);
57 makeSelectionAndDump(1, 0, 3, halfMaxLength + 1);
58 makeSelectionAndDump(1, 0, 3, maxLength);
59 next()
60 },
61
62 function testSelectWithinMessageWithMultipleTruncatedUrls(next) {
63 makeSelectionAndDump(4, 0, 4, halfMaxLength);
64 makeSelectionAndDump(4, 0, 4, halfMaxLength + 1);
65 makeSelectionAndDump(4, 0, 4, secondLongUrlIndexInMixedUrl);
66 makeSelectionAndDump(4, 0, 4, secondLongUrlIndexInMixedUrl + halfMax Length);
67 makeSelectionAndDump(4, 0, 4, secondLongUrlIndexInMixedUrl + halfMax Length + 1);
68 makeSelectionAndDump(4, 0, 4, secondLongUrlIndexInMixedUrl + maxLeng th);
69
70 makeSelectionAndDump(4, halfMaxLength, 4, halfMaxLength + 1);
71 makeSelectionAndDump(4, halfMaxLength, 4, secondLongUrlIndexInMixedU rl);
72 makeSelectionAndDump(4, halfMaxLength, 4, secondLongUrlIndexInMixedU rl + halfMaxLength);
73 makeSelectionAndDump(4, halfMaxLength, 4, secondLongUrlIndexInMixedU rl + halfMaxLength + 1);
74 makeSelectionAndDump(4, halfMaxLength, 4, secondLongUrlIndexInMixedU rl + maxLength);
75
76 makeSelectionAndDump(4, halfMaxLength + 1, 4, secondLongUrlIndexInMi xedUrl);
77 makeSelectionAndDump(4, halfMaxLength + 1, 4, secondLongUrlIndexInMi xedUrl + halfMaxLength);
78 makeSelectionAndDump(4, halfMaxLength + 1, 4, secondLongUrlIndexInMi xedUrl + halfMaxLength + 1);
79 makeSelectionAndDump(4, halfMaxLength + 1, 4, secondLongUrlIndexInMi xedUrl + maxLength);
80
81 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl, 4, secondLongU rlIndexInMixedUrl + halfMaxLength);
82 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl, 4, secondLongU rlIndexInMixedUrl + halfMaxLength + 1);
83 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl, 4, secondLongU rlIndexInMixedUrl + maxLength);
84
85 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl + halfMaxLength , 4, secondLongUrlIndexInMixedUrl + halfMaxLength + 1);
86 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl + halfMaxLength , 4, secondLongUrlIndexInMixedUrl + maxLength);
87
88 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl + halfMaxLength + 1, 4, secondLongUrlIndexInMixedUrl + maxLength);
89 next()
90 },
91
92 function testSelectWithinShortUrlWithHashes(next)
93 {
94 var hashedUrlMaxLength = consoleMessageText(5).length;
95 var hashedUrlHalfMaxLength = Math.ceil(hashedUrlMaxLength / 2);
96 makeSelectionAndDump(5, 0, 5, hashedUrlHalfMaxLength);
97 makeSelectionAndDump(5, 0, 5, hashedUrlMaxLength);
98 makeSelectionAndDump(5, hashedUrlHalfMaxLength, 5, hashedUrlMaxLengt h);
99 next();
100 },
101
102 function testSelectWithinUrlWithHashes(next)
103 {
104 var hashedUrlMaxLength = consoleMessageText(6).length;
105 var hashedUrlHalfMaxLength = Math.ceil(hashedUrlMaxLength / 2);
106 makeSelectionAndDump(6, 0, 6, hashedUrlHalfMaxLength);
107 makeSelectionAndDump(6, 0, 6, hashedUrlHalfMaxLength + 1);
108 makeSelectionAndDump(6, 0, 6, hashedUrlMaxLength);
109 makeSelectionAndDump(6, hashedUrlHalfMaxLength, 6, hashedUrlHalfMaxL ength + 1);
110 makeSelectionAndDump(6, hashedUrlHalfMaxLength, 6, hashedUrlMaxLengt h);
111 makeSelectionAndDump(6, hashedUrlHalfMaxLength + 1, 6, 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(8).element();
129 var anchorElement = messageElement.querySelector('.console-message-a nchor');
130
131 // Remove the anchor for this test.
132 anchorElement.remove();
133
134 // Artificially insert a non-text node element in the beginning.
135 var artificialEmptyPrefixElement = createElementWithClass('div', 'ar tificialEmptyPrefixElement');
136 messageElement.insertBefore(artificialEmptyPrefixElement, messageEle ment.firstChild);
137
138 // Use .childNodes to ensure we get all nodes.
139 InspectorTest.addResult("\nMaking artifical selection from empty pre fix to end");
140 window.getSelection().setBaseAndExtent(artificialEmptyPrefixElement, 0, messageElement.lastChild, messageElement.childNodes.length - 1);
141
142 var selectedText = viewport._selectedText();
143 if (selectedText)
144 InspectorTest.addResult("Selection length: " + selectedText.leng th + ", " + "text: " + selectedText.replace(/\bVM\d+/g, "VM"));
145 else
146 InspectorTest.addResult("No selection");
147 next();
148 }
149 ];
150
151 InspectorTest.waitForConsoleMessages(expectedMessageCount, () => {
152 viewport.invalidate();
153
154 // Get the max truncated length from the first longUrl logged.
155 try {
156 var longUrlMessageText = consoleMessageText(1);
157 maxLength = longUrlMessageText.length;
158 halfMaxLength = Math.ceil(maxLength / 2);
159 secondLongUrlIndexInMixedUrl = maxLength + 1 + shortUrl.length + 1;
160 InspectorTest.addResult("Long url has max length: " + maxLength + ", text: " + longUrlMessageText);
161 } catch (e) {
162 InspectorTest.addResult("FAIL: Could not get max truncation length f rom first longUrl message.");
163 InspectorTest.completeTest();
164 return;
165 }
166 InspectorTest.runTestSuite(tests);
167 });
168 InspectorTest.evaluateInConsole(prepareCode);
169
170 function consoleMessageText(index) {
171 var messageElement = consoleView._visibleViewMessages[index].element();
172 return messageElement.querySelector('.console-message-text').deepTextCon tent();
173 }
174
175 function makeSelectionAndDump(fromMessage, fromTextOffset, toMessage, toText Offset, includeAnchor, useTextContainer) {
176 InspectorTest.addResult("\nMaking selection: " + fromMessage + ", " + fr omTextOffset + ", " + toMessage + ", " + toTextOffset);
177
178 // Ignore the anchor text on the start/end message, just use their conte nts.
179 if (!includeAnchor) {
180 var fromAnchor = consoleView.itemElement(fromMessage).element().quer ySelector('.console-message-anchor');
181 var toAnchor = consoleView.itemElement(toMessage).element().querySel ector('.console-message-anchor');
182 fromTextOffset += fromAnchor ? fromAnchor.deepTextContent().length : 0;
183 toTextOffset += toAnchor ? toAnchor.deepTextContent().length : 0;
184 }
185 InspectorTest.selectConsoleMessages(fromMessage, fromTextOffset, toMessa ge, toTextOffset, useTextContainer);
186 var selectedText = viewport._selectedText();
187 if (selectedText)
188 InspectorTest.addResult("Selection length: " + selectedText.length + ", " + "text: " + selectedText.replace(/\bVM\d+/g, "VM"));
189 else
190 InspectorTest.addResult("No selection");
191 }
192
193 function testHighlightedUrlWithSearchQuery(query, next) {
194 // Clear any existing ranges to avoid using them as the query.
195 window.getSelection().removeAllRanges();
196 InspectorTest.addSniffer(consoleView, "_searchFinishedForTests", onSearc h);
197 consoleView._searchableView._searchInputElement.value = query;
198 consoleView._searchableView._regexButton.setToggled(false);
199 consoleView._searchableView._caseSensitiveButton.setToggled(false);
200 consoleView._searchableView.showSearchField();
201 InspectorTest.addResult("Searching for text: " + query);
202
203 function onSearch() {
204 var matches = consoleView.element.childTextNodes().filter(node => no de.parentElement.classList.contains("highlighted-search-result")).map(node => no de.parentElement);
205 InspectorTest.addResult("Highlighted " + matches.length + " matches" );
206
207 // Use TextNodes for containers to get inside the highlighted match element.
208 makeSelectionAndDump(7, 0, 7, halfMaxLength, false, true);
209 makeSelectionAndDump(7, 0, 7, halfMaxLength + 1, false, true);
210 makeSelectionAndDump(7, 0, 7, maxLength, false, true);
211 makeSelectionAndDump(7, halfMaxLength, 7, halfMaxLength + 1);
212 makeSelectionAndDump(7, halfMaxLength, 7, maxLength);
213 makeSelectionAndDump(7, halfMaxLength + 1, 7, maxLength);
214 next();
215 }
216 }
217 }
218 </script>
219 </head>
220 <body onload="runTest()">
221 <p>Tests that console copies tree outline messages properly.</p>
222 </body>
223 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698