From 1023757bf3bd45ec2ccdd5670ffbe2313243a6e2 Mon Sep 17 00:00:00 2001 From: "jianli@chromium.org" Date: Thu, 10 Sep 2009 17:39:26 +0000 Subject: [PATCH] WebCore: [V8] Make XMLHttpRequest.send handle File object. 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 | 14 ++++++ .../local/resources/file-for-drag-to-send.txt | 1 + .../tests/local/resources/send-dragged-file.js | 58 ++++++++++++++++++++++ .../tests/local/send-dragged-file-expected.txt | 11 ++++ .../http/tests/local/send-dragged-file.html | 13 +++++ WebCore/ChangeLog | 12 +++++ .../bindings/v8/custom/V8XMLHttpRequestCustom.cpp | 9 +++- 7 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 LayoutTests/http/tests/local/resources/file-for-drag-to-send.txt create mode 100644 LayoutTests/http/tests/local/resources/send-dragged-file.js create mode 100644 LayoutTests/http/tests/local/send-dragged-file-expected.txt create mode 100644 LayoutTests/http/tests/local/send-dragged-file.html diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 138100e..e7a8ea3e 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,17 @@ +2009-09-10 Jian Li + + 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 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 index 0000000..5ab2f8a --- /dev/null +++ b/LayoutTests/http/tests/local/resources/file-for-drag-to-send.txt @@ -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 index 0000000..3c393e8 --- /dev/null +++ b/LayoutTests/http/tests/local/resources/send-dragged-file.js @@ -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 index 0000000..680b16d --- /dev/null +++ b/LayoutTests/http/tests/local/send-dragged-file-expected.txt @@ -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 index 0000000..3f2210a --- /dev/null +++ b/LayoutTests/http/tests/local/send-dragged-file.html @@ -0,0 +1,13 @@ + + + + + + + +

+
+ + + + diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index f8fd3dd..2c74216 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,15 @@ +2009-09-10 Jian Li + + 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 Reviewed by Darin Adler. diff --git a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp index b980680..8f2366b 100644 --- a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp +++ b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp @@ -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 arg = args[0]; - // FIXME: upstream handles "File" objects too. if (IsDocumentType(arg)) { v8::Handle object = v8::Handle::Cast(arg); Document* document = V8DOMWrapper::convertDOMWrapperToNode(object); ASSERT(document); xmlHttpRequest->send(document, ec); + } else if (V8File::HasInstance(arg)) { + v8::Handle object = v8::Handle::Cast(arg); + File* file = V8DOMWrapper::convertDOMWrapperToNative(object); + ASSERT(file); + xmlHttpRequest->send(file, ec); } else xmlHttpRequest->send(toWebCoreStringWithNullCheck(arg), ec); } -- 1.8.3.1