From 3aec4e1fbc3a6ce631d857ba8b40783734c0cc39 Mon Sep 17 00:00:00 2001 From: David Johnson Date: Mon, 27 Oct 2014 15:35:07 -0700 Subject: [PATCH] Add xml support to our fake XMLHttpRequest --- fakes/FakeXMLHttpRequestFactory.js | 5 +++++ tests/browser/module.domtest.js | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/fakes/FakeXMLHttpRequestFactory.js b/fakes/FakeXMLHttpRequestFactory.js index f2e21ae9..52214e36 100755 --- a/fakes/FakeXMLHttpRequestFactory.js +++ b/fakes/FakeXMLHttpRequestFactory.js @@ -1,4 +1,5 @@ /*jslint browser: true */ +/*global XMLDocument:true*/ module({ }, function (imports) { @@ -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) { diff --git a/tests/browser/module.domtest.js b/tests/browser/module.domtest.js index 8d9b1f88..506cacfe 100755 --- a/tests/browser/module.domtest.js +++ b/tests/browser/module.domtest.js @@ -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 = ""; + 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); + }); }); });