Title: [96323] trunk
Revision
96323
Author
[email protected]
Date
2011-09-29 05:59:17 -0700 (Thu, 29 Sep 2011)

Log Message

Web Inspector: Make search-in-resource test simpler.
https://bugs.webkit.org/show_bug.cgi?id=69025

Source/WebCore:

Changed search-in-resource test.
Removed error parameter from content provider's searchInContent callback.

Reviewed by Pavel Feldman.

* inspector/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::searchInResource):
(WebCore::InspectorPageAgent::searchInResources):
* inspector/front-end/Resource.js:
(WebInspector.Resource.prototype.searchInContent):

LayoutTests:

Reviewed by Pavel Feldman.

* http/tests/inspector/search/search-in-resource-expected.txt:
* http/tests/inspector/search/search-in-resource.html:
* http/tests/inspector/search/search-in-resources.html:
* http/tests/inspector/search/search-test.js:
(initialize_SearchTest.InspectorTest.runAfterResourcesAreCreated):
(initialize_SearchTest.InspectorTest._runAfterResourcesAreCreated):
(initialize_SearchTest.InspectorTest._runAfterResourcesAreCreated.maybeCallback):
(initialize_SearchTest.InspectorTest._runAfterResourcesAreCreated.addSniffer):
(initialize_SearchTest.InspectorTest._runAfterResourcesAreCreated.onResourceBind):
(initialize_SearchTest.InspectorTest._runAfterResourcesAreCreated.visit):
(initialize_SearchTest):

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (96322 => 96323)


--- trunk/LayoutTests/ChangeLog	2011-09-29 12:29:13 UTC (rev 96322)
+++ trunk/LayoutTests/ChangeLog	2011-09-29 12:59:17 UTC (rev 96323)
@@ -1,3 +1,22 @@
+2011-09-29  Vsevolod Vlasov  <[email protected]>
+
+        Web Inspector: Make search-in-resource test simpler.
+        https://bugs.webkit.org/show_bug.cgi?id=69025
+
+        Reviewed by Pavel Feldman.
+
+        * http/tests/inspector/search/search-in-resource-expected.txt:
+        * http/tests/inspector/search/search-in-resource.html:
+        * http/tests/inspector/search/search-in-resources.html:
+        * http/tests/inspector/search/search-test.js:
+        (initialize_SearchTest.InspectorTest.runAfterResourcesAreCreated):
+        (initialize_SearchTest.InspectorTest._runAfterResourcesAreCreated):
+        (initialize_SearchTest.InspectorTest._runAfterResourcesAreCreated.maybeCallback):
+        (initialize_SearchTest.InspectorTest._runAfterResourcesAreCreated.addSniffer):
+        (initialize_SearchTest.InspectorTest._runAfterResourcesAreCreated.onResourceBind):
+        (initialize_SearchTest.InspectorTest._runAfterResourcesAreCreated.visit):
+        (initialize_SearchTest):
+
 2011-09-27  Pavel Feldman  <[email protected]>
 
         Web Inspector: Scripts panel without folders causes errors when creating content scripts section.

Modified: trunk/LayoutTests/http/tests/inspector/search/search-in-resource-expected.txt (96322 => 96323)


--- trunk/LayoutTests/http/tests/inspector/search/search-in-resource-expected.txt	2011-09-29 12:29:13 UTC (rev 96322)
+++ trunk/LayoutTests/http/tests/inspector/search/search-in-resource-expected.txt	2011-09-29 12:59:17 UTC (rev 96323)
@@ -8,16 +8,4 @@
 lineNumber: 9, line: '    searchTestUniqueString();'
 lineNumber: 10, line: '    // SEARCHTestUniqueString();'
 
-http://127.0.0.1:8000/inspector/search/resources/search.css
-Search matches: 
-lineNumber: 0, line: 'div.searchTestUniqueString {'
-lineNumber: 4, line: 'div.searchTestUniqueString:hover {'
-lineNumber: 5, line: '    /* another searchTestUniqueString occurence */'
 
-http://127.0.0.1:8000/inspector/search/resources/search.html
-Search matches: 
-lineNumber: 5, line: '<div>searchTestUniqueString</div>'
-lineNumber: 7, line: '<!-- searchTestUniqueString -->'
-lineNumber: 9, line: '<div id="searchTestUniqueString">div text</div>'
-
-

Modified: trunk/LayoutTests/http/tests/inspector/search/search-in-resource.html (96322 => 96323)


