| // Copyright 2017 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| (async function() { |
| TestRunner.addResult(`Tests console search.\n`); |
| |
| await TestRunner.loadModule('console_test_runner'); |
| await TestRunner.showPanel('console'); |
| await TestRunner.evaluateInPagePromise(` |
| console.log("FIRST MATCH, SECOND MATCH"); |
| for (var i = 0; i < 200; ++i) |
| console.log("Message #" + i); |
| var a = {}; |
| for (var i = 0; i < 200; ++i) |
| a["field_" + i] = "value #" + i; |
| console.dir(a); |
| console.log("LAST MATCH"); |
| `); |
| |
| function addResult(result) { |
| viewport.refresh(); |
| TestRunner.addResult(result); |
| } |
| |
| function setQuery(text, isRegex, caseSensitive, callback) { |
| TestRunner.addSniffer(consoleView, '_searchFinishedForTests', callback); |
| consoleView._searchableView._searchInputElement.value = text; |
| consoleView._searchableView._regexButton.setToggled(isRegex); |
| consoleView._searchableView._caseSensitiveButton.setToggled(caseSensitive); |
| consoleView._searchableView.showSearchField(); |
| } |
| |
| function matchesText() { |
| return consoleView._searchableView.contentElement.querySelector('.search-results-matches').textContent; |
| } |
| |
| function dumpMatches() { |
| var matches = consoleView.element |
| .childTextNodes() |
| .filter(node => node.parentElement.classList.contains('highlighted-search-result')) |
| .map(node => node.parentElement); |
| addResult('number of visible matches: ' + matches.length); |
| for (var i = 0; i < matches.length; ++i) addResult(' match ' + i + ': ' + matches[i].className); |
| addResult(''); |
| } |
| |
| var consoleView = Console.ConsoleView.instance(); |
| var viewport = consoleView._viewport; |
| const maximumViewportMessagesCount = 150; |
| TestRunner.runTestSuite([ |
| function waitForMessages(next) { |
| // NOTE: keep in sync with populateConsoleWithMessages above. |
| const expectedMessageCount = 203; |
| ConsoleTestRunner.waitForConsoleMessages(expectedMessageCount, next); |
| }, |
| |
| function assertViewportHeight(next) { |
| viewport.invalidate(); |
| var viewportMessagesCount = viewport._lastVisibleIndex - viewport._firstVisibleIndex; |
| if (viewportMessagesCount > maximumViewportMessagesCount) { |
| TestRunner.addResult( |
| String.sprintf( |
| "Test cannot be run because viewport can fit %d messages, while %d is the test's maximum.", |
| viewportMessagesCount, |
| maximumViewportMessagesCount |
| ) |
| ); |
| TestRunner.completeTest(); |
| return; |
| } |
| next(); |
| }, |
| |
| function testSearchOutsideOfViewport(next) { |
| setQuery('Message', false, false, function() { |
| TestRunner.addResult("Search matches: '" + matchesText() + "'"); |
| next(); |
| }); |
| }, |
| |
| function scrollConsoleToTop(next) { |
| viewport.forceScrollItemToBeFirst(0); |
| addResult('first visible message index: ' + viewport.firstVisibleIndex()); |
| next(); |
| }, |
| |
| function testCanJumpForward(next) { |
| setQuery('MATCH', false, false, function() { |
| // Find first match. |
| consoleView._searchableView.handleFindNextShortcut(); |
| addResult('first visible message index: ' + viewport.firstVisibleIndex()); |
| |
| // Find second match. |
| consoleView._searchableView.handleFindNextShortcut(); |
| addResult('first visible message index: ' + viewport.firstVisibleIndex()); |
| |
| // Find last match. |
| consoleView._searchableView.handleFindNextShortcut(); |
| addResult('last visible message index: ' + viewport.lastVisibleIndex()); |
| next(); |
| }); |
| }, |
| |
| function testCanJumpBackward(next) { |
| setQuery('MATCH', false, false, function() { |
| // Start out at the first match. |
| consoleView._searchableView.handleFindNextShortcut(); |
| |
| // Find last match. |
| consoleView._searchableView.handleFindPreviousShortcut(); |
| addResult('last visible message index: ' + viewport.lastVisibleIndex()); |
| |
| // Find second match. |
| consoleView._searchableView.handleFindPreviousShortcut(); |
| addResult('first visible message index: ' + viewport.firstVisibleIndex()); |
| |
| // Find first match. |
| consoleView._searchableView.handleFindPreviousShortcut(); |
| addResult('first visible message index: ' + viewport.firstVisibleIndex()); |
| next(); |
| }); |
| }, |
| |
| function scrollConsoleToTop(next) { |
| viewport.forceScrollItemToBeFirst(0); |
| addResult('first visible message index: ' + viewport.firstVisibleIndex()); |
| next(); |
| }, |
| |
| function testCanMarkCurrentMatch(next) { |
| function addCurrentMarked() { |
| var matches = document.querySelectorAll('.highlighted-search-result'); |
| addResult('number of visible matches: ' + matches.length); |
| for (var i = 0; i < matches.length; ++i) addResult('match ' + i + ': ' + matches[i].className); |
| } |
| |
| setQuery('MATCH', false, false, function() { |
| // Find first match. |
| consoleView._searchableView.handleFindNextShortcut(); |
| addCurrentMarked(); |
| |
| // Find second match. |
| consoleView._searchableView.handleFindNextShortcut(); |
| addCurrentMarked(); |
| |
| next(); |
| }); |
| }, |
| |
| function testCanJumpForwardBetweenTreeElementMatches(next) { |
| function dumpElements(callback) { |
| consoleView._searchableView.handleFindNextShortcut(); |
| var currentResultElem = consoleView.element |
| .childTextNodes() |
| .filter(node => node.parentElement.classList.contains('current-search-result'))[0]; |
| addResult('matched tree element: ' + currentResultElem.textContent); |
| callback(); |
| } |
| |
| function searchField1(callback) { |
| // Find first match. |
| setQuery('field_1', false, false, dumpElements.bind(null, callback)); |
| } |
| |
| function searchField199(callback) { |
| // Find last match. |
| setQuery('field_199', false, false, dumpElements.bind(null, callback)); |
| } |
| |
| ConsoleTestRunner.expandConsoleMessages(searchField1.bind(null, searchField199.bind(null, next))); |
| }, |
| |
| function testCaseInsensitiveRegex(next) { |
| setQuery('. MATCH', true, false, function() { |
| consoleView._searchableView.handleFindNextShortcut(); |
| dumpMatches(); |
| next(); |
| }); |
| }, |
| |
| function testCaseSensitiveTextWithoutMatches(next) { |
| setQuery('match', false, true, function() { |
| consoleView._searchableView.handleFindNextShortcut(); |
| dumpMatches(); |
| next(); |
| }); |
| }, |
| |
| function testCaseSensitiveTextWithMatches(next) { |
| setQuery('MATCH', false, true, function() { |
| consoleView._searchableView.handleFindNextShortcut(); |
| dumpMatches(); |
| next(); |
| }); |
| }, |
| |
| function testCaseSensitiveRegexWithoutMatches(next) { |
| setQuery('. match', true, true, function() { |
| consoleView._searchableView.handleFindNextShortcut(); |
| dumpMatches(); |
| next(); |
| }); |
| }, |
| |
| function testCaseSensitiveRegexWithMatches(next) { |
| setQuery('. MATCH', true, true, function() { |
| consoleView._searchableView.handleFindNextShortcut(); |
| dumpMatches(); |
| next(); |
| }); |
| } |
| ]); |
| })(); |