OLD | NEW |
(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." + "0123456789".repeat(15) + ".com"; |
| 10 var shortUrl = "www.bar.com"; |
| 11 var mixedUrl = longUrl + " " + shortUrl + " " + longUrl; |
| 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 `; |
| 20 |
| 21 var consoleView = Console.ConsoleView.instance(); |
| 22 var viewport = Console.ConsoleView.instance()._viewport; |
| 23 var maxLength; |
| 24 var halfMaxLength; |
| 25 var secondLongUrlIndexInMixedUrl; |
| 26 |
| 27 var tests = [ |
| 28 function testSelectWithinTruncatedUrl(next) |
| 29 { |
| 30 makeSelectionAndDump(1, 0, 1, halfMaxLength); |
| 31 makeSelectionAndDump(1, 0, 1, halfMaxLength + 1); |
| 32 makeSelectionAndDump(1, 0, 1, maxLength); |
| 33 makeSelectionAndDump(1, halfMaxLength, 1, halfMaxLength + 1); |
| 34 makeSelectionAndDump(1, halfMaxLength, 1, maxLength); |
| 35 makeSelectionAndDump(1, halfMaxLength + 1, 1, maxLength); |
| 36 next(); |
| 37 }, |
| 38 |
| 39 function testSelectAcrossMultipleMessages(next) { |
| 40 makeSelectionAndDump(1, 0, 2, shortUrl.length); |
| 41 makeSelectionAndDump(1, halfMaxLength, 2, shortUrl.length); |
| 42 makeSelectionAndDump(1, halfMaxLength + 1, 2, shortUrl.length); |
| 43 next() |
| 44 }, |
| 45 |
| 46 function testSelectAcrossMultipleMessagesWithTruncatedUrls(next) { |
| 47 makeSelectionAndDump(1, 0, 3, halfMaxLength); |
| 48 makeSelectionAndDump(1, 0, 3, halfMaxLength + 1); |
| 49 makeSelectionAndDump(1, 0, 3, maxLength); |
| 50 next() |
| 51 }, |
| 52 |
| 53 function testSelectWithinMessageWithMultipleTruncatedUrls(next) { |
| 54 makeSelectionAndDump(4, 0, 4, halfMaxLength); |
| 55 makeSelectionAndDump(4, 0, 4, halfMaxLength + 1); |
| 56 makeSelectionAndDump(4, 0, 4, secondLongUrlIndexInMixedUrl); |
| 57 makeSelectionAndDump(4, 0, 4, secondLongUrlIndexInMixedUrl + halfMax
Length); |
| 58 makeSelectionAndDump(4, 0, 4, secondLongUrlIndexInMixedUrl + halfMax
Length + 1); |
| 59 makeSelectionAndDump(4, 0, 4, secondLongUrlIndexInMixedUrl + maxLeng
th); |
| 60 |
| 61 makeSelectionAndDump(4, halfMaxLength, 4, halfMaxLength + 1); |
| 62 makeSelectionAndDump(4, halfMaxLength, 4, secondLongUrlIndexInMixedU
rl); |
| 63 makeSelectionAndDump(4, halfMaxLength, 4, secondLongUrlIndexInMixedU
rl + halfMaxLength); |
| 64 makeSelectionAndDump(4, halfMaxLength, 4, secondLongUrlIndexInMixedU
rl + halfMaxLength + 1); |
| 65 makeSelectionAndDump(4, halfMaxLength, 4, secondLongUrlIndexInMixedU
rl + maxLength); |
| 66 |
| 67 makeSelectionAndDump(4, halfMaxLength + 1, 4, secondLongUrlIndexInMi
xedUrl); |
| 68 makeSelectionAndDump(4, halfMaxLength + 1, 4, secondLongUrlIndexInMi
xedUrl + halfMaxLength); |
| 69 makeSelectionAndDump(4, halfMaxLength + 1, 4, secondLongUrlIndexInMi
xedUrl + halfMaxLength + 1); |
| 70 makeSelectionAndDump(4, halfMaxLength + 1, 4, secondLongUrlIndexInMi
xedUrl + maxLength); |
| 71 |
| 72 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl, 4, secondLongU
rlIndexInMixedUrl + halfMaxLength); |
| 73 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl, 4, secondLongU
rlIndexInMixedUrl + halfMaxLength + 1); |
| 74 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl, 4, secondLongU
rlIndexInMixedUrl + maxLength); |
| 75 |
| 76 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl + halfMaxLength
, 4, secondLongUrlIndexInMixedUrl + halfMaxLength + 1); |
| 77 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl + halfMaxLength
, 4, secondLongUrlIndexInMixedUrl + maxLength); |
| 78 |
| 79 makeSelectionAndDump(4, secondLongUrlIndexInMixedUrl + halfMaxLength
+ 1, 4, secondLongUrlIndexInMixedUrl + maxLength); |
| 80 next() |
| 81 } |
| 82 ]; |
| 83 |
| 84 InspectorTest.waitForConsoleMessages(5, () => { |
| 85 viewport.invalidate(); |
| 86 |
| 87 // Get the max truncated length from the first longUrl logged. |
| 88 try { |
| 89 var longUrlMessage = consoleView._visibleViewMessages[1].element(); |
| 90 var longUrlMessageText = longUrlMessage.querySelector('.console-mess
age-text').deepTextContent(); |
| 91 maxLength = longUrlMessageText.length; |
| 92 halfMaxLength = maxLength >> 1; |
| 93 secondLongUrlIndexInMixedUrl = maxLength + 1 + shortUrl.length + 1; |
| 94 InspectorTest.addResult("Long url has max length: " + maxLength + ",
text: " + longUrlMessageText); |
| 95 } catch (e) { |
| 96 InspectorTest.addResult("FAIL: Could not get max truncation length f
rom first longUrl message."); |
| 97 InspectorTest.completeTest(); |
| 98 return; |
| 99 } |
| 100 InspectorTest.runTestSuite(tests); |
| 101 }); |
| 102 InspectorTest.evaluateInConsole(prepareCode); |
| 103 |
| 104 function makeSelectionAndDump(fromMessage, fromTextOffset, toMessage, toText
Offset, includeAnchor) { |
| 105 InspectorTest.addResult("\nMaking selection: " + fromMessage + ", " + fr
omTextOffset + ", " + toMessage + ", " + toTextOffset); |
| 106 |
| 107 // Ignore the anchor text on the start/end message, just use their conte
nts. |
| 108 if (!includeAnchor) { |
| 109 var fromAnchor = consoleView.itemElement(fromMessage).element().quer
ySelector('.console-message-anchor'); |
| 110 var toAnchor = consoleView.itemElement(toMessage).element().querySel
ector('.console-message-anchor'); |
| 111 fromTextOffset += fromAnchor ? fromAnchor.deepTextContent().length :
0; |
| 112 toTextOffset += toAnchor ? toAnchor.deepTextContent().length : 0; |
| 113 } |
| 114 InspectorTest.selectConsoleMessages(fromMessage, fromTextOffset, toMessa
ge, toTextOffset); |
| 115 var selectedText = viewport._selectedText(); |
| 116 if (selectedText) |
| 117 InspectorTest.addResult("Selection length: " + selectedText.length +
", " + "text: " + selectedText.replace(/\bVM\d+/g, "VM")); |
| 118 else |
| 119 InspectorTest.addResult("No selection"); |
| 120 } |
| 121 } |
| 122 </script> |
| 123 </head> |
| 124 <body onload="runTest()"> |
| 125 <p>Tests that console copies tree outline messages properly.</p> |
| 126 </body> |
| 127 </html> |
OLD | NEW |