--- trunk/LayoutTests/http/tests/inspector/search/search-in-resource.html	2011-09-29 12:29:13 UTC (rev 96322)
+++ trunk/LayoutTests/http/tests/inspector/search/search-in-resource.html	2011-09-29 12:59:17 UTC (rev 96323)
@@ -1,41 +1,24 @@
 <html>
 <head>
 <script src=""
-<script src=""
 <script src=""
 <script>
 function test()
 {
     // This file should not match search query.
     var text = "searchTest" + "UniqueString";
-    InspectorTest.runAfterResourcesAreFinished(["search.js", "search.css", "search.html"], step2);
+    InspectorTest.runAfterResourcesAreCreated(["search.js"], step2);
 
     function step2()
     {
         var resource = WebInspector.resourceForURL("http://127.0.0.1:8000/inspector/search/resources/search.js");
         InspectorTest.addResult(resource.url);
-        PageAgent.searchInResource(resource.frameId, resource.url, text, step3);
+        resource.searchInContent(text, step3);
     }
 
-    function step3(error, searchMatches)
+    function step3(searchMatches)
     {
         InspectorTest.dumpSearchMatches(searchMatches);
-        var resource = WebInspector.resourceForURL("http://127.0.0.1:8000/inspector/search/resources/search.css");
-        InspectorTest.addResult(resource.url);
-        PageAgent.searchInResource(resource.frameId, resource.url, text, step4);
-    }
-
-    function step4(error, searchMatches)
-    {
-        InspectorTest.dumpSearchMatches(searchMatches);
-        var resource = WebInspector.resourceForURL("http://127.0.0.1:8000/inspector/search/resources/search.html");
-        InspectorTest.addResult(resource.url);
-        PageAgent.searchInResource(resource.frameId, resource.url, text, step5);
-    }
-
-    function step5(error, searchMatches)
-    {
-        InspectorTest.dumpSearchMatches(searchMatches);
         InspectorTest.completeTest();
     }
 }

Modified: trunk/LayoutTests/http/tests/inspector/search/search-in-resources.html (96322 => 96323)


--- trunk/LayoutTests/http/tests/inspector/search/search-in-resources.html	2011-09-29 12:29:13 UTC (rev 96322)
+++ trunk/LayoutTests/http/tests/inspector/search/search-in-resources.html	2011-09-29 12:59:17 UTC (rev 96323)
@@ -1,7 +1,6 @@
 <html>
 <head>
 <script src=""
-<script src=""
 <script src=""
 <script>
 function test()

Modified: trunk/LayoutTests/http/tests/inspector/search/search-test.js (96322 => 96323)


--- trunk/LayoutTests/http/tests/inspector/search/search-test.js	2011-09-29 12:29:13 UTC (rev 96322)
+++ trunk/LayoutTests/http/tests/inspector/search/search-test.js	2011-09-29 12:59:17 UTC (rev 96323)
@@ -16,4 +16,50 @@
     InspectorTest.addResult("");
 };
 
+InspectorTest.runAfterResourcesAreCreated = function(resourceURLs, callback)
+{
+    InspectorTest._runAfterResourcesAreCreated(resourceURLs.keySet(), callback);
+}
+
+InspectorTest._runAfterResourcesAreCreated = function(resourceURLs, callback)
+{
+    function checkResource(resource)
+    {
+        for (var url in resourceURLs) {
+            if (resource.url.indexOf(url) !== -1)
+                delete resourceURLs[url];
+        }
+    }
+
+    function maybeCallback()
+    {
+        if (!Object.keys(resourceURLs).length) {
+            callback();
+            return true;
+        }
+    }
+
+    function addSniffer(resource)
+    {
+        InspectorTest.addSniffer(WebInspector.ResourceTreeModel.prototype, "_bindResourceURL", onResourceBind.bind(this));
+    }
+
+    function onResourceBind(resource)
+    {
+        checkResource(resource);
+        if (!maybeCallback())
+            addSniffer();
+    }
+
+    function visit(resource)
+    {
+        checkResource(resource);
+        return maybeCallback();
+    }
+
+    var succeeded = WebInspector.resourceTreeModel.forAllResources(visit);
+    if (!succeeded)
+        addSniffer();
+}
+
 };

Modified: trunk/Source/WebCore/ChangeLog (96322 => 96323)


