Web Inspector: Resource content is not loaded if Resource.requestContent method is...
authorvsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Jun 2012 09:32:59 +0000 (09:32 +0000)
committervsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Jun 2012 09:32:59 +0000 (09:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90153

Reviewed by Yury Semikhatsky.

Source/WebCore:

Test: http/tests/inspector/resource-tree/resource-request-content-while-loading.html

* inspector/front-end/NetworkRequest.js:
* inspector/front-end/Resource.js:
(WebInspector.Resource):
(WebInspector.Resource.prototype.requestContent):
(WebInspector.Resource.prototype._requestFinished):

LayoutTests:

Resource.requestContent() now checks that request (if there is one) was already loaded before requesting content from PageAgent.
Drive-by: Removed unneeded legacy request._resource field.
* http/tests/inspector/network/network-request-revision-content.html:
* http/tests/inspector/resource-tree/resource-request-content-while-loading-expected.txt: Added.
* http/tests/inspector/resource-tree/resource-request-content-while-loading.html: Added.
* http/tests/inspector/resources-test.js:
(initialize_ResourceTest.InspectorTest.runAfterResourcesAreFinished.checkResources):
(initialize_ResourceTest.InspectorTest.runAfterResourcesAreFinished):
(initialize_ResourceTest.InspectorTest.showResource.showResourceCallback):
(initialize_ResourceTest.InspectorTest.showResource):
(initialize_ResourceTest.InspectorTest.resourceMatchingURL.visit):
(initialize_ResourceTest.InspectorTest.resourceMatchingURL):
(initialize_ResourceTest):
* inspector/debugger/raw-source-code.html:

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

LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/network/network-request-revision-content.html
LayoutTests/http/tests/inspector/resource-tree/resource-request-content-while-loading-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/inspector/resource-tree/resource-request-content-while-loading.html [new file with mode: 0644]
LayoutTests/http/tests/inspector/resources-test.js
LayoutTests/inspector/debugger/raw-source-code.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/NetworkRequest.js
Source/WebCore/inspector/front-end/Resource.js

index 26bff64..b4ce8ff 100644 (file)
@@ -1,3 +1,26 @@
+2012-06-28  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: Resource content is not loaded if Resource.requestContent method is called before network request is finished.
+        https://bugs.webkit.org/show_bug.cgi?id=90153
+
+        Reviewed by Yury Semikhatsky.
+
+        Resource.requestContent() now checks that request (if there is one) was already loaded before requesting content from PageAgent.
+        Drive-by: Removed unneeded legacy request._resource field.
+
+        * http/tests/inspector/network/network-request-revision-content.html:
+        * http/tests/inspector/resource-tree/resource-request-content-while-loading-expected.txt: Added.
+        * http/tests/inspector/resource-tree/resource-request-content-while-loading.html: Added.
+        * http/tests/inspector/resources-test.js:
+        (initialize_ResourceTest.InspectorTest.runAfterResourcesAreFinished.checkResources):
+        (initialize_ResourceTest.InspectorTest.runAfterResourcesAreFinished):
+        (initialize_ResourceTest.InspectorTest.showResource.showResourceCallback):
+        (initialize_ResourceTest.InspectorTest.showResource):
+        (initialize_ResourceTest.InspectorTest.resourceMatchingURL.visit):
+        (initialize_ResourceTest.InspectorTest.resourceMatchingURL):
+        (initialize_ResourceTest):
+        * inspector/debugger/raw-source-code.html:
+
 2012-06-27  Vsevolod Vlasov  <vsevik@chromium.org>
 
         Web Inspector: IDBObjectStore.autoIncrement flag not exposed
index f584ead..8e3d627 100644 (file)
@@ -18,7 +18,7 @@ function test()
     function step2(msg)
     {
         var request = WebInspector.panels.network.requests[WebInspector.panels.network.requests.length - 1];
-        resource = request.resource();
+        resource = WebInspector.resourceForURL(request.url);
         resource.addRevision("");
         resource.history[0].requestContent(step3);
     }
diff --git a/LayoutTests/http/tests/inspector/resource-tree/resource-request-content-while-loading-expected.txt b/LayoutTests/http/tests/inspector/resource-tree/resource-request-content-while-loading-expected.txt
new file mode 100644 (file)
index 0000000..7e2c379
--- /dev/null
@@ -0,0 +1,9 @@
+Tests resource content is correctly loaded if Resource.requestContent was called before network request was finished.
+
+Bug 90153
+Resource url: http://127.0.0.1:8000/inspector/resource-tree/resources/styles-initial.css
+Resource content: html {
+    background-color: green;
+}
+
+
diff --git a/LayoutTests/http/tests/inspector/resource-tree/resource-request-content-while-loading.html b/LayoutTests/http/tests/inspector/resource-tree/resource-request-content-while-loading.html
new file mode 100644 (file)
index 0000000..770d4b9
--- /dev/null
@@ -0,0 +1,45 @@
+<html>
+<head>
+<script src="../inspector-test.js"></script>
+<script src="../resources-test.js"></script>
+<script src="resource-tree-test.js"></script>
+<link rel="stylesheet" href="resources/styles-initial.css">
+<script>
+function test()
+{
+      var contentWasRequested = false;
+      var resource;
+      InspectorTest.addSniffer(WebInspector.ResourceTreeFrame.prototype, "_addRequest", requestAdded, true);
+      InspectorTest.addSniffer(PageAgent, "getResourceContent", pageAgentGetResourceContentCalled, true);
+      InspectorTest.reloadPage(function() {});
+
+      function requestAdded(request)
+      {
+          if (request.url.indexOf("styles-initial") === -1)
+              return;
+          resource = InspectorTest.resourceMatchingURL("styles-initial");
+          if (!resource || !resource.request || contentWasRequested)
+              return;
+          resource.requestContent(contentLoaded);
+          contentWasRequested = true;
+      }
+
+      function pageAgentGetResourceContentCalled()
+      {
+          InspectorTest.assertTrue(resource.request.finished);
+      }
+
+      function contentLoaded(content)
+      {
+          InspectorTest.addResult("Resource url: " + resource.url);
+          InspectorTest.addResult("Resource content: " + content);
+          InspectorTest.completeTest();
+      }
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>Tests resource content is correctly loaded if Resource.requestContent was called before network request was finished.</p>
+<a href="https://bugs.webkit.org/show_bug.cgi?id=90153">Bug 90153</a>
+</body>
+</html>
index e623e30..9c09734 100644 (file)
@@ -41,13 +41,10 @@ InspectorTest.runAfterResourcesAreFinished = function(resourceURLs, callback)
 
     function checkResources()
     {
-        WebInspector.resourceTreeModel.forAllResources(visit);
-        function visit(resource)
-        {
-            for (url in resourceURLsMap) {
-                if (resource.url.indexOf(url) !== -1)
-                    delete resourceURLsMap[url];
-            }
+        for (url in resourceURLsMap) {
+            var resource = InspectorTest.resourceMatchingURL(url);
+            if (resource)
+                delete resourceURLsMap[url];
         }
         if (!Object.keys(resourceURLsMap).length) {
             WebInspector.resourceTreeModel.removeEventListener(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, checkResources);
@@ -72,21 +69,31 @@ InspectorTest.showResource = function(resourceURL, callback)
 
     function showResourceCallback()
     {
-        WebInspector.resourceTreeModel.forAllResources(visit);
-        function visit(resource)
-        {
-            if (resource.url.indexOf(resourceURL) !== -1) {
-                WebInspector.panels.resources.showResource(resource, 1);
-                var sourceFrame = WebInspector.panels.resources._resourceViewForResource(resource);
-                if (sourceFrame.loaded)
-                    callbackWrapper(sourceFrame);
-                else
-                    InspectorTest.addSniffer(sourceFrame, "onTextViewerContentLoaded", callbackWrapper.bind(null, sourceFrame));
-                return true;
-            }
-        }
+        var resource = InspectorTest.resourceMatchingURL(resourceURL);
+        if (!resource)
+            return;
+        WebInspector.panels.resources.showResource(resource, 1);
+        var sourceFrame = WebInspector.panels.resources._resourceViewForResource(resource);
+        if (sourceFrame.loaded)
+            callbackWrapper(sourceFrame);
+        else
+            InspectorTest.addSniffer(sourceFrame, "onTextViewerContentLoaded", callbackWrapper.bind(null, sourceFrame));
     }
     InspectorTest.runAfterResourcesAreFinished([resourceURL], showResourceCallback);
 }
 
+InspectorTest.resourceMatchingURL = function(resourceURL, callback)
+{
+    var result = null;
+    WebInspector.resourceTreeModel.forAllResources(visit);
+    function visit(resource)
+    {
+        if (resource.url.indexOf(resourceURL) !== -1) {
+            result = resource;
+            return true;
+        }
+    }
+    return result;
+}
+
 }
index f7b538c..4532b8e 100644 (file)
@@ -59,7 +59,7 @@ function test()
     {
         var resource = null;
         if (request && request.finished) {
-            resource = request.resource();
+            resource = WebInspector.resourceForURL(request.url)
             request = null;
         }
         var rawSourceCode = new WebInspector.RawSourceCode("id", script, resource, request, compilerSourceMapping);
index 57a8a8e..e663f7a 100644 (file)
@@ -1,3 +1,18 @@
+2012-06-28  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: Resource content is not loaded if Resource.requestContent method is called before network request is finished.
+        https://bugs.webkit.org/show_bug.cgi?id=90153
+
+        Reviewed by Yury Semikhatsky.
+
+        Test: http/tests/inspector/resource-tree/resource-request-content-while-loading.html
+
+        * inspector/front-end/NetworkRequest.js:
+        * inspector/front-end/Resource.js:
+        (WebInspector.Resource):
+        (WebInspector.Resource.prototype.requestContent):
+        (WebInspector.Resource.prototype._requestFinished):
+
 2012-06-29  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r121529.
index 7862850..7f8995a 100644 (file)
@@ -802,22 +802,6 @@ WebInspector.NetworkRequest.prototype = {
     },
 
     /**
-     * @param {WebInspector.Resource} resource
-     */
-    setResource: function(resource)
-    {
-        this._resource = resource;
-    },
-
-    /**
-     * @return {WebInspector.Resource}
-     */
-    resource: function()
-    {
-        return this._resource;
-    },
-
-    /**
      * @return {Object}
      */
     frames: function()
index 0b4b945..99836c2 100644 (file)
@@ -42,8 +42,6 @@
 WebInspector.Resource = function(request, url, documentURL, frameId, loaderId, type, mimeType, isHidden)
 {
     this._request = request;
-    if (this._request)
-        this._request.setResource(this);
     this.url = url;
     this._documentURL = documentURL;
     this._frameId = frameId;
@@ -56,6 +54,8 @@ WebInspector.Resource = function(request, url, documentURL, frameId, loaderId, t
     /** @type {?string} */ this._content;
     /** @type {boolean} */ this._contentEncoded;
     this._pendingContentCallbacks = [];
+    if (this._request && !this._request.finished)
+        this._request.addEventListener(WebInspector.NetworkRequest.Events.FinishedLoading, this._requestFinished, this);
 }
 
 WebInspector.Resource._domainModelBindings = [];
@@ -400,7 +400,8 @@ WebInspector.Resource.prototype = {
         }
 
         this._pendingContentCallbacks.push(callback);
-        this._innerRequestContent();
+        if (!this._request || this._request.finished)
+            this._innerRequestContent();
     },
 
     canonicalMimeType: function()
@@ -457,6 +458,15 @@ WebInspector.Resource.prototype = {
         return "data:" + this.mimeType + (this._contentEncoded ? ";base64," : ",") + this._content;
     },
 
+
+    _requestFinished: function()
+    {
+        this._request.removeEventListener(WebInspector.NetworkRequest.Events.FinishedLoading, this._requestFinished, this);
+        if (this._pendingContentCallbacks.length)
+            this._innerRequestContent();
+    },
+
+
     _innerRequestContent: function()
     {
         if (this._contentRequested)