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

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: reset tests with zero width space Created 3 years, 8 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 function test()
7 {
8 var longUrl = "www." + "0123456789".repeat(15) + ".com";
9 var shortUrl = "www.bar.com";
10 var mixedUrl = longUrl + " " + shortUrl + " " + longUrl;
11 var highlightedUrl = "www." + "z".repeat(200) + ".com";
12 var prepareCode = `
13 // Keep this as the first url logged to record the max truncated length.
14 console.log("${longUrl}");
15
16 console.log("${shortUrl}");
17 console.log("${longUrl}");
18 console.log("${mixedUrl}");
19 console.log("${highlightedUrl}");
20 `;
21
22 var expectedMessageCount = 6;
23 var consoleView = Console.ConsoleView.instance();
24 var viewport = Console.ConsoleView.instance()._viewport;
25 var maxLength;
26 var halfMaxLength;
27 var secondLongUrlIndexInMixedUrl;
28
29 var tests = [
30 function testSelectWithinTruncatedUrl(next)
31 {
32 makeSelectionAndDump(1, 0, 1, halfMaxLength);
33 makeSelectionAndDump(1, 0, 1, halfMaxLength + 1);
34 makeSelectionAndDump(1, 0, 1, maxLength);
35 makeSelectionAndDump(1, halfMaxLength, 1, halfMaxLength + 1);
36 makeSelectionAndDump(1, halfMaxLength, 1, maxLength);
37 makeSelectionAndDump(1, halfMaxLength + 1, 1, maxLength);
38 next();
39 },
40
41 function testSelectAcrossMultipleMessages(next) {
42 makeSelectionAndDump(1, 0, 2, shortUrl.length);
43 makeSelectionAndDump(1, halfMaxLength, 2, shortUrl.length);
44 makeSelectionAndDump(1, halfMaxLength + 1, 2, shortUrl.length);
45 next()
46 },
47
48 function testSelectAcrossMultipleMessagesWithTruncatedUrls(next) {
49 makeSelectionAndDump(1, 0, 3, halfMaxLength);
50 makeSelectionAndDump(1, 0, 3, halfMaxLength + 1);
51 makeSelectionAndDump(1, 0, 3, maxLength);
52 next()
53 },
54
55 function testSelectWithinMessageWithMultipleTruncatedUrls(next) {
56 makeSelectionAndDump(4, 0, 4, halfMaxLength);
57 makeSelectionAndDump(4, 0, 4, halfMaxLength + 1);
58 makeSelectionAndDump(4, 0, 4, secondLongUrlIndexInMixedUrl);
59 makeSelectionAndDump(4, 0, 4, secondLongUrlIndexInMixedUrl + halfMax Length);
60 makeSelectionAndDump(4, 0, 4, secondLongUrlIndexInMixedUrl + halfMax Length + 1);
61 makeSelectionAndDump(4, 0, 4, secondLongUrlIndexInMixedUrl + maxLeng th);
62
63 makeSelectionAndDump(4, halfMaxLength, 4, halfMaxLength + 1);
64 makeSelectionAndDump(4, halfMaxLength, 4, secondLongUrlIndexInMixedU rl);
65 makeSelectionAndDump(4, halfMaxLength, 4, secondLongUrlIndexInMixedU rl + halfMaxLength);
66 makeSelectionAndDump(4, halfMaxLength, 4, secondLongUrlIndexInMixedU rl + halfMaxLength + 1);
67 makeSelectionAndDump(4, halfMaxLength, 4, secondLongUrlIndexInMixedU rl + maxLength);
68
69 makeSelectionAndDump(4, halfMaxLength + 1, 4, secondLongUrlIndexInMi xedUrl);
70 makeSelectionAndDump(4, halfMaxLength + 1, 4, secondLongUrlIndexInMi xedUrl + halfMaxLength);
71 makeSelectionAndDump(4, halfMaxLength + 1, 4, secondLongUrlIndexInMi xedUrl + halfMaxLength + 1);
72 makeSelectionAndDump(4, halfMaxLength + 1, 4, secondLongUrlIndexInMi xedUrl + maxLength);
73
74 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl, 4, secondLongU rlIndexInMixedUrl + halfMaxLength);
75 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl, 4, secondLongU rlIndexInMixedUrl + halfMaxLength + 1);
76 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl, 4, secondLongU rlIndexInMixedUrl + maxLength);
77
78 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl + halfMaxLength , 4, secondLongUrlIndexInMixedUrl + halfMaxLength + 1);
79 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl + halfMaxLength , 4, secondLongUrlIndexInMixedUrl + maxLength);
80
81 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl + halfMaxLength + 1, 4, secondLongUrlIndexInMixedUrl + maxLength);
82 next()
83 },
84
85 function testSelectWithinHighlightedUrlBeginning(next) {
86 testHighlightedUrlWithSearchQuery("www.", next);
87 },
88
89 function testSelectWithinHighlightedUrlMiddle(next) {
90 testHighlightedUrlWithSearchQuery("zzzzz", next);
91 },
92
93 function testSelectWithinHighlightedUrlEnd(next) {
94 testHighlightedUrlWithSearchQuery(".com", next);
95 }
96 ];
97
98 InspectorTest.waitForConsoleMessages(expectedMessageCount, () => {
99 viewport.invalidate();
100
101 // Get the max truncated length from the first longUrl logged.
102 try {
103 var longUrlMessage = consoleView._visibleViewMessages[1].element();
104 var longUrlMessageText = longUrlMessage.querySelector('.console-mess age-text').deepTextContent();
105 maxLength = longUrlMessageText.length;
106 halfMaxLength = Math.ceil(maxLength / 2);
107 secondLongUrlIndexInMixedUrl = maxLength + 1 + shortUrl.length + 1;
108 InspectorTest.addResult("Long url has max length: " + maxLength + ", text: " + longUrlMessageText);
109 } catch (e) {
110 InspectorTest.addResult("FAIL: Could not get max truncation length f rom first longUrl message.");
111 InspectorTest.completeTest();
112 return;
113 }
114 InspectorTest.runTestSuite(tests);
115 });
116 InspectorTest.evaluateInConsole(prepareCode);
117
118 function makeSelectionAndDump(fromMessage, fromTextOffset, toMessage, toText Offset, includeAnchor, useTextContainer) {
119 InspectorTest.addResult("\nMaking selection: " + fromMessage + ", " + fr omTextOffset + ", " + toMessage + ", " + toTextOffset);
120
121 // Ignore the anchor text on the start/end message, just use their conte nts.
122 if (!includeAnchor) {
123 var fromAnchor = consoleView.itemElement(fromMessage).element().quer ySelector('.console-message-anchor');
124 var toAnchor = consoleView.itemElement(toMessage).element().querySel ector('.console-message-anchor');
125 fromTextOffset += fromAnchor ? fromAnchor.deepTextContent().length : 0;
126 toTextOffset += toAnchor ? toAnchor.deepTextContent().length : 0;
127 }
128 InspectorTest.selectConsoleMessages(fromMessage, fromTextOffset, toMessa ge, toTextOffset, useTextContainer);
129 var selectedText = viewport._selectedText();
130 if (selectedText)
131 InspectorTest.addResult("Selection length: " + selectedText.length + ", " + "text: " + selectedText.replace(/\bVM\d+/g, "VM"));
132 else
133 InspectorTest.addResult("No selection");
134 }
135
136 function testHighlightedUrlWithSearchQuery(query, next) {
137 // Clear any existing ranges to avoid using them as the query.
138 window.getSelection().removeAllRanges();
139 InspectorTest.addSniffer(consoleView, "_searchFinishedForTests", onSearc h);
140 consoleView._searchableView._searchInputElement.value = query;
141 consoleView._searchableView._regexButton.setToggled(false);
142 consoleView._searchableView._caseSensitiveButton.setToggled(false);
143 consoleView._searchableView.showSearchField();
144 InspectorTest.addResult("Searching for text: " + query);
145
146 function onSearch() {
147 var matches = consoleView.element.childTextNodes().filter(node => no de.parentElement.classList.contains("highlighted-search-result")).map(node => no de.parentElement);
148 InspectorTest.addResult("Highlighted " + matches.length + " matches" );
149
150 // Use TextNodes for containers to get inside the highlighted match element.
151 makeSelectionAndDump(5, 0, 5, halfMaxLength, false, true);
152 makeSelectionAndDump(5, 0, 5, halfMaxLength + 1, false, true);
153 makeSelectionAndDump(5, 0, 5, maxLength, false, true);
154 makeSelectionAndDump(5, halfMaxLength, 5, halfMaxLength + 1);
155 makeSelectionAndDump(5, halfMaxLength, 5, maxLength);
156 makeSelectionAndDump(5, halfMaxLength + 1, 5, maxLength);
157 next();
158 }
159 }
160 }
161 </script>
162 </head>
163 <body onload="runTest()">
164 <p>Tests that console copies tree outline messages properly.</p>
165 </body>
166 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698