Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: LayoutTests/http/tests/local/formdata/send-form-data-with-empty-name.html

Issue 609733004: FormData allow empty names to append (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added issue title in description Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/http/tests/local/formdata/send-form-data-with-empty-name-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/local/formdata/send-form-data-with-empty-name.html
diff --git a/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-name.html b/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-name.html
new file mode 100644
index 0000000000000000000000000000000000000000..8d5203d192d222cc3c8f1594e587f5ddc62625e6
--- /dev/null
+++ b/LayoutTests/http/tests/local/formdata/send-form-data-with-empty-name.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../../../../resources/js-test.js"></script>
+<script>
+description("Test that we can send empty name in FormData.append()");
+
+self.jsTestIsAsync = true;
+
+function shouldContain(string, substring, message) {
+ if (string.indexOf(substring) >= 0)
+ testPassed(message);
+ else
+ testFailed("the FormData containing" + substring + " failed to echo correctly");
+}
+
+function firstTest() {
+ var formData = new FormData();
+ formData.append('', 'empty');
+ formData.append('hello', 'world');
+ var xhr = new XMLHttpRequest();
+ xhr.open('POST', 'http://127.0.0.1:8000/xmlhttprequest/resources/post-echo.cgi', true);
+ xhr.onload = function() {
+ shouldContain(xhr.response, 'name=""\r\n\r\nempty',
+ 'the FormData of string type containing a empty name echoed correctly');
+ shouldContain(xhr.response, 'name="hello"\r\n\r\nworld',
+ 'the FormData of string type containing a name echoed correctly');
+ secondTest();
+ };
+ xhr.send(formData);
+}
+
+function secondTest() {
+ var formData = new FormData();
+ formData.append('', new Blob(), 'empty-name.txt');
+ formData.append('testFile', new Blob(), 'custom-name.txt');
+ var xhr = new XMLHttpRequest();
+ xhr.open('POST', 'http://127.0.0.1:8000/xmlhttprequest/resources/post-echo.cgi', true);
+ xhr.onload = function() {
+ shouldContain(xhr.response, 'name=""; filename="empty-name.txt"',
+ 'the FormData of file type containing a empty name echoed correctly');
+ shouldContain(xhr.response, 'name="testFile"; filename="custom-name.txt"',
+ 'the FormData of file type containing a name echoed correctly');
+ finishJSTest();
+ };
+ xhr.send(formData);
+}
+firstTest();
+</script>
+</body>
+</html>
« no previous file with comments | « no previous file | LayoutTests/http/tests/local/formdata/send-form-data-with-empty-name-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698