| <html> |
| <head> |
| <script src="../http/tests/inspector/inspector-test.js"></script> |
| <script src="../http/tests/inspector/sources-test.js"></script> |
| <script> |
| |
| function test() |
| { |
| |
| var overridenInput = []; |
| var overrideShowMatchingItems = true; |
| var history = []; |
| |
| function StubDelegate() |
| { |
| WebInspector.FilteredListWidget.Delegate.call(this, history); |
| } |
| StubDelegate.prototype = { |
| itemKeyAt: function(itemIndex) { return overridenInput[itemIndex]; }, |
| itemScoreAt: function(itemIndex) { return 0; }, |
| itemCount: function() { return overridenInput.length; }, |
| selectItem: function(itemIndex, promptValue) |
| { |
| InspectorTest.addResult("Selected item index: " + itemIndex); |
| }, |
| shouldShowMatchingItems: function() { return overrideShowMatchingItems; }, |
| |
| __proto__: WebInspector.FilteredListWidget.Delegate.prototype |
| } |
| |
| var delegate = new StubDelegate(); |
| |
| function checkQuery(query, input, hideMatchingItems, acceptAutocomplete, next) |
| { |
| overridenInput = input; |
| overrideShowMatchingItems = !hideMatchingItems; |
| |
| InspectorTest.addResult("Input:" + JSON.stringify(input)); |
| |
| var filteredSelectionDialog = new WebInspector.FilteredListWidget(delegate); |
| filteredSelectionDialog.showAsDialog(); |
| InspectorTest.addSniffer(filteredSelectionDialog, "_autocompletedForTests", onautocomplete); |
| filteredSelectionDialog.setQuery(query); |
| filteredSelectionDialog._updateAfterItemsLoaded(); |
| |
| function onautocomplete() |
| { |
| if (acceptAutocomplete) { |
| dump(); |
| InspectorTest.addSniffer(filteredSelectionDialog, "_autocompletedForTests", accept); |
| filteredSelectionDialog._prompt.acceptAutoComplete(); |
| } else { |
| accept(); |
| } |
| } |
| |
| function dump() |
| { |
| InspectorTest.addResult("Query:" + JSON.stringify(filteredSelectionDialog._value())); |
| var items = filteredSelectionDialog._filteredItems; |
| var output = []; |
| for (var i = 0; i < items.length; ++i) |
| output.push(delegate.itemKeyAt(items[i])); |
| InspectorTest.addResult("Output:" + JSON.stringify(output)); |
| InspectorTest.addResult("Completion:" + JSON.stringify(filteredSelectionDialog._prompt.text())); |
| } |
| |
| function accept() |
| { |
| dump(); |
| filteredSelectionDialog._onEnter(InspectorTest.createKeyEvent("Enter")); |
| InspectorTest.addResult("History:" + JSON.stringify(history)); |
| next(); |
| } |
| } |
| |
| InspectorTest.runTestSuite([ |
| function emptyQueryMatchesEverything(next) |
| { |
| checkQuery("", ["a", "bc"], false, false, next); |
| }, |
| |
| function caseSensitiveMatching(next) |
| { |
| checkQuery("aB", ["abc", "acB"], false, false, next); |
| }, |
| |
| function caseInsensitiveMatching(next) |
| { |
| checkQuery("ab", ["abc", "bac", "a_B"], false, false, next); |
| }, |
| |
| function dumplicateSymbolsInQuery(next) |
| { |
| checkQuery("aab", ["abab", "abaa", "caab", "baac", "fooaab"], false, false, next); |
| }, |
| |
| function dangerousInputEscaping(next) |
| { |
| checkQuery("^[]{}()\\.$*+?|", ["^[]{}()\\.$*+?|", "0123456789abcdef"], false, false, next); |
| }, |
| |
| function itemIndexIsNotReportedInGoToLine(next) |
| { |
| checkQuery(":1", [":1:2:3.js"], true, false, next); |
| }, |
| |
| function autoCompleteIsLast(next) |
| { |
| checkQuery("", ["abc", "abcd"], false, false, next); |
| }, |
| |
| function autoCompleteAccept(next) |
| { |
| checkQuery("a", ["abc", "abcd", "aabcd"], false, true, next); |
| } |
| ]); |
| } |
| |
| </script> |
| </head> |
| |
| <body onload="runTest()"> |
| <p> |
| Check to see that FilteredItemSelectionDialog uses proper regex to filter results. |
| </p> |
| |
| </body> |
| </html> |