Merge pull request #13676 from MoonE/test-improvements
Test improvements
This commit is contained in:
@@ -107,7 +107,7 @@ const createTextStyle = function (feature, resolution, dom) {
|
|||||||
const openSans = document.createElement('link');
|
const openSans = document.createElement('link');
|
||||||
openSans.href = 'https://fonts.googleapis.com/css?family=Open+Sans';
|
openSans.href = 'https://fonts.googleapis.com/css?family=Open+Sans';
|
||||||
openSans.rel = 'stylesheet';
|
openSans.rel = 'stylesheet';
|
||||||
document.getElementsByTagName('head')[0].appendChild(openSans);
|
document.head.appendChild(openSans);
|
||||||
openSansAdded = true;
|
openSansAdded = true;
|
||||||
}
|
}
|
||||||
const font = weight + ' ' + size + '/' + height + ' ' + dom.font.value;
|
const font = weight + ' ' + size + '/' + height + ' ' + dom.font.value;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export function jsonp(url, callback, opt_errback, opt_callbackParam) {
|
|||||||
cleanup();
|
cleanup();
|
||||||
callback(data);
|
callback(data);
|
||||||
};
|
};
|
||||||
document.getElementsByTagName('head')[0].appendChild(script);
|
document.head.appendChild(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ResponseError extends Error {
|
export class ResponseError extends Error {
|
||||||
|
|||||||
BIN
test/browser/spec/ol/data/fonts/ubuntu-regular-webfont.woff2
Normal file
BIN
test/browser/spec/ol/data/fonts/ubuntu-regular-webfont.woff2
Normal file
Binary file not shown.
@@ -6,6 +6,7 @@ import GeometryCollection from '../../../../../src/ol/geom/GeometryCollection.js
|
|||||||
import Icon from '../../../../../src/ol/style/Icon.js';
|
import Icon from '../../../../../src/ol/style/Icon.js';
|
||||||
import IconAnchorUnits from '../../../../../src/ol/style/IconAnchorUnits.js';
|
import IconAnchorUnits from '../../../../../src/ol/style/IconAnchorUnits.js';
|
||||||
import IconOrigin from '../../../../../src/ol/style/IconOrigin.js';
|
import IconOrigin from '../../../../../src/ol/style/IconOrigin.js';
|
||||||
|
import ImageState from '../../../../../src/ol/ImageState.js';
|
||||||
import KML, {
|
import KML, {
|
||||||
getDefaultFillStyle,
|
getDefaultFillStyle,
|
||||||
getDefaultImageStyle,
|
getDefaultImageStyle,
|
||||||
@@ -2323,7 +2324,7 @@ describe('ol.format.KML', function () {
|
|||||||
expect(f).to.be.an(Feature);
|
expect(f).to.be.an(Feature);
|
||||||
const styleFunction = f.getStyleFunction();
|
const styleFunction = f.getStyleFunction();
|
||||||
expect(styleFunction).not.to.be(undefined);
|
expect(styleFunction).not.to.be(undefined);
|
||||||
const styleArray = styleFunction(f, 0);
|
const styleArray = /** @type {Array<Style>} */ (styleFunction(f, 0));
|
||||||
expect(styleArray).to.be.an(Array);
|
expect(styleArray).to.be.an(Array);
|
||||||
expect(styleArray).to.have.length(1);
|
expect(styleArray).to.have.length(1);
|
||||||
const style = styleArray[0];
|
const style = styleArray[0];
|
||||||
@@ -2342,11 +2343,13 @@ describe('ol.format.KML', function () {
|
|||||||
expect(style.getText()).to.be(getDefaultTextStyle());
|
expect(style.getText()).to.be(getDefaultTextStyle());
|
||||||
expect(style.getZIndex()).to.be(undefined);
|
expect(style.getZIndex()).to.be(undefined);
|
||||||
|
|
||||||
setTimeout(function () {
|
imageStyle.listenImageChange(function (evt) {
|
||||||
expect(imageStyle.getSize()).to.eql([20, 20]);
|
if (imageStyle.getImageState() === ImageState.LOADED) {
|
||||||
expect(imageStyle.getScale()).to.be(1.6); // 32 / 20
|
expect(imageStyle.getSize()).to.eql([20, 20]);
|
||||||
done();
|
expect(imageStyle.getScale()).to.be(1.6); // 32 / 20
|
||||||
}, 200);
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can read a IconStyle's hotspot", function () {
|
it("can read a IconStyle's hotspot", function () {
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ describe('ol/layer/MapboxVector', () => {
|
|||||||
originalFetch = fetch;
|
originalFetch = fetch;
|
||||||
window.fetch = function (url) {
|
window.fetch = function (url) {
|
||||||
fetchUrl = url;
|
fetchUrl = url;
|
||||||
return Promise.resolve();
|
return Promise.resolve({ok: false});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ describe('ol/layer/WebGLTile', function () {
|
|||||||
source: new DataTileSource({
|
source: new DataTileSource({
|
||||||
loader(z, x, y) {
|
loader(z, x, y) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
resolve(new ImageData(256, 256));
|
resolve(new ImageData(256, 256).data);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -278,15 +278,15 @@ describe('ol/layer/WebGLTile', function () {
|
|||||||
attribute vec2 a_textureCoord;
|
attribute vec2 a_textureCoord;
|
||||||
|
|
||||||
uniform mat4 u_tileTransform;
|
uniform mat4 u_tileTransform;
|
||||||
uniform float u_texturePixelWidth;
|
uniform float u_texturePixelWidth;
|
||||||
uniform float u_texturePixelHeight;
|
uniform float u_texturePixelHeight;
|
||||||
uniform float u_textureResolution;
|
uniform float u_textureResolution;
|
||||||
uniform float u_textureOriginX;
|
uniform float u_textureOriginX;
|
||||||
uniform float u_textureOriginY;
|
uniform float u_textureOriginY;
|
||||||
uniform float u_depth;
|
uniform float u_depth;
|
||||||
|
|
||||||
varying vec2 v_textureCoord;
|
varying vec2 v_textureCoord;
|
||||||
varying vec2 v_mapCoord;
|
varying vec2 v_mapCoord;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
v_textureCoord = a_textureCoord;
|
v_textureCoord = a_textureCoord;
|
||||||
@@ -419,7 +419,7 @@ describe('ol/layer/WebGLTile', function () {
|
|||||||
source: new DataTileSource({
|
source: new DataTileSource({
|
||||||
loader(z, x, y) {
|
loader(z, x, y) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
resolve(new ImageData(256, 256));
|
resolve(new ImageData(256, 256).data);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -434,7 +434,7 @@ describe('ol/layer/WebGLTile', function () {
|
|||||||
source: new DataTileSource({
|
source: new DataTileSource({
|
||||||
loader(z, x, y) {
|
loader(z, x, y) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
resolve(new ImageData(256, 256));
|
resolve(new ImageData(256, 256).data);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -450,7 +450,7 @@ describe('ol/layer/WebGLTile', function () {
|
|||||||
source: new DataTileSource({
|
source: new DataTileSource({
|
||||||
loader(z, x, y) {
|
loader(z, x, y) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
resolve(new ImageData(256, 256));
|
resolve(new ImageData(256, 256).data);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -589,7 +589,7 @@ describe('ol/layer/WebGLTile', function () {
|
|||||||
sourceless.setSource(
|
sourceless.setSource(
|
||||||
new DataTileSource({
|
new DataTileSource({
|
||||||
loader(z, x, y) {
|
loader(z, x, y) {
|
||||||
return new ImageData(256, 256);
|
return new ImageData(256, 256).data;
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ describe('ol/net', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('jsonp()', function () {
|
describe('jsonp()', function () {
|
||||||
const head = document.getElementsByTagName('head')[0];
|
const head = document.head;
|
||||||
const origAppendChild = head.appendChild;
|
const origAppendChild = head.appendChild;
|
||||||
const origCreateElement = document.createElement;
|
const origCreateElement = document.createElement;
|
||||||
const origSetTimeout = setTimeout;
|
const origSetTimeout = setTimeout;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ describe('ol.render.canvas', function () {
|
|||||||
font.href =
|
font.href =
|
||||||
'https://fonts.googleapis.com/css?family=Abel&text=wmytzilWMYTZIL%40%23%2F%26%3F%24%2510';
|
'https://fonts.googleapis.com/css?family=Abel&text=wmytzilWMYTZIL%40%23%2F%26%3F%24%2510';
|
||||||
font.rel = 'stylesheet';
|
font.rel = 'stylesheet';
|
||||||
const head = document.getElementsByTagName('head')[0];
|
|
||||||
|
|
||||||
describe('ol.render.canvas.registerFont()', function () {
|
describe('ol.render.canvas.registerFont()', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -65,7 +64,7 @@ describe('ol.render.canvas', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('triggers redraw and clear measurements for fonts that become available', function (done) {
|
it('triggers redraw and clear measurements for fonts that become available', function (done) {
|
||||||
head.appendChild(font);
|
document.head.appendChild(font);
|
||||||
render.checkedFonts.addEventListener(
|
render.checkedFonts.addEventListener(
|
||||||
'propertychange',
|
'propertychange',
|
||||||
function onPropertyChange(e) {
|
function onPropertyChange(e) {
|
||||||
@@ -75,6 +74,8 @@ describe('ol.render.canvas', function () {
|
|||||||
);
|
);
|
||||||
expect(e.key).to.be('normal\nnormal\nAbel');
|
expect(e.key).to.be('normal\nnormal\nAbel');
|
||||||
expect(render.textHeights).to.eql({});
|
expect(render.textHeights).to.eql({});
|
||||||
|
|
||||||
|
document.head.removeChild(font);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,15 +18,20 @@ import {
|
|||||||
getWidth,
|
getWidth,
|
||||||
} from '../../../../../../src/ol/extent.js';
|
} from '../../../../../../src/ol/extent.js';
|
||||||
import {checkedFonts} from '../../../../../../src/ol/render/canvas.js';
|
import {checkedFonts} from '../../../../../../src/ol/render/canvas.js';
|
||||||
|
import {createFontStyle} from '../../../util.js';
|
||||||
import {fromExtent} from '../../../../../../src/ol/geom/Polygon.js';
|
import {fromExtent} from '../../../../../../src/ol/geom/Polygon.js';
|
||||||
import {get as getProjection} from '../../../../../../src/ol/proj.js';
|
import {get as getProjection} from '../../../../../../src/ol/proj.js';
|
||||||
|
|
||||||
describe('ol.renderer.canvas.VectorLayer', function () {
|
describe('ol.renderer.canvas.VectorLayer', function () {
|
||||||
describe('constructor', function () {
|
describe('constructor', function () {
|
||||||
const head = document.getElementsByTagName('head')[0];
|
const fontFamily = 'Ubuntu - VectorLayerTest';
|
||||||
const font = document.createElement('link');
|
const font = createFontStyle({
|
||||||
font.href = 'https://fonts.googleapis.com/css?family=Droid+Sans';
|
fontFamily: fontFamily,
|
||||||
font.rel = 'stylesheet';
|
src: {
|
||||||
|
url: '/spec/ol/data/fonts/ubuntu-regular-webfont.woff2',
|
||||||
|
format: 'woff2',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
let target;
|
let target;
|
||||||
|
|
||||||
@@ -156,7 +161,7 @@ describe('ol.renderer.canvas.VectorLayer', function () {
|
|||||||
|
|
||||||
it('re-renders for fonts that become available', function (done) {
|
it('re-renders for fonts that become available', function (done) {
|
||||||
checkedFonts.values_ = {};
|
checkedFonts.values_ = {};
|
||||||
head.appendChild(font);
|
font.add();
|
||||||
const map = new Map({
|
const map = new Map({
|
||||||
view: new View({
|
view: new View({
|
||||||
center: [0, 0],
|
center: [0, 0],
|
||||||
@@ -167,7 +172,7 @@ describe('ol.renderer.canvas.VectorLayer', function () {
|
|||||||
const layerStyle = new Style({
|
const layerStyle = new Style({
|
||||||
text: new Text({
|
text: new Text({
|
||||||
text: 'layer',
|
text: 'layer',
|
||||||
font: '12px "Droid Sans",sans-serif',
|
font: `12px "${fontFamily}",sans-serif`,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -181,9 +186,13 @@ describe('ol.renderer.canvas.VectorLayer', function () {
|
|||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
const revision = layer.getRevision();
|
const revision = layer.getRevision();
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
expect(layer.getRevision()).to.be(revision + 1);
|
try {
|
||||||
head.removeChild(font);
|
font.remove();
|
||||||
done();
|
expect(layer.getRevision()).to.be(revision + 1);
|
||||||
|
done();
|
||||||
|
} catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
}, 1600);
|
}, 1600);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import View from '../../../../../../src/ol/View.js';
|
|||||||
import XYZ from '../../../../../../src/ol/source/XYZ.js';
|
import XYZ from '../../../../../../src/ol/source/XYZ.js';
|
||||||
import {checkedFonts} from '../../../../../../src/ol/render/canvas.js';
|
import {checkedFonts} from '../../../../../../src/ol/render/canvas.js';
|
||||||
import {create} from '../../../../../../src/ol/transform.js';
|
import {create} from '../../../../../../src/ol/transform.js';
|
||||||
|
import {createFontStyle} from '../../../util.js';
|
||||||
import {createXYZ} from '../../../../../../src/ol/tilegrid.js';
|
import {createXYZ} from '../../../../../../src/ol/tilegrid.js';
|
||||||
import {getCenter} from '../../../../../../src/ol/extent.js';
|
import {getCenter} from '../../../../../../src/ol/extent.js';
|
||||||
import {get as getProjection} from '../../../../../../src/ol/proj.js';
|
import {get as getProjection} from '../../../../../../src/ol/proj.js';
|
||||||
@@ -24,10 +25,14 @@ import {getUid} from '../../../../../../src/ol/util.js';
|
|||||||
|
|
||||||
describe('ol/renderer/canvas/VectorTileLayer', function () {
|
describe('ol/renderer/canvas/VectorTileLayer', function () {
|
||||||
describe('constructor', function () {
|
describe('constructor', function () {
|
||||||
const head = document.getElementsByTagName('head')[0];
|
const fontFamily = 'Ubuntu - VectorTileLayerTest';
|
||||||
const font = document.createElement('link');
|
const font = createFontStyle({
|
||||||
font.href = 'https://fonts.googleapis.com/css?family=Dancing+Script';
|
fontFamily: fontFamily,
|
||||||
font.rel = 'stylesheet';
|
src: {
|
||||||
|
url: '/spec/ol/data/fonts/ubuntu-regular-webfont.woff2',
|
||||||
|
format: 'woff2',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
let map,
|
let map,
|
||||||
layer,
|
layer,
|
||||||
@@ -200,14 +205,18 @@ describe('ol/renderer/canvas/VectorTileLayer', function () {
|
|||||||
it('re-renders for fonts that become available', function (done) {
|
it('re-renders for fonts that become available', function (done) {
|
||||||
map.renderSync();
|
map.renderSync();
|
||||||
checkedFonts.values_ = {};
|
checkedFonts.values_ = {};
|
||||||
head.appendChild(font);
|
font.add();
|
||||||
layerStyle[0].getText().setFont('12px "Dancing Script",sans-serif');
|
layerStyle[0].getText().setFont(`12px "${fontFamily}",sans-serif`);
|
||||||
layer.changed();
|
layer.changed();
|
||||||
const revision = layer.getRevision();
|
const revision = layer.getRevision();
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
head.removeChild(font);
|
try {
|
||||||
expect(layer.getRevision()).to.be(revision + 1);
|
font.remove();
|
||||||
done();
|
expect(layer.getRevision()).to.be(revision + 1);
|
||||||
|
done();
|
||||||
|
} catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
}, 1600);
|
}, 1600);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -14,3 +14,33 @@ export function overrideRAF() {
|
|||||||
window.cancelAnimationFrame = caf;
|
window.cancelAnimationFrame = caf;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createFontStyle(options) {
|
||||||
|
const styleNode = document.createElement('style');
|
||||||
|
const src = Array.isArray(options.src) ? options.src : [options.src];
|
||||||
|
function toCssSource(src) {
|
||||||
|
const url = typeof src === 'string' ? src : src.url;
|
||||||
|
const format = typeof src === 'string' ? undefined : src.format;
|
||||||
|
return `url('${url}')${format ? ` format('${format}')` : ''}`;
|
||||||
|
}
|
||||||
|
const ruleText = `
|
||||||
|
@font-face {
|
||||||
|
font-family: '${options.fontFamily}';
|
||||||
|
font-style: ${options.fontStyle || 'normal'};
|
||||||
|
font-weight: ${
|
||||||
|
options.fontWeight === undefined ? 400 : options.fontWeight
|
||||||
|
};
|
||||||
|
src: ${src.map(toCssSource).join(',\n ')};
|
||||||
|
}`;
|
||||||
|
return {
|
||||||
|
add() {
|
||||||
|
document.head.appendChild(styleNode);
|
||||||
|
if (styleNode.sheet.cssRules.length === 0) {
|
||||||
|
styleNode.sheet.insertRule(ruleText);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
remove() {
|
||||||
|
document.head.removeChild(styleNode);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user