Fix cross browser issues for responseXML
- IE8 doesn't support indexOf, use our own arrayContains - Most browsers don't allow 'text/html' when using a DOMParser, so we won't support it for now. - Firefox doesn't want to serialize Documents over selenium, so don't have them in as our expected, just use instanceof ourselves
This commit is contained in:
parent
4751eaafbb
commit
9681f79ece
@ -101,7 +101,7 @@ getJasmineRequireObj().AjaxFakeRequest = function() {
|
|||||||
|
|
||||||
function parseXml(xmlText, contentType) {
|
function parseXml(xmlText, contentType) {
|
||||||
if (global.DOMParser) {
|
if (global.DOMParser) {
|
||||||
return (new global.DOMParser()).parseFromString(xmlText, contentType);
|
return (new global.DOMParser()).parseFromString(xmlText, 'text/xml');
|
||||||
} else {
|
} else {
|
||||||
var xml = new global.ActiveXObject("Microsoft.XMLDOM");
|
var xml = new global.ActiveXObject("Microsoft.XMLDOM");
|
||||||
xml.async = "false";
|
xml.async = "false";
|
||||||
@ -110,10 +110,10 @@ getJasmineRequireObj().AjaxFakeRequest = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var xmlParsables = ['text/html', 'text/xml', 'application/xml'];
|
var xmlParsables = ['text/xml', 'application/xml'];
|
||||||
|
|
||||||
function getResponseXml(responseText, contentType) {
|
function getResponseXml(responseText, contentType) {
|
||||||
if (xmlParsables.indexOf(contentType.toLowerCase()) >= 0) {
|
if (arrayContains(xmlParsables, contentType.toLowerCase())) {
|
||||||
return parseXml(responseText, contentType);
|
return parseXml(responseText, contentType);
|
||||||
} else if (contentType.match(/\+xml$/)) {
|
} else if (contentType.match(/\+xml$/)) {
|
||||||
return parseXml(responseText, 'text/xml');
|
return parseXml(responseText, 'text/xml');
|
||||||
|
@ -393,10 +393,10 @@ describe('FakeRequest', function() {
|
|||||||
request.response({ status: 200, contentType: 'text/xml', responseText: '<dom><stuff/></dom>' });
|
request.response({ status: 200, contentType: 'text/xml', responseText: '<dom><stuff/></dom>' });
|
||||||
|
|
||||||
if (typeof window.Document !== 'undefined') {
|
if (typeof window.Document !== 'undefined') {
|
||||||
expect(request.responseXML).toEqual(jasmine.any(window.Document));
|
expect(request.responseXML instanceof window.Document).toBe(true);
|
||||||
} else {
|
} else {
|
||||||
// IE 8
|
// IE 8
|
||||||
expect(request.responseXML).toEqual(jasmine.any(window.ActiveXObject));
|
expect(request.responseXML instanceof window.ActiveXObject).toBe(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -408,25 +408,10 @@ describe('FakeRequest', function() {
|
|||||||
request.response({ status: 200, contentType: 'application/xml', responseText: '<dom><stuff/></dom>' });
|
request.response({ status: 200, contentType: 'application/xml', responseText: '<dom><stuff/></dom>' });
|
||||||
|
|
||||||
if (typeof window.Document !== 'undefined') {
|
if (typeof window.Document !== 'undefined') {
|
||||||
expect(request.responseXML).toEqual(jasmine.any(window.Document));
|
expect(request.responseXML instanceof window.Document).toBe(true);
|
||||||
} else {
|
} else {
|
||||||
// IE 8
|
// IE 8
|
||||||
expect(request.responseXML).toEqual(jasmine.any(window.ActiveXObject));
|
expect(request.responseXML instanceof window.ActiveXObject).toBe(true);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('parses a text/html document into responseXML', function() {
|
|
||||||
var request = new this.FakeRequest();
|
|
||||||
request.open();
|
|
||||||
request.send();
|
|
||||||
|
|
||||||
request.response({ status: 200, contentType: 'text/html', responseText: '<dom><stuff/></dom>' });
|
|
||||||
|
|
||||||
if (typeof window.Document !== 'undefined') {
|
|
||||||
expect(request.responseXML).toEqual(jasmine.any(window.Document));
|
|
||||||
} else {
|
|
||||||
// IE 8
|
|
||||||
expect(request.responseXML).toEqual(jasmine.any(window.ActiveXObject));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -438,10 +423,10 @@ describe('FakeRequest', function() {
|
|||||||
request.response({ status: 200, contentType: 'application/text+xml', responseText: '<dom><stuff/></dom>' });
|
request.response({ status: 200, contentType: 'application/text+xml', responseText: '<dom><stuff/></dom>' });
|
||||||
|
|
||||||
if (typeof window.Document !== 'undefined') {
|
if (typeof window.Document !== 'undefined') {
|
||||||
expect(request.responseXML).toEqual(jasmine.any(window.Document));
|
expect(request.responseXML instanceof window.Document).toBe(true);
|
||||||
} else {
|
} else {
|
||||||
// IE 8
|
// IE 8
|
||||||
expect(request.responseXML).toEqual(jasmine.any(window.ActiveXObject));
|
expect(request.responseXML instanceof window.ActiveXObject).toBe(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -56,7 +56,7 @@ getJasmineRequireObj().AjaxFakeRequest = function() {
|
|||||||
|
|
||||||
function parseXml(xmlText, contentType) {
|
function parseXml(xmlText, contentType) {
|
||||||
if (global.DOMParser) {
|
if (global.DOMParser) {
|
||||||
return (new global.DOMParser()).parseFromString(xmlText, contentType);
|
return (new global.DOMParser()).parseFromString(xmlText, 'text/xml');
|
||||||
} else {
|
} else {
|
||||||
var xml = new global.ActiveXObject("Microsoft.XMLDOM");
|
var xml = new global.ActiveXObject("Microsoft.XMLDOM");
|
||||||
xml.async = "false";
|
xml.async = "false";
|
||||||
@ -65,10 +65,10 @@ getJasmineRequireObj().AjaxFakeRequest = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var xmlParsables = ['text/html', 'text/xml', 'application/xml'];
|
var xmlParsables = ['text/xml', 'application/xml'];
|
||||||
|
|
||||||
function getResponseXml(responseText, contentType) {
|
function getResponseXml(responseText, contentType) {
|
||||||
if (xmlParsables.indexOf(contentType.toLowerCase()) >= 0) {
|
if (arrayContains(xmlParsables, contentType.toLowerCase())) {
|
||||||
return parseXml(responseText, contentType);
|
return parseXml(responseText, contentType);
|
||||||
} else if (contentType.match(/\+xml$/)) {
|
} else if (contentType.match(/\+xml$/)) {
|
||||||
return parseXml(responseText, 'text/xml');
|
return parseXml(responseText, 'text/xml');
|
||||||
|
Loading…
Reference in New Issue
Block a user