Commit b4605b49 authored by jianli@chromium.org's avatar jianli@chromium.org
Browse files

XMLHttpRequestUpload events do not fire when sending a raw file or FormData object.

https://bugs.webkit.org/show_bug.cgi?id=37771

Reviewed by David Levin.

WebCore:

Test: http/tests/local/formdata/upload-events.html

* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::createRequest):

LayoutTests:

Add a layout test to test upload events firing.

* http/tests/local/formdata/resources/send-form-data-common.js:
(dumpResponse):
(sendFormData):
(testSendingFormData):
* http/tests/local/formdata/script-tests/send-form-data-with-sliced-file.js:
* http/tests/local/formdata/script-tests/send-form-data.js:
* http/tests/local/formdata/script-tests/upload-events.js: Added.
* http/tests/local/formdata/upload-events-expected.txt: Added.
* http/tests/local/formdata/upload-events.html: Added.
* platform/gtk/Skipped: Skip the new test because eventSender.beginDragWithFiles is not supported in gtk platform.
* platform/qt/Skipped: Skip the new test because eventSender.beginDragWithFiles is not supported in qt platform.
* platform/win/Skipped: Skip the new test because eventSender.beginDragWithFiles is not supported in win platform.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@58841 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 449d88ca
2010-05-05 Jian Li <jianli@chromium.org>
Reviewed by David Levin.
XMLHttpRequestUpload events do not fire when sending a raw file or FormData object.
https://bugs.webkit.org/show_bug.cgi?id=37771
Add a layout test to test upload events firing.
* http/tests/local/formdata/resources/send-form-data-common.js:
(dumpResponse):
(sendFormData):
(testSendingFormData):
* http/tests/local/formdata/script-tests/send-form-data-with-sliced-file.js:
* http/tests/local/formdata/script-tests/send-form-data.js:
* http/tests/local/formdata/script-tests/upload-events.js: Added.
* http/tests/local/formdata/upload-events-expected.txt: Added.
* http/tests/local/formdata/upload-events.html: Added.
* platform/gtk/Skipped: Skip the new test because eventSender.beginDragWithFiles is not supported in gtk platform.
* platform/qt/Skipped: Skip the new test because eventSender.beginDragWithFiles is not supported in qt platform.
* platform/win/Skipped: Skip the new test because eventSender.beginDragWithFiles is not supported in win platform.
2010-05-05 Dirk Pranke <dpranke@chromium.org>
 
