Source/WebCore: Cleanup in multipart FormData sending code.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Mar 2013 21:25:35 +0000 (21:25 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Mar 2013 21:25:35 +0000 (21:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=111603

Patch by Victor Costan <costan@gmail.com> on 2013-03-06
Reviewed by Alexey Proskuryakov.

No new tests. This is cleanup.

* platform/network/FormDataBuilder.cpp:
(WebCore::appendQuotedString): use proper types (e.g, size_t instead of
unsigned long)

LayoutTests: Cleanup in multipart FormData tests.
https://bugs.webkit.org/show_bug.cgi?id=111603

Patch by Victor Costan <costan@gmail.com> on 2013-03-06
Reviewed by Alexey Proskuryakov.

* http/tests/local/formdata/resources/send-form-data-common.js:
(sendFormData): JavaScript style cleanup.
(testSendingFormData): JavaScript style, bugfix in checking if
eventSender.beginDragWithFiles needs to be called.
* http/tests/local/formdata/send-form-data-with-filename-expected.txt: Better test description.
* http/tests/local/formdata/send-form-data-with-filename.html: Better test description.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/local/formdata/resources/send-form-data-common.js
LayoutTests/http/tests/local/formdata/send-form-data-with-filename-expected.txt
LayoutTests/http/tests/local/formdata/send-form-data-with-filename.html
Source/WebCore/ChangeLog
Source/WebCore/platform/network/FormDataBuilder.cpp

index a6962f5..3b7b367 100644 (file)
@@ -1,3 +1,17 @@
+2013-03-06  Victor Costan  <costan@gmail.com>
+
+        Cleanup in multipart FormData tests.
+        https://bugs.webkit.org/show_bug.cgi?id=111603
+
+        Reviewed by Alexey Proskuryakov.
+
+        * http/tests/local/formdata/resources/send-form-data-common.js:
+        (sendFormData): JavaScript style cleanup.
+        (testSendingFormData): JavaScript style, bugfix in checking if
+        eventSender.beginDragWithFiles needs to be called.
+        * http/tests/local/formdata/send-form-data-with-filename-expected.txt: Better test description.
+        * http/tests/local/formdata/send-form-data-with-filename.html: Better test description.
+
 2013-03-06  Ryosuke Niwa  <rniwa@webkit.org>
 
         Add a flaky crash test expectation to platform/mac/fast/speechsynthesis/speech-synthesis-cancel.html
index 712e585..d3967a6 100644 (file)
@@ -28,10 +28,10 @@ function sendFormData(formDataList, fileSliced, sendAsAsync, addEventHandlers)
 {
     var formData = new FormData();
     for (var i = 0; i < formDataList.length; i++) {
-        if (formDataList[i]['filename'] != undefined)
-            formData.append(formDataList[i]['name'], formDataList[i]['value'], formDataList[i]['filename']);
+        if (formDataList[i].filename !== undefined)
+            formData.append(formDataList[i].name, formDataList[i].value, formDataList[i].filename);
         else
-            formData.append(formDataList[i]['name'], formDataList[i]['value']);
+            formData.append(formDataList[i].name, formDataList[i].value);
     }
 
     var xhr = new XMLHttpRequest();
@@ -49,11 +49,11 @@ function testSendingFormData(dataList, sendAsAsync, addEventHandlers)
 {
     var filesToDrag = [];
     for (var i = 0; i < dataList.length; i++) {
-        if (dataList[i]['type'] == 'file')
-            filesToDrag.push(dataList[i]['value']);
+        if (dataList[i].type === 'file')
+            filesToDrag.push(dataList[i].value);
     }
 
-    if (filesToDrag) {
+    if (filesToDrag.length !== 0) {
         eventSender.beginDragWithFiles(filesToDrag);
         moveMouseToCenterOfElement(fileInput);
         eventSender.mouseUp();
@@ -63,22 +63,27 @@ function testSendingFormData(dataList, sendAsAsync, addEventHandlers)
     var formDataList = [];
     var fileSliced = false;
     for (var i = 0; i < dataList.length; i++) {
-        if (dataList[i]['type'] == 'file') {
-            var fileName = getFileName(dataList[i]['value']);
+        var field = {name: dataList[i].name};
+        if (dataList[i].type === 'file') {
+            var fileName = getFileName(dataList[i].value);
             for (var j = 0; j < files.length; j++) {
                 if (fileName == files[j].name) {
                     var file = files[j];
-                    if (dataList[i]['start'] && dataList[i]['length']) {
+                    if ('start' in dataList[i] && 'length' in dataList[i]) {
                         fileSliced = true;
-                        file = file.slice(dataList[i]['start'], dataList[i]['start'] + dataList[i]['length']);
+                        file = file.slice(dataList[i].start, dataList[i].start + dataList[i].length);
                     }
-                    formDataList.push({'name': dataList[i]['name'], 'value': file, 'filename': dataList[i]['filename']});
+                    field.value = file;
                     break;
                 }
             }
-        } else {
-            formDataList.push({'name': dataList[i]['name'], 'value': dataList[i]['value']});
         }
+        else
+            field.value = dataList[i].value;
+        if (dataList[i]['filename'])
+            field.filename = dataList[i].filename;
+
+        formDataList.push(field);
     }
 
     sendFormData(formDataList, fileSliced, sendAsAsync, addEventHandlers);
index 1a9de35..1d76f2b 100644 (file)
@@ -1,4 +1,4 @@
-Test for sending FormData via XMLHttpRequest.
+Test that filename passed to FormData.append() takes precedence over filename in File.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
index 3ca00f5..e6ac2f9 100644 (file)
@@ -8,7 +8,7 @@
 <div id="console"></div>
 <script src="resources/send-form-data-common.js"></script>
 <script>
-description("Test for sending FormData via XMLHttpRequest.");
+description("Test that filename passed to FormData.append() takes precedence over filename in File.");
 
 function runTest()
 {
index 3c677bb..44b247e 100644 (file)
@@ -1,3 +1,16 @@
+2013-03-06  Victor Costan <costan@gmail.com>
+
+        Cleanup in multipart FormData sending code.
+        https://bugs.webkit.org/show_bug.cgi?id=111603
+
+        Reviewed by Alexey Proskuryakov.
+
+        No new tests. This is cleanup.
+
+        * platform/network/FormDataBuilder.cpp:
+        (WebCore::appendQuotedString): use proper types (e.g, size_t instead of
+        unsigned long)
+
 2013-03-06  Tony Gentilcore  <tonyg@chromium.org>
 
         Threaded HTML parser should use 8 bit strings for attributes
index a8b3904..66ff69e 100644 (file)
@@ -59,9 +59,9 @@ static void appendQuotedString(Vector<char>& buffer, const CString& string)
     // Append a string as a quoted value, escaping quotes and line breaks.
     // FIXME: Is it correct to use percent escaping here? Other browsers do not encode these characters yet,
     // so we should test popular servers to find out if there is an encoding form they can handle.
-    unsigned length = string.length();
-    for (unsigned i = 0; i < length; ++i) {
-        unsigned char c = string.data()[i];
+    size_t length = string.length();
+    for (size_t i = 0; i < length; ++i) {
+        char c = string.data()[i];
 
         switch (c) {
         case  0x0a: