2011-02-01 Andrey Kosyakov <caseq@chromium.org>
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Feb 2011 18:05:28 +0000 (18:05 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Feb 2011 18:05:28 +0000 (18:05 +0000)
        Reviewed by Pavel Feldman.

        Web Inspector: add test for OPTIONS requests caused by CORS preflight checking to appear in Network panel
        https://bugs.webkit.org/show_bug.cgi?id=53501

        * http/tests/inspector/network-preflight-options-expected.txt: Added.
        * http/tests/inspector/network-preflight-options.html: Added.
        * http/tests/inspector/resources/cors-target.php: Added.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/network-preflight-options-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/inspector/network-preflight-options.html [new file with mode: 0755]
LayoutTests/http/tests/inspector/resources/cors-target.php [new file with mode: 0755]
Source/WebCore/inspector/front-end/Resource.js

index 57ec753..2981caf 100644 (file)
@@ -1,3 +1,14 @@
+2011-02-01  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: add test for OPTIONS requests caused by CORS preflight checking to appear in Network panel
+        https://bugs.webkit.org/show_bug.cgi?id=53501
+
+        * http/tests/inspector/network-preflight-options-expected.txt: Added.
+        * http/tests/inspector/network-preflight-options.html: Added.
+        * http/tests/inspector/resources/cors-target.php: Added.
+
 2011-02-02  Martin Robinson  <mrobinson@igalia.com>
 
         Skip another test that uses modal dialogs.
diff --git a/LayoutTests/http/tests/inspector/network-preflight-options-expected.txt b/LayoutTests/http/tests/inspector/network-preflight-options-expected.txt
new file mode 100644 (file)
index 0000000..21940b5
--- /dev/null
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: line 1: XMLHttpRequest cannot load http://localhost:8000/inspector/resources/cors-target.php?deny=yes. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
+CONSOLE MESSAGE: line 1: XMLHttpRequest cannot load http://localhost:8000/inspector/resources/cors-target.php?deny=yes. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
+Tests that preflight OPTIONS requests appear in Network resources
+
+POST http://localhost:8000/inspector/resources/cors-target.php?deny=yes
+OPTIONS http://localhost:8000/inspector/resources/cors-target.php?deny=yes
+OPTIONS http://localhost:8000/inspector/resources/cors-target.php
+POST http://localhost:8000/inspector/resources/cors-target.php
+
diff --git a/LayoutTests/http/tests/inspector/network-preflight-options.html b/LayoutTests/http/tests/inspector/network-preflight-options.html
new file mode 100755 (executable)
index 0000000..1bcabe5
--- /dev/null
@@ -0,0 +1,47 @@
+<html>
+<head>
+<script src="inspector-test2.js"></script>
+<script type="text/javascript">
+
+function sendXHR(url, forcePreflight)
+{
+    var xhr = new XMLHttpRequest();
+    xhr.open("POST", url, false);
+    xhr.setRequestHeader("Content-Type", forcePreflight ? "application/xml" : "text/plain");
+    try {
+        xhr.send("<xml></xml>");  // Denied requests will cause exceptions.
+    } catch (e) {
+    }
+}
+
+function doCrossOriginXHR()
+{
+    var targetURL = "http://localhost:8000/inspector/resources/cors-target.php";
+    // Failed POSTs with no preflight check should result in a POST request being logged
+    sendXHR(targetURL + "?deny=yes", false);
+    // Failed POSTs with preflight check should result in an OPTIONS request being logged
+    sendXHR(targetURL + "?deny=yes", true);
+    // Successful POSTs with preflight check should result in an OPTIONS request followed by POST request being logged
+    // Generate request name based on timestamp to defeat caching (this is only relevant for repeated invocations of the test in signle instance of DRT)
+    sendXHR(targetURL + "?date=" + Date.now(), true);
+}
+
+var test = function()
+{
+    function onResource(event)
+    {
+        var resource = event.data;
+        InspectorTest.addResult(resource.requestMethod + " " +  resource.url.replace(/[&?]date=\d+/, ""));
+        if (resource.requestMethod === "POST" && !/\?deny=yes/.test(resource.url))
+            InspectorTest.completeTest();
+    }
+    WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.ResourceFinished, onResource);
+    InspectorTest.evaluateInPage("doCrossOriginXHR();");
+}
+
+</script>
+</head>
+<body onload="runTest()">
+<p>Tests that preflight OPTIONS requests appear in Network resources</p>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/inspector/resources/cors-target.php b/LayoutTests/http/tests/inspector/resources/cors-target.php
new file mode 100755 (executable)
index 0000000..d784baf
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+    parse_str($_SERVER['QUERY_STRING'], $queryParams);
+    if ($queryParams["deny"] != "yes") {
+        header("Access-control-allow-origin: http://127.0.0.1:8000");
+        header("Access-control-allow-headers: Content-Type");
+    }
+    header("Content-Type: text/plain");
+
+    print "body"
+?>
index 3790fdd..9108d2d 100644 (file)
@@ -31,7 +31,6 @@ WebInspector.Resource = function(identifier, url)
     this.url = url;
     this._startTime = -1;
     this._endTime = -1;
-    this._requestMethod = "";
     this._category = WebInspector.resourceCategories.other;
     this._pendingContentCallbacks = [];
     this._responseHeadersSize = 0;