Skip to content

Commit

Permalink
Add xml support to our fake XMLHttpRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
David Johnson committed Oct 27, 2014
1 parent 2b86a48 commit 3aec4e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fakes/FakeXMLHttpRequestFactory.js
@@ -1,4 +1,5 @@
/*jslint browser: true */
/*global XMLDocument:true*/

module({
}, function (imports) {
Expand Down Expand Up @@ -239,6 +240,10 @@ module({
}
this.response = view.buffer;
}
} else if(typeof XMLDocument !== 'undefined' && //node does not have XMLDocument so this will allow node tests to run
data instanceof XMLDocument) {
this.response = (new XMLSerializer()).serializeToString(data);
this.responseXML = data;
} else {
this.response = data;
if (!definePropertyWorks) {
Expand Down
13 changes: 13 additions & 0 deletions tests/browser/module.domtest.js
Expand Up @@ -140,5 +140,18 @@ module({
module.getLoadEventLog()[url].map(function(k) { return k.event_name; }));
});

test("XML responseType handles XMLDocument in _dataReceived", function() {
var xmlText = "<books/>";
var domParser = new DOMParser();
var xmlData = domParser.parseFromString(xmlText,"text/xml");
var xhr = new this.xhrFactory;

xhr.open('GET', 'http://url');
xhr._headersReceived(200, '', {});
xhr._dataReceived(xmlData);
xhr._done();
assert.equal(xmlText, xhr.response);
assert.equal(xmlData, xhr.responseXML);
});
});
});

0 comments on commit 3aec4e1

Please sign in to comment.