2011-01-17 Andrey Kosyakov <caseq@chromium.org>
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Jan 2011 17:10:32 +0000 (17:10 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Jan 2011 17:10:32 +0000 (17:10 +0000)
        Reviewed by Pavel Feldman.

        Web Inspector: [Extensions API] webInspector.resources.onFinished is not fired for redirected resources
        Make resource start/finish hanlding more consistent.
        https://bugs.webkit.org/show_bug.cgi?id=52452

        * inspector/front-end/AuditLauncherView.js: Ignore WebSocket resources when displaying progress indicator
        (WebInspector.AuditLauncherView.prototype._resetResourceCount):
        (WebInspector.AuditLauncherView.prototype.resourceStarted):
        (WebInspector.AuditLauncherView.prototype.resourceFinished):
        * inspector/front-end/NetworkManager.js:
        (WebInspector.NetworkManager): Factor out resource start/finish logic to _startResource()/_finishResource()
        (WebInspector.NetworkManager.prototype.identifierForInitialRequest):
        (WebInspector.NetworkManager.prototype.willSendRequest):
        (WebInspector.NetworkManager.prototype.markResourceAsCached):
        (WebInspector.NetworkManager.prototype.didReceiveResponse):
        (WebInspector.NetworkManager.prototype.didReceiveContentLength):
        (WebInspector.NetworkManager.prototype.didFinishLoading):
        (WebInspector.NetworkManager.prototype.didFailLoading):
        (WebInspector.NetworkManager.prototype.didLoadResourceFromMemoryCache):
        (WebInspector.NetworkManager.prototype.didCreateWebSocket):
        (WebInspector.NetworkManager.prototype.willSendWebSocketHandshakeRequest):
        (WebInspector.NetworkManager.prototype.didReceiveWebSocketHandshakeResponse):
        (WebInspector.NetworkManager.prototype.didCloseWebSocket):
        (WebInspector.NetworkManager.prototype._appendRedirect):
        (WebInspector.NetworkManager.prototype._startResource):
        (WebInspector.NetworkManager.prototype._finishResource):

2011-01-17  Andrey Kosyakov  <caseq@chromium.org>

        Reviewed by Pavel Feldman.

        Web Inspector: [Extensions API] webInspector.resources.onFinished is not fired for redirected resources
        Added test for finished event being sent for redirected resources.
        https://bugs.webkit.org/show_bug.cgi?id=52452

        * http/tests/inspector/extensions-resources-redirect-expected.txt:
        * http/tests/inspector/extensions-resources-redirect.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@75950 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/extensions-resources-redirect-expected.txt
LayoutTests/http/tests/inspector/extensions-resources-redirect.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/AuditLauncherView.js
Source/WebCore/inspector/front-end/NetworkManager.js

index ed9e7bf..4919965 100644 (file)
@@ -1,3 +1,14 @@
+2011-01-17  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: [Extensions API] webInspector.resources.onFinished is not fired for redirected resources
+        Added test for finished event being sent for redirected resources.
+        https://bugs.webkit.org/show_bug.cgi?id=52452
+
+        * http/tests/inspector/extensions-resources-redirect-expected.txt:
+        * http/tests/inspector/extensions-resources-redirect.html:
+
 2011-01-17  Pavel Feldman  <pfeldman@chromium.org>
 
         Not reviewed: first timeline-network-resource flakiness.
index 17a8bc4..c1903de 100644 (file)
@@ -5,7 +5,11 @@ Started extension.
 
 Running tests...
 RUNNING TEST: extension_testGetRedirectResourceContent
+
 content: undefined, encoding: undefined
+RUNNING TEST: extension_testRedirectResourceFinished
+Finished resource: http://127.0.0.1:8000/loading/resources/redirect-methods-result.php?redirected=true
+Finished resource: http://127.0.0.1:8000/loading/resources/redirect-methods-result.php?status=302
 RUNNING TEST: extension_testRedirectResourcesInHAR
 Resources in HAR:
 http://127.0.0.1:8000/inspector/extensions-resources-redirect.html
@@ -13,6 +17,8 @@ http://127.0.0.1:8000/inspector/extensions-resources-test.js
 http://127.0.0.1:8000/inspector/extensions-test.js
 http://127.0.0.1:8000/inspector/inspector-test2.js
 http://127.0.0.1:8000/loading/resources/redirect-methods-result.php?redirected=true
+http://127.0.0.1:8000/loading/resources/redirect-methods-result.php?redirected=true
+http://127.0.0.1:8000/loading/resources/redirect-methods-result.php?status=302
 http://127.0.0.1:8000/loading/resources/redirect-methods-result.php?status=302
 All tests done.
 
index 4b64989..8e831f1 100755 (executable)
@@ -58,13 +58,28 @@ function extension_testRedirectResourcesInHAR(nextTest)
     extension_doRequest(onFinished);
 }
 
