summaryrefslogtreecommitdiff
path: root/test/storage
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-01-04 12:30:13 +0100
committerKonstantin Käfer <mail@kkaefer.com>2016-01-15 11:59:26 +0100
commit21e4029acf757898da8695474f94642f9858acd8 (patch)
tree567a10b18b4f1b573de5ae151018f6518244138a /test/storage
parent957415823a003111f6efecd1a1552a30f999235a (diff)
downloadqtlocation-mapboxgl-21e4029acf757898da8695474f94642f9858acd8.tar.gz
[core] use stale styles
This adds support for using cached styles that are stale. They're treated like changing styles; when the refreshed style changed compared to the one we've already had, we're swapping out the entire style, which might cause a slight flicker.
Diffstat (limited to 'test/storage')
-rw-r--r--test/storage/cache_stale.cpp51
-rwxr-xr-xtest/storage/server.js3
2 files changed, 54 insertions, 0 deletions
diff --git a/test/storage/cache_stale.cpp b/test/storage/cache_stale.cpp
new file mode 100644
index 0000000000..cc421f7c34
--- /dev/null
+++ b/test/storage/cache_stale.cpp
@@ -0,0 +1,51 @@
+#include "storage.hpp"
+
+#include <mbgl/platform/default/headless_display.hpp>
+#include <mbgl/platform/default/headless_view.hpp>
+#include <mbgl/storage/sqlite_cache.hpp>
+#include <mbgl/storage/default_file_source.hpp>
+
+#include <mbgl/platform/log.hpp>
+#include <mbgl/util/work_request.hpp>
+#include <mbgl/util/io.hpp>
+
+using namespace mbgl;
+using namespace std::literals::chrono_literals;
+using namespace std::literals::string_literals;
+
+namespace {
+
+void checkRendering(Map& map, const char *name, std::chrono::milliseconds timeout) {
+ test::checkImage("test/fixtures/stale/"s + name, test::render(map, timeout), 0.001, 0.1);
+}
+
+Response expiredItem(const std::string& path) {
+ Response response;
+ response.data = std::make_shared<std::string>(util::read_file("test/fixtures/"s + path));
+ response.expires = 0s;
+ return response;
+}
+
+const std::string prefix = "http://127.0.0.1:3000";
+
+}
+
+auto display = std::make_shared<mbgl::HeadlessDisplay>();
+
+TEST_F(Storage, CacheStaleStyle) {
+ HeadlessView view(display, 1);
+
+ auto cache = SQLiteCache::getShared(":memory:");
+
+ // Rig the cache with an expired stylesheet.
+ const std::string stylePath = "stale/style.json";
+ const Resource styleResource{ Resource::Kind::Style, prefix + "/" + stylePath };
+ cache->put(styleResource, expiredItem(stylePath));
+
+ DefaultFileSource fileSource(":memory:", ".");
+
+ Map map(view, fileSource, MapMode::Still);
+ map.setStyleURL(styleResource.url);
+
+ checkRendering(map, "stale_style", 1000ms);
+}
diff --git a/test/storage/server.js b/test/storage/server.js
index 5d547b1506..0024330037 100755
--- a/test/storage/server.js
+++ b/test/storage/server.js
@@ -32,6 +32,9 @@ app.get('/test', function (req, res) {
res.send('Hello World!');
});
+app.get('/stale/*', function() {
+ // Never respond.
+});
var cacheCounter = 0;
app.get('/cache', function(req, res) {