Web Inspector: No response body available for cached resource requests with error...
authorvsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Apr 2012 12:08:39 +0000 (12:08 +0000)
committervsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Apr 2012 12:08:39 +0000 (12:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=84265

Source/WebCore:

Reviewed by Pavel Feldman.

InspectorResourceAgent now saves failed subresource request response body in its cache.
Saved data is shown on front-end.

Test: http/tests/inspector/network/network-image-404.html

* inspector/InspectorResourceAgent.cpp:
(WebCore::InspectorResourceAgent::didReceiveData):
* inspector/NetworkResourcesData.cpp:
(WebCore::NetworkResourcesData::responseReceived):
(WebCore::NetworkResourcesData::httpStatusCode):
(WebCore):
* inspector/NetworkResourcesData.h:
(WebCore::NetworkResourcesData::ResourceData::httpStatusCode):
(WebCore::NetworkResourcesData::ResourceData::setHTTPStatusCode):
(ResourceData):
(NetworkResourcesData):
* inspector/front-end/RequestView.js:
(WebInspector.RequestView.hasTextContent):

LayoutTests:

* http/tests/inspector/network/network-image-404-expected.txt: Added.
* http/tests/inspector/network/network-image-404.html: Added.
* http/tests/inspector/network/resources/404.php: Added.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/network/network-image-404-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/inspector/network/network-image-404.html [new file with mode: 0644]
LayoutTests/http/tests/inspector/network/resources/404.php [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorResourceAgent.cpp
Source/WebCore/inspector/NetworkResourcesData.cpp
Source/WebCore/inspector/NetworkResourcesData.h
Source/WebCore/inspector/front-end/RequestView.js

index 311a89c..61ebdab 100644 (file)
@@ -1,3 +1,12 @@
+2012-04-18  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: No response body available for cached resource requests with error status codes.
+        https://bugs.webkit.org/show_bug.cgi?id=84265
+
+        * http/tests/inspector/network/network-image-404-expected.txt: Added.
+        * http/tests/inspector/network/network-image-404.html: Added.
+        * http/tests/inspector/network/resources/404.php: Added.
+
 2012-04-19  Ádám Kallai  <kadam@inf.u-szeged.hu>
 
         [Qt] Gardening. Skip failing reftest after 114574.
diff --git a/LayoutTests/http/tests/inspector/network/network-image-404-expected.txt b/LayoutTests/http/tests/inspector/network/network-image-404-expected.txt
new file mode 100644 (file)
index 0000000..e3f04e6
--- /dev/null
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: line 15: Done.
+Tests content is available for failed image request.
+
+Bug 84265
+http://127.0.0.1:8000/inspector/network/resources/404.php
+resource.type: image
+resource.content before requesting content: undefined
+resource.content after requesting content: 404 - resource was not found.
+
diff --git a/LayoutTests/http/tests/inspector/network/network-image-404.html b/LayoutTests/http/tests/inspector/network/network-image-404.html
new file mode 100644 (file)
index 0000000..b287580
--- /dev/null
@@ -0,0 +1,54 @@
+<html>
+<head>
+<script src="../inspector-test.js"></script>
+<script src="../network-test.js"></script>
+<script>
+function loadData()
+{
+    var image = new Image();
+    image.src = "resources/404.php";
+    image.onerror = resourceLoaded;
+}
+
+function resourceLoaded()
+{
+    console.log("Done.");
+}
+
+function test()
+{
+    // Since this test could be run together with other inspector backend cache
+    // tests, we need to reset size limits to default ones.
+    InspectorTest.resetInspectorResourcesData(step1);
+
+    function step1()
+    {
+        InspectorTest.addConsoleSniffer(step2);
+        InspectorTest.evaluateInPage("loadData()");
+    }
+
+    function step2()
+    {
+        var request1 = WebInspector.panels.network.requests[WebInspector.panels.network.requests.length - 1];
+        InspectorTest.addResult(request1.url);
+        InspectorTest.addResult("resource.type: " + request1.type);
+        InspectorTest.addResult("resource.content before requesting content: " + request1.content);
+        InspectorTest.assertTrue(!request1.failed, "Resource loading failed.");
+        request1.requestContent(step3);
+    }
+
+    function step3()
+    {
+        var request1 = WebInspector.panels.network.requests[WebInspector.panels.network.requests.length - 1];
+        InspectorTest.addResult("resource.content after requesting content: " + request1.content);
+
+        InspectorTest.completeTest();
+    }
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>Tests content is available for failed image request.</p>
+<a href="https://bugs.webkit.org/show_bug.cgi?id=84265">Bug 84265</a>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/inspector/network/resources/404.php b/LayoutTests/http/tests/inspector/network/resources/404.php
new file mode 100644 (file)
index 0000000..f1376ce
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+    header("HTTP/1.0 404 Not Found");
+    echo("404 - resource was not found.");
+?>
index fd759b6..9b77188 100644 (file)
@@ -1,3 +1,29 @@
+2012-04-18  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: No response body available for cached resource requests with error status codes.
+        https://bugs.webkit.org/show_bug.cgi?id=84265
+
+        Reviewed by Pavel Feldman.
+
+        InspectorResourceAgent now saves failed subresource request response body in its cache.
+        Saved data is shown on front-end.
+
+        Test: http/tests/inspector/network/network-image-404.html
+
+        * inspector/InspectorResourceAgent.cpp:
+        (WebCore::InspectorResourceAgent::didReceiveData):
+        * inspector/NetworkResourcesData.cpp:
+        (WebCore::NetworkResourcesData::responseReceived):
+        (WebCore::NetworkResourcesData::httpStatusCode):
+        (WebCore):
+        * inspector/NetworkResourcesData.h:
+        (WebCore::NetworkResourcesData::ResourceData::httpStatusCode):
+        (WebCore::NetworkResourcesData::ResourceData::setHTTPStatusCode):
+        (ResourceData):
+        (NetworkResourcesData):
+        * inspector/front-end/RequestView.js:
+        (WebInspector.RequestView.hasTextContent):
+
 2012-04-19  Pavel Feldman  <pfeldman@chromium.org>
 
         Web Inspector: reuse ParsedUrl in the UISourceCode
index 0d0c793..44a54d9 100644 (file)
@@ -276,10 +276,15 @@ void InspectorResourceAgent::didReceiveResponse(unsigned long identifier, Docume
         didReceiveData(identifier, 0, cachedResourceSize, 0);
 }
 
+static bool isErrorStatusCode(int statusCode)
+{
+    return statusCode >= 400;
+}
+
 void InspectorResourceAgent::didReceiveData(unsigned long identifier, const char* data, int dataLength, int encodedDataLength)
 {
     String requestId = IdentifiersFactory::requestId(identifier);
-    if (data && m_resourcesData->resourceType(requestId) == InspectorPageAgent::OtherResource)
+    if (data && (m_resourcesData->resourceType(requestId) == InspectorPageAgent::OtherResource || (m_resourcesData->resourceType(requestId) != InspectorPageAgent::DocumentResource && isErrorStatusCode(m_resourcesData->httpStatusCode(requestId)))))
         m_resourcesData->maybeAddResourceData(requestId, data, dataLength);
 
     m_frontend->dataReceived(requestId, currentTime(), dataLength, encodedDataLength);
index 52ebaf3..a383ab0 100644 (file)
@@ -147,6 +147,7 @@ void NetworkResourcesData::responseReceived(const String& requestId, const Strin
     resourceData->setFrameId(frameId);
     resourceData->setUrl(response.url());
     resourceData->setDecoder(createOtherResourceTextDecoder(response.mimeType(), response.textEncodingName()));
+    resourceData->setHTTPStatusCode(response.httpStatusCode());
 }
 
 void NetworkResourcesData::setResourceType(const String& requestId, InspectorPageAgent::ResourceType type)
@@ -165,6 +166,14 @@ InspectorPageAgent::ResourceType NetworkResourcesData::resourceType(const String
     return resourceData->type();
 }
 
+int NetworkResourcesData::httpStatusCode(const String& requestId)
+{
+    ResourceData* resourceData = m_requestIdToResourceDataMap.get(requestId);
+    if (!resourceData)
+        return 0;
+    return resourceData->httpStatusCode();
+}
+
 void NetworkResourcesData::setResourceContent(const String& requestId, const String& content)
 {
     ResourceData* resourceData = m_requestIdToResourceDataMap.get(requestId);
index 8edd499..99c3e84 100644 (file)
@@ -73,6 +73,9 @@ public:
         InspectorPageAgent::ResourceType type() const { return m_type; }
         void setType(InspectorPageAgent::ResourceType type) { m_type = type; }
 
+        int httpStatusCode() const { return m_httpStatusCode; }
+        void setHTTPStatusCode(int httpStatusCode) { m_httpStatusCode = httpStatusCode; }
+
         String textEncodingName() const { return m_textEncodingName; }
         void setTextEncodingName(const String& textEncodingName) { m_textEncodingName = textEncodingName; }
 
@@ -99,6 +102,7 @@ public:
         RefPtr<SharedBuffer> m_dataBuffer;
         bool m_isContentPurged;
         InspectorPageAgent::ResourceType m_type;
+        int m_httpStatusCode;
 
         String m_textEncodingName;
         RefPtr<TextResourceDecoder> m_decoder;
@@ -115,6 +119,7 @@ public:
     void responseReceived(const String& requestId, const String& frameId, const ResourceResponse&);
     void setResourceType(const String& requestId, InspectorPageAgent::ResourceType);
     InspectorPageAgent::ResourceType resourceType(const String& requestId);
+    int httpStatusCode(const String& requestId);
     void setResourceContent(const String& requestId, const String& content);
     void maybeAddResourceData(const String& requestId, const char* data, int dataLength);
     void maybeDecodeDataToContent(const String& requestId);
index c05690f..5c21641 100644 (file)
@@ -58,7 +58,7 @@ WebInspector.RequestView.hasTextContent = function(request)
 {
     if (request.type.isTextType())
         return true; 
-    if (request.type === WebInspector.resourceTypes.Other)
+    if (request.type === WebInspector.resourceTypes.Other || request.hasErrorStatusCode())
         return request.content && !request.contentEncoded;
     return false;
 }