Test(ImageOverlay+TileLayer): crossOrigin option to IMG crossorigin attribute (#6022)
* Test(ImageOverlay): crossOrigin option to IMG crossorigin attribute typical values: false (default), true => '', <string> => <string> now that a string value can be passed to this option. * Test(TileLayer): crossOrigin option to IMG crossorigin attribute typical values: false (default), true => '', <string> => <string> now that a string value can be passed to this option. * Style(TileLayerSpec): remove commented code * Style(TileLayerSpec): remove more commented code
This commit is contained in:
parent
34251900ae
commit
2dc70945f8
@ -141,4 +141,45 @@ describe('ImageOverlay', function () {
|
||||
expect(overlay.setZIndex()).to.equal(overlay);
|
||||
});
|
||||
});
|
||||
|
||||
// For tests that do not actually need to append the map container to the document.
|
||||
// This saves PhantomJS memory.
|
||||
describe('_image2', function () {
|
||||
var c, map, overlay;
|
||||
var blankUrl = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
|
||||
var bounds = [[40.712216, -74.22655], [40.773941, -74.12544]];
|
||||
|
||||
// Create map and overlay for each test
|
||||
beforeEach(function () {
|
||||
c = document.createElement('div');
|
||||
c.style.width = '400px';
|
||||
c.style.height = '400px';
|
||||
map = new L.Map(c);
|
||||
map.setView(new L.LatLng(55.8, 37.6), 6); // view needs to be set so when layer is added it is initialized
|
||||
});
|
||||
|
||||
// Clean up after each test run
|
||||
afterEach(function () {
|
||||
map.removeLayer(overlay);
|
||||
overlay = null;
|
||||
map = null;
|
||||
});
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attributes
|
||||
testCrossOriginValue(undefined, null); // Falsy value (other than empty string '') => no attribute set.
|
||||
testCrossOriginValue(true, '');
|
||||
testCrossOriginValue('anonymous', 'anonymous');
|
||||
testCrossOriginValue('use-credentials', 'use-credentials');
|
||||
|
||||
function testCrossOriginValue(crossOrigin, expectedValue) {
|
||||
it('uses crossOrigin option value ' + crossOrigin, function () {
|
||||
overlay = L.imageOverlay(blankUrl, bounds, {
|
||||
crossOrigin: crossOrigin
|
||||
});
|
||||
map.addLayer(overlay);
|
||||
|
||||
expect(overlay._image.getAttribute('crossorigin')).to.be(expectedValue);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -173,13 +173,24 @@ describe('TileLayer', function () {
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
if (div) {
|
||||
document.body.removeChild(div);
|
||||
}
|
||||
});
|
||||
|
||||
function kittenLayerFactory(options) {
|
||||
return L.tileLayer(placeKitten, options || {});
|
||||
}
|
||||
|
||||
function eachImg(layer, callback) {
|
||||
var imgtags = layer._container.children[0].children;
|
||||
for (var i in imgtags) {
|
||||
if (imgtags[i].tagName === 'IMG') {
|
||||
callback(imgtags[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe("number of kittens loaded", function () {
|
||||
|
||||
var clock, kittenLayer, counts;
|
||||
@ -299,15 +310,6 @@ describe('TileLayer', function () {
|
||||
map = L.map(div).setView([0, 0], 2);
|
||||
});
|
||||
|
||||
function eachImg(layer, callback) {
|
||||
var imgtags = layer._container.children[0].children;
|
||||
for (var i in imgtags) {
|
||||
if (imgtags[i].tagName === 'IMG') {
|
||||
callback(imgtags[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it('replaces {y} with y coordinate', function () {
|
||||
var layer = L.tileLayer('http://example.com/{z}/{y}/{x}.png').addTo(map);
|
||||
|
||||
@ -419,4 +421,38 @@ describe('TileLayer', function () {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('options', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
div = document.createElement('div');
|
||||
div.style.width = '400px';
|
||||
div.style.height = '400px';
|
||||
|
||||
map = L.map(div).setView([0, 0], 2);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
map = null;
|
||||
div = null;
|
||||
});
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attributes
|
||||
testCrossOriginValue(undefined, null); // Falsy value (other than empty string '') => no attribute set.
|
||||
testCrossOriginValue(true, '');
|
||||
testCrossOriginValue('anonymous', 'anonymous');
|
||||
testCrossOriginValue('use-credentials', 'use-credentials');
|
||||
|
||||
function testCrossOriginValue(crossOrigin, expectedValue) {
|
||||
it('uses crossOrigin value ' + crossOrigin, function () {
|
||||
var layer = L.tileLayer('http://example.com/{z}/{y}/{x}.png', {
|
||||
crossOrigin: crossOrigin
|
||||
}).addTo(map);
|
||||
|
||||
eachImg(layer, function (img) {
|
||||
expect(img.getAttribute('crossorigin')).to.be(expectedValue);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user