3 <script src=
"../../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"../../http/tests/inspector/console-test.js"></script>
6 function populateConsoleWithMessages()
8 console
.log("FIRST MATCH, SECOND MATCH");
9 for (var i
= 0; i
< 200; ++i
)
10 console
.log("Message #" + i
);
12 for (var i
= 0; i
< 200; ++i
)
13 a
["field_" + i
] = "value #" + i
;
15 console
.log("LAST MATCH");
18 //# sourceURL=console-search.html
24 function addResult(result
)
27 InspectorTest
.addResult(result
);
30 function setQuery(text
, isRegex
, caseSensitive
, callback
)
32 InspectorTest
.addSniffer(consoleView
, "_searchFinishedForTests", callback
);
33 consoleView
._searchableView
._searchInputElement
.value
= text
;
34 consoleView
._searchableView
._regexButton
.setToggled(isRegex
);
35 consoleView
._searchableView
._caseSensitiveButton
.setToggled(caseSensitive
);
36 consoleView
._searchableView
.showSearchField();
39 function matchesText()
41 return consoleView
._searchableView
.contentElement
.querySelector(".search-results-matches").textContent
;
44 function dumpMatches()
46 var matches
= document
.querySelectorAll("html /deep/ .highlighted-search-result");
47 addResult("number of visible matches: " + matches
.length
);
48 for (var i
= 0; i
< matches
.length
; ++i
)
49 addResult(" match " + i
+ ": " + matches
[i
].className
);
53 var consoleView
= WebInspector
.ConsolePanel
._view();
54 var viewport
= consoleView
._viewport
;
55 const maximumViewportMessagesCount
= 150;
56 InspectorTest
.runTestSuite([
57 function waitForMessages(next
)
59 // NOTE: keep in sync with populateConsoleWithMessages above.
60 const expectedMessageCount
= 203;
61 InspectorTest
.waitForConsoleMessages(expectedMessageCount
, next
);
64 function assertViewportHeight(next
)
66 viewport
.invalidate();
67 var viewportMessagesCount
= viewport
._lastVisibleIndex
- viewport
._firstVisibleIndex
;
68 if (viewportMessagesCount
> maximumViewportMessagesCount
) {
69 InspectorTest
.addResult(String
.sprintf(
70 "Test cannot be run because viewport can fit %d messages, while %d is the test's maximum.",
71 viewportMessagesCount
, maximumViewportMessagesCount
));
72 InspectorTest
.completeTest();
78 function testSearchOutsideOfViewport(next
)
80 setQuery("Message", false, false, function() {
81 InspectorTest
.addResult("Search matches: '" + matchesText() + "'");
86 function scrollConsoleToTop(next
)
88 viewport
.forceScrollItemToBeFirst(0);
89 addResult("first visible message index: " + viewport
.firstVisibleIndex());
93 function testCanJumpForward(next
)
95 setQuery("MATCH", false, false, function() {
97 consoleView
._searchableView
.handleFindNextShortcut();
98 addResult("first visible message index: " + viewport
.firstVisibleIndex());
100 // Find second match.
101 consoleView
._searchableView
.handleFindNextShortcut();
102 addResult("first visible message index: " + viewport
.firstVisibleIndex());
105 consoleView
._searchableView
.handleFindNextShortcut();
106 addResult("last visible message index: " + viewport
.lastVisibleIndex());
111 function testCanJumpBackward(next
)
113 setQuery("MATCH", false, false, function() {
114 // Start out at the first match.
115 consoleView
._searchableView
.handleFindNextShortcut();
118 consoleView
._searchableView
.handleFindPreviousShortcut();
119 addResult("last visible message index: " + viewport
.lastVisibleIndex());
121 // Find second match.
122 consoleView
._searchableView
.handleFindPreviousShortcut();
123 addResult("first visible message index: " + viewport
.firstVisibleIndex());
126 consoleView
._searchableView
.handleFindPreviousShortcut();
127 addResult("first visible message index: " + viewport
.firstVisibleIndex());
132 function scrollConsoleToTop(next
)
134 viewport
.forceScrollItemToBeFirst(0);
135 addResult("first visible message index: " + viewport
.firstVisibleIndex());
139 function testCanMarkCurrentMatch(next
)
141 function addCurrentMarked()
143 var matches
= document
.querySelectorAll(".highlighted-search-result");
144 addResult("number of visible matches: " + matches
.length
);
145 for (var i
= 0; i
< matches
.length
; ++i
)
146 addResult("match " + i
+ ": " + matches
[i
].className
);
149 setQuery("MATCH", false, false, function() {
151 consoleView
._searchableView
.handleFindNextShortcut();
154 // Find second match.
155 consoleView
._searchableView
.handleFindNextShortcut();
162 function testCanJumpForwardBetweenTreeElementMatches(next
)
164 function dumpElements(callback
)
166 consoleView
._searchableView
.handleFindNextShortcut();
167 var currentResultElem
= document
.querySelector("html /deep/ .current-search-result");
168 addResult("matched tree element: " + currentResultElem
.innerHTML
);
172 function searchField1(callback
)
175 setQuery("field_1", false, false, dumpElements
.bind(null, callback
));
178 function searchField199(callback
)
181 setQuery("field_199", false, false, dumpElements
.bind(null, callback
));
184 InspectorTest
.expandConsoleMessages(searchField1
.bind(null, searchField199
.bind(null, next
)));
188 function testCaseInsensitiveRegex(next
)
190 setQuery(". MATCH", true, false, function() {
191 consoleView
._searchableView
.handleFindNextShortcut();
197 function testCaseSensitiveTextWithoutMatches(next
)
199 setQuery("match", false, true, function() {
200 consoleView
._searchableView
.handleFindNextShortcut();
206 function testCaseSensitiveTextWithMatches(next
)
208 setQuery("MATCH", false, true, function() {
209 consoleView
._searchableView
.handleFindNextShortcut();
215 function testCaseSensitiveRegexWithoutMatches(next
)
217 setQuery(". match", true, true, function() {
218 consoleView
._searchableView
.handleFindNextShortcut();
224 function testCaseSensitiveRegexWithMatches(next
)
226 setQuery(". MATCH", true, true, function() {
227 consoleView
._searchableView
.handleFindNextShortcut();
236 <body onload=
"populateConsoleWithMessages()">
238 Tests console search.