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