Added: trunk/LayoutTests/http/tests/inspector/search/resources-search-match-index-expected.txt (0 => 98339)
--- trunk/LayoutTests/http/tests/inspector/search/resources-search-match-index-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/search/resources-search-match-index-expected.txt 2011-10-25 13:49:24 UTC (rev 98339)
@@ -0,0 +1,120 @@
+Tests search match index calculation in resources panel.
+
+Bug 66050
+
+Running: test1
+Running test for matches counts: [1]
+Element index: 1, index: 0, match index: 1.
+Element index: 1, index: 0, match index: 1.
+Element index: 1, index: 0, match index: 1.
+Element index: 1, index: 0, match index: 1.
+Element index: 1, index: 0, match index: 1.
+Element index: 1, index: 0, match index: 1.
+
+
+Running: test2
+Running test for matches counts: [1,2,3]
+Element index: 1, index: 0, match index: 1.
+Element index: 2, index: 0, match index: 2.
+Element index: 2, index: 1, match index: 3.
+Element index: 3, index: 0, match index: 4.
+Element index: 3, index: 1, match index: 5.
+Element index: 3, index: 2, match index: 6.
+Element index: 1, index: 0, match index: 1.
+Element index: 3, index: 2, match index: 6.
+Element index: 3, index: 1, match index: 5.
+Element index: 3, index: 0, match index: 4.
+Element index: 2, index: 1, match index: 3.
+Element index: 2, index: 0, match index: 2.
+Element index: 1, index: 0, match index: 1.
+Element index: 3, index: 2, match index: 6.
+Element index: 1, index: 0, match index: 1.
+Element index: 3, index: 2, match index: 6.
+
+
+Running: test3
+Running test for matches counts: [1,0,2,0,3]
+Element index: 1, index: 0, match index: 1.
+Element index: 3, index: 0, match index: 2.
+Element index: 3, index: 1, match index: 3.
+Element index: 5, index: 0, match index: 4.
+Element index: 5, index: 1, match index: 5.
+Element index: 5, index: 2, match index: 6.
+Element index: 1, index: 0, match index: 1.
+Element index: 5, index: 2, match index: 6.
+Element index: 5, index: 1, match index: 5.
+Element index: 5, index: 0, match index: 4.
+Element index: 3, index: 1, match index: 3.
+Element index: 3, index: 0, match index: 2.
+Element index: 1, index: 0, match index: 1.
+Element index: 5, index: 2, match index: 6.
+Element index: 1, index: 0, match index: 1.
+Element index: 5, index: 2, match index: 6.
+Element index: 3, index: 0, match index: 2.
+Element index: 1, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 4.
+Element index: 3, index: 1, match index: 3.
+
+
+Running: test4
+Running test for matches counts: [0,0,0,3,0,0,0,3,0,0,0]
+Element index: 4, index: 0, match index: 1.
+Element index: 4, index: 1, match index: 2.
+Element index: 4, index: 2, match index: 3.
+Element index: 8, index: 0, match index: 4.
+Element index: 8, index: 1, match index: 5.
+Element index: 8, index: 2, match index: 6.
+Element index: 4, index: 0, match index: 1.
+Element index: 8, index: 2, match index: 6.
+Element index: 8, index: 1, match index: 5.
+Element index: 8, index: 0, match index: 4.
+Element index: 4, index: 2, match index: 3.
+Element index: 4, index: 1, match index: 2.
+Element index: 4, index: 0, match index: 1.
+Element index: 8, index: 2, match index: 6.
+Element index: 4, index: 0, match index: 1.
+Element index: 8, index: 2, match index: 6.
+Element index: 4, index: 0, match index: 1.
+Element index: 8, index: 2, match index: 6.
+Element index: 4, index: 0, match index: 1.
+Element index: 8, index: 2, match index: 6.
+Element index: 4, index: 0, match index: 1.
+Element index: 8, index: 2, match index: 6.
+Element index: 8, index: 0, match index: 4.
+Element index: 4, index: 2, match index: 3.
+Element index: 8, index: 0, match index: 4.
+Element index: 4, index: 2, match index: 3.
+Element index: 8, index: 0, match index: 4.
+Element index: 4, index: 2, match index: 3.
+Element index: 4, index: 0, match index: 1.
+Element index: 8, index: 2, match index: 6.
+Element index: 4, index: 0, match index: 1.
+Element index: 8, index: 2, match index: 6.
+Element index: 4, index: 0, match index: 1.
+Element index: 8, index: 2, match index: 6.
+
+
+Running: test5
+Running test for matches counts: [0,0,0,0,1,0,0,0]
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+Element index: 5, index: 0, match index: 1.
+
+
Property changes on: trunk/LayoutTests/http/tests/inspector/search/resources-search-match-index-expected.txt
___________________________________________________________________
Added: trunk/LayoutTests/http/tests/inspector/search/resources-search-match-index.html (0 => 98339)
--- trunk/LayoutTests/http/tests/inspector/search/resources-search-match-index.html (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/search/resources-search-match-index.html 2011-10-25 13:49:24 UTC (rev 98339)
@@ -0,0 +1,128 @@
+<html>
+<head>
+<script src=""
+<script>
+function test()
+{
+ var FakeElement = function(elements, index, searchMatchesCount)
+ {
+ this._elements = elements;
+ this.index = index;
+ this.searchMatchesCount = searchMatchesCount;
+ };
+
+ FakeElement.prototype = {
+ // Ignore all parameters.
+ traversePreviousTreeElement: function()
+ {
+ return this.index > 0 ? this._elements[this.index - 1] : null;
+ },
+
+ // Ignore all parameters.
+ traverseNextTreeElement: function()
+ {
+ return this.index < this._elements.length - 1 ? this._elements[this.index + 1] : null;
+ }
+ };
+
+ function createElementsTreeWithMatchesCounts(matchesCounts)
+ {
+ var elements = [];
+ var totalMatchesCount = 0;
+ var element = new FakeElement(elements, 0, 0);
+ elements.push(element);
+ for (var i = 0; i < matchesCounts.length; ++i) {
+ element = new FakeElement(elements, i + 1, matchesCounts[i]);
+ elements.push(element);
+ totalMatchesCount += matchesCounts[i];
+ }
+ elements.totalMatchesCount = totalMatchesCount;
+ return elements;
+ }
+
+ function dumpSearchResult(searchResult)
+ {
+ if (searchResult) {
+ var elementIndex = searchResult.treeElement.index;
+ var index = searchResult.index;
+ var matchIndex = searchResult.currentMatchIndex;
+ InspectorTest.addResult("Element index: " + elementIndex + ", index: " + index + ", match index: " + matchIndex + ".");
+ } else
+ InspectorTest.addResult("No search result found.");
+ }
+
+ function runTestForMatchesCounts(matchesCounts)
+ {
+ InspectorTest.addResult("Running test for matches counts: " + JSON.stringify(matchesCounts));
+ var elements = createElementsTreeWithMatchesCounts(matchesCounts);
+ var controller = new WebInspector.ResourcesSearchController(elements[0], elements.totalMatchesCount);
+ var lastSearchResult;
+
+ // First of all make a full cycle through the tree.
+ for (var i = 0; i < elements.totalMatchesCount + 1; ++i) {
+ lastSearchResult = controller.nextSearchResult(lastSearchResult ? lastSearchResult.treeElement : null);
+ dumpSearchResult(lastSearchResult);
+ if (!lastSearchResult)
+ break;
+ }
+
+ // Then make another one in the opposite direction.
+ for (var i = 0; i < elements.totalMatchesCount + 1; ++i) {
+ lastSearchResult = controller.previousSearchResult(lastSearchResult ? lastSearchResult.treeElement : null);
+ dumpSearchResult(lastSearchResult);
+ if (!lastSearchResult)
+ break;
+ }
+
+ // Now dump next and previous search results for each element without search matches.
+ for (var i = 0; i < elements.length; ++i) {
+ if (elements[i].searchMatchesCount === 0) {
+ var searchResult = controller.nextSearchResult(elements[i]);
+ dumpSearchResult(searchResult);
+ searchResult = controller.previousSearchResult(elements[i]);
+ dumpSearchResult(searchResult);
+ }
+ }
+ InspectorTest.addResult("");
+ }
+
+ InspectorTest.runTestSuite([
+ function test1(next)
+ {
+ runTestForMatchesCounts([1]);
+ next();
+ },
+
+ function test2(next)
+ {
+ runTestForMatchesCounts([1, 2, 3]);
+ next();
+ },
+
+ function test3(next)
+ {
+ runTestForMatchesCounts([1, 0, 2, 0, 3]);
+ next();
+ },
+
+ function test4(next)
+ {
+ runTestForMatchesCounts([0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0]);
+ next();
+ },
+
+ function test5(next)
+ {
+ runTestForMatchesCounts([0, 0, 0, 0, 1, 0, 0, 0]);
+ next();
+ }
+ ]);
+
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<p>Tests search match index calculation in resources panel.</p>
+<a href="" 66050</a>
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/inspector/search/resources-search-match-index.html
___________________________________________________________________
Modified: trunk/Source/WebCore/inspector/front-end/ResourcesPanel.js (98338 => 98339)
--- trunk/Source/WebCore/inspector/front-end/ResourcesPanel.js 2011-10-25 13:45:47 UTC (rev 98338)
+++ trunk/Source/WebCore/inspector/front-end/ResourcesPanel.js 2011-10-25 13:49:24 UTC (rev 98339)
@@ -646,7 +646,7 @@
}
WebInspector.searchController.updateSearchMatchesCount(totalMatchesCount, this);
- this._searchController = new WebInspector.ResourcesSearchController(this.resourcesListTreeElement);
+ this._searchController = new WebInspector.ResourcesSearchController(this.resourcesListTreeElement, totalMatchesCount);
if (this.sidebarTree.selectedTreeElement && this.sidebarTree.selectedTreeElement.searchMatchesCount)
this.jumpToNextSearchResult();
@@ -694,6 +694,7 @@
return; // User has selected another view while we were searching.
if (this._lastSearchResultIndex != -1)
this.visibleView.jumpToSearchResult(this._lastSearchResultIndex);
+ WebInspector.searchController.updateCurrentMatchIndex(searchResult.currentMatchIndex, this);
}
// Then run SourceFrame search if needed and jump to search result index when done.
@@ -894,6 +895,11 @@
this.titleElement.textContent = this._titleText;
},
+ get searchMatchesCount()
+ {
+ return 0;
+ },
+
isEventWithinDisclosureTriangle: function(event)
{
// Override it since we use margin-left in place of treeoutline's text-indent.
@@ -1588,20 +1594,26 @@
/**
* @constructor
+ * @param {WebInspector.BaseStorageTreeElement} rootElement
+ * @param {number} matchesCount
*/
-WebInspector.ResourcesSearchController = function(rootElement)
+WebInspector.ResourcesSearchController = function(rootElement, matchesCount)
{
this._root = rootElement;
+ this._matchesCount = matchesCount;
this._traverser = new WebInspector.SearchResultsTreeElementsTraverser(rootElement);
this._lastTreeElement = null;
this._lastIndex = -1;
}
WebInspector.ResourcesSearchController.prototype = {
+ /**
+ * @param {WebInspector.BaseStorageTreeElement} currentTreeElement
+ */
nextSearchResult: function(currentTreeElement)
{
if (!currentTreeElement)
- return this._searchResult(this._traverser.first(), 0);
+ return this._searchResult(this._traverser.first(), 0, 1);
if (!currentTreeElement.searchMatchesCount)
return this._searchResult(this._traverser.next(currentTreeElement), 0);
@@ -1610,35 +1622,55 @@
return this._searchResult(currentTreeElement, 0);
if (this._lastIndex == currentTreeElement.searchMatchesCount - 1)
- return this._searchResult(this._traverser.next(currentTreeElement), 0);
+ return this._searchResult(this._traverser.next(currentTreeElement), 0, this._currentMatchIndex % this._matchesCount + 1);
- return this._searchResult(currentTreeElement, this._lastIndex + 1);
+ return this._searchResult(currentTreeElement, this._lastIndex + 1, this._currentMatchIndex + 1);
},
+ /**
+ * @param {WebInspector.BaseStorageTreeElement} currentTreeElement
+ */
previousSearchResult: function(currentTreeElement)
{
if (!currentTreeElement) {
var treeElement = this._traverser.last();
- return this._searchResult(treeElement, treeElement.searchMatchesCount - 1);
+ return this._searchResult(treeElement, treeElement.searchMatchesCount - 1, this._matchesCount);
}
- if (currentTreeElement.searchMatchesCount && this._lastTreeElement === currentTreeElement && this._lastIndex > 0)
- return this._searchResult(currentTreeElement, this._lastIndex - 1);
+ if (currentTreeElement.searchMatchesCount && this._lastTreeElement === currentTreeElement) {
+ if (this._lastIndex > 0)
+ return this._searchResult(currentTreeElement, this._lastIndex - 1, this._currentMatchIndex - 1);
+ else {
+ var treeElement = this._traverser.previous(currentTreeElement);
+ var currentMatchIndex = this._currentMatchIndex - 1 ? this._currentMatchIndex - 1 : this._matchesCount;
+ return this._searchResult(treeElement, treeElement.searchMatchesCount - 1, currentMatchIndex);
+ }
+ }
var treeElement = this._traverser.previous(currentTreeElement)
return this._searchResult(treeElement, treeElement.searchMatchesCount - 1);
},
- _searchResult: function(treeElement, index)
+ /**
+ * @param {WebInspector.BaseStorageTreeElement} treeElement
+ * @param {number} index
+ * @param {number=} currentMatchIndex
+ * @return {Object}
+ */
+ _searchResult: function(treeElement, index, currentMatchIndex)
{
this._lastTreeElement = treeElement;
this._lastIndex = index;
- return {treeElement: treeElement, index: index};
+ if (!currentMatchIndex)
+ currentMatchIndex = this._traverser.matchIndex(treeElement, index);
+ this._currentMatchIndex = currentMatchIndex;
+ return {treeElement: treeElement, index: index, currentMatchIndex: currentMatchIndex};
}
}
/**
* @constructor
+ * @param {WebInspector.BaseStorageTreeElement} rootElement
*/
WebInspector.SearchResultsTreeElementsTraverser = function(rootElement)
{
@@ -1646,49 +1678,96 @@
}
WebInspector.SearchResultsTreeElementsTraverser.prototype = {
+ /**
+ * @return {WebInspector.BaseStorageTreeElement}
+ */
first: function()
{
return this.next(this._root);
},
+ /**
+ * @return {WebInspector.BaseStorageTreeElement}
+ */
last: function()
{
return this.previous(this._root);
},
+ /**
+ * @param {WebInspector.BaseStorageTreeElement} startTreeElement
+ * @return {WebInspector.BaseStorageTreeElement}
+ */
next: function(startTreeElement)
{
var treeElement = startTreeElement;
do {
treeElement = this._traverseNext(treeElement) || this._root;
- } while (treeElement != startTreeElement && !this._elementHasSearchResults(treeElement));
+ } while (treeElement != startTreeElement && !this._elementSearchMatchesCount(treeElement));
return treeElement;
},
+ /**
+ * @param {WebInspector.BaseStorageTreeElement} startTreeElement
+ * @return {WebInspector.BaseStorageTreeElement}
+ */
previous: function(startTreeElement)
{
var treeElement = startTreeElement;
do {
treeElement = this._traversePrevious(treeElement) || this._lastTreeElement();
- } while (treeElement != startTreeElement && !this._elementHasSearchResults(treeElement));
+ } while (treeElement != startTreeElement && !this._elementSearchMatchesCount(treeElement));
return treeElement;
},
- _traverseNext: function(treeElement)
+ /**
+ * @param {WebInspector.BaseStorageTreeElement} startTreeElement
+ * @param {number} index
+ * @return {number}
+ */
+ matchIndex: function(startTreeElement, index)
{
- return treeElement.traverseNextTreeElement(false, this._root, true);
+ var matchIndex = 1;
+ var treeElement = this._root;
+ while (treeElement != startTreeElement) {
+ matchIndex += this._elementSearchMatchesCount(treeElement);
+ treeElement = this._traverseNext(treeElement) || this._root;
+ if (treeElement === this._root)
+ return 0;
+ }
+ return matchIndex + index;
},
- _elementHasSearchResults: function(treeElement)
+ /**
+ * @param {WebInspector.BaseStorageTreeElement} treeElement
+ * @return {number}
+ */
+ _elementSearchMatchesCount: function(treeElement)
{
- return treeElement instanceof WebInspector.FrameResourceTreeElement && treeElement.searchMatchesCount;
+ return treeElement.searchMatchesCount;
},
+ /**
+ * @param {WebInspector.BaseStorageTreeElement} treeElement
+ * @return {WebInspector.BaseStorageTreeElement}
+ */
+ _traverseNext: function(treeElement)
+ {
+ return /** @type {WebInspector.BaseStorageTreeElement} */ treeElement.traverseNextTreeElement(false, this._root, true);
+ },
+
+ /**
+ * @param {WebInspector.BaseStorageTreeElement} treeElement
+ * @return {WebInspector.BaseStorageTreeElement}
+ */
_traversePrevious: function(treeElement)
{
- return treeElement.traversePreviousTreeElement(false, this._root, true);
+ return /** @type {WebInspector.BaseStorageTreeElement} */ treeElement.traversePreviousTreeElement(false, true);
},
+ /**
+ * @return {WebInspector.BaseStorageTreeElement}
+ */
_lastTreeElement: function()
{
var treeElement = this._root;