Skip to content
This repository has been archived by the owner on Dec 21, 2018. It is now read-only.

Commit

Permalink
Support for specifying request body encoding for WebPage::openUrl
Browse files Browse the repository at this point in the history
Added a simple test in test/webpage-spec.js

Test data from http://code.google.com/p/phantomjs/issues/detail?id=1043
  • Loading branch information
MaxDesiatov authored and vitallium committed May 28, 2013
1 parent 521f7a4 commit 183d8b6
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/webpage-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,49 @@ describe("WebPage object", function() {

});

it("should process request body properly for POST", function() {
var server = require('webserver').create();
server.listen(12345, function(request, response) {
// echo received request body in response body;
response.setHeader('Content-Type', 'text/html; charset=utf-8');
response.write(Object.keys(request.post)[0]);
response.close();
});

var url = "http://localhost:12345/foo/body";

var handled = false;
runs(function() {
expect(handled).toEqual(false);
var utfString = '안녕';
var openOptions = {
operation: 'POST',
data: utfString,
encoding: 'utf8'
};
var pageOptions = {
onLoadFinished: function(status) {
expect(status == 'success').toEqual(true);
handled = true;

expect(page.plainText).toEqual(utfString);
}
};

var page = new WebPage(pageOptions);

page.openUrl(url, openOptions, {});
});

waits(50);

runs(function() {
expect(handled).toEqual(true);
server.close();
});

});

it("should return properly from a 401 status", function() {
var server = require('webserver').create();
server.listen(12345, function(request, response) {
Expand Down

0 comments on commit 183d8b6

Please sign in to comment.