Unreviewed, expectations fix.
......
......@@ -19,15 +19,8 @@ function getFileName(filePath)
return filePath.substr(index + 1);
}
function sendFormData(formDataList, fileSliced)
function dumpResponse(xhr, fileSliced)
{
var formData = new FormData();
for (var i = 0; i < formDataList.length; i++)
formData.append(formDataList[i]['name'], formDataList[i]['value']);
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://127.0.0.1:8000/xmlhttprequest/resources/multipart-post-echo.php", false);
xhr.send(formData);
var responseText = xhr.responseText;
// If we're sending a sliced file among the FormData, a uniquely generated name prefixed with "Blob" is used.
......@@ -38,7 +31,24 @@ function sendFormData(formDataList, fileSliced)
debug(responseText);
}
function testSendingFormData(dataList)
function sendFormData(formDataList, fileSliced, sendAsAsync, addEventHandlers)
{
var formData = new FormData();
for (var i = 0; i < formDataList.length; i++)
formData.append(formDataList[i]['name'], formDataList[i]['value']);
var xhr = new XMLHttpRequest();
if (addEventHandlers)
addEventHandlers(xhr, fileSliced);
xhr.open("POST", "http://127.0.0.1:8000/xmlhttprequest/resources/multipart-post-echo.php", sendAsAsync);
xhr.send(formData);
if (!sendAsAsync)
dumpResponse(xhr, fileSliced);
}
function testSendingFormData(dataList, sendAsAsync, addEventHandlers)
{
var filesToDrag = [];
for (var i = 0; i < dataList.length; i++) {
......@@ -74,5 +84,11 @@ function testSendingFormData(dataList)
}
}
sendFormData(formDataList, fileSliced);
sendFormData(formDataList, fileSliced, sendAsAsync, addEventHandlers);
}
function formDataTestingCleanup()
{
// Clean up after ourselves
fileInput.parentNode.removeChild(fileInput);
}
......@@ -29,8 +29,7 @@ function runTest()
if (window.eventSender) {
runTest();
// Clean up after ourselves
fileInput.parentNode.removeChild(fileInput);
formDataTestingCleanup();
} else {
testFailed("This test is not interactive, please run using DumpRenderTree");
}
......
......@@ -39,8 +39,7 @@ function runTest()
if (window.eventSender) {
runTest();
// Clean up after ourselves
fileInput.parentNode.removeChild(fileInput);
formDataTestingCleanup();
} else {
testFailed("This test is not interactive, please run using DumpRenderTree");
}
......
description("Test that upload events are fired when sending FormData via XMLHttpRequest.");
var progressEventFired = false;
function progressHandler(evt)
{
// Dump the progress event only once in order to get a consistent result.
if (progressEventFired)
return;
progressEventFired = true;
debug("onprogress event fired on XMLHttpRequestUpload: " + evt);
}
function loadstartHandler(evt)
{
debug("loadstart event fired on XMLHttpRequestUpload: " + evt);
}
function loadHandler(evt)
{
debug("load event fired on XMLHttpRequestUpload: " + evt);
}
function readystatechangeHandler(evt, xhr, fileSliced)
{
if (xhr.readyState == xhr.DONE) {
dumpResponse(xhr, fileSliced);
finishJSTest();
}
}
function addXHREventHandlers(xhr, fileSliced)
{
xhr.upload.onprogress = progressHandler;
xhr.upload.onloadstart = loadstartHandler;
xhr.upload.onload = loadHandler;
xhr.onreadystatechange = function(evt) { readystatechangeHandler(evt, xhr, fileSliced); };
}
function runTest()
{
testSendingFormData(
[
{ 'type': 'string', 'name': 'string1', 'value': 'foo' },
{ 'type': 'file', 'name': 'file1', 'value': '../resources/file-for-drag-to-send.txt' }
],
true,
addXHREventHandlers
);
}
if (window.eventSender) {
window.jsTestIsAsync = true;
runTest();
formDataTestingCleanup();
} else {
testFailed("This test is not interactive, please run using DumpRenderTree");
}
var successfullyParsed = true;
Test that upload events are fired when sending FormData via XMLHttpRequest.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
loadstart event fired on XMLHttpRequestUpload: [object XMLHttpRequestProgressEvent]
onprogress event fired on XMLHttpRequestUpload: [object XMLHttpRequestProgressEvent]
load event fired on XMLHttpRequestUpload: [object XMLHttpRequestProgressEvent]
string1=foo&file1=file-for-drag-to-send.txt:1234567890
PASS successfullyParsed is true
TEST COMPLETE
<!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-form-data-common.js"></script>
<script src="script-tests/upload-events.js"></script>
<script src="../../../../fast/js/resources/js-test-post.js"></script>
</body>
</html>
......@@ -3429,6 +3429,7 @@ http/tests/local/send-dragged-file.html
http/tests/local/send-sliced-dragged-file.html
http/tests/local/formdata/send-form-data.html
http/tests/local/formdata/send-form-data-with-sliced-file.html
http/tests/local/formdata/upload-events.html
http/tests/media/video-play-stall-seek.html
http/tests/media/video-play-stall.html
http/tests/media/video-seekable-stall.html
......
......@@ -49,6 +49,7 @@ http/tests/local/send-dragged-file.html
http/tests/local/send-sliced-dragged-file.html
http/tests/local/formdata/send-form-data.html
http/tests/local/formdata/send-form-data-with-sliced-file.html
http/tests/local/formdata/upload-events.html
# Failing navigation tests
http/tests/navigation/anchor-frames.html
......
......@@ -678,6 +678,7 @@ http/tests/local/send-dragged-file.html
http/tests/local/send-sliced-dragged-file.html
http/tests/local/formdata/send-form-data.html
http/tests/local/formdata/send-form-data-with-sliced-file.html
http/tests/local/formdata/upload-events.html
# <https://bugs.webkit.org/show_bug.cgi?id=29289>
plugins/destroy-during-npp-new.html
......
2010-05-05 Jian Li <jianli@chromium.org>
Reviewed by David Levin.
XMLHttpRequestUpload events do not fire when sending a raw file or FormData object.
https://bugs.webkit.org/show_bug.cgi?id=37771
Test: http/tests/local/formdata/upload-events.html
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::createRequest):
2010-05-05 Csaba Osztrogonác <ossy@webkit.org>
 
Reviewed by Simon Hausmann.
......@@ -529,7 +529,7 @@ void XMLHttpRequest::createRequest(ExceptionCode& ec)
// We also remember whether upload events should be allowed for this request in case the upload listeners are
// added after the request is started.
m_uploadEventsAllowed = !isSimpleCrossOriginAccessRequest(m_method, m_requestHeaders);
m_uploadEventsAllowed = m_sameOriginRequest || !isSimpleCrossOriginAccessRequest(m_method, m_requestHeaders);
ResourceRequest request(m_url);
request.setHTTPMethod(m_method);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment