Merge pull request #1254 from bartvde/parsertests
change the afterLoad utility test functions (r=@elemoine,@tschaub)
This commit is contained in:
@@ -5,7 +5,7 @@ describe('ol.parser.gpx', function() {
|
||||
var parser = new ol.parser.GPX();
|
||||
|
||||
describe('Test GPX parser', function() {
|
||||
it('Read works correctly', function() {
|
||||
it('Read works correctly', function(done) {
|
||||
var url = 'spec/ol/parser/gpx/data.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
@@ -35,6 +35,7 @@ describe('ol.parser.gpx', function() {
|
||||
[-0.166259525, 51.3576354272]]);
|
||||
expect(attributes['name']).to.eql('Track');
|
||||
expect(attributes['type']).to.eql('Track');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Write works correctly for points', function() {
|
||||
|
||||
@@ -9,10 +9,8 @@ describe('ol.parser.ogc.exceptionreport', function() {
|
||||
|
||||
it('OCG WMS 1.3.0 exceptions', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/exceptionreport/wms1_3_0.xml';
|
||||
goog.net.XhrIo.send(url, function(e) {
|
||||
var xhr = e.target;
|
||||
var result = parser.read(xhr.getResponseXml());
|
||||
var exceptions = result.exceptionReport.exceptions;
|
||||
afterLoadXml(url, function(xml) {
|
||||
var exceptions = parser.read(xml).exceptionReport.exceptions;
|
||||
expect(exceptions.length).to.be(4);
|
||||
var str = 'Plain text message about an error.';
|
||||
expect(goog.string.trim(exceptions[0].text)).to.be(str);
|
||||
@@ -37,10 +35,8 @@ describe('ol.parser.ogc.exceptionreport', function() {
|
||||
|
||||
it('test read exception OWSCommon 1.0.0', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/exceptionreport/ows1_0_0.xml';
|
||||
goog.net.XhrIo.send(url, function(e) {
|
||||
var xhr = e.target;
|
||||
var result = parser.read(xhr.getResponseXml());
|
||||
var report = result.exceptionReport;
|
||||
afterLoadXml(url, function(xml) {
|
||||
var report = parser.read(xml).exceptionReport;
|
||||
var exception = report.exceptions[0];
|
||||
|
||||
expect(report.version).to.eql('1.0.0');
|
||||
@@ -57,10 +53,8 @@ describe('ol.parser.ogc.exceptionreport', function() {
|
||||
|
||||
it('test read exception OWSCommon 1.1.0', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/exceptionreport/ows1_1_0.xml';
|
||||
goog.net.XhrIo.send(url, function(e) {
|
||||
var xhr = e.target;
|
||||
var result = parser.read(xhr.getResponseXml());
|
||||
var report = result.exceptionReport;
|
||||
afterLoadXml(url, function(xml) {
|
||||
var report = parser.read(xml).exceptionReport;
|
||||
var exception = report.exceptions[0];
|
||||
|
||||
expect(report.version).to.eql('1.1.0');
|
||||
@@ -76,6 +70,5 @@ describe('ol.parser.ogc.exceptionreport', function() {
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('goog.net.XhrIo');
|
||||
goog.require('goog.string');
|
||||
goog.require('ol.parser.ogc.ExceptionReport');
|
||||
|
||||
@@ -34,5 +34,4 @@ describe('ol.parser.ogc.wmscapabilities_v1_0_0', function() {
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.net.XhrIo');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities');
|
||||
|
||||
@@ -256,5 +256,4 @@ describe('ol.parser.ogc.wmscapabilities_v1_1_1', function() {
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.net.XhrIo');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities');
|
||||
|
||||
@@ -57,5 +57,4 @@ describe('ol.parser.ogc.wmscapabilities_v1_1_1_wmsc', function() {
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.net.XhrIo');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities');
|
||||
|
||||
@@ -138,5 +138,4 @@ describe('ol.parser.ogc.wmscapabilities_v1_3_0', function() {
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('goog.net.XhrIo');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities');
|
||||
|
||||
@@ -8,9 +8,8 @@ describe('ol.parser.ogc.wmtscapabilities_v1_0_0', function() {
|
||||
it('Test ows', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmtscapabilities_v1_0_0/' +
|
||||
'ogcsample.xml';
|
||||
goog.net.XhrIo.send(url, function(e) {
|
||||
var xhr = e.target;
|
||||
var obj = parser.read(xhr.getResponseXml());
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var serviceIdentification = obj.serviceIdentification;
|
||||
var serviceProvider = obj.serviceProvider;
|
||||
var operationsMetadata = obj.operationsMetadata;
|
||||
@@ -57,9 +56,8 @@ describe('ol.parser.ogc.wmtscapabilities_v1_0_0', function() {
|
||||
it('Test layers', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmtscapabilities_v1_0_0/' +
|
||||
'ogcsample.xml';
|
||||
goog.net.XhrIo.send(url, function(e) {
|
||||
var xhr = e.target;
|
||||
var obj = parser.read(xhr.getResponseXml());
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var contents = obj.contents;
|
||||
var layer = contents.layers[0];
|
||||
var wgs84Bbox = layer.bounds;
|
||||
@@ -128,9 +126,8 @@ describe('ol.parser.ogc.wmtscapabilities_v1_0_0', function() {
|
||||
it('Test tileMatrixSets', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmtscapabilities_v1_0_0/' +
|
||||
'ogcsample.xml';
|
||||
goog.net.XhrIo.send(url, function(e) {
|
||||
var xhr = e.target;
|
||||
var obj = parser.read(xhr.getResponseXml());
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var tileMatrixSets = obj.contents.tileMatrixSets;
|
||||
var bigWorld = tileMatrixSets['BigWorld'];
|
||||
|
||||
@@ -159,5 +156,4 @@ describe('ol.parser.ogc.wmtscapabilities_v1_0_0', function() {
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('goog.net.XhrIo');
|
||||
goog.require('ol.parser.ogc.WMTSCapabilities');
|
||||
|
||||
@@ -2,25 +2,23 @@
|
||||
(function(global) {
|
||||
|
||||
function afterLoad(type, path, next) {
|
||||
goog.net.XhrIo.send(path, function(event) {
|
||||
var xhr = event.target;
|
||||
var client = new XMLHttpRequest();
|
||||
client.open('GET', path, true);
|
||||
client.onload = function() {
|
||||
var data;
|
||||
if (xhr.isSuccess()) {
|
||||
if (type === 'xml') {
|
||||
data = xhr.getResponseXml();
|
||||
} else if (type === 'json') {
|
||||
data = xhr.getResponseJson();
|
||||
} else {
|
||||
data = xhr.getResponseText();
|
||||
}
|
||||
if (type === 'xml') {
|
||||
data = client.responseXML;
|
||||
} else {
|
||||
throw new Error(path + ' loading failed: ' + xhr.getStatus());
|
||||
data = client.responseText;
|
||||
}
|
||||
if (!data) {
|
||||
throw new Error(path + ' loading failed: ' + client.status);
|
||||
}
|
||||
next(data);
|
||||
});
|
||||
};
|
||||
client.send();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} path Relative path to file (e.g. 'spec/ol/foo.json').
|
||||
* @param {function(Object)} next Function to call with response object on
|
||||
|
||||
Reference in New Issue
Block a user