WebCore: [V8] Make XMLHttpRequest.send handle File object.
authorjianli@chromium.org <jianli@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Sep 2009 17:39:26 +0000 (17:39 +0000)
committerjianli@chromium.org <jianli@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Sep 2009 17:39:26 +0000 (17:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=28924

Reviewed by Eric Seidel.

Test: http/tests/local/send-dragged-file.html

* bindings/v8/custom/V8XMLHttpRequestCustom.cpp:
(WebCore::CALLBACK_FUNC_DECL):

LayoutTests: [V8] Make XMLHttpRequest.send handle File object.
https://bugs.webkit.org/show_bug.cgi?id=28924

Reviewed by Eric Seidel.

Add a new layout test.

* http/tests/local/resources/file-for-drag-to-send.txt: Added.
* http/tests/local/resources/send-dragged-file.js: Added.
* http/tests/local/send-dragged-file-expected.txt: Added.
* http/tests/local/send-dragged-file.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/local/resources/file-for-drag-to-send.txt [new file with mode: 0644]
LayoutTests/http/tests/local/resources/send-dragged-file.js [new file with mode: 0644]
LayoutTests/http/tests/local/send-dragged-file-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/local/send-dragged-file.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp

index 138100e..e7a8ea3 100644 (file)
@@ -1,3 +1,17 @@
+2009-09-10  Jian Li  <jianli@chromium.org>
+
+        Reviewed by Eric Seidel.
+
+        [V8] Make XMLHttpRequest.send handle File object.
+        https://bugs.webkit.org/show_bug.cgi?id=28924
+
+        Add a new layout test.
+
+        * http/tests/local/resources/file-for-drag-to-send.txt: Added.
+        * http/tests/local/resources/send-dragged-file.js: Added.
+        * http/tests/local/send-dragged-file-expected.txt: Added.
+        * http/tests/local/send-dragged-file.html: Added.
+
 2009-09-09  Steve Block  <steveblock@google.com>
 
         Reviewed by Darin Adler.
diff --git a/LayoutTests/http/tests/local/resources/file-for-drag-to-send.txt b/LayoutTests/http/tests/local/resources/file-for-drag-to-send.txt
new file mode 100644 (file)
index 0000000..5ab2f8a
--- /dev/null
@@ -0,0 +1 @@
+Hello
\ No newline at end of file
diff --git a/LayoutTests/http/tests/local/resources/send-dragged-file.js b/LayoutTests/http/tests/local/resources/send-dragged-file.js
new file mode 100644 (file)
index 0000000..3c393e8
--- /dev/null
@@ -0,0 +1,58 @@
+description("Test for sending a dragged file via XMLHttpRequest.");
+
+var fileInput = document.createElement("input");
+fileInput.type = "file";
+fileInput.style.width = "100px";
+fileInput.style.height = "100px";
+// Important that we put this at the top of the doc so that logging does not cause it to go out of view (where it can't be dragged to)
+document.body.insertBefore(fileInput, document.body.firstChild);
+
+fileInput.addEventListener("dragenter", function() {
+    event.preventDefault();
+}, false);
+
+fileInput.addEventListener("dragover", function() {
+    event.preventDefault();
+}, false);
+
+fileInput.addEventListener("drop", function() {
+    if (event.dataTransfer.types.indexOf("Files") != -1 && event.dataTransfer.files.length == 1)
+        testPassed("event.dataTransfer contains a File object on drop.");
+    else {
+        testFailed("event.dataTransfer does not contain a File object on drop.");
+        return;
+    }
+
+    var xhr = new XMLHttpRequest();
+    xhr.open("POST", "http://127.0.0.1:8000/xmlhttprequest/resources/post-echo.cgi", false);
+    xhr.send(event.dataTransfer.files[0]);
+    if (xhr.responseText == "Hello")
+        testPassed("Expected response data received.");
+    else
+        testFailed("Unexpected response data received: " + xhr.responseText);
+
+    event.preventDefault();
+}, false);
+
+function moveMouseToCenterOfElement(element) {
+    var centerX = element.offsetLeft + element.offsetWidth / 2;
+    var centerY = element.offsetTop + element.offsetHeight / 2;
+    eventSender.mouseMoveTo(centerX, centerY);
+}
+
+function runTest()
+{
+    eventSender.beginDragWithFiles(["resources/file-for-drag-to-send.txt"]);
+    moveMouseToCenterOfElement(fileInput);
+    eventSender.mouseUp();
+}
+
+if (window.eventSender) {
+    runTest();
+    // Clean up after ourselves
+    fileInput.parentNode.removeChild(fileInput);
+} else {
+    testFailed("This test is not interactive, please run using DumpRenderTree");
+}
+
+var successfullyParsed = true;
diff --git a/LayoutTests/http/tests/local/send-dragged-file-expected.txt b/LayoutTests/http/tests/local/send-dragged-file-expected.txt
new file mode 100644 (file)
index 0000000..680b16d
--- /dev/null
@@ -0,0 +1,11 @@
+Test for sending a dragged file via XMLHttpRequest.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS event.dataTransfer contains a File object on drop.
+PASS Expected response data received.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/local/send-dragged-file.html b/LayoutTests/http/tests/local/send-dragged-file.html
new file mode 100644 (file)
index 0000000..3f2210a
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../../fast/js/resources/js-test-style.css">
+<script src="../../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/send-dragged-file.js"></script>
+<script src="../../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index f8fd3dd..2c74216 100644 (file)
@@ -1,3 +1,15 @@
+2009-09-10  Jian Li  <jianli@chromium.org>
+
+        Reviewed by Eric Seidel.
+
+        [V8] Make XMLHttpRequest.send handle File object.
+        https://bugs.webkit.org/show_bug.cgi?id=28924
+
+        Test: http/tests/local/send-dragged-file.html
+
+        * bindings/v8/custom/V8XMLHttpRequestCustom.cpp:
+        (WebCore::CALLBACK_FUNC_DECL):
+
 2009-09-10  Zoltan Horvath  <zoltan@webkit.org>
 
         Reviewed by Darin Adler.
index b980680..8f2366b 100644 (file)
@@ -33,8 +33,9 @@
 
 #include "Frame.h"
 #include "V8Binding.h"
-#include "V8Document.h"
 #include "V8CustomBinding.h"
+#include "V8Document.h"
+#include "V8File.h"
 #include "V8HTMLDocument.h"
 #include "V8ObjectEventListener.h"
 #include "V8Proxy.h"
@@ -366,12 +367,16 @@ CALLBACK_FUNC_DECL(XMLHttpRequestSend)
         xmlHttpRequest->send(ec);
     else {
         v8::Handle<v8::Value> arg = args[0];
-        // FIXME: upstream handles "File" objects too.
         if (IsDocumentType(arg)) {
             v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
             Document* document = V8DOMWrapper::convertDOMWrapperToNode<Document>(object);
             ASSERT(document);
             xmlHttpRequest->send(document, ec);
+        } else if (V8File::HasInstance(arg)) {
+            v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
+            File* file = V8DOMWrapper::convertDOMWrapperToNative<File>(object);
+            ASSERT(file);
+            xmlHttpRequest->send(file, ec);
         } else
             xmlHttpRequest->send(toWebCoreStringWithNullCheck(arg), ec);
     }