+function extension_testRedirectResourceFinished(nextTest)
+{
+    var finishedCount = 0;
+    function onFinished(resource)
+    {
+        output("Finished resource: " + resource.request.url);
+        if (++finishedCount === 2) {
+            webInspector.resources.onFinished.removeListener(onFinished);
+            nextTest();
+        }
+    }
+    webInspector.resources.onFinished.addListener(onFinished);
+    webInspector.inspectedWindow.eval("doRequest(true)");
+}
+
 var requestDone = false;
 
-function doRequest()
+function doRequest(force)
 {
     // Only do request once per test suite, to make tests independent on each other.
     // Returns true iff request is alredy done (so the caller shouldn't wait for onFinished).
-    if (requestDone)
+    if (requestDone && !force)
         return true;
     requestDone = true;
     // We can't use XHR here -- the content for XHRs is pushed from back-end.
index b29fe48..553405a 100644 (file)
@@ -1,3 +1,33 @@
+2011-01-17  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: [Extensions API] webInspector.resources.onFinished is not fired for redirected resources
+        Make resource start/finish hanlding more consistent.
+        https://bugs.webkit.org/show_bug.cgi?id=52452
+
+        * inspector/front-end/AuditLauncherView.js: Ignore WebSocket resources when displaying progress indicator
+        (WebInspector.AuditLauncherView.prototype._resetResourceCount):
+        (WebInspector.AuditLauncherView.prototype.resourceStarted):
+        (WebInspector.AuditLauncherView.prototype.resourceFinished):
+        * inspector/front-end/NetworkManager.js:
+        (WebInspector.NetworkManager): Factor out resource start/finish logic to _startResource()/_finishResource()
+        (WebInspector.NetworkManager.prototype.identifierForInitialRequest):
+        (WebInspector.NetworkManager.prototype.willSendRequest):
+        (WebInspector.NetworkManager.prototype.markResourceAsCached):
+        (WebInspector.NetworkManager.prototype.didReceiveResponse):
+        (WebInspector.NetworkManager.prototype.didReceiveContentLength):
+        (WebInspector.NetworkManager.prototype.didFinishLoading):
+        (WebInspector.NetworkManager.prototype.didFailLoading):
+        (WebInspector.NetworkManager.prototype.didLoadResourceFromMemoryCache):
+        (WebInspector.NetworkManager.prototype.didCreateWebSocket):
+        (WebInspector.NetworkManager.prototype.willSendWebSocketHandshakeRequest):
+        (WebInspector.NetworkManager.prototype.didReceiveWebSocketHandshakeResponse):
+        (WebInspector.NetworkManager.prototype.didCloseWebSocket):
+        (WebInspector.NetworkManager.prototype._appendRedirect):
+        (WebInspector.NetworkManager.prototype._startResource):
+        (WebInspector.NetworkManager.prototype._finishResource):
+
 2011-01-17  Pavel Feldman  <pfeldman@chromium.org>
 
         Reviewed by Yury Semikhatsky.
index 3ec4ba2..c140589 100644 (file)
@@ -82,20 +82,21 @@ WebInspector.AuditLauncherView.prototype = {
     _resetResourceCount: function()
     {
         this.loadedResources = 0;
-
-        // We never receive a resourceStarted notification for the main resource
-        // (see InspectorController.willSendRequest())
-        this.totalResources = 1;
+        this.totalResources = 0;
     },
 
     resourceStarted: function(resource)
     {
-        ++this.totalResources;
+        // Ignore long-living WebSockets for the sake of progress indicator, as we won't be waiting them anyway.
+        if (resource.type !== WebInspector.Resource.Type.WebSocket)
+            ++this.totalResources;
     },
 
     resourceFinished: function(resource)
     {
-        ++this.loadedResources;
+        // See resorceStarted for details.
+        if (resource.type !== WebInspector.Resource.Type.WebSocket)
+            ++this.loadedResources;
     },
 
     reset: function()
index 3942db6..a657377 100644 (file)
@@ -30,7 +30,7 @@
 
 WebInspector.NetworkManager = function(resourceTreeModel)
 {
-    this._resourcesById = {};
+    this._inflightResources = {};
     this._resourceTreeModel = resourceTreeModel;
     this._lastIdentifierForCachedResource = 0;
     InspectorBackend.registerDomainDispatcher("Network", this);
@@ -96,16 +96,12 @@ WebInspector.NetworkManager.prototype = {
 
     identifierForInitialRequest: function(identifier, url, loader, callStack)
     {
-        var resource = this._resourceTreeModel.createResource(identifier, url, loader, callStack);
-        this._resourcesById[identifier] = resource;
-
-        WebInspector.panels.network.appendResource(resource);
-        WebInspector.panels.audits.resourceStarted(resource);
+        this._startResource(this._resourceTreeModel.createResource(identifier, url, loader, callStack));
     },
 
     willSendRequest: function(identifier, time, request, redirectResponse)
     {
-        var resource = this._resourcesById[identifier];
+        var resource = this._inflightResources[identifier];
         if (!resource)
             return;
 
@@ -113,24 +109,22 @@ WebInspector.NetworkManager.prototype = {
         // See http/tests/misc/will-send-request-returns-null-on-redirect.html
         var isRedirect = !redirectResponse.isNull && request.url.length;
         if (isRedirect) {
-            resource.endTime = time;
             this.didReceiveResponse(identifier, time, "Other", redirectResponse);
-            resource = this._appendRedirect(resource.identifier, request.url);
+            resource = this._appendRedirect(resource.identifier, time, request.url);
         }
 
         WebInspector.NetworkManager.updateResourceWithRequest(resource, request);
         resource.startTime = time;
 
-        if (isRedirect) {
-            WebInspector.panels.network.appendResource(resource);
-            WebInspector.panels.audits.resourceStarted(resource);
-        } else
+        if (isRedirect)
+            this._startResource(resource);
+        else
             WebInspector.panels.network.refreshResource(resource);
     },
 
     markResourceAsCached: function(identifier)
     {
-        var resource = this._resourcesById[identifier];
+        var resource = this._inflightResources[identifier];
         if (!resource)
             return;
 
@@ -140,7 +134,7 @@ WebInspector.NetworkManager.prototype = {
 
     didReceiveResponse: function(identifier, time, resourceType, response)
     {
-        var resource = this._resourcesById[identifier];
+        var resource = this._inflightResources[identifier];
         if (!resource)
             return;
 
@@ -155,7 +149,7 @@ WebInspector.NetworkManager.prototype = {
 
     didReceiveContentLength: function(identifier, time, lengthReceived)
     {
-        var resource = this._resourcesById[identifier];
+        var resource = this._inflightResources[identifier];
         if (!resource)
             return;
 
@@ -167,34 +161,22 @@ WebInspector.NetworkManager.prototype = {
 
     didFinishLoading: function(identifier, finishTime)
     {
-        var resource = this._resourcesById[identifier];
+        var resource = this._inflightResources[identifier];
         if (!resource)
             return;
 
-        resource.endTime = finishTime;
-        resource.finished = true;
-
-        WebInspector.panels.network.refreshResource(resource);
-        WebInspector.panels.audits.resourceFinished(resource);
-        WebInspector.extensionServer.notifyResourceFinished(resource);
-        delete this._resourcesById[identifier];
+        this._finishResource(resource, finishTime);
     },
 
     didFailLoading: function(identifier, time, localizedDescription)
     {
-        var resource = this._resourcesById[identifier];
+        var resource = this._inflightResources[identifier];
         if (!resource)
             return;
 
         resource.failed = true;
         resource.localizedFailDescription = localizedDescription;
-        resource.finished = true;
-        resource.endTime = time;
-
-        WebInspector.panels.network.refreshResource(resource);
-        WebInspector.panels.audits.resourceFinished(resource);
-        WebInspector.extensionServer.notifyResourceFinished(resource);
-        delete this._resourcesById[identifier];
+        this._finishResource(resource, time);
     },
 
     didLoadResourceFromMemoryCache: function(time, cachedResource)
@@ -203,12 +185,9 @@ WebInspector.NetworkManager.prototype = {
         WebInspector.NetworkManager.updateResourceWithCachedResource(resource, cachedResource);
         resource.cached = true;
         resource.requestMethod = "GET";
-        resource.startTime = resource.responseReceivedTime = resource.endTime = time;
-        resource.finished = true;
-
-        WebInspector.panels.network.appendResource(resource);
-        WebInspector.panels.audits.resourceStarted(resource);
-        WebInspector.panels.audits.resourceFinished(resource);
+        this._startResource(resource);
+        resource.startTime = resource.responseReceivedTime = time;
+        this._finishResource(resource, time);
         this._resourceTreeModel.addResourceToFrame(resource.loader.frameId, resource);
     },
 
@@ -245,14 +224,13 @@ WebInspector.NetworkManager.prototype = {
     didCreateWebSocket: function(identifier, requestURL)
     {
         var resource = this._resourceTreeModel.createResource(identifier, requestURL);
-        this._resourcesById[identifier] = resource;
         resource.type = WebInspector.Resource.Type.WebSocket;
-        WebInspector.panels.network.appendResource(resource);
+        this._startResource(resource);
     },
 
     willSendWebSocketHandshakeRequest: function(identifier, time, request)
     {
-        var resource = this._resourcesById[identifier];
+        var resource = this._inflightResources[identifier];
         if (!resource)
             return;
 
@@ -266,7 +244,7 @@ WebInspector.NetworkManager.prototype = {
 
     didReceiveWebSocketHandshakeResponse: function(identifier, time, response)
     {
-        var resource = this._resourcesById[identifier];
+        var resource = this._inflightResources[identifier];
         if (!resource)
             return;
 
@@ -281,21 +259,19 @@ WebInspector.NetworkManager.prototype = {
 
     didCloseWebSocket: function(identifier, time)
     {
-        var resource = this._resourcesById[identifier];
+        var resource = this._inflightResources[identifier];
         if (!resource)
             return;
-        resource.endTime = time;
-
-        WebInspector.panels.network.refreshResource(resource);
+        this._finishResource(resource, time);
     },
 
-    _appendRedirect: function(identifier, redirectURL)
+    _appendRedirect: function(identifier, time, redirectURL)
     {
-        var originalResource = this._resourcesById[identifier];
+        var originalResource = this._inflightResources[identifier];
         var previousRedirects = originalResource.redirects || [];
-        originalResource.finished = true;
         originalResource.identifier = "redirected:" + identifier + "." + previousRedirects.length;
         delete originalResource.redirects;
+        this._finishResource(originalResource, time);
         // We bound resource early, but it happened to be a redirect and won't make it through to
         // the resource tree -- so unbind it.
         // FIXME: we should bind upon adding to the tree only (encapsulated into ResourceTreeModel),
@@ -304,7 +280,23 @@ WebInspector.NetworkManager.prototype = {
         
         var newResource = this._resourceTreeModel.createResource(identifier, redirectURL, originalResource.loader, originalResource.stackTrace);
         newResource.redirects = previousRedirects.concat(originalResource);
-        this._resourcesById[identifier] = newResource;
         return newResource;
+    },
+
+    _startResource: function(resource, skipRefresh)
+    {
+        this._inflightResources[resource.identifier] = resource;
+        WebInspector.panels.network.appendResource(resource, skipRefresh);
+        WebInspector.panels.audits.resourceStarted(resource);
+    },
+
+    _finishResource: function(resource, finishTime)
+    {
+        resource.endTime = finishTime;
+        resource.finished = true;
+        WebInspector.panels.network.refreshResource(resource);
+        WebInspector.panels.audits.resourceFinished(resource);
+        WebInspector.extensionServer.notifyResourceFinished(resource);
+        delete this._inflightResources[resource.identifier];
     }
 }