diff --git a/CHANGES.md b/CHANGES.md index 31430957a8e0..299dba2d9513 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,8 @@ Change Log ##### Breaking Changes :mega: * `GeometryVisualizer` now requires `primitive` and `groundPrimitive` parameters. [#6316](https://github.com/AnalyticalGraphicsInc/cesium/pull/6316) +* For all classes/functions that take a `Resource` instance, all additional parameters that are part of the `Resource` class have been removed. This generally includes `proxy`, `headers` and `query` parameters. +* All low level load functions including `loadArrayBuffer`, `loadBlob`, `loadImage`, `loadJson`, `loadJsonp`, `loadText`, `loadXML` and `loadWithXhr` have been removed. Please use the equivalent `fetch` functions on the `Resource` class. ##### Deprecated :hourglass_flowing_sand: * `ClippingPlaneCollection` is now supported in Internet Explorer, so `ClippingPlaneCollection.isSupported` has been deprecated and will be removed in Cesium 1.45. diff --git a/Source/Core/CesiumTerrainProvider.js b/Source/Core/CesiumTerrainProvider.js index be235b5c505d..d174eac726fa 100644 --- a/Source/Core/CesiumTerrainProvider.js +++ b/Source/Core/CesiumTerrainProvider.js @@ -94,10 +94,6 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('CesiumTerrainProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - this._tilingScheme = new GeographicTilingScheme({ numberOfLevelZeroTilesX : 2, numberOfLevelZeroTilesY : 1, @@ -152,9 +148,7 @@ define([ var overallAvailability = []; when(options.url) .then(function(url) { - var resource = Resource.createIfNeeded(url, { - proxy: options.proxy - }); + var resource = Resource.createIfNeeded(url); resource.appendForwardSlash(); lastResource = resource; metadataResource = lastResource.getDerivedResource({ diff --git a/Source/Core/GoogleEarthEnterpriseMetadata.js b/Source/Core/GoogleEarthEnterpriseMetadata.js index 2d6b5e7fd66b..66a43f6f55a1 100644 --- a/Source/Core/GoogleEarthEnterpriseMetadata.js +++ b/Source/Core/GoogleEarthEnterpriseMetadata.js @@ -7,7 +7,6 @@ define([ './defaultValue', './defined', './defineProperties', - './deprecationWarning', './GoogleEarthEnterpriseTileInformation', './isBitSet', './Math', @@ -24,7 +23,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, GoogleEarthEnterpriseTileInformation, isBitSet, CesiumMath, @@ -67,23 +65,16 @@ define([ //>>includeEnd('debug'); var url = resourceOrUrl; - var proxy; + if (typeof url !== 'string' && !(url instanceof Resource)) { //>>includeStart('debug', pragmas.debug); Check.typeOf.string('resourceOrUrl.url', resourceOrUrl.url); //>>includeEnd('debug'); - if (defined(resourceOrUrl.proxy)) { - deprecationWarning('GoogleEarthEnterpriseMetadata', 'The options.url & options.proxy parameters have been deprecated. Specify a URL string or a Resource as the only parameter.'); - } - url = resourceOrUrl.url; - proxy = resourceOrUrl.proxy; } - var resource = Resource.createIfNeeded(url, { - proxy: proxy - }); + var resource = Resource.createIfNeeded(url); resource.appendForwardSlash(); this._resource = resource; diff --git a/Source/Core/GoogleEarthEnterpriseTerrainProvider.js b/Source/Core/GoogleEarthEnterpriseTerrainProvider.js index 40fcffa7e54a..ff430a868918 100644 --- a/Source/Core/GoogleEarthEnterpriseTerrainProvider.js +++ b/Source/Core/GoogleEarthEnterpriseTerrainProvider.js @@ -4,7 +4,6 @@ define([ './defaultValue', './defined', './defineProperties', - './deprecationWarning', './DeveloperError', './Event', './GeographicTilingScheme', @@ -27,7 +26,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, Event, GeographicTilingScheme, @@ -126,17 +124,11 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('GoogleEarthEnterpriseTerrainProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - var metadata; if (defined(options.metadata)) { metadata = options.metadata; } else { - var resource = Resource.createIfNeeded(options.url, { - proxy: options.proxy - }); + var resource = Resource.createIfNeeded(options.url); metadata = new GoogleEarthEnterpriseMetadata(resource); } diff --git a/Source/Core/Resource.js b/Source/Core/Resource.js index 0817c18f8b66..22a82c3c4e45 100644 --- a/Source/Core/Resource.js +++ b/Source/Core/Resource.js @@ -347,13 +347,12 @@ define([ * A helper function to create a resource depending on whether we have a String or a Resource * * @param {Resource|String} resource A Resource or a String to use when creating a new Resource. - * @param {Object} options If resource is a String, these are the options passed to the Resource constructor. It is ignored otherwise. * * @returns {Resource} If resource is a String, a Resource constructed with the url and options. Otherwise the resource parameter is returned. * * @private */ - Resource.createIfNeeded = function(resource, options) { + Resource.createIfNeeded = function(resource) { if (resource instanceof Resource) { // Keep existing request object. This function is used internally to duplicate a Resource, so that it can't // be modified outside of a class that holds it (eg. an imagery or terrain provider). Since the Request objects @@ -368,9 +367,9 @@ define([ return resource; } - var args = defaultClone(options, {}); - args.url = resource; - return new Resource(args); + return new Resource({ + url: resource + }); }; defineProperties(Resource, { @@ -848,13 +847,8 @@ define([ * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} */ - Resource.prototype.fetchImage = function (preferBlob, allowCrossOrigin) { - if (defined(allowCrossOrigin)) { - deprecationWarning('Resource.fetchImage.allowCrossOrigin', 'The allowCrossOrigin parameter has been deprecated and will be removed in Cesium 1.44. It no longer needs to be specified.'); - } - + Resource.prototype.fetchImage = function (preferBlob) { preferBlob = defaultValue(preferBlob, false); - allowCrossOrigin = defaultValue(allowCrossOrigin, true); checkAndResetRequest(this.request); @@ -864,7 +858,7 @@ define([ // 3. It's a blob URI // 4. It doesn't have request headers and we preferBlob is false if (!xhrBlobSupported || this.isDataUri || this.isBlobUri || (!this.hasHeaders && !preferBlob)) { - return fetchImage(this, allowCrossOrigin); + return fetchImage(this, true); } var blobPromise = this.fetchBlob(); @@ -907,21 +901,21 @@ define([ }); }; - function fetchImage(resource, allowCrossOrigin) { + function fetchImage(resource) { var request = resource.request; request.url = resource.url; request.requestFunction = function() { var url = resource.url; var crossOrigin = false; - // data URIs can't have allowCrossOrigin set. + // data URIs can't have crossorigin set. if (!resource.isDataUri && !resource.isBlobUri) { crossOrigin = resource.isCrossOriginUrl; } var deferred = when.defer(); - Resource._Implementations.createImage(url, crossOrigin && allowCrossOrigin, deferred); + Resource._Implementations.createImage(url, crossOrigin, deferred); return deferred.promise; }; @@ -945,7 +939,7 @@ define([ request.state = RequestState.UNISSUED; request.deferred = undefined; - return fetchImage(resource, allowCrossOrigin); + return fetchImage(resource); } return when.reject(e); @@ -970,7 +964,7 @@ define([ */ Resource.fetchImage = function (options) { var resource = new Resource(options); - return resource.fetchImage(options.preferBlob, options.allowCrossOrigin); + return resource.fetchImage(options.preferBlob); }; /** diff --git a/Source/Core/VRTheWorldTerrainProvider.js b/Source/Core/VRTheWorldTerrainProvider.js index a416dae9ead4..6088b9a790d6 100644 --- a/Source/Core/VRTheWorldTerrainProvider.js +++ b/Source/Core/VRTheWorldTerrainProvider.js @@ -4,7 +4,6 @@ define([ './defaultValue', './defined', './defineProperties', - './deprecationWarning', './DeveloperError', './Ellipsoid', './Event', @@ -22,7 +21,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, Ellipsoid, Event, @@ -71,13 +69,7 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('VRTheWorldTerrainProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - - var resource = Resource.createIfNeeded(options.url, { - proxy: options.proxy - }); + var resource = Resource.createIfNeeded(options.url); this._resource = resource; diff --git a/Source/Core/loadArrayBuffer.js b/Source/Core/loadArrayBuffer.js deleted file mode 100644 index 8bb93545014c..000000000000 --- a/Source/Core/loadArrayBuffer.js +++ /dev/null @@ -1,55 +0,0 @@ -define([ - './Check', - './defined', - './deprecationWarning', - './Resource' - ], function( - Check, - defined, - deprecationWarning, - Resource) { - 'use strict'; - - /** - * Asynchronously loads the given URL as raw binary data. Returns a promise that will resolve to - * an ArrayBuffer once loaded, or reject if the URL failed to load. The data is loaded - * using XMLHttpRequest, which means that in order to make requests to another origin, - * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. - * - * @exports loadArrayBuffer - * - * @param {Resource|String} urlOrResource The URL of the binary data. - * @param {Object} [headers] HTTP headers to send with the requests. - * @param {Request} [request] The request object. Intended for internal use only. - * @returns {Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. - * - * @example - * // load a single URL asynchronously - * Cesium.loadArrayBuffer('some/url').then(function(arrayBuffer) { - * // use the data - * }).otherwise(function(error) { - * // an error occurred - * }); - * - * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} - * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} - * - * @deprecated - */ - function loadArrayBuffer(urlOrResource, headers, request) { - //>>includeStart('debug', pragmas.debug); - Check.defined('urlOrResource', urlOrResource); - //>>includeEnd('debug'); - - deprecationWarning('loadArrayBuffer', 'loadArrayBuffer is deprecated and will be removed in Cesium 1.44. Please use Resource.fetchArrayBuffer instead.'); - - var resource = Resource.createIfNeeded(urlOrResource, { - headers: headers, - request: request - }); - - return resource.fetchArrayBuffer(); - } - - return loadArrayBuffer; -}); diff --git a/Source/Core/loadBlob.js b/Source/Core/loadBlob.js deleted file mode 100644 index 5523d30fa324..000000000000 --- a/Source/Core/loadBlob.js +++ /dev/null @@ -1,55 +0,0 @@ -define([ - './Check', - './defined', - './deprecationWarning', - './Resource' - ], function( - Check, - defined, - deprecationWarning, - Resource) { - 'use strict'; - - /** - * Asynchronously loads the given URL as a blob. Returns a promise that will resolve to - * a Blob once loaded, or reject if the URL failed to load. The data is loaded - * using XMLHttpRequest, which means that in order to make requests to another origin, - * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. - * - * @exports loadBlob - * - * @param {Resource|String} urlOrResource The URL of the data. - * @param {Object} [headers] HTTP headers to send with the requests. - * @param {Request} [request] The request object. Intended for internal use only. - * @returns {Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. - * - * @example - * // load a single URL asynchronously - * Cesium.loadBlob('some/url').then(function(blob) { - * // use the data - * }).otherwise(function(error) { - * // an error occurred - * }); - * - * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} - * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} - * - * @deprecated - */ - function loadBlob(urlOrResource, headers, request) { - //>>includeStart('debug', pragmas.debug); - Check.defined('urlOrResource', urlOrResource); - //>>includeEnd('debug'); - - deprecationWarning('loadBlob', 'loadBlob is deprecated and will be removed in Cesium 1.44. Please use Resource.fetchBlob instead.'); - - var resource = Resource.createIfNeeded(urlOrResource, { - headers: headers, - request: request - }); - - return resource.fetchBlob(); - } - - return loadBlob; -}); diff --git a/Source/Core/loadCRN.js b/Source/Core/loadCRN.js index 74b4ef5180fe..2af0dfedafe4 100644 --- a/Source/Core/loadCRN.js +++ b/Source/Core/loadCRN.js @@ -2,7 +2,6 @@ define([ '../ThirdParty/when', './CompressedTextureBuffer', './defined', - './deprecationWarning', './DeveloperError', './Resource', './TaskProcessor' @@ -10,7 +9,6 @@ define([ when, CompressedTextureBuffer, defined, - deprecationWarning, DeveloperError, Resource, TaskProcessor) { @@ -48,30 +46,18 @@ define([ * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} */ - function loadCRN(resourceOrUrlOrBuffer, headers, request) { + function loadCRN(resourceOrUrlOrBuffer) { //>>includeStart('debug', pragmas.debug); if (!defined(resourceOrUrlOrBuffer)) { throw new DeveloperError('resourceOrUrlOrBuffer is required.'); } //>>includeEnd('debug'); - if (defined(headers)) { - deprecationWarning('loadCRN.headers', 'The headers parameter has been deprecated. Set the headers property on the Resource parameter.'); - } - - if (defined(request)) { - deprecationWarning('loadCRN.request', 'The request parameter has been deprecated. Set the request property on the Resource parameter.'); - } - var loadPromise; if (resourceOrUrlOrBuffer instanceof ArrayBuffer || ArrayBuffer.isView(resourceOrUrlOrBuffer)) { loadPromise = when.resolve(resourceOrUrlOrBuffer); } else { - var resource = Resource.createIfNeeded(resourceOrUrlOrBuffer, { - headers: headers, - request: request - }); - + var resource = Resource.createIfNeeded(resourceOrUrlOrBuffer); loadPromise = resource.fetchArrayBuffer(); } diff --git a/Source/Core/loadImage.js b/Source/Core/loadImage.js deleted file mode 100644 index b347f5cc35ec..000000000000 --- a/Source/Core/loadImage.js +++ /dev/null @@ -1,79 +0,0 @@ -define([ - './Check', - './defined', - './defineProperties', - './deprecationWarning', - './Resource' - ], function( - Check, - defined, - defineProperties, - deprecationWarning, - Resource) { - 'use strict'; - - /** - * Asynchronously loads the given image URL. Returns a promise that will resolve to - * an {@link Image} once loaded, or reject if the image failed to load. - * - * @exports loadImage - * - * @param {Resource|String} urlOrResource The source URL of the image. - * @param {Boolean} [allowCrossOrigin=true] Whether to request the image using Cross-Origin - * Resource Sharing (CORS). CORS is only actually used if the image URL is actually cross-origin. - * Data URIs are never requested using CORS. - * @param {Request} [request] The request object. Intended for internal use only. - * @returns {Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. - * - * - * @example - * // load a single image asynchronously - * Cesium.loadImage('some/image/url.png').then(function(image) { - * // use the loaded image - * }).otherwise(function(error) { - * // an error occurred - * }); - * - * // load several images in parallel - * when.all([loadImage('image1.png'), loadImage('image2.png')]).then(function(images) { - * // images is an array containing all the loaded images - * }); - * - * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} - * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} - * - * @deprecated - */ - function loadImage(urlOrResource, allowCrossOrigin, request) { - //>>includeStart('debug', pragmas.debug); - Check.defined('urlOrResource', urlOrResource); - //>>includeEnd('debug'); - - deprecationWarning('loadImage', 'loadImage is deprecated and will be removed in Cesium 1.44. Please use Resource.fetchImage instead.'); - - var resource = Resource.createIfNeeded(urlOrResource, { - request: request - }); - - return resource.fetchImage(false, allowCrossOrigin); - } - - defineProperties(loadImage, { - createImage : { - get : function() { - return Resource._Implementations.createImage; - }, - set : function(value) { - Resource._Implementations.createImage = value; - } - }, - - defaultCreateImage : { - get : function() { - return Resource._DefaultImplementations.createImage; - } - } - }); - - return loadImage; -}); diff --git a/Source/Core/loadImageViaBlob.js b/Source/Core/loadImageViaBlob.js deleted file mode 100644 index 7b2003690d23..000000000000 --- a/Source/Core/loadImageViaBlob.js +++ /dev/null @@ -1,66 +0,0 @@ -define([ - './Check', - './defined', - './deprecationWarning', - './Resource' - ], function( - Check, - defined, - deprecationWarning, - Resource) { - 'use strict'; - - /** - * Asynchronously loads the given image URL by first downloading it as a blob using - * XMLHttpRequest and then loading the image from the buffer via a blob URL. - * This allows access to more information that is not accessible via normal - * Image-based downloading, such as the size of the response. This function - * returns a promise that will resolve to - * an {@link Image} once loaded, or reject if the image failed to load. The - * returned image will have a "blob" property with the Blob itself. If the browser - * does not support an XMLHttpRequests with a responseType of 'blob', or if the - * provided URI is a data URI, this function is equivalent to calling {@link loadImage}, - * and the extra blob property will not be present. - * - * @exports loadImageViaBlob - * - * @param {Resource|String} urlOrResource The source URL of the image. - * @param {Request} [request] The request object. Intended for internal use only. - * @returns {Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. - * - * - * @example - * // load a single image asynchronously - * Cesium.loadImageViaBlob('some/image/url.png').then(function(image) { - * var blob = image.blob; - * // use the loaded image or XHR - * }).otherwise(function(error) { - * // an error occurred - * }); - * - * // load several images in parallel - * when.all([loadImageViaBlob('image1.png'), loadImageViaBlob('image2.png')]).then(function(images) { - * // images is an array containing all the loaded images - * }); - * - * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} - * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} - * - * @deprecated - */ - function loadImageViaBlob(urlOrResource, request) { - //>>includeStart('debug', pragmas.debug); - Check.defined('urlOrResource', urlOrResource); - //>>includeEnd('debug'); - - deprecationWarning('loadImageViaBlob', 'loadImageViaBlob is deprecated and will be removed in Cesium 1.44. Please use Resource.fetchImage instead.'); - - var resource = Resource.createIfNeeded(urlOrResource, { - request: request - }); - - return resource.fetchImage(true); - } - - return loadImageViaBlob; -}); diff --git a/Source/Core/loadJson.js b/Source/Core/loadJson.js deleted file mode 100644 index 6fabe58f5612..000000000000 --- a/Source/Core/loadJson.js +++ /dev/null @@ -1,65 +0,0 @@ -define([ - './clone', - './defined', - './deprecationWarning', - './DeveloperError', - './Resource' - ], function( - clone, - defined, - deprecationWarning, - DeveloperError, - Resource) { - 'use strict'; - - // note: */* below is */* but that ends the comment block early - /** - * Asynchronously loads the given URL as JSON. Returns a promise that will resolve to - * a JSON object once loaded, or reject if the URL failed to load. The data is loaded - * using XMLHttpRequest, which means that in order to make requests to another origin, - * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. This function - * adds 'Accept: application/json,*/*;q=0.01' to the request headers, if not - * already specified. - * - * @exports loadJson - * - * @param {Resource|String} urlOrResource The URL to request. - * @param {Object} [headers] HTTP headers to send with the request. - * 'Accept: application/json,*/*;q=0.01' is added to the request headers automatically - * if not specified. - * @param {Request} [request] The request object. Intended for internal use only. - * @returns {Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. - * - * - * @example - * Cesium.loadJson('http://someUrl.com/someJson.txt').then(function(jsonData) { - * // Do something with the JSON object - * }).otherwise(function(error) { - * // an error occurred - * }); - * - * @see loadText - * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} - * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} - * - * @deprecated - */ - function loadJson(urlOrResource, headers, request) { - //>>includeStart('debug', pragmas.debug); - if (!defined(urlOrResource)) { - throw new DeveloperError('urlOrResource is required.'); - } - //>>includeEnd('debug'); - - deprecationWarning('loadJson', 'loadJson is deprecated and will be removed in Cesium 1.44. Please use Resource.fetchJson instead.'); - - var resource = Resource.createIfNeeded(urlOrResource, { - headers: headers, - request: request - }); - - return resource.fetchJson(); - } - - return loadJson; -}); diff --git a/Source/Core/loadJsonp.js b/Source/Core/loadJsonp.js deleted file mode 100644 index a011ca37d9bd..000000000000 --- a/Source/Core/loadJsonp.js +++ /dev/null @@ -1,89 +0,0 @@ -define([ - './clone', - './defined', - './defineProperties', - './deprecationWarning', - './DeveloperError', - './Resource' - ], function( - clone, - defined, - defineProperties, - deprecationWarning, - DeveloperError, - Resource) { - 'use strict'; - - /** - * Requests a resource using JSONP. - * - * @exports loadJsonp - * - * @param {Resource|String} urlOrResource The URL to request. - * @param {String} [callbackParameterName='callback'] The callback parameter name that the server expects. - * @param {Request} [request] The request object. Intended for internal use only. - * @returns {Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. - * - * - * @example - * // load a data asynchronously - * resource.loadJsonp().then(function(data) { - * // use the loaded data - * }).otherwise(function(error) { - * // an error occurred - * }); - * - * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} - * - * @deprecated - */ - function loadJsonp(urlOrResource, callbackParameterName, request) { - //>>includeStart('debug', pragmas.debug); - if (!defined(urlOrResource)) { - throw new DeveloperError('urlOrResource is required.'); - } - //>>includeEnd('debug'); - - deprecationWarning('loadJsonp', 'loadJsonp is deprecated and will be removed in Cesium 1.44. Please use Resource.fetchJsonp instead.'); - - var proxy; - var queryParameters; - if (typeof callbackParameterName === 'object') { - var options = callbackParameterName; - if (defined(options.parameters)) { - queryParameters = clone(options.parameters); - } - if (defined(options.proxy)) { - proxy = options.proxy; - } - callbackParameterName = options.callbackParameterName; - } - - var resource = Resource.createIfNeeded(urlOrResource, { - proxy : proxy, - queryParameters : queryParameters, - request: request - }); - - return resource.fetchJsonp(callbackParameterName); - } - - defineProperties(loadJsonp, { - loadAndExecuteScript : { - get : function() { - return Resource._Implementations.loadAndExecuteScript; - }, - set : function(value) { - Resource._Implementations.loadAndExecuteScript = value; - } - }, - - defaultLoadAndExecuteScript : { - get : function() { - return Resource._DefaultImplementations.loadAndExecuteScript; - } - } - }); - - return loadJsonp; -}); diff --git a/Source/Core/loadKTX.js b/Source/Core/loadKTX.js index bd3212922994..94bfb7a3690b 100644 --- a/Source/Core/loadKTX.js +++ b/Source/Core/loadKTX.js @@ -3,7 +3,6 @@ define([ './Check', './CompressedTextureBuffer', './defined', - './deprecationWarning', './PixelFormat', './Resource', './RuntimeError' @@ -12,7 +11,6 @@ define([ Check, CompressedTextureBuffer, defined, - deprecationWarning, PixelFormat, Resource, RuntimeError) { @@ -69,27 +67,16 @@ define([ * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} */ - function loadKTX(resourceOrUrlOrBuffer, headers, request) { + function loadKTX(resourceOrUrlOrBuffer) { //>>includeStart('debug', pragmas.debug); Check.defined('resourceOrUrlOrBuffer', resourceOrUrlOrBuffer); //>>includeEnd('debug'); - if (defined(headers)) { - deprecationWarning('loadCRN.headers', 'The headers parameter has been deprecated. Set the headers property on the Resource parameter.'); - } - - if (defined(request)) { - deprecationWarning('loadCRN.request', 'The request parameter has been deprecated. Set the request property on the Resource parameter.'); - } - var loadPromise; if (resourceOrUrlOrBuffer instanceof ArrayBuffer || ArrayBuffer.isView(resourceOrUrlOrBuffer)) { loadPromise = when.resolve(resourceOrUrlOrBuffer); } else { - var resource = Resource.createIfNeeded(resourceOrUrlOrBuffer, { - headers: headers, - request: request - }); + var resource = Resource.createIfNeeded(resourceOrUrlOrBuffer); loadPromise = resource.fetchArrayBuffer(); } diff --git a/Source/Core/loadText.js b/Source/Core/loadText.js deleted file mode 100644 index 1aab479c89de..000000000000 --- a/Source/Core/loadText.js +++ /dev/null @@ -1,63 +0,0 @@ -define([ - './Check', - './defined', - './deprecationWarning', - './Resource' - ], function( - Check, - defined, - deprecationWarning, - Resource) { - 'use strict'; - - /** - * Asynchronously loads the given URL as text. Returns a promise that will resolve to - * a String once loaded, or reject if the URL failed to load. The data is loaded - * using XMLHttpRequest, which means that in order to make requests to another origin, - * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. - * - * @exports loadText - * - * @param {Resource|String} urlOrResource The URL to request. - * @param {Object} [headers] HTTP headers to send with the requests. - * @param {Request} [request] The request object. Intended for internal use only. - * @returns {Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. - * - * - * @example - * // load text from a URL, setting a custom header - * var resource = new Resource({ - * url: 'http://someUrl.com/someJson.txt', - * headers: { - * 'X-Custom-Header' : 'some value' - * } - * }); - * Cesium.loadText(resource).then(function(text) { - * // Do something with the text - * }).otherwise(function(error) { - * // an error occurred - * }); - * - * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest|XMLHttpRequest} - * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} - * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} - * - * @deprecated - */ - function loadText(urlOrResource, headers, request) { - //>>includeStart('debug', pragmas.debug); - Check.defined('urlOrResource', urlOrResource); - //>>includeEnd('debug'); - - deprecationWarning('loadText', 'loadText is deprecated and will be removed in Cesium 1.44. Please use Resource.fetchText instead.'); - - var resource = Resource.createIfNeeded(urlOrResource, { - headers: headers, - request: request - }); - - return resource.fetchText(); - } - - return loadText; -}); diff --git a/Source/Core/loadWithXhr.js b/Source/Core/loadWithXhr.js deleted file mode 100644 index 0afb09b7a4d0..000000000000 --- a/Source/Core/loadWithXhr.js +++ /dev/null @@ -1,92 +0,0 @@ -define([ - '../ThirdParty/when', - './Check', - './defaultValue', - './defineProperties', - './deprecationWarning', - './Resource' - ], function( - when, - Check, - defaultValue, - defineProperties, - deprecationWarning, - Resource) { - 'use strict'; - - /** - * Asynchronously loads the given URL. Returns a promise that will resolve to - * the result once loaded, or reject if the URL failed to load. The data is loaded - * using XMLHttpRequest, which means that in order to make requests to another origin, - * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. - * - * @exports loadWithXhr - * - * @param {Object} options Object with the following properties: - * @param {Resource|String} options.url The URL of the data. - * @param {String} [options.responseType] The type of response. This controls the type of item returned. - * @param {String} [options.method='GET'] The HTTP method to use. - * @param {String} [options.data] The data to send with the request, if any. - * @param {Object} [options.headers] HTTP headers to send with the request, if any. - * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server. - * @param {Request} [options.request] The request object. - * @returns {Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. - * - * - * @example - * // Load a single URL asynchronously. In real code, you should use loadBlob instead. - * Cesium.loadWithXhr({ - * url : 'some/url', - * responseType : 'blob' - * }).then(function(blob) { - * // use the data - * }).otherwise(function(error) { - * // an error occurred - * }); - * - * @see loadArrayBuffer - * @see loadBlob - * @see loadJson - * @see loadText - * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} - * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} - * - * @deprecated - */ - function loadWithXhr(options) { - //>>includeStart('debug', pragmas.debug); - Check.defined('options', options); - //>>includeEnd('debug'); - - deprecationWarning('loadWithXhr', 'loadWithXhr is deprecated and will be removed in Cesium 1.44. Please use Resource.fetch instead.'); - - // Take advantage that most parameters are the same - var resource = new Resource(options); - - return resource._makeRequest({ - responseType: options.responseType, - overrideMimeType: options.overrideMimeType, - method: defaultValue(options.method, 'GET'), - data: options.data - }); - } - - defineProperties(loadWithXhr, { - load : { - get : function() { - return Resource._Implementations.loadWithXhr; - }, - set : function(value) { - Resource._Implementations.loadWithXhr = value; - } - }, - - defaultLoad : { - get : function() { - return Resource._DefaultImplementations.loadWithXhr; - } - } - }); - - return loadWithXhr; -}); diff --git a/Source/Core/loadXML.js b/Source/Core/loadXML.js deleted file mode 100644 index b3291f153f2e..000000000000 --- a/Source/Core/loadXML.js +++ /dev/null @@ -1,59 +0,0 @@ -define([ - './Check', - './defined', - './deprecationWarning', - './Resource' - ], function( - Check, - defined, - deprecationWarning, - Resource) { - 'use strict'; - - /** - * Asynchronously loads the given URL as XML. Returns a promise that will resolve to - * an XML Document once loaded, or reject if the URL failed to load. The data is loaded - * using XMLHttpRequest, which means that in order to make requests to another origin, - * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. - * - * @exports loadXML - * - * @param {Resource|String} urlOrResource The URL to request. - * @param {Object} [headers] HTTP headers to send with the requests. - * @param {Request} [request] The request object. Intended for internal use only. - * @returns {Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. - * - * - * @example - * // load XML from a URL, setting a custom header - * Cesium.loadXML('http://someUrl.com/someXML.xml', { - * 'X-Custom-Header' : 'some value' - * }).then(function(document) { - * // Do something with the document - * }).otherwise(function(error) { - * // an error occurred - * }); - * - * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest|XMLHttpRequest} - * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} - * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} - * - * @deprecated - */ - function loadXML(urlOrResource, headers, request) { - //>>includeStart('debug', pragmas.debug); - Check.defined('urlOrResource', urlOrResource); - //>>includeEnd('debug'); - - deprecationWarning('loadXML', 'loadXML is deprecated and will be removed in Cesium 1.44. Please use Resource.fetchXML instead.'); - - var resource = Resource.createIfNeeded(urlOrResource, { - headers: headers, - request: request - }); - - return resource.fetchXML(); - } - - return loadXML; -}); diff --git a/Source/DataSources/CzmlDataSource.js b/Source/DataSources/CzmlDataSource.js index 53c66da6e221..4a521272b462 100644 --- a/Source/DataSources/CzmlDataSource.js +++ b/Source/DataSources/CzmlDataSource.js @@ -11,7 +11,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/DistanceDisplayCondition', '../Core/Ellipsoid', @@ -99,7 +98,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, DistanceDisplayCondition, Ellipsoid, @@ -1969,28 +1967,17 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); - if (defined(options.query)) { - deprecationWarning('CzmlDataSource.query', 'The options.query parameter has been deprecated. Specify czml or options.sourceUri as a Resource instance and add query parameters there.'); - } - var promise = czml; var sourceUri = options.sourceUri; - var query = options.query; // If the czml is a URL if (typeof czml === 'string' || (czml instanceof Resource)) { - czml = Resource.createIfNeeded(czml, { - queryParameters: query - }); - + czml = Resource.createIfNeeded(czml); promise = czml.fetchJson(); - sourceUri = defaultValue(sourceUri, czml.clone()); } - sourceUri = Resource.createIfNeeded(sourceUri, { - queryParameters: query - }); + sourceUri = Resource.createIfNeeded(sourceUri); DataSource.setLoading(dataSource, true); diff --git a/Source/DataSources/KmlDataSource.js b/Source/DataSources/KmlDataSource.js index 7386cb470ac1..efee7838d693 100644 --- a/Source/DataSources/KmlDataSource.js +++ b/Source/DataSources/KmlDataSource.js @@ -11,7 +11,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/Ellipsoid', '../Core/Event', @@ -78,7 +77,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, Ellipsoid, Event, @@ -2367,25 +2365,11 @@ define([ var sourceUri = options.sourceUri; var uriResolver = options.uriResolver; var context = options.context; - var query = options.query; - - if (defined(options.query)) { - deprecationWarning('KmlDataSource.query', 'The options.query parameter has been deprecated. Specify data or options.sourceUri as a Resource instance and add query parameters there.'); - } - - if (defined(dataSource._proxy)) { - deprecationWarning('KmlDataSource.proxy', 'The options.proxy parameter has been deprecated. Specify data or options.sourceUri as a Resource instance and set the proxy property there.'); - } var promise = data; if (typeof data === 'string' || (data instanceof Resource)) { - data = Resource.createIfNeeded(data, { - proxy: dataSource._proxy, - queryParameters: query - }); - + data = Resource.createIfNeeded(data); promise = data.fetchBlob(); - sourceUri = defaultValue(sourceUri, data.clone()); } else { sourceUri = defaultValue(sourceUri, Resource.DEFAULT.clone()); @@ -2393,16 +2377,6 @@ define([ sourceUri = Resource.createIfNeeded(sourceUri); - // Explicitly set these deprecated properties because we can use the default - // resource which won't have these set. - if (defined(dataSource._proxy)) { - sourceUri.proxy = dataSource._proxy; - } - - if (defined(query)) { - sourceUri.setQueryParameters(query); - } - return when(promise) .then(function(dataToLoad) { if (dataToLoad instanceof Blob) { @@ -2517,7 +2491,6 @@ define([ this._entityCollection = new EntityCollection(this); this._name = undefined; this._isLoading = false; - this._proxy = options.proxy; // TODO: Deprecation warning this._pinBuilder = new PinBuilder(); this._networkLinks = new AssociativeArray(); this._entityCluster = new EntityCluster(); @@ -2695,7 +2668,6 @@ define([ * @param {Object} [options] An object with the following properties: * @param {Resource|String} [options.sourceUri] Overrides the url to use for resolving relative links and other KML network features. * @param {Boolean} [options.clampToGround=false] true if we want the geometry features (Polygons, LineStrings and LinearRings) clamped to the ground. If true, lines will use corridors so use Entity.corridor instead of Entity.polyline. - * @param {Object} [options.query] Key-value pairs which are appended to all URIs in the CZML. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The global ellipsoid used for geographical calculations. * * @returns {Promise.} A promise that will resolve to this instances once the KML is loaded. diff --git a/Source/Scene/ArcGisMapServerImageryProvider.js b/Source/Scene/ArcGisMapServerImageryProvider.js index 7644ed4fe608..489d6d632abe 100644 --- a/Source/Scene/ArcGisMapServerImageryProvider.js +++ b/Source/Scene/ArcGisMapServerImageryProvider.js @@ -6,7 +6,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/Event', '../Core/GeographicTilingScheme', @@ -29,7 +28,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, Event, GeographicTilingScheme, @@ -115,13 +113,7 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('ArcGisMapServerImageryProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - - var resource = Resource.createIfNeeded(options.url, { - proxy: options.proxy - }); + var resource = Resource.createIfNeeded(options.url); resource.appendForwardSlash(); if (defined(options.token)) { diff --git a/Source/Scene/BingMapsImageryProvider.js b/Source/Scene/BingMapsImageryProvider.js index c84f5c18a139..b80e0f45b043 100644 --- a/Source/Scene/BingMapsImageryProvider.js +++ b/Source/Scene/BingMapsImageryProvider.js @@ -6,7 +6,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/Event', '../Core/Math', @@ -27,7 +26,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, Event, CesiumMath, @@ -104,17 +102,9 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('BingMapsImageryProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - this._key = BingMapsApi.getKey(options.key); this._keyErrorCredit = BingMapsApi.getErrorCredit(options.key); - - this._resource = Resource.createIfNeeded(options.url, { - proxy: options.proxy - }); - + this._resource = Resource.createIfNeeded(options.url); this._tileProtocol = options.tileProtocol; this._mapStyle = defaultValue(options.mapStyle, BingMapsStyle.AERIAL); this._culture = defaultValue(options.culture, ''); diff --git a/Source/Scene/GoogleEarthEnterpriseImageryProvider.js b/Source/Scene/GoogleEarthEnterpriseImageryProvider.js index 25e99b644153..5e71d409ef50 100644 --- a/Source/Scene/GoogleEarthEnterpriseImageryProvider.js +++ b/Source/Scene/GoogleEarthEnterpriseImageryProvider.js @@ -4,7 +4,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/Event', '../Core/GeographicTilingScheme', @@ -24,7 +23,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, Event, GeographicTilingScheme, @@ -108,17 +106,11 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('GoogleEarthEnterpriseImageryProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - var metadata; if (defined(options.metadata)) { metadata = options.metadata; } else { - var resource = Resource.createIfNeeded(options.url, { - proxy: options.proxy - }); + var resource = Resource.createIfNeeded(options.url); metadata = new GoogleEarthEnterpriseMetadata(resource); } this._metadata = metadata; diff --git a/Source/Scene/GoogleEarthEnterpriseMapsProvider.js b/Source/Scene/GoogleEarthEnterpriseMapsProvider.js index 3a961721987a..71072b497f02 100644 --- a/Source/Scene/GoogleEarthEnterpriseMapsProvider.js +++ b/Source/Scene/GoogleEarthEnterpriseMapsProvider.js @@ -4,7 +4,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/Event', '../Core/GeographicTilingScheme', @@ -21,7 +20,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, Event, GeographicTilingScheme, @@ -114,16 +112,10 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('GoogleEarthEnterpriseMapsProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - var url = options.url; var path = defaultValue(options.path, '/default_map'); - var resource = Resource.createIfNeeded(url, { - proxy : options.proxy - }).getDerivedResource({ + var resource = Resource.createIfNeeded(url).getDerivedResource({ // We used to just append path to url, so now that we do proper URI resolution, removed the / url : (path[0] === '/') ? path.substring(1) : path }); diff --git a/Source/Scene/ImageryProvider.js b/Source/Scene/ImageryProvider.js index ee8e77b37f30..61f49b663a56 100644 --- a/Source/Scene/ImageryProvider.js +++ b/Source/Scene/ImageryProvider.js @@ -2,7 +2,6 @@ define([ '../Core/Check', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/loadCRN', '../Core/loadKTX', @@ -11,7 +10,6 @@ define([ Check, defined, defineProperties, - deprecationWarning, DeveloperError, loadCRN, loadKTX, @@ -334,18 +332,12 @@ define([ * should be retried later. The resolved image may be either an * Image or a Canvas DOM object. */ - ImageryProvider.loadImage = function(imageryProvider, url, request) { + ImageryProvider.loadImage = function(imageryProvider, url) { //>>includeStart('debug', pragmas.debug); Check.defined('url', url); //>>includeEnd('debug'); - if (defined(request)) { - deprecationWarning('ImageryProvider.loadImage.request', 'The request parameter has been deprecated. Set the request property on the Resource parameter.'); - } - - var resource = Resource.createIfNeeded(url, { - request: request - }); + var resource = Resource.createIfNeeded(url); if (ktxRegex.test(resource)) { return loadKTX(resource); diff --git a/Source/Scene/IonImageryProvider.js b/Source/Scene/IonImageryProvider.js index 48205d1dea2d..dad80fe8b42a 100644 --- a/Source/Scene/IonImageryProvider.js +++ b/Source/Scene/IonImageryProvider.js @@ -8,7 +8,6 @@ define([ '../Core/DeveloperError', '../Core/Event', '../Core/IonResource', - '../Core/loadJson', '../Core/Resource', '../Core/RuntimeError', '../ThirdParty/when', @@ -32,7 +31,6 @@ define([ DeveloperError, Event, IonResource, - loadJson, Resource, RuntimeError, when, diff --git a/Source/Scene/MapboxImageryProvider.js b/Source/Scene/MapboxImageryProvider.js index 9c47f7798526..204c8e34bc99 100644 --- a/Source/Scene/MapboxImageryProvider.js +++ b/Source/Scene/MapboxImageryProvider.js @@ -3,7 +3,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/MapboxApi', '../Core/Resource', @@ -13,7 +12,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, MapboxApi, Resource, @@ -62,19 +60,13 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('MapboxImageryProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - var url = options.url; if (!defined(url)) { url = 'https://api.mapbox.com/v4/'; } this._url = url; - var resource = Resource.createIfNeeded(url, { - proxy: options.proxy - }); + var resource = Resource.createIfNeeded(url); var accessToken = MapboxApi.getAccessToken(options.accessToken); this._mapId = mapId; diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index 43dd7fb2f08d..3dbd5afb53fe 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -10,7 +10,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/destroyObject', '../Core/DeveloperError', '../Core/DistanceDisplayCondition', @@ -89,7 +88,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, destroyObject, DeveloperError, DistanceDisplayCondition, @@ -1171,23 +1169,15 @@ define([ } //>>includeEnd('debug'); - if (defined(options.headers)) { - deprecationWarning('Model.fromGltf.headers', 'The options.headers parameter has been deprecated. Specify options.url as a Resource instance and set the headers property there.'); - } - var url = options.url; options = clone(options); // Create resource for the model file - var modelResource = Resource.createIfNeeded(url, { - headers : options.headers - }); + var modelResource = Resource.createIfNeeded(url); // Setup basePath to get dependent files var basePath = defaultValue(options.basePath, modelResource.clone()); - var resource = Resource.createIfNeeded(basePath, { - headers : options.headers - }); + var resource = Resource.createIfNeeded(basePath); // If no cache key is provided, use the absolute URL, since two URLs with // different relative paths could point to the same model. diff --git a/Source/Scene/ModelInstanceCollection.js b/Source/Scene/ModelInstanceCollection.js index e771dfae5857..f21c9d785f7b 100644 --- a/Source/Scene/ModelInstanceCollection.js +++ b/Source/Scene/ModelInstanceCollection.js @@ -7,7 +7,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/destroyObject', '../Core/DeveloperError', '../Core/Matrix4', @@ -35,7 +34,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, destroyObject, DeveloperError, Matrix4, diff --git a/Source/Scene/SingleTileImageryProvider.js b/Source/Scene/SingleTileImageryProvider.js index 1ad86c008ebf..b31a10dcdfb2 100644 --- a/Source/Scene/SingleTileImageryProvider.js +++ b/Source/Scene/SingleTileImageryProvider.js @@ -3,7 +3,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/Event', '../Core/GeographicTilingScheme', @@ -17,7 +16,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, Event, GeographicTilingScheme, @@ -58,13 +56,7 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('SingleTileImageryProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - - var resource = Resource.createIfNeeded(options.url, { - proxy: options.proxy - }); + var resource = Resource.createIfNeeded(options.url); var rectangle = defaultValue(options.rectangle, Rectangle.MAX_VALUE); var tilingScheme = new GeographicTilingScheme({ diff --git a/Source/Scene/UrlTemplateImageryProvider.js b/Source/Scene/UrlTemplateImageryProvider.js index f325eade8085..6c5929ab33f9 100644 --- a/Source/Scene/UrlTemplateImageryProvider.js +++ b/Source/Scene/UrlTemplateImageryProvider.js @@ -8,7 +8,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/Event', '../Core/GeographicTilingScheme', @@ -29,7 +28,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, Event, GeographicTilingScheme, @@ -579,21 +577,11 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('UrlTemplateImageryProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - var customTags = properties.customTags; var allTags = combine(tags, customTags); var allPickFeaturesTags = combine(pickFeaturesTags, customTags); - - var resource = Resource.createIfNeeded(properties.url, { - proxy: properties.proxy - }); - - var pickFeaturesResource = Resource.createIfNeeded(properties.pickFeaturesUrl, { - proxy: properties.proxy - }); + var resource = Resource.createIfNeeded(properties.url); + var pickFeaturesResource = Resource.createIfNeeded(properties.pickFeaturesUrl); that.enablePickFeatures = defaultValue(properties.enablePickFeatures, that.enablePickFeatures); that._urlSchemeZeroPadding = defaultValue(properties.urlSchemeZeroPadding, that.urlSchemeZeroPadding); diff --git a/Source/Scene/WebMapServiceImageryProvider.js b/Source/Scene/WebMapServiceImageryProvider.js index 581e06f23e70..e8c410f01da4 100644 --- a/Source/Scene/WebMapServiceImageryProvider.js +++ b/Source/Scene/WebMapServiceImageryProvider.js @@ -3,7 +3,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/freezeObject', '../Core/GeographicTilingScheme', @@ -19,7 +18,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, freezeObject, GeographicTilingScheme, @@ -103,14 +101,7 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('WebMapServiceImageryProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - - var resource = Resource.createIfNeeded(options.url, { - proxy: options.proxy - }); - + var resource = Resource.createIfNeeded(options.url); var pickFeatureResource = resource.clone(); resource.setQueryParameters(WebMapServiceImageryProvider.DefaultParameters, true); diff --git a/Source/Scene/WebMapTileServiceImageryProvider.js b/Source/Scene/WebMapTileServiceImageryProvider.js index 6378d84595f6..bc89458c6b0b 100644 --- a/Source/Scene/WebMapTileServiceImageryProvider.js +++ b/Source/Scene/WebMapTileServiceImageryProvider.js @@ -4,7 +4,6 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/Event', '../Core/freezeObject', @@ -24,7 +23,6 @@ define([ defaultValue, defined, defineProperties, - deprecationWarning, DeveloperError, Event, freezeObject, @@ -157,13 +155,7 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('WebMapTileServiceImageryProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - - var resource = Resource.createIfNeeded(options.url, { - proxy: options.proxy - }); + var resource = Resource.createIfNeeded(options.url); var style = options.style; var tileMatrixSetID = options.tileMatrixSetID; diff --git a/Source/Scene/createOpenStreetMapImageryProvider.js b/Source/Scene/createOpenStreetMapImageryProvider.js index da0a604ad770..1df01809fd65 100644 --- a/Source/Scene/createOpenStreetMapImageryProvider.js +++ b/Source/Scene/createOpenStreetMapImageryProvider.js @@ -3,7 +3,6 @@ define([ '../Core/Credit', '../Core/defaultValue', '../Core/defined', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/Rectangle', '../Core/Resource', @@ -14,7 +13,6 @@ define([ Credit, defaultValue, defined, - deprecationWarning, DeveloperError, Rectangle, Resource, @@ -68,14 +66,7 @@ define([ var url = defaultValue(options.url, 'https://a.tile.openstreetmap.org/'); url = appendForwardSlash(url); url += '{z}/{x}/{y}.' + defaultValue(options.fileExtension, 'png'); - - if (defined(options.proxy)) { - deprecationWarning('createOpenStreetMapImageryProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - - var resource = Resource.createIfNeeded(url, { - proxy: options.proxy - }); + var resource = Resource.createIfNeeded(url); var tilingScheme = new WebMercatorTilingScheme({ ellipsoid : options.ellipsoid }); diff --git a/Source/Scene/createTileMapServiceImageryProvider.js b/Source/Scene/createTileMapServiceImageryProvider.js index 8034a0b6a871..c9b433b888dd 100644 --- a/Source/Scene/createTileMapServiceImageryProvider.js +++ b/Source/Scene/createTileMapServiceImageryProvider.js @@ -3,7 +3,6 @@ define([ '../Core/Cartographic', '../Core/defaultValue', '../Core/defined', - '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/GeographicTilingScheme', '../Core/Rectangle', @@ -18,7 +17,6 @@ define([ Cartographic, defaultValue, defined, - deprecationWarning, DeveloperError, GeographicTilingScheme, Rectangle, @@ -91,10 +89,6 @@ define([ } //>>includeEnd('debug'); - if (defined(options.proxy)) { - deprecationWarning('createTileMapServiceImageryProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.'); - } - var deferred = when.defer(); var imageryProvider = new UrlTemplateImageryProvider(deferred.promise); @@ -103,9 +97,7 @@ define([ var xmlResource; when(options.url) .then(function(url) { - resource = Resource.createIfNeeded(url, { - proxy : options.proxy - }); + resource = Resource.createIfNeeded(url); resource.appendForwardSlash(); xmlResource = resource.getDerivedResource({ diff --git a/Specs/Core/CesiumTerrainProviderSpec.js b/Specs/Core/CesiumTerrainProviderSpec.js index b994158567c6..7b44e32baa88 100644 --- a/Specs/Core/CesiumTerrainProviderSpec.js +++ b/Specs/Core/CesiumTerrainProviderSpec.js @@ -509,30 +509,6 @@ defineSuite([ }); }); - it('uses the proxy if one is supplied', function() { - var baseUrl = 'made/up/url'; - - Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) { - expect(url.indexOf('/proxy/?')).toBe(0); - - // Just return any old file, as long as its big enough - Resource._DefaultImplementations.loadWithXhr('Data/EarthOrientationParameters/IcrfToFixedStkComponentsRotationData.json', responseType, method, data, headers, deferred); - }; - - returnHeightmapTileJson(); - - var terrainProvider = new CesiumTerrainProvider({ - url : baseUrl, - proxy : new DefaultProxy('/proxy/') - }); - - return pollToPromise(function() { - return terrainProvider.ready; - }).then(function() { - return terrainProvider.requestTileGeometry(0, 0, 0); - }); - }); - it('provides HeightmapTerrainData', function() { Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) { // Just return any old file, as long as its big enough diff --git a/Specs/Core/GoogleEarthEnterpriseMetadataSpec.js b/Specs/Core/GoogleEarthEnterpriseMetadataSpec.js index eca718321a99..371f4e2ebcd5 100644 --- a/Specs/Core/GoogleEarthEnterpriseMetadataSpec.js +++ b/Specs/Core/GoogleEarthEnterpriseMetadataSpec.js @@ -244,43 +244,4 @@ defineSuite([ expect(e.message).toContain(url); }); }); - - it('routes requests through a proxy if one is specified', function() { - var proxy = new DefaultProxy('/proxy/'); - var baseurl = 'http://fake.fake.invalid/'; - - var req = 0; - spyOn(Resource._Implementations, 'loadWithXhr').and.callFake(function(url, responseType, method, data, headers, deferred, overrideMimeType) { - expect(responseType).toEqual('arraybuffer'); - if (req === 0) { - expect(url).toEqual(proxy.getURL(baseurl + 'dbRoot.v5?output=proto')); - deferred.reject(); // Reject dbRoot request and use defaults - } else { - expect(url).toEqual(proxy.getURL(baseurl + 'flatfile?q2-0-q.1')); - Resource._DefaultImplementations.loadWithXhr('Data/GoogleEarthEnterprise/gee.metadata', responseType, method, data, headers, deferred); - } - ++req; - }); - - var provider = new GoogleEarthEnterpriseMetadata({ - url : baseurl, - proxy : proxy - }); - - expect(provider._resource._url).toEqual(baseurl); - expect(provider.proxy).toEqual(proxy); - - return provider.readyPromise.then(function(result) { - expect(result).toBe(true); - - var tileInfo = provider._tileInfo['0']; - expect(tileInfo).toBeDefined(); - expect(tileInfo._bits).toEqual(0x40); - expect(tileInfo.cnodeVersion).toEqual(2); - expect(tileInfo.imageryVersion).toEqual(1); - expect(tileInfo.terrainVersion).toEqual(1); - expect(tileInfo.ancestorHasTerrain).toEqual(false); - expect(tileInfo.terrainState).toBeUndefined(); - }); - }); }); diff --git a/Specs/Core/GoogleEarthEnterpriseTerrainProviderSpec.js b/Specs/Core/GoogleEarthEnterpriseTerrainProviderSpec.js index 4f298258e55b..beb43d4764c0 100644 --- a/Specs/Core/GoogleEarthEnterpriseTerrainProviderSpec.js +++ b/Specs/Core/GoogleEarthEnterpriseTerrainProviderSpec.js @@ -260,28 +260,6 @@ defineSuite([ }); describe('requestTileGeometry', function() { - it('uses the proxy if one is supplied', function() { - installMockGetQuadTreePacket(); - var baseUrl = 'made/up/url'; - - Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) { - expect(url.indexOf('/proxy/?')).toBe(0); - - Resource._DefaultImplementations.loadWithXhr('Data/GoogleEarthEnterprise/gee.terrain', responseType, method, data, headers, deferred); - }; - - terrainProvider = new GoogleEarthEnterpriseTerrainProvider({ - url : baseUrl, - proxy : new DefaultProxy('/proxy/') - }); - - return pollToPromise(function() { - return terrainProvider.ready; - }).then(function() { - return terrainProvider.requestTileGeometry(0, 0, 0); - }); - }); - it('provides GoogleEarthEnterpriseTerrainData', function() { installMockGetQuadTreePacket(); Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) { diff --git a/Specs/Core/VRTheWorldTerrainProviderSpec.js b/Specs/Core/VRTheWorldTerrainProviderSpec.js index 03668e9e40b1..63f7ce792a13 100644 --- a/Specs/Core/VRTheWorldTerrainProviderSpec.js +++ b/Specs/Core/VRTheWorldTerrainProviderSpec.js @@ -232,29 +232,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('uses the proxy if one is supplied', function() { - var baseUrl = 'made/up/url'; - - Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - expect(url.indexOf('/proxy/?')).toBe(0); - expect(url.indexOf(encodeURIComponent('.tif?cesium=true'))).toBeGreaterThanOrEqualTo(0); - - // Just return any old image. - Resource._DefaultImplementations.createImage('Data/Images/Red16x16.png', crossOrigin, deferred); - }; - - var terrainProvider = new VRTheWorldTerrainProvider({ - url : baseUrl, - proxy : new DefaultProxy('/proxy/') - }); - - return pollToPromise(function() { - return terrainProvider.ready; - }).then(function() { - return terrainProvider.requestTileGeometry(0, 0, 0); - }); - }); - it('provides HeightmapTerrainData', function() { var baseUrl = 'made/up/url'; diff --git a/Specs/Core/loadArrayBufferSpec.js b/Specs/Core/loadArrayBufferSpec.js deleted file mode 100644 index b523eb1798b9..000000000000 --- a/Specs/Core/loadArrayBufferSpec.js +++ /dev/null @@ -1,183 +0,0 @@ -defineSuite([ - 'Core/loadArrayBuffer', - 'Core/Request', - 'Core/RequestErrorEvent', - 'Core/RequestScheduler', - 'Core/Resource' - ], function( - loadArrayBuffer, - Request, - RequestErrorEvent, - RequestScheduler, - Resource) { - 'use strict'; - - var fakeXHR; - - beforeEach(function() { - fakeXHR = jasmine.createSpyObj('XMLHttpRequest', ['send', 'open', 'setRequestHeader', 'abort', 'getAllResponseHeaders']); - fakeXHR.simulateLoad = function(response) { - fakeXHR.status = 200; - fakeXHR.response = response; - if (typeof fakeXHR.onload === 'function') { - fakeXHR.onload(); - } - }; - fakeXHR.simulateError = function() { - fakeXHR.response = ''; - if (typeof fakeXHR.onerror === 'function') { - fakeXHR.onerror(); - } - }; - fakeXHR.simulateHttpError = function(statusCode, response) { - fakeXHR.status = statusCode; - fakeXHR.response = response; - if (typeof fakeXHR.onload === 'function') { - fakeXHR.onload(); - } - }; - - spyOn(window, 'XMLHttpRequest').and.returnValue(fakeXHR); - }); - - it('throws with no url', function() { - expect(function() { - loadArrayBuffer(); - }).toThrowDeveloperError(); - }); - - it('creates and sends request without any custom headers', function() { - var testUrl = 'http://example.invalid/testuri'; - loadArrayBuffer(testUrl); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', testUrl, true); - expect(fakeXHR.setRequestHeader).not.toHaveBeenCalled(); - expect(fakeXHR.send).toHaveBeenCalled(); - }); - - it('creates and sends request with custom headers', function() { - var testUrl = 'http://example.invalid/testuri'; - loadArrayBuffer(testUrl, { - 'Accept' : 'application/json', - 'Cache-Control' : 'no-cache' - }); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', testUrl, true); - expect(fakeXHR.setRequestHeader.calls.count()).toEqual(2); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Accept', 'application/json'); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Cache-Control', 'no-cache'); - expect(fakeXHR.send).toHaveBeenCalled(); - }); - - it('returns a promise that resolves when the request loads', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadArrayBuffer(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var response = 'some response'; - fakeXHR.simulateLoad(response); - expect(resolvedValue).toEqual(response); - expect(rejectedError).toBeUndefined(); - }); - - it('returns a promise that resolves when the request loads with Resource', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadArrayBuffer(new Resource({ - url: testUrl - })); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var response = 'some response'; - fakeXHR.simulateLoad(response); - expect(resolvedValue).toEqual(response); - expect(rejectedError).toBeUndefined(); - }); - - it('returns a promise that rejects when the request errors', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadArrayBuffer(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - fakeXHR.simulateError(); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - expect(rejectedError.statusCode).toBeUndefined(); - expect(rejectedError.response).toBeUndefined(); - }); - - it('returns a promise that rejects when the request results in an HTTP error code', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadArrayBuffer(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var error = 'some error'; - fakeXHR.simulateHttpError(404, error); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - expect(rejectedError.statusCode).toEqual(404); - expect(rejectedError.response).toEqual(error); - }); - - it('returns undefined if the request is throttled', function() { - var oldMaximumRequests = RequestScheduler.maximumRequests; - RequestScheduler.maximumRequests = 0; - - var request = new Request({ - throttle : true - }); - - var testUrl = 'http://example.invalid/testuri'; - var promise = loadArrayBuffer(testUrl, undefined, request); - expect(promise).toBeUndefined(); - - RequestScheduler.maximumRequests = oldMaximumRequests; - }); -}); diff --git a/Specs/Core/loadBlobSpec.js b/Specs/Core/loadBlobSpec.js deleted file mode 100644 index 65ee6f68b529..000000000000 --- a/Specs/Core/loadBlobSpec.js +++ /dev/null @@ -1,176 +0,0 @@ -defineSuite([ - 'Core/loadBlob', - 'Core/Request', - 'Core/RequestErrorEvent', - 'Core/RequestScheduler', - 'Core/Resource' - ], function( - loadBlob, - Request, - RequestErrorEvent, - RequestScheduler, - Resource) { - 'use strict'; - - var fakeXHR; - - beforeEach(function() { - fakeXHR = jasmine.createSpyObj('XMLHttpRequest', ['send', 'open', 'setRequestHeader', 'abort', 'getAllResponseHeaders']); - fakeXHR.simulateLoad = function(response) { - fakeXHR.status = 200; - fakeXHR.response = response; - if (typeof fakeXHR.onload === 'function') { - fakeXHR.onload(); - } - }; - fakeXHR.simulateError = function() { - fakeXHR.response = ''; - if (typeof fakeXHR.onerror === 'function') { - fakeXHR.onerror(); - } - }; - fakeXHR.simulateHttpError = function(statusCode, response) { - fakeXHR.status = statusCode; - fakeXHR.response = response; - if (typeof fakeXHR.onload === 'function') { - fakeXHR.onload(); - } - }; - - spyOn(window, 'XMLHttpRequest').and.returnValue(fakeXHR); - }); - - it('throws with no url', function() { - expect(function() { - loadBlob(); - }).toThrowDeveloperError(); - }); - - it('creates and sends request without any custom headers', function() { - var testUrl = 'http://example.invalid/testuri'; - loadBlob(testUrl); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', testUrl, true); - expect(fakeXHR.setRequestHeader).not.toHaveBeenCalled(); - expect(fakeXHR.send).toHaveBeenCalled(); - }); - - it('creates and sends request with custom headers', function() { - var testUrl = 'http://example.invalid/testuri'; - loadBlob(testUrl, { - 'Accept' : 'application/json', - 'Cache-Control' : 'no-cache' - }); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', testUrl, true); - expect(fakeXHR.setRequestHeader.calls.count()).toEqual(2); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Accept', 'application/json'); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Cache-Control', 'no-cache'); - expect(fakeXHR.send).toHaveBeenCalled(); - }); - - it('creates and sends request with custom headers with Resource', function() { - var testUrl = 'http://example.invalid/testuri'; - var resource = new Resource({ - url: testUrl, - headers: { - 'Accept' : 'application/json', - 'Cache-Control' : 'no-cache' - } - }); - loadBlob(resource); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', testUrl, true); - expect(fakeXHR.setRequestHeader.calls.count()).toEqual(2); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Accept', 'application/json'); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Cache-Control', 'no-cache'); - expect(fakeXHR.send).toHaveBeenCalled(); - }); - - it('returns a promise that resolves when the request loads', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadBlob(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var response = 'some response'; - fakeXHR.simulateLoad(response); - expect(resolvedValue).toEqual(response); - expect(rejectedError).toBeUndefined(); - }); - - it('returns a promise that rejects when the request errors', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadBlob(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - fakeXHR.simulateError(); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - expect(rejectedError.statusCode).toBeUndefined(); - expect(rejectedError.response).toBeUndefined(); - }); - - it('returns a promise that rejects when the request results in an HTTP error code', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadBlob(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var error = 'some error'; - fakeXHR.simulateHttpError(404, error); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - expect(rejectedError.statusCode).toEqual(404); - expect(rejectedError.response).toEqual(error); - }); - - it('returns undefined if the request is throttled', function() { - var oldMaximumRequests = RequestScheduler.maximumRequests; - RequestScheduler.maximumRequests = 0; - - var request = new Request({ - throttle : true - }); - - var testUrl = 'http://example.invalid/testuri'; - var promise = loadBlob(testUrl, undefined, request); - expect(promise).toBeUndefined(); - - RequestScheduler.maximumRequests = oldMaximumRequests; - }); -}); diff --git a/Specs/Core/loadCRNSpec.js b/Specs/Core/loadCRNSpec.js index 84d5d6bca807..4afde0019b45 100644 --- a/Specs/Core/loadCRNSpec.js +++ b/Specs/Core/loadCRNSpec.js @@ -55,20 +55,6 @@ defineSuite([ expect(fakeXHR.send).toHaveBeenCalled(); }); - it('creates and sends request with custom headers', function() { - var testUrl = 'http://example.invalid/testuri'; - loadCRN(testUrl, { - 'Accept' : 'application/json', - 'Cache-Control' : 'no-cache' - }); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', testUrl, true); - expect(fakeXHR.setRequestHeader.calls.count()).toEqual(2); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Accept', 'application/json'); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Cache-Control', 'no-cache'); - expect(fakeXHR.send).toHaveBeenCalled(); - }); - it('creates and sends request with custom headers with Resource', function() { var testUrl = 'http://example.invalid/testuri'; var resource = new Resource({ @@ -226,12 +212,12 @@ defineSuite([ var oldMaximumRequests = RequestScheduler.maximumRequests; RequestScheduler.maximumRequests = 0; - var request = new Request({ - throttle : true - }); - - var testUrl = 'http://example.invalid/testuri'; - var promise = loadCRN(testUrl, undefined, request); + var promise = loadCRN(new Resource({ + url: 'http://example.invalid/testuri', + request: new Request({ + throttle: true + }) + })); expect(promise).toBeUndefined(); RequestScheduler.maximumRequests = oldMaximumRequests; diff --git a/Specs/Core/loadImageSpec.js b/Specs/Core/loadImageSpec.js deleted file mode 100644 index 50f0a43fdc6b..000000000000 --- a/Specs/Core/loadImageSpec.js +++ /dev/null @@ -1,318 +0,0 @@ -defineSuite([ - 'Core/loadImage', - 'Core/Request', - 'Core/RequestScheduler', - 'Core/Resource', - 'ThirdParty/when' - ], function( - loadImage, - Request, - RequestScheduler, - Resource, - when) { - 'use strict'; - - var dataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2Nk+M/wHwAEBgIA5agATwAAAABJRU5ErkJggg=='; - - it('can load an image', function() { - return loadImage('./Data/Images/Green.png').then(function(loadedImage) { - expect(loadedImage.width).toEqual(1); - expect(loadedImage.height).toEqual(1); - }); - }); - - it('can load an image from a data URI', function() { - return loadImage(dataUri).then(function(loadedImage) { - expect(loadedImage.width).toEqual(1); - expect(loadedImage.height).toEqual(1); - }); - }); - - it('throws with if url is missing', function() { - expect(function() { - loadImage(); - }).toThrowDeveloperError(); - }); - - it('sets the crossOrigin property for cross-origin images', function() { - var fakeImage = {}; - var imageConstructorSpy = spyOn(window, 'Image').and.returnValue(fakeImage); - - loadImage('http://example.invalid/someImage.png'); - expect(imageConstructorSpy).toHaveBeenCalled(); - expect(fakeImage.crossOrigin).toEqual(''); - }); - - it('does not set the crossOrigin property for cross-origin images when allowCrossOrigin is false', function() { - var fakeImage = {}; - var imageConstructorSpy = spyOn(window, 'Image').and.returnValue(fakeImage); - - loadImage('http://example.invalid/someImage.png', false); - expect(imageConstructorSpy).toHaveBeenCalled(); - expect(fakeImage.crossOrigin).toBeUndefined(); - }); - - it('does not set the crossOrigin property for non-cross-origin images', function() { - var fakeImage = {}; - var imageConstructorSpy = spyOn(window, 'Image').and.returnValue(fakeImage); - - loadImage('./someImage.png', false); - expect(imageConstructorSpy).toHaveBeenCalled(); - expect(fakeImage.crossOrigin).toBeUndefined(); - }); - - it('does not set the crossOrigin property for data URIs', function() { - var fakeImage = {}; - var imageConstructorSpy = spyOn(window, 'Image').and.returnValue(fakeImage); - - loadImage(dataUri); - expect(imageConstructorSpy).toHaveBeenCalled(); - expect(fakeImage.crossOrigin).toBeUndefined(); - }); - - it('resolves the promise when the image loads', function() { - var fakeImage = {}; - spyOn(window, 'Image').and.returnValue(fakeImage); - - var success = false; - var failure = false; - var loadedImage; - - when(loadImage(dataUri), function(image) { - success = true; - loadedImage = image; - }, function() { - failure = true; - }); - - // neither callback has fired yet - expect(success).toEqual(false); - expect(failure).toEqual(false); - - fakeImage.onload(); - expect(success).toEqual(true); - expect(failure).toEqual(false); - expect(loadedImage).toBe(fakeImage); - }); - - it('rejects the promise when the image errors', function() { - var fakeImage = {}; - spyOn(window, 'Image').and.returnValue(fakeImage); - - var success = false; - var failure = false; - var loadedImage; - - when(loadImage(dataUri), function(image) { - success = true; - loadedImage = image; - }, function() { - failure = true; - }); - - // neither callback has fired yet - expect(success).toEqual(false); - expect(failure).toEqual(false); - - fakeImage.onerror(); - expect(success).toEqual(false); - expect(failure).toEqual(true); - expect(loadedImage).toBeUndefined(); - }); - - it('returns undefined if the request is throttled', function() { - var oldMaximumRequests = RequestScheduler.maximumRequests; - RequestScheduler.maximumRequests = 0; - - var request = new Request({ - throttle : true - }); - - var testUrl = 'http://example.invalid/testuri'; - var promise = loadImage(testUrl, undefined, request); - expect(promise).toBeUndefined(); - - RequestScheduler.maximumRequests = oldMaximumRequests; - }); - - it('Calls loadWithXhr with blob response type if headers is set', function() { - var expectedUrl = 'http://example.invalid/testuri.png'; - var expectedHeaders = { - 'X-my-header': 'my-value' - }; - spyOn(Resource._Implementations, 'loadWithXhr').and.callFake(function(url, responseType, method, data, headers, deferred, overrideMimeType) { - expect(url).toEqual(expectedUrl); - expect(headers).toEqual(expectedHeaders); - expect(responseType).toEqual('blob'); - - var binary = atob(dataUri.split(',')[1]); - var array = []; - for(var i = 0; i < binary.length; i++) { - array.push(binary.charCodeAt(i)); - } - - deferred.resolve(new Blob([new Uint8Array(array)], {type: 'image/png'})); - }); - - var testResource = new Resource({ - url: expectedUrl, - headers: expectedHeaders - }); - var promise = loadImage(testResource); - expect(promise).toBeDefined(); - - return promise - .then(function(image) { - expect(image).toBeDefined(); - }); - }); - - it('Doesn\'t call loadWithXhr with blob response type if headers is set but is a data URI', function() { - spyOn(Resource._Implementations, 'loadWithXhr').and.callFake(function(url, responseType, method, data, headers, deferred, overrideMimeType) { - deferred.reject('this shouldn\'t happen'); - }); - - spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) { - expect(url).toEqual(dataUri); - return loadImage.defaultCreateImage(url, crossOrigin, deferred); - }); - - var testResource = new Resource({ - url: dataUri, - headers: { - 'X-my-header': 'my-value' - } - }); - var promise = loadImage(testResource); - expect(promise).toBeDefined(); - - return promise - .then(function(image) { - expect(image).toBeDefined(); - }); - }); - - describe('retries when Resource has the callback set', function() { - it('rejects after too many retries', function() { - var fakeImage = {}; - spyOn(window, 'Image').and.returnValue(fakeImage); - - var cb = jasmine.createSpy('retry').and.returnValue(true); - - var resource = new Resource({ - url : 'http://example.invalid/image.png', - retryCallback: cb, - retryAttempts: 1 - }); - - var promise = loadImage(resource); - - expect(promise).toBeDefined(); - - var success = false; - var failure = false; - promise.then(function() { - success = true; - }).otherwise(function () { - failure = true; - }); - - expect(success).toBe(false); - expect(failure).toBe(false); - - fakeImage.onerror('some error'); // This should retry - expect(success).toBe(false); - expect(failure).toBe(false); - - expect(cb.calls.count()).toEqual(1); - var receivedResource = cb.calls.argsFor(0)[0]; - expect(receivedResource.url).toEqual(resource.url); - expect(receivedResource._retryCount).toEqual(1); - expect(cb.calls.argsFor(0)[1]).toEqual('some error'); - - fakeImage.onerror(); // This fails because we only retry once - expect(success).toBe(false); - expect(failure).toBe(true); - }); - - it('rejects after callback returns false', function() { - var fakeImage = {}; - spyOn(window, 'Image').and.returnValue(fakeImage); - - var cb = jasmine.createSpy('retry').and.returnValue(false); - - var resource = new Resource({ - url : 'http://example.invalid/image.png', - retryCallback: cb, - retryAttempts: 2 - }); - - var promise = loadImage(resource); - - expect(promise).toBeDefined(); - - var success = false; - var failure = false; - promise.then(function(value) { - success = true; - }).otherwise(function (error) { - failure = true; - }); - - expect(success).toBe(false); - expect(failure).toBe(false); - - fakeImage.onerror('some error'); // This fails because the callback returns false - expect(success).toBe(false); - expect(failure).toBe(true); - - expect(cb.calls.count()).toEqual(1); - var receivedResource = cb.calls.argsFor(0)[0]; - expect(receivedResource.url).toEqual(resource.url); - expect(receivedResource._retryCount).toEqual(1); - expect(cb.calls.argsFor(0)[1]).toEqual('some error'); - }); - - it('resolves after retry', function() { - var fakeImage = {}; - spyOn(window, 'Image').and.returnValue(fakeImage); - - var cb = jasmine.createSpy('retry').and.returnValue(true); - - var resource = new Resource({ - url : 'http://example.invalid/image.png', - retryCallback: cb, - retryAttempts: 1 - }); - - var promise = loadImage(resource); - - expect(promise).toBeDefined(); - - var success = false; - var failure = false; - promise.then(function(value) { - success = true; - }).otherwise(function (error) { - failure = true; - }); - - expect(success).toBe(false); - expect(failure).toBe(false); - - fakeImage.onerror('some error'); // This should retry - expect(success).toBe(false); - expect(failure).toBe(false); - - expect(cb.calls.count()).toEqual(1); - var receivedResource = cb.calls.argsFor(0)[0]; - expect(receivedResource.url).toEqual(resource.url); - expect(receivedResource._retryCount).toEqual(1); - expect(cb.calls.argsFor(0)[1]).toEqual('some error'); - - fakeImage.onload(); - expect(success).toBe(true); - expect(failure).toBe(false); - }); - }); -}); diff --git a/Specs/Core/loadImageViaBlobSpec.js b/Specs/Core/loadImageViaBlobSpec.js deleted file mode 100644 index 85bd0a3d1ce8..000000000000 --- a/Specs/Core/loadImageViaBlobSpec.js +++ /dev/null @@ -1,128 +0,0 @@ -defineSuite([ - 'Core/loadImageViaBlob', - 'Core/Request', - 'Core/RequestScheduler', - 'Core/Resource', - 'ThirdParty/when' - ], function( - loadImageViaBlob, - Request, - RequestScheduler, - Resource, - when) { - 'use strict'; - - var dataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2Nk+M/wHwAEBgIA5agATwAAAABJRU5ErkJggg=='; - - it('can load an image', function() { - return loadImageViaBlob('./Data/Images/Green.png').then(function(loadedImage) { - expect(loadedImage.width).toEqual(1); - expect(loadedImage.height).toEqual(1); - }); - }); - - it('can load an image from a data URI', function() { - return loadImageViaBlob(dataUri).then(function(loadedImage) { - expect(loadedImage.width).toEqual(1); - expect(loadedImage.height).toEqual(1); - }); - }); - - it('throws with if url is missing', function() { - expect(function() { - loadImageViaBlob(); - }).toThrowDeveloperError(); - }); - - it('resolves the promise when the image loads', function() { - var fakeImage = {}; - spyOn(window, 'Image').and.returnValue(fakeImage); - - var success = false; - var failure = false; - var loadedImage; - - when(loadImageViaBlob(dataUri), function(image) { - success = true; - loadedImage = image; - }, function() { - failure = true; - }); - - // neither callback has fired yet - expect(success).toEqual(false); - expect(failure).toEqual(false); - - fakeImage.onload(); - expect(success).toEqual(true); - expect(failure).toEqual(false); - expect(loadedImage).toBe(fakeImage); - }); - - it('resolves the promise when the image loads with Resource', function() { - var fakeImage = {}; - spyOn(window, 'Image').and.returnValue(fakeImage); - - var success = false; - var failure = false; - var loadedImage; - - when(loadImageViaBlob(new Resource({ - url: dataUri - })), function(image) { - success = true; - loadedImage = image; - }, function() { - failure = true; - }); - - // neither callback has fired yet - expect(success).toEqual(false); - expect(failure).toEqual(false); - - fakeImage.onload(); - expect(success).toEqual(true); - expect(failure).toEqual(false); - expect(loadedImage).toBe(fakeImage); - }); - - it('rejects the promise when the image errors', function() { - var fakeImage = {}; - spyOn(window, 'Image').and.returnValue(fakeImage); - - var success = false; - var failure = false; - var loadedImage; - - when(loadImageViaBlob(dataUri), function(image) { - success = true; - loadedImage = image; - }, function() { - failure = true; - }); - - // neither callback has fired yet - expect(success).toEqual(false); - expect(failure).toEqual(false); - - fakeImage.onerror(); - expect(success).toEqual(false); - expect(failure).toEqual(true); - expect(loadedImage).toBeUndefined(); - }); - - it('returns undefined if the request is throttled', function() { - var oldMaximumRequests = RequestScheduler.maximumRequests; - RequestScheduler.maximumRequests = 0; - - var request = new Request({ - throttle : true - }); - - var testUrl = 'http://example.invalid/testuri'; - var promise = loadImageViaBlob(testUrl, request); - expect(promise).toBeUndefined(); - - RequestScheduler.maximumRequests = oldMaximumRequests; - }); -}); diff --git a/Specs/Core/loadJsonSpec.js b/Specs/Core/loadJsonSpec.js deleted file mode 100644 index 6e36721d3be3..000000000000 --- a/Specs/Core/loadJsonSpec.js +++ /dev/null @@ -1,181 +0,0 @@ -defineSuite([ - 'Core/loadJson', - 'Core/Request', - 'Core/RequestErrorEvent', - 'Core/RequestScheduler' - ], function( - loadJson, - Request, - RequestErrorEvent, - RequestScheduler) { - 'use strict'; - - var fakeXHR; - - beforeEach(function() { - fakeXHR = jasmine.createSpyObj('XMLHttpRequest', ['send', 'open', 'setRequestHeader', 'abort', 'getAllResponseHeaders']); - fakeXHR.simulateLoad = function(response) { - fakeXHR.simulateHttpResponse(200, response); - }; - fakeXHR.simulateError = function() { - fakeXHR.response = ''; - if (typeof fakeXHR.onerror === 'function') { - fakeXHR.onerror(); - } - }; - fakeXHR.simulateHttpResponse = function(statusCode, response) { - fakeXHR.status = statusCode; - fakeXHR.response = response; - if (typeof fakeXHR.onload === 'function') { - fakeXHR.onload(); - } - }; - - spyOn(window, 'XMLHttpRequest').and.returnValue(fakeXHR); - }); - - it('throws with no url', function() { - expect(function() { - loadJson(); - }).toThrowDeveloperError(); - }); - - it('creates and sends request, adding Accept header when headers are provided', function() { - var headers = { - 'Cache-Control' : 'no-cache' - }; - loadJson('test', headers); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', 'test', true); - expect(fakeXHR.setRequestHeader.calls.count()).toEqual(2); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Accept', 'application/json,*/*;q=0.01'); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Cache-Control', 'no-cache'); - expect(fakeXHR.send).toHaveBeenCalled(); - - // the headers object we passed in should not have been modified - expect(Object.keys(headers)).toEqual(['Cache-Control']); - }); - - it('creates and sends request, adding Accept header when headers are not provided', function() { - loadJson('test'); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', 'test', true); - expect(fakeXHR.setRequestHeader.calls.count()).toEqual(1); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Accept', 'application/json,*/*;q=0.01'); - expect(fakeXHR.send).toHaveBeenCalled(); - }); - - it('returns a promise that resolves when the request loads', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadJson(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var response = '{"good":"data"}'; - fakeXHR.simulateLoad(response); - expect(resolvedValue).toEqual({ - good : 'data' - }); - expect(rejectedError).toBeUndefined(); - }); - - it('returns a promise that rejects when the request errors', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadJson(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - fakeXHR.simulateError(); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - expect(rejectedError.statusCode).toBeUndefined(); - expect(rejectedError.response).toBeUndefined(); - }); - - it('returns a promise that rejects when the request results in an HTTP error code', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadJson(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var error = 'some error'; - fakeXHR.simulateHttpResponse(404, error); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - expect(rejectedError.statusCode).toEqual(404); - expect(rejectedError.response).toEqual(error); - }); - - it('returns a promise that resolves with undefined when the status code ise 204', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadJson(testUrl); - - expect(promise).toBeDefined(); - - var resolved = false; - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolved = true; - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - fakeXHR.simulateHttpResponse(204); - expect(resolved).toBe(true); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - }); - - it('returns undefined if the request is throttled', function() { - var oldMaximumRequests = RequestScheduler.maximumRequests; - RequestScheduler.maximumRequests = 0; - - var request = new Request({ - throttle : true - }); - - var testUrl = 'http://example.invalid/testuri'; - var promise = loadJson(testUrl, undefined, request); - expect(promise).toBeUndefined(); - - RequestScheduler.maximumRequests = oldMaximumRequests; - }); -}); diff --git a/Specs/Core/loadJsonpSpec.js b/Specs/Core/loadJsonpSpec.js deleted file mode 100644 index 31824c434396..000000000000 --- a/Specs/Core/loadJsonpSpec.js +++ /dev/null @@ -1,232 +0,0 @@ -defineSuite([ - 'Core/loadJsonp', - 'Core/DefaultProxy', - 'Core/queryToObject', - 'Core/Request', - 'Core/RequestErrorEvent', - 'Core/RequestScheduler', - 'Core/Resource', - 'ThirdParty/Uri' - ], function( - loadJsonp, - DefaultProxy, - queryToObject, - Request, - RequestErrorEvent, - RequestScheduler, - Resource, - Uri) { - 'use strict'; - - it('throws with no url', function() { - expect(function() { - loadJsonp(); - }).toThrowDeveloperError(); - }); - - it('returns a promise that resolves when the request loads', function() { - var testUrl = 'http://example.invalid/testuri'; - spyOn(loadJsonp, 'loadAndExecuteScript').and.callFake(function (url, name, deffered){ - expect(url).toContain(testUrl); - expect(name).toContain('loadJsonp'); - expect(deffered).toBeDefined(); - }); - loadJsonp(testUrl); - }); - - it('returns a promise that rejects when the request errors', function() { - var testUrl = 'http://example.invalid/testuri'; - return loadJsonp(testUrl).otherwise(function(error) { - expect(error).toBeDefined(); - }); - }); - - it('Appends parameters specified in options', function() { - var testUrl = 'test'; - var options = { - parameters: { - isTest : 'true', - myNum : 8 - } - }; - spyOn(loadJsonp, 'loadAndExecuteScript').and.callFake(function(url, functionName, deferred) { - expect(url).toContain('isTest=true&myNum=8'); - }); - loadJsonp(testUrl, options); - }); - - it('Uses callback name specified in options', function() { - var testUrl = 'test'; - var options = { - callbackParameterName : 'testCallback' - }; - spyOn(loadJsonp, 'loadAndExecuteScript').and.callFake(function(url, functionName, deferred) { - expect(url).toContain('testCallback=loadJsonp'); - }); - loadJsonp(testUrl, options); - }); - - it('Uses proxy url is proxy is specified', function() { - var testUrl = 'test'; - var testProxy = '/proxy/'; - var options = { - proxy: new DefaultProxy(testProxy) - }; - spyOn(loadJsonp, 'loadAndExecuteScript').and.callFake(function(url, functionName, deferred) { - expect(url).toStartWith(options.proxy.getURL(testUrl)); - }); - loadJsonp(testUrl, options); - }); - - it('returns undefined if the request is throttled', function() { - var oldMaximumRequests = RequestScheduler.maximumRequests; - RequestScheduler.maximumRequests = 0; - - var request = new Request({ - throttle : true - }); - - var testUrl = 'http://example.invalid/testuri'; - var promise = loadJsonp(testUrl, undefined, request); - expect(promise).toBeUndefined(); - - RequestScheduler.maximumRequests = oldMaximumRequests; - }); - - describe('retries when Resource has the callback set', function() { - it('rejects after too many retries', function() { - //var cb = jasmine.createSpy('retry').and.returnValue(true); - var cb = jasmine.createSpy('retry').and.callFake(function(resource, error) { - return true; - }); - - var lastDeferred; - spyOn(loadJsonp, 'loadAndExecuteScript').and.callFake(function(url, functionName, deferred) { - lastDeferred = deferred; - }); - - var resource = new Resource({ - url : 'http://example.invalid', - retryCallback: cb, - retryAttempts: 1 - }); - - var promise = loadJsonp(resource); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - lastDeferred.reject('some error'); // This should retry - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - expect(cb.calls.count()).toEqual(1); - var receivedResource = cb.calls.argsFor(0)[0]; - expect(receivedResource.url).toEqual(resource.url + '?callback=' + receivedResource.queryParameters.callback); - expect(receivedResource._retryCount).toEqual(1); - expect(cb.calls.argsFor(0)[1]).toEqual('some error'); - - lastDeferred.reject('another error'); // This fails because we only retry once - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toEqual('another error'); - }); - - it('rejects after callback returns false', function() { - var cb = jasmine.createSpy('retry').and.returnValue(false); - - var lastDeferred; - spyOn(loadJsonp, 'loadAndExecuteScript').and.callFake(function(url, functionName, deferred) { - lastDeferred = deferred; - }); - - var resource = new Resource({ - url : 'http://example.invalid', - retryCallback: cb, - retryAttempts: 2 - }); - - var promise = loadJsonp(resource); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - lastDeferred.reject('some error'); // This fails because the callback returns false - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toEqual('some error'); - - expect(cb.calls.count()).toEqual(1); - var receivedResource = cb.calls.argsFor(0)[0]; - expect(receivedResource.url).toEqual(resource.url + '?callback=' + receivedResource.queryParameters.callback); - expect(receivedResource._retryCount).toEqual(1); - expect(cb.calls.argsFor(0)[1]).toEqual('some error'); - }); - - it('resolves after retry', function() { - var cb = jasmine.createSpy('retry').and.returnValue(true); - - var lastDeferred; - var lastUrl; - spyOn(loadJsonp, 'loadAndExecuteScript').and.callFake(function(url, functionName, deferred) { - lastUrl = url; - lastDeferred = deferred; - }); - - var resource = new Resource({ - url : 'http://example.invalid', - retryCallback: cb, - retryAttempts: 1 - }); - - var promise = loadJsonp(resource); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - lastDeferred.reject('some error'); // This should retry - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - expect(cb.calls.count()).toEqual(1); - var receivedResource = cb.calls.argsFor(0)[0]; - expect(receivedResource.url).toEqual(resource.url + '?callback=' + receivedResource.queryParameters.callback); - expect(receivedResource._retryCount).toEqual(1); - expect(cb.calls.argsFor(0)[1]).toEqual('some error'); - - var uri = new Uri(lastUrl); - var query = queryToObject(uri.query); - window[query.callback]('something good'); - expect(resolvedValue).toEqual('something good'); - expect(rejectedError).toBeUndefined(); - }); - }); -}); diff --git a/Specs/Core/loadKTXSpec.js b/Specs/Core/loadKTXSpec.js index b12c16eb7696..e20a1f91dbf7 100644 --- a/Specs/Core/loadKTXSpec.js +++ b/Specs/Core/loadKTXSpec.js @@ -4,6 +4,7 @@ defineSuite([ 'Core/Request', 'Core/RequestErrorEvent', 'Core/RequestScheduler', + 'Core/Resource', 'Core/RuntimeError' ], function( loadKTX, @@ -11,6 +12,7 @@ defineSuite([ Request, RequestErrorEvent, RequestScheduler, + Resource, RuntimeError) { 'use strict'; @@ -58,20 +60,6 @@ defineSuite([ expect(fakeXHR.send).toHaveBeenCalled(); }); - it('creates and sends request with custom headers', function() { - var testUrl = 'http://example.invalid/testuri'; - loadKTX(testUrl, { - 'Accept' : 'application/json', - 'Cache-Control' : 'no-cache' - }); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', testUrl, true); - expect(fakeXHR.setRequestHeader.calls.count()).toEqual(2); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Accept', 'application/json'); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Cache-Control', 'no-cache'); - expect(fakeXHR.send).toHaveBeenCalled(); - }); - it('returns a promise that rejects when the request errors', function() { var testUrl = 'http://example.invalid/testuri'; var promise = loadKTX(testUrl); @@ -437,12 +425,12 @@ defineSuite([ var oldMaximumRequests = RequestScheduler.maximumRequests; RequestScheduler.maximumRequests = 0; - var request = new Request({ - throttle : true - }); - - var testUrl = 'http://example.invalid/testuri'; - var promise = loadKTX(testUrl, undefined, request); + var promise = loadKTX(new Resource({ + url: 'http://example.invalid/testuri', + request: new Request({ + throttle: true + }) + })); expect(promise).toBeUndefined(); RequestScheduler.maximumRequests = oldMaximumRequests; diff --git a/Specs/Core/loadTextSpec.js b/Specs/Core/loadTextSpec.js deleted file mode 100644 index b901228afdb0..000000000000 --- a/Specs/Core/loadTextSpec.js +++ /dev/null @@ -1,156 +0,0 @@ -defineSuite([ - 'Core/loadText', - 'Core/Request', - 'Core/RequestErrorEvent', - 'Core/RequestScheduler' - ], function( - loadText, - Request, - RequestErrorEvent, - RequestScheduler) { - 'use strict'; - - var fakeXHR; - - beforeEach(function() { - fakeXHR = jasmine.createSpyObj('XMLHttpRequest', ['send', 'open', 'setRequestHeader', 'abort', 'getAllResponseHeaders']); - fakeXHR.simulateLoad = function(response) { - fakeXHR.status = 200; - fakeXHR.response = response; - if (typeof fakeXHR.onload === 'function') { - fakeXHR.onload(); - } - }; - fakeXHR.simulateError = function() { - fakeXHR.response = ''; - if (typeof fakeXHR.onerror === 'function') { - fakeXHR.onerror(); - } - }; - fakeXHR.simulateHttpError = function(statusCode, response) { - fakeXHR.status = statusCode; - fakeXHR.response = response; - if (typeof fakeXHR.onload === 'function') { - fakeXHR.onload(); - } - }; - - spyOn(window, 'XMLHttpRequest').and.returnValue(fakeXHR); - }); - - it('throws with no url', function() { - expect(function() { - loadText(); - }).toThrowDeveloperError(); - }); - - it('creates and sends request without any custom headers', function() { - var testUrl = 'http://example.invalid/testuri'; - loadText(testUrl); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', testUrl, true); - expect(fakeXHR.setRequestHeader).not.toHaveBeenCalled(); - expect(fakeXHR.send).toHaveBeenCalled(); - }); - - it('creates and sends request with custom headers', function() { - var testUrl = 'http://example.invalid/testuri'; - loadText(testUrl, { - 'Accept' : 'application/json', - 'Cache-Control' : 'no-cache' - }); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', testUrl, true); - expect(fakeXHR.setRequestHeader.calls.count()).toEqual(2); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Accept', 'application/json'); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Cache-Control', 'no-cache'); - expect(fakeXHR.send).toHaveBeenCalled(); - }); - - it('returns a promise that resolves when the request loads', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadText(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var response = 'some response'; - fakeXHR.simulateLoad(response); - expect(resolvedValue).toEqual(response); - expect(rejectedError).toBeUndefined(); - }); - - it('returns a promise that rejects when the request errors', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadText(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - fakeXHR.simulateError(); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - expect(rejectedError.statusCode).toBeUndefined(); - expect(rejectedError.response).toBeUndefined(); - }); - - it('returns a promise that rejects when the request results in an HTTP error code', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadText(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var error = 'some error'; - fakeXHR.simulateHttpError(404, error); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - expect(rejectedError.statusCode).toEqual(404); - expect(rejectedError.response).toEqual(error); - }); - - it('returns undefined if the request is throttled', function() { - var oldMaximumRequests = RequestScheduler.maximumRequests; - RequestScheduler.maximumRequests = 0; - - var request = new Request({ - throttle : true - }); - - var testUrl = 'http://example.invalid/testuri'; - var promise = loadText(testUrl, undefined, request); - expect(promise).toBeUndefined(); - - RequestScheduler.maximumRequests = oldMaximumRequests; - }); -}); diff --git a/Specs/Core/loadWithXhrSpec.js b/Specs/Core/loadWithXhrSpec.js deleted file mode 100644 index 7cc62802096c..000000000000 --- a/Specs/Core/loadWithXhrSpec.js +++ /dev/null @@ -1,561 +0,0 @@ -defineSuite([ - 'Core/loadWithXhr', - 'Core/Request', - 'Core/RequestErrorEvent', - 'Core/RequestScheduler', - 'Core/Resource' - ], function( - loadWithXhr, - Request, - RequestErrorEvent, - RequestScheduler, - Resource) { - 'use strict'; - - it('throws with no url', function() { - expect(function() { - loadWithXhr(); - }).toThrowDeveloperError(); - }); - - it('returns undefined if the request is throttled', function() { - var oldMaximumRequests = RequestScheduler.maximumRequests; - RequestScheduler.maximumRequests = 0; - - var request = new Request({ - throttle : true - }); - - var testUrl = 'http://example.invalid/testuri'; - var promise = loadWithXhr({ - url : testUrl, - request : request - }); - expect(promise).toBeUndefined(); - - RequestScheduler.maximumRequests = oldMaximumRequests; - }); - - describe('data URI loading', function() { - it('can load URI escaped text with default response type', function() { - return loadWithXhr({ - url : 'data:,Hello%2C%20World!' - }).then(function(result) { - expect(result).toEqual('Hello, World!'); - }); - }); - - it('can load URI escaped text with responseType=text', function() { - return loadWithXhr({ - url : 'data:,Hello%2C%20World!', - responseType : 'text' - }).then(function(result) { - expect(result).toEqual('Hello, World!'); - }); - }); - - it('can load Base64 encoded text with default response type', function() { - return loadWithXhr({ - url : 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==' - }).then(function(result) { - expect(result).toEqual('Hello, World!'); - }); - }); - - it('can load Base64 encoded text with responseType=text', function() { - return loadWithXhr({ - url : 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==', - responseType : 'text' - }).then(function(result) { - expect(result).toEqual('Hello, World!'); - }); - }); - - it('can load Base64 & URI encoded text with default responseType', function() { - return loadWithXhr({ - url : 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D' - }).then(function(result) { - expect(result).toEqual('Hello, World!'); - }); - }); - - it('can load Base64 & URI encoded text with responseType=text', function() { - return loadWithXhr({ - url : 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D', - responseType : 'text' - }).then(function(result) { - expect(result).toEqual('Hello, World!'); - }); - }); - - it('can load URI escaped HTML as text with default responseType', function() { - return loadWithXhr({ - url : 'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E' - }).then(function(result) { - expect(result).toEqual('

