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