--- trunk/Source/WebCore/ChangeLog	2011-09-29 12:29:13 UTC (rev 96322)
+++ trunk/Source/WebCore/ChangeLog	2011-09-29 12:59:17 UTC (rev 96323)
@@ -1,3 +1,19 @@
+2011-09-29  Vsevolod Vlasov  <[email protected]>
+
+        Web Inspector: Make search-in-resource test simpler.
+        https://bugs.webkit.org/show_bug.cgi?id=69025
+
+        Changed search-in-resource test.
+        Removed error parameter from content provider's searchInContent callback.
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/InspectorPageAgent.cpp:
+        (WebCore::InspectorPageAgent::searchInResource):
+        (WebCore::InspectorPageAgent::searchInResources):
+        * inspector/front-end/Resource.js:
+        (WebInspector.Resource.prototype.searchInContent):
+
 2011-09-29  Hans Wennborg  <[email protected]>
 
         IndexedDB: Use LevelDB also for in-memory databases

Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.cpp (96322 => 96323)


--- trunk/Source/WebCore/inspector/InspectorPageAgent.cpp	2011-09-29 12:29:13 UTC (rev 96322)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.cpp	2011-09-29 12:59:17 UTC (rev 96323)
@@ -484,19 +484,17 @@
     return false;
 }
 
-void InspectorPageAgent::searchInResource(ErrorString*, const String& frameId, const String& url, const String& query, RefPtr<InspectorArray>* object)
+void InspectorPageAgent::searchInResource(ErrorString*, const String& frameId, const String& url, const String& query, RefPtr<InspectorArray>* results)
 {
-    RefPtr<InspectorArray> result = InspectorArray::create();
+    *results = InspectorArray::create();
 
     Frame* frame = frameForId(frameId);
     KURL kurl(ParsedURLString, url);
 
     FrameLoader* frameLoader = frame ? frame->loader() : 0;
     DocumentLoader* loader = frameLoader ? frameLoader->documentLoader() : 0;
-    if (!loader) {
-        *object = result;
+    if (!loader)
         return;
-    }
 
     String content;
     bool success = false;
@@ -508,13 +506,10 @@
         success = textContentForCachedResource(resource, &content);
     }
 
-    if (!success) {
-        *object = result;
+    if (!success)
         return;
-    }
 
-    result = ContentSearchUtils::searchInTextByLines(query, content);
-    *object = result;
+    *results = ContentSearchUtils::searchInTextByLines(query, content);
 }
 
 static PassRefPtr<InspectorObject> buildObjectForSearchResult(const String& frameId, const String& url, int matchesCount)
@@ -527,9 +522,9 @@
     return result;
 }
 
-void InspectorPageAgent::searchInResources(ErrorString*, const String& text, const bool* const optionalCaseSensitive, const bool* const optionalIsRegex, RefPtr<InspectorArray>* object)
+void InspectorPageAgent::searchInResources(ErrorString*, const String& text, const bool* const optionalCaseSensitive, const bool* const optionalIsRegex, RefPtr<InspectorArray>* results)
 {
-    RefPtr<InspectorArray> result = InspectorArray::create();
+    RefPtr<InspectorArray> searchResults = InspectorArray::create();
 
     bool isRegex = optionalIsRegex ? *optionalIsRegex : false;
     bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false;
@@ -543,17 +538,17 @@
             if (textContentForCachedResource(cachedResource, &content)) {
                 int matchesCount = ContentSearchUtils::countRegularExpressionMatches(regex, content);
                 if (matchesCount)
-                    result->pushValue(buildObjectForSearchResult(frameId(frame), cachedResource->url(), matchesCount));
+                    searchResults->pushValue(buildObjectForSearchResult(frameId(frame), cachedResource->url(), matchesCount));
             }
         }
         if (mainResourceContent(frame, false, &content)) {
             int matchesCount = ContentSearchUtils::countRegularExpressionMatches(regex, content);
             if (matchesCount)
-                result->pushValue(buildObjectForSearchResult(frameId(frame), frame->document()->url(), matchesCount));
+                searchResults->pushValue(buildObjectForSearchResult(frameId(frame), frame->document()->url(), matchesCount));
         }
     }
 
-    *object = result;
+    *results = searchResults;
 }
 
 void InspectorPageAgent::didClearWindowObjectInWorld(Frame* frame, DOMWrapperWorld* world)

Modified: trunk/Source/WebCore/inspector/front-end/Resource.js (96322 => 96323)


--- trunk/Source/WebCore/inspector/front-end/Resource.js	2011-09-29 12:29:13 UTC (rev 96322)
+++ trunk/Source/WebCore/inspector/front-end/Resource.js	2011-09-29 12:59:17 UTC (rev 96323)
@@ -869,7 +869,12 @@
 
     searchInContent: function(query, callback)
     {
-        PageAgent.searchInResource(query, callback);
+        function callbackWrapper(error, searchMatches)
+        {
+            callback(searchMatches || []);
+        }
+
+        PageAgent.searchInResource(this.frameId, this.url, query, callbackWrapper);
     },
 
     populateImageSource: function(image)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to