Hello, World!

'); - }); - }); - - it('can load URI escaped HTML as text with responseType=text', function() { - return loadWithXhr({ - url : 'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E', - responseType : 'text' - }).then(function(result) { - expect(result).toEqual('

Hello, World!

'); - }); - }); - - it('can load URI escaped text as JSON', function() { - return loadWithXhr({ - url : 'data:application/json,%7B%22key%22%3A%22value%22%7D', - responseType : 'json' - }).then(function(result) { - expect(result.key).toEqual('value'); - }); - }); - - it('can load Base64 encoded text as JSON', function() { - return loadWithXhr({ - url : 'data:application/json;base64,eyJrZXkiOiJ2YWx1ZSJ9', - responseType : 'json' - }).then(function(result) { - expect(result.key).toEqual('value'); - }); - }); - - it('can load URI escaped HTML as document', function() { - return loadWithXhr({ - url : 'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E', - responseType : 'document' - }).then(function(result) { - expect(result.querySelector('h1')).not.toBeNull(); - }); - }); - - var tile = 'data:;base64,rZ+P95jW+j0AAABAplRYwQAAAAAAAAAAFwEcw/RY1UUqDN/so3WJQETWnpq/aabA19EOeYzEh8D+6WPqtldYQYlaPeMGcRRAO+KDbxWIcsMAAAAAAAAAANsAAAD+N/03/mf/UQDq/f/+T/8foDBgL/8TACwAWP8H/xf/H/8b/yMAGP8r/wv/H/8P/w8ACP8PAEj/F/8TADwAIAAg/w8AMAAg/wcAGP8v/xf/J4gPIBOnIv8P/wf/FwAo/xfkM+MXACwACAAAAAgAGAAA/w//B/8P/wf/D/8XmgmZGf8XAAgAEBYZFQkAGAAQABj/DwAQAAgAEAAA/w8ACP8P/w8AIP8v2QD9DScR/w8AGAAQABAACAAQABwABAAIAAAAAAAI/xf/HwAQ/y8ADP8j/wf/D/8HRAlDEQAAABAAIP8fADAAFP8P/xP/H/8H5wf4Ag8TAAAABAAEAAD/D/8HAAAAAAAANhLKBf8HABAAIAAA/y95GHoIAAD/D/8DAAz/BwAAAAD/DwAAAAAAAAAAABD/Gz4Vwhb/G/8XAKz9t/4XAAj/D/0P/g8AAP0PAAAAAP4P/Q8AAAAAAAD+//8TABT/PwBA/y8AGP8n/w8AKAAYABAAAAAAAAAAAP8PABD/DwAQAAD/DwAIAAgAAP8PABD9//4P/Q/+H/8P/Q/+EwAYAAz/H/8PABj9H/43ABAACP1PAADWBdUF/gMADv0R/g8AEP8LdwCHBwAI/wsACP8HAAAACAAMAAQACP8DAAwACP8P/wcAIP8PABAACAAE/xsAAP8HABj/H/8HABT/CwAQABAAAL4WFwSlAv8PABAAAAAIAAh0A4wEAAD/B/8P/w8AAAAQAAgAEAAQ/wcAAAAI9wQHCwAAABAAAAgI+Af/BwAA/wcAEAAA/xf/BwAYAAAAGAAAAAD/DwAQuw/4AMQO/w8AGAAAAAAAEP8HAAT/E/8HABAAIFESUgoACP8D/wsAFP8T/w//D/8H1hvVA/8PACAADAAEAAgABAAQ/xMACP8HYREzDGkK/w8AHP8j/w8AAAAY/w8AMP8P5hoaHf8PACD/BwAQAAQ5HjoS/yf/HwAU/xv/B/8P/w8AEP8PACAAEAAgAAj/G7ItTh7/CwAIAAQACP8f/w//D/8P/w//DwAQ/w//DwAAAEAAEAAQABAAEP8TAAT/B/8H/wcACP8HABj/JwAIAAD/D/8P/w//D/8PAAD/DwAA/w8AAP8PAAD/D/8H/wcAQAAA/w8AAAAA/w8ABAAAABT/JwAIAAD/BwAYABD/D/83ABBwbM1nul3BXggB7QCqADoARH8JagIPNQkNGk5YCQunTVhLcUvMAAsBWAAbAKkArQCgAckA0AAXABwAGwCCAL4AHgqlCgIWfxVhAGAA3wByAKTgYdIxDm8AIwAxAIYAQwAYqNmncha+DYckCgDaADcAiwCuAs4GFAUvBlcI0vb59iAAYQAHAHbgr986A34DMgGBCbIAOABKAH4AlwDMABUB4QC4AdkBDm0OV83CDQCdAPsAPgAuAdwA6AAzAD4W3QmLC+Rs3WzvANwAgQPOCxEAuwomAFUAXoP9gygAKiIvEVYKWQUlFJsAWgQUBrYPnGdRNw9MQgAVAGAAlAA4AHMAkgAXASYApJgDkeZO+VX8BVQRkxb8w2vEpQB0AEcAHgCOAIAAWwCgAFMACQApAE0AKAA5AHTgz99zAD4AtABVAK4ApwCfAD8ApgAeAGMAagBYAD8AwwBMACAAEwBkAAgBLQCKZhlmQgA+AJxXuxLVRE8ATQCAAfIkBxvDA6kIEQA5AAIAPgA1ACwAEAAcADIAFwCSALkAIgGlAZwAnADrAJkAKQAJAMYAcwAaAG0ADwAFALcBuACSAQAAAAAAAAAAAwAAAAMAAwAAAAMABAACAAAABgAAAAAABQAIAAEAAgAIAAAABwABAAkABwAAAAAAAAADAAoACAABAAoAAgAEAAoACAAAAAAACgAAAAQAAQALAAIAAQAAAAUAAQAAAAYABgABAAgAAAAJAAAAAQAKAAMACgACAAkACwAJAAAACgADAAEAAQAOAAwAAAAPAAIADwABAAAAAQAAABEAEAARAAEAFAAQAAAAAQARAAIAAgADAAAAAwABAAAABAABAAMAAAAGAAcABgABAAAABAAHAAAAAQAIAAIAAAAKAAsACgABAAQACwANAAEAAAAOAA0AAQACAA4AAAAAAA8AEQACAA8ADwABAAMAEgACABEAEgATAAAAAQADABMAFAAAAAIAAQAVABYAFgAXAAEAAgABAAAAAgAAAAIAAQADABkABAACAAAAAQAHAAUABwABAAAABwAIAAEACQAHAAAAAAAJAAAACgAAAAQAAgALAAUACwADAAEAAAAPAA4AAQAOAAUADwABABIAAgAAAAIAEwACAAEABgADAAIAEwAAABMAFAACAAEAAgAAAAAAAgAEAAYAAwAEAAEACAACAAYACAAHAAAACQAAAAQAAgABAAoAAAAKAAAACwAOAAAABQAMAAMAAgAMAAEADwAQAAAAAgAQAAEAAAACABIAEgAUAAEAAAADAAIAAAAEAAIABAABAAUABQABAAYAAAAIAAcABwACAAEACAAAAAAAAwACAAoAAQAMAAoAAAAMAA0AAQANAAIAAAANAAAAAAASAA8AAwABAA8ADwAEAAIAEQASAAEAAAASAAAAEwACABUAAwABABMAAAAEAAYAAQACAAQAAAAAAAgACAABAAMABwACAAgAAgAHAAAAAQAIAAoACgAAAAIADAABAAsADQABAAwADQAOAAAAAgAOAAAAAQAPAAAAAwABABAAEgAAABIABAASAAEAEwAAAAIAFQABABQAAQAAAAMAAwAAAAcABAACAAEAAQAFAAcABQAAAAAABwAAAAkAAQAIAAIAAwAIAAAAAQAJAAUAAgAAAAsACwABAAAADAABAA4ADwAOAAEAAAASABAAAgABABAAAQARABIAAAASAAIAEgABAAAAFQATAAEAAAAEAAAABgAHAAUAAQAFAAcABQACAAQABwAAAAIACAAKAAEACgAAAAIAAQALAAAAAQAMAA0ADgABAA0AAAACAA8AAQAPAAAADQABABAAEQASAA0AEgABAA0AAQASAAAAAgABAAAAAQAEAAMAAAAFAAAAAAAHAAMAAQAIAAcAAgAHAAQACAAAAAoAAQAJAAAACgADAAEACwAAAA0ADAADAAAAAQACAA0ADwAOAAIAAgAQAA8AAgAAABEAEwARAAAAAQASAAIAAQAAABUAFAAVAAEAAQAAABUAFQABACkAAgAAAAAAAgAEAAUAAwAEAAAAAQAFAAIABwAAAAcABwABAAQAAAAAAAoAAwAKAAEACgAMAAIAAAANAAwADQABAAMAAAACAA0ADQAQAAEAAAAAAAQABgAEAAEAAwACAAQAAQAFAAYABQAAAAAABwADAAIABwAAAAoAAQAIAAIAAAAOAAsACwACAAEADQAOAAEAAAAAAA8ADwABAA4AAgAPAAAAAQAQAAQAAAATABAAEAADAAEAPAA7ABMAAQA8ABMAPAABAAAAAQACAAAAAwAFAAEABQAGAAAAAAAHAAIAAwAHAAEACAAAAAAACAACAAoAAQAEAAoACAAMAAAAAQADAAkADAANAAkADgABAA0ADwAAAA8AAgAPAAAAAQAQAAIAAAASAAAAEwAUAAEABAATAAIAFAAVAAEAAQAVAAAAAwACAAEAAQAAAAQAAQAGAAQAAAAHAAAACAACAAcAAQAIAAMAAAAKAAgACAADAAEADAAKAAEADAAAAAwAAgAAAA4AAgAOAAEAAAARAA4ADgADAAEAAAAAABMAAwACABMAEwABABIAAAAVABMAAQATAAIAAgAAAAAABAABAAMABQACAAQABgAIAAUAAAADAAYABgAJAAEAAAACAAoACQABAAoAAAAKAAAAAwALAAAAAQAMAAMAAgAMAA4ADgAQAAIAAAADABEAEQAQAAEAAAAAABIAFAACABIAAwASAAEAFAAVAAIAAgAAAAIAAwAWAAAAAAADAAUAAgABAAUAAAAFAAQABQABAAcAAAAKAAgACAACAAEACgABAAsACwABAAAACgAMAAEACgAAAAAAAQAPAAwAAwACAAwAAAAQAAIAEAABABEAAQATABEAAQAAAAAAAAAEAAIAAAAXAAUABQACAAEABAAFAAYABgAHAAQAAAAIAAkACQAAAAIACwABAAoACwAMAAEAAQAMAAAAEAABAA0AEAAOAAAAAgARAAEAAAAQABEAAQARAAAAAgABAAAAAgATAAAAAwAAAAMABAAAAAAABgAEAAIAAQADAAYABABCAAAAQwAFAAAABAAGAAIAAQAGABkABAAAAAQAVQAFAAMABQBVAAEAAAAHAAUABQACAAEABwABAAAAAgADAFoAAgAAAAIAAQADAFsAWwAEAFkAWQAEAFcABABYAFcAWAAGAEkABgBIAEkAMwBIAAUAHQAzAAUAWwBaAAEAAQBaAAAAAABcAF4AXAABAAIAAAACAGAAXwBgAAIAAAAAAAMAAgADAGIAYgB0AAIAAAACAAMAdQABAAMAAgABAAAAAgAAAAIAAwB3AHgAAQADAAAAAQAEAHkAAAADAAIAAwABAAAAewCPAAMAAwCPAAIAAAADAAAAkQCSAAQABAACAAMAAQAEAJIAAQAAAAMAkwCmAAIApgABAAIApgClAAEAIQAAACEAIQABAAAAAQA4ACIAAAACAAMAOQACADgAOAACAAAAAAACAAQABAADAAEAAwAAAAIAAAAEAAMAAwACAAEABAABAAAAPQAFAD8AAQAAAAYAQAAGAAEAAAAEAAAABAAFAAAABgAHAAIAAQAGAAMABwAAAAMAAQAEAAMAvQC+AAQABAABAL0ABAC+AAIAvgAGAAIAAAAGAAcAAQAHALsAuwAHAL8ABgABAAAABwBaAEYAWgAHAAEAAQACAAAAvgADAL0AAQADAL4AAgBcAFsAAQCZAAIAAgCZAFwArACZAAEAvgCsAAEAXACZAJgAwAAAAMMAwQAFAAAAAgDCAAEA2AACANYAxAACANgAEQAAAAEAnwCoANUA2QAFANoAzgDLAMkApwCmAKMAqgCsAK0AqwACAAAAAQAEABEAAAAEAK4ADAAkAMYAxQDIAMIAwQC/ALsAugC5ALIAsAC8AL0AAgAAAJ8ArgA='; - - it('can load Base64 encoded data as arraybuffer', function() { - return loadWithXhr({ - url : tile, - responseType : 'arraybuffer' - }).then(function(result) { - expect(result.byteLength).toEqual(3914); - }); - }); - - var image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEISURBVEhLvVXBDYQwDOuojHKj8LhBbpTbpBCEkZsmIVTXq1RVQGrHiWlLmTTqPiZBlyLgy/KSZQ5JSHDQ/mCYCsC8106kDU0AdwRnvYZArWRcAl0dcYJq1hWCb3hBrumbDAVMwAC82WoRvgMnVMDBnB0nYZFTbE6BBvdUGqVqCbjBIk3PyFFR/NU7EKzru+qZsau3ryPwwCRLKYOzutZuCL6fUmWeJGzNzL/RxAMrUmASSCkkAayk2IxPlwhAAYGpsiHQjbLccfdOY5gKkCXAMi7SscAwbQpAnKyctWyUZ6z8ja3OGMepwD8asz+9FnSvbhU8uVOHFIwQsI3/p0CfhuqCSQuxLqsN6mu8SS+N42MAAAAASUVORK5CYII='; - - it('can load Base64 encoded data as blob', function() { - return loadWithXhr({ - url : image, - responseType : 'blob' - }).then(function(result) { - expect(result.type).toEqual('image/png'); - - /*global URL*/ - var blobUrl = URL.createObjectURL(result); - - return Resource.fetchImage(blobUrl).then(function(image) { - expect(image.width).toEqual(24); - expect(image.height).toEqual(24); - }); - }); - }); - - xit('can support 2xx HTTP status (other than 200)', function() { - return loadWithXhr({ - method : 'POST', - url : 'http://jsonplaceholder.typicode.com/posts', - data : { - title : 'foo', - body : 'bar', - userId : 1 - } - }).then(function(result) { - expect(JSON.parse(result).id).toEqual(101); - }); - }); - }); - - describe('URL loading using XHR', function() { - describe('returns a promise that rejects when the request', function() { - it('results in an HTTP status code greater than or equal to 300', function() { - return loadWithXhr({ - url : 'http://example.invalid' - }).then(function() { - fail('expected promise to reject'); - }).otherwise(function(err) { - expect(err instanceof RequestErrorEvent).toBe(true); - }); - }); - - it('loads an invalid JSON string response with a json responseType', function() { - return loadWithXhr({ - url : 'Data/htmlString.txt', - responseType : 'json' - }).then(function() { - fail('expected promise to reject'); - }).otherwise(function(err) { - expect(err).toBeDefined(); - expect(err instanceof Error).toBe(true); - }); - }); - }); - - describe('returns a promise that resolves when the request loads', function() { - it('a non-null response with default responseType', function() { - return loadWithXhr({ - url : 'Data/Models/Box/ReadMe.txt' - }).then(function(result) { - expect(result).toBe('CesiumBoxTest-NoTechnique.gltf is a modified glTF that has techniques, shaders & programs removed.'); - }); - }); - - it('a non-null response with a browser-supported responseType', function() { - return loadWithXhr({ - url : 'Data/Models/Box/ReadMe.txt', - responseType : 'text' - }).then(function(result) { - expect(result).toBe('CesiumBoxTest-NoTechnique.gltf is a modified glTF that has techniques, shaders & programs removed.'); - }); - }); - - it('a valid JSON string response as JSON with a json responseType', function() { - return loadWithXhr({ - url : 'Data/jsonString.txt', - responseType : 'json' - }).then(function(result) { - expect(result).toEqual(jasmine.objectContaining({hello : 'world'})); - }); - }); - }); - }); - - describe('URL loading using mocked XHR', function() { - var fakeXHR; - - beforeEach(function() { - fakeXHR = jasmine.createSpyObj('XMLHttpRequest', ['send', 'open', 'setRequestHeader', 'abort', 'getAllResponseHeaders']); - fakeXHR.simulateError = function() { - fakeXHR.response = ''; - if (typeof fakeXHR.onerror === 'function') { - fakeXHR.onerror(); - } - }; - fakeXHR.simulateHttpResponse = function(statusCode, response) { - fakeXHR.status = statusCode; - fakeXHR.response = response; - if (typeof fakeXHR.onload === 'function') { - fakeXHR.onload(); - } - }; - fakeXHR.simulateResponseXMLLoad = function(responseXML) { - fakeXHR.status = 200; - fakeXHR.responseXML = responseXML; - if (typeof fakeXHR.onload === 'function') { - fakeXHR.onload(); - } - }; - fakeXHR.simulateResponseTextLoad = function(responseText) { - fakeXHR.simulateHttpResponse(200, responseText); - }; - - spyOn(window, 'XMLHttpRequest').and.returnValue(fakeXHR); - }); - - describe('returns a promise that rejects when the request', function() { - it('errors', function() { - var promise = loadWithXhr({ - url : 'http://example.invalid' - }); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - fakeXHR.simulateError(); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - }); - - it('results in an HTTP status code less than 200', function() { - var promise = loadWithXhr({ - url : 'http://example.invalid' - }); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - fakeXHR.simulateHttpResponse(199); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - }); - - it('resolves undefined for status code 204', function() { - var promise = loadWithXhr({ - url : 'http://example.invalid' - }); - - expect(promise).toBeDefined(); - - var resolved = false; - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolved = true; - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - fakeXHR.simulateHttpResponse(204); - expect(resolved).toBe(true); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - }); - }); - - describe('returns a promise that resolves when the request loads', function() { - it('a null response with a \'\' responseType and non-null responseXML with child nodes', function() { - var promise = loadWithXhr({ - url : 'http://example.invalid', - responseType : '' - }); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var responseXML = { - hasChildNodes : jasmine.createSpy('hasChildNodes').and.returnValue(true) - }; - fakeXHR.simulateResponseXMLLoad(responseXML); - expect(resolvedValue).toEqual(responseXML); - expect(rejectedError).toBeUndefined(); - }); - - it('a null response with a document responseType and non-null responseXML with child nodes', function() { - var promise = loadWithXhr({ - url : 'http://example.invalid', - responseType : 'document' - }); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var responseXML = { - hasChildNodes : jasmine.createSpy('hasChildNodes').and.returnValue(true) - }; - fakeXHR.simulateResponseXMLLoad(responseXML); - expect(resolvedValue).toEqual(responseXML); - expect(rejectedError).toBeUndefined(); - }); - - it('a null response with a \'\' responseType and non-null responseText', function() { - var promise = loadWithXhr({ - url : 'http://example.invalid', - responseType : '' - }); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var responseText = 'hello world'; - fakeXHR.simulateResponseTextLoad(responseText); - expect(resolvedValue).toEqual(responseText); - expect(rejectedError).toBeUndefined(); - }); - - it('a null response with a text responseType and non-null responseText', function() { - var promise = loadWithXhr({ - url : 'http://example.invalid', - responseType : 'text' - }); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var responseText = 'hello world'; - fakeXHR.simulateResponseTextLoad(responseText); - expect(resolvedValue).toEqual(responseText); - expect(rejectedError).toBeUndefined(); - }); - }); - - describe('retries when Resource has the callback set', function() { - it('rejects after too many retries', function() { - var cb = jasmine.createSpy('retry').and.returnValue(true); - - var resource = new Resource({ - url : 'http://example.invalid', - retryCallback: cb, - retryAttempts: 1 - }); - - var promise = loadWithXhr(resource); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - fakeXHR.simulateError(); // This should retry - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - expect(cb.calls.count()).toEqual(1); - var receivedResource = cb.calls.argsFor(0)[0]; - expect(receivedResource.url).toEqual(resource.url); - expect(receivedResource._retryCount).toEqual(1); - expect(cb.calls.argsFor(0)[1] instanceof RequestErrorEvent).toBe(true); - - fakeXHR.simulateError(); // This fails because we only retry once - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - }); - - it('rejects after callback returns false', function() { - var cb = jasmine.createSpy('retry').and.returnValue(false); - - var resource = new Resource({ - url : 'http://example.invalid', - retryCallback: cb, - retryAttempts: 2 - }); - - var promise = loadWithXhr(resource); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - fakeXHR.simulateError(); // This fails because the callback returns false - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - - expect(cb.calls.count()).toEqual(1); - var receivedResource = cb.calls.argsFor(0)[0]; - expect(receivedResource.url).toEqual(resource.url); - expect(receivedResource._retryCount).toEqual(1); - expect(cb.calls.argsFor(0)[1] instanceof RequestErrorEvent).toBe(true); - }); - - it('resolves after retry', function() { - var cb = jasmine.createSpy('retry').and.returnValue(true); - - var resource = new Resource({ - url : 'http://example.invalid', - retryCallback: cb, - retryAttempts: 1 - }); - - var promise = loadWithXhr(resource); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }).otherwise(function (error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - fakeXHR.simulateError(); // This should retry - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - expect(cb.calls.count()).toEqual(1); - var receivedResource = cb.calls.argsFor(0)[0]; - expect(receivedResource.url).toEqual(resource.url); - expect(receivedResource._retryCount).toEqual(1); - expect(cb.calls.argsFor(0)[1] instanceof RequestErrorEvent).toBe(true); - - fakeXHR.simulateHttpResponse(200, 'OK'); - expect(resolvedValue).toBeDefined(); - expect(rejectedError).toBeUndefined(); - }); - }); - }); -}); diff --git a/Specs/Core/loadXMLSpec.js b/Specs/Core/loadXMLSpec.js deleted file mode 100644 index b79f6ccc6af7..000000000000 --- a/Specs/Core/loadXMLSpec.js +++ /dev/null @@ -1,158 +0,0 @@ -defineSuite([ - 'Core/loadXML', - 'Core/Request', - 'Core/RequestErrorEvent', - 'Core/RequestScheduler' - ], function( - loadXML, - Request, - RequestErrorEvent, - RequestScheduler) { - 'use strict'; - - var fakeXHR; - - beforeEach(function() { - fakeXHR = jasmine.createSpyObj('XMLHttpRequest', ['send', 'open', 'setRequestHeader', 'abort', 'overrideMimeType', 'getAllResponseHeaders']); - fakeXHR.simulateLoad = function(response) { - var parser = new DOMParser(); - fakeXHR.status = 200; - fakeXHR.response = parser.parseFromString(response, 'text/xml'); - fakeXHR.responseXML = fakeXHR.response; - if (typeof fakeXHR.onload === 'function') { - fakeXHR.onload(); - } - }; - fakeXHR.simulateError = function() { - if (typeof fakeXHR.onerror === 'function') { - fakeXHR.onerror(); - } - }; - fakeXHR.simulateHttpError = function(statusCode, response) { - fakeXHR.status = statusCode; - fakeXHR.response = response; - if (typeof fakeXHR.onload === 'function') { - fakeXHR.onload(); - } - }; - - spyOn(window, 'XMLHttpRequest').and.returnValue(fakeXHR); - }); - - it('throws with no url', function() { - expect(function() { - loadXML(); - }).toThrowDeveloperError(); - }); - - it('creates and sends request without any custom headers', function() { - var testUrl = 'http://example.invalid/testuri'; - loadXML(testUrl); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', testUrl, true); - expect(fakeXHR.setRequestHeader).not.toHaveBeenCalled(); - expect(fakeXHR.send).toHaveBeenCalled(); - }); - - it('creates and sends request with custom headers', function() { - var testUrl = 'http://example.invalid/testuri'; - loadXML(testUrl, { - 'Accept' : 'application/json', - 'Cache-Control' : 'no-cache' - }); - - expect(fakeXHR.open).toHaveBeenCalledWith('GET', testUrl, true); - expect(fakeXHR.setRequestHeader.calls.count()).toEqual(2); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Accept', 'application/json'); - expect(fakeXHR.setRequestHeader).toHaveBeenCalledWith('Cache-Control', 'no-cache'); - expect(fakeXHR.send).toHaveBeenCalled(); - }); - - it('returns a promise that resolves when the request loads', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadXML(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var response = 'response'; - fakeXHR.simulateLoad(response); - var someElements = resolvedValue.getElementsByTagName('some'); - expect(someElements.length).toBeGreaterThan(0); - expect(rejectedError).toBeUndefined(); - }); - - it('returns a promise that rejects when the request errors', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadXML(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - fakeXHR.simulateError(); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - expect(rejectedError.statusCode).toBeUndefined(); - expect(rejectedError.response).toBeUndefined(); - }); - - it('returns a promise that rejects when the request results in an HTTP error code', function() { - var testUrl = 'http://example.invalid/testuri'; - var promise = loadXML(testUrl); - - expect(promise).toBeDefined(); - - var resolvedValue; - var rejectedError; - promise.then(function(value) { - resolvedValue = value; - }, function(error) { - rejectedError = error; - }); - - expect(resolvedValue).toBeUndefined(); - expect(rejectedError).toBeUndefined(); - - var error = 'some error'; - fakeXHR.simulateHttpError(404, error); - expect(resolvedValue).toBeUndefined(); - expect(rejectedError instanceof RequestErrorEvent).toBe(true); - expect(rejectedError.statusCode).toEqual(404); - expect(rejectedError.response).toEqual(error); - }); - - it('returns undefined if the request is throttled', function() { - var oldMaximumRequests = RequestScheduler.maximumRequests; - RequestScheduler.maximumRequests = 0; - - var request = new Request({ - throttle : true - }); - - var testUrl = 'http://example.invalid/testuri'; - var promise = loadXML(testUrl, undefined, request); - expect(promise).toBeUndefined(); - - RequestScheduler.maximumRequests = oldMaximumRequests; - }); -}); diff --git a/Specs/DataSources/CzmlDataSourceSpec.js b/Specs/DataSources/CzmlDataSourceSpec.js index ab523869977c..fe019bcaf18f 100644 --- a/Specs/DataSources/CzmlDataSourceSpec.js +++ b/Specs/DataSources/CzmlDataSourceSpec.js @@ -625,55 +625,6 @@ defineSuite([ }); }); - it('appends query to all uri', function() { - var source = 'http://some.url.invalid/'; - var packet = { - billboard : { - image : [{ - interval : '2013-01-01T00:00:00Z/2013-01-01T01:00:00Z', - uri : 'image.png' - }, { - interval : '2013-01-01T01:00:00Z/2013-01-01T02:00:00Z', - uri : 'image2.png' - }] - } - }; - - var dataSource = new CzmlDataSource(); - return dataSource.load(makePacket(packet), { - sourceUri: source, - query: { - token: 34570, - password: "Passw0rd" - } - }).then(function(dataSource) { - var entity = dataSource.entities.values[0]; - var imageProperty = entity.billboard.image; - expect(imageProperty.getValue(JulianDate.fromIso8601('2013-01-01T00:00:00Z')).url).toEqual(source + 'image.png' + '?token=34570&password=Passw0rd'); - expect(imageProperty.getValue(JulianDate.fromIso8601('2013-01-01T01:00:00Z')).url).toEqual(source + 'image2.png' + '?token=34570&password=Passw0rd'); - }); - }); - - it('appends query tokens to source URL', function() { - var dataSource = new CzmlDataSource(); - var requestNetworkLink = when.defer(); - - spyOn(Resource._Implementations, 'loadWithXhr').and.callFake(function(url, responseType, method, data, headers, deferred, overrideMimeType) { - requestNetworkLink.resolve(url); - deferred.reject(); - }); - - dataSource.process(simpleUrl, { - query: { - "token": 30203, - "pass": "passw0rd" - } - }); - return requestNetworkLink.promise.then(function(url) { - expect(url).toEqual(simpleUrl + '?token=30203&pass=passw0rd'); - }); - }); - it('CZML adds data for constrained billboard.', function() { var billboardPacket = { billboard : { diff --git a/Specs/DataSources/KmlDataSourceSpec.js b/Specs/DataSources/KmlDataSourceSpec.js index 202d4da998a0..4cc468910011 100644 --- a/Specs/DataSources/KmlDataSourceSpec.js +++ b/Specs/DataSources/KmlDataSourceSpec.js @@ -1655,57 +1655,6 @@ defineSuite([ }); }); - it('IconStyle: Sets billboard image with proxy', function() { - var kml = '\ - \ - \ - '; - - var proxy = new DefaultProxy('/proxy/'); - return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), { - camera : options.camera, - canvas : options.canvas, - sourceUri : 'http://test.invalid', - proxy : proxy - }).then(function(dataSource) { - var entities = dataSource.entities.values; - var billboard = entities[0].billboard; - expect(billboard.image.getValue().url).toEqual(proxy.getURL('http://test.invalid/image.png')); - }); - }); - - it('IconStyle: Sets billboard image with query', function() { - var kml = '\ - \ - \ - '; - - return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), { - camera : options.camera, - canvas : options.canvas, - sourceUri : 'http://test.invalid', - query : { - "test": true - } - }).then(function(dataSource) { - var entities = dataSource.entities.values; - var billboard = entities[0].billboard; - expect(billboard.image.getValue().url).toEqual('http://test.invalid/image.png?test=true'); - }); - }); - it('IconStyle: Sets billboard image with subregion', function() { var kml = '\