From 9dea370b8431cfb4c57c81ef213a08eb8161813c Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Wed, 10 May 2023 15:37:42 +0300 Subject: [PATCH] Add unit test that checks if SourceCache waits until source is loaded before preloading tiles --- test/unit/source/source_cache.test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/unit/source/source_cache.test.js b/test/unit/source/source_cache.test.js index af4f43e47cf..568c5dd1543 100644 --- a/test/unit/source/source_cache.test.js +++ b/test/unit/source/source_cache.test.js @@ -1897,5 +1897,27 @@ test('SourceCache#_preloadTiles', (t) => { sourceCache.getSource().onAdd(); }); + t.test('waits until source is loaded before preloading tiles', (t) => { + const transform = new Transform(); + transform.resize(511, 511); + transform.zoom = 0; + + const {sourceCache} = createSourceCache({ + loadTile (tile, callback) { + t.ok(sourceCache._sourceLoaded, 'source is loaded before preloading tiles'); + t.equal(tile.tileID.key, new OverscaledTileID(0, 0, 0, 0, 0).key,); + tile.state = 'loaded'; + callback(null); + } + }); + + // Marks source as not loaded + sourceCache._sourceLoaded = false; + sourceCache._preloadTiles(transform, () => t.end()); + + // Fires event that marks source as loaded + sourceCache.getSource().onAdd(); + }); + t.end(); });