Skip to content

Commit

Permalink
ENYO-1402: enyo.Ajax does not correctly manage FormData (Bad Content-…
Browse files Browse the repository at this point in the history
…Type header)

- Added a few information to run the tests
- Added some ajax tests for content-type with FormData

Enyo-DCO-1.0-Signed-off-by: Yves Del Medico <yves.del-medico@hp.com>
  • Loading branch information
yves-del-medico committed Nov 8, 2012
1 parent a3b705e commit 8b58eda
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tools/README.md
Expand Up @@ -16,3 +16,8 @@ The last parameter in the output path, if not ending in a `/`, will be used as t
The `package.js` file must be in the same directory as the invocation.

For convenience, packages should include a `minify` folder with both a Windows batch and Unix shell script that runs the minifier.

## Running tests
1. You first need to install an http server handling php (MANP or WAMP, ...)
2. Configure your http server to server the files of the enyo project
3. Point your browser to enyo/tools/... to run the various testcases.
16 changes: 16 additions & 0 deletions tools/test/ajax/php/test4.php
@@ -0,0 +1,16 @@
<?php
$method = @$_SERVER['REQUEST_METHOD'];
switch ($method) {
case 'POST':
post();
break;
default:
echo "invalid method";
}

function post() {
$c = @$_SERVER["CONTENT_TYPE"];
$result = array('status' => "post", 'ctype' => $c);
echo json_encode($result);
}
?>
29 changes: 29 additions & 0 deletions tools/test/ajax/tests/AjaxTest.js
Expand Up @@ -68,6 +68,35 @@ enyo.kind({
return inValue.ctype == contentType;
});
},
testContentTypeDefault: function() {
var contentType = "application/x-www-form-urlencoded";
this._testAjax({url: "php/test4.php", method: "POST", postBody: "data"}, null, function(inValue) {
var status = (inValue.ctype.indexOf(contentType) === 0);
if (status) {
enyo.log("Bad CT: " + inValue.ctype + " expected: " + contentType);
}
return status;
});
},
testContentTypeFormData: function() {
if (window.FormData) {
var formData = new FormData();
formData.append('token', "data");
var contentType = "multipart/form-data";
this._testAjax({url: "php/test4.php", method: "POST", postBody: formData}, null, function(inValue) {
var status = (inValue.ctype.indexOf(contentType) === 0)
&& (inValue.ctype.indexOf("boundary=--") > 10);
if ( ! status) {
enyo.log("Bad CT: " + inValue.ctype + " expected: " + contentType);
}
return status;
});
} else {
// We are probably on IE which does not support XHR2 and FormData before IE 10
// See http://caniuse.com/#search=xhr2
this.finish("");
}
},
testXhrStatus: function() {
var ajax = this._testAjax({url: "php/test2.php"}, null, function(inValue) {
return ajax.xhr.status == 200;
Expand Down

0 comments on commit 8b58eda

Please sign in to comment.