summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-02-25 18:06:48 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-02-25 23:15:47 +0200
commitc85e7cbce01d655424906750aeb6288e3ecf586d (patch)
tree1b2ea277c358d96db392596c54437f8e2d9f0a71
parent7c48611f9ee04e1320e1667ea0dae7c355a9935b (diff)
downloadqtlocation-mapboxgl-c85e7cbce01d655424906750aeb6288e3ecf586d.tar.gz
Add OfflineDownload.NoFreezingOnCachedTilesAndNewStyle unit test
-rw-r--r--test/src/mbgl/test/stub_file_source.cpp9
-rw-r--r--test/src/mbgl/test/stub_file_source.hpp4
-rw-r--r--test/storage/offline_download.test.cpp36
3 files changed, 49 insertions, 0 deletions
diff --git a/test/src/mbgl/test/stub_file_source.cpp b/test/src/mbgl/test/stub_file_source.cpp
index 8870a45bdc..f1fb79bea3 100644
--- a/test/src/mbgl/test/stub_file_source.cpp
+++ b/test/src/mbgl/test/stub_file_source.cpp
@@ -70,6 +70,15 @@ void StubFileSource::remove(AsyncRequest* req) {
}
}
+void StubFileSource::setProperty(const std::string& key, const mapbox::base::Value& value) {
+ properties[key] = value;
+}
+
+mapbox::base::Value StubFileSource::getProperty(const std::string& key) const {
+ auto it = properties.find(key);
+ return (it != properties.end()) ? it->second : mapbox::base::Value();
+}
+
optional<Response> StubFileSource::defaultResponse(const Resource& resource) {
switch (resource.kind) {
case Resource::Kind::Style:
diff --git a/test/src/mbgl/test/stub_file_source.hpp b/test/src/mbgl/test/stub_file_source.hpp
index 46bb33d5e2..b88adc93df 100644
--- a/test/src/mbgl/test/stub_file_source.hpp
+++ b/test/src/mbgl/test/stub_file_source.hpp
@@ -5,6 +5,7 @@
#include <mbgl/storage/resource.hpp>
#include <mbgl/util/timer.hpp>
+#include <map>
#include <unordered_map>
namespace mbgl {
@@ -22,6 +23,8 @@ public:
std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
bool canRequest(const Resource&) const override { return true; }
void remove(AsyncRequest*);
+ void setProperty(const std::string&, const mapbox::base::Value&) override;
+ mapbox::base::Value getProperty(const std::string&) const override;
using ResponseFunction = std::function<optional<Response> (const Resource&)>;
@@ -48,6 +51,7 @@ private:
std::unordered_map<AsyncRequest*, std::tuple<Resource, ResponseFunction, Callback>> pending;
ResponseType type;
util::Timer timer;
+ std::map<std::string, mapbox::base::Value> properties;
};
} // namespace mbgl
diff --git a/test/storage/offline_download.test.cpp b/test/storage/offline_download.test.cpp
index ff0965039e..45ecb31d8e 100644
--- a/test/storage/offline_download.test.cpp
+++ b/test/storage/offline_download.test.cpp
@@ -1026,3 +1026,39 @@ TEST(OfflineDownload, InterruptAndResume) {
download.setState(OfflineRegionDownloadState::Active);
test.loop.run();
}
+
+TEST(OfflineDownload, NoFreezingOnCachedTilesAndNewStyle) {
+ OfflineTest test;
+ auto region = test.createRegion();
+ ASSERT_TRUE(region);
+ OfflineDownload download(region->getID(),
+ OfflineTilePyramidRegionDefinition(
+ "http://127.0.0.1:3000/style.json", LatLngBounds::world(), 1.0, 1.0, 1.0, true),
+ test.db,
+ test.fileSource);
+
+ test.fileSource.setProperty(MAX_CONCURRENT_REQUESTS_KEY, 2u);
+ test.fileSource.styleResponse = [&](const Resource&) { return test.response("inline_source.style.json"); };
+ // Number of resources must exceed MAX_CONCURRENT_REQUESTS_KEY
+ test.db.put(Resource::tile("http://127.0.0.1:3000/{z}-{x}-{y}.vector.pbf", 1, 0, 0, 1, Tileset::Scheme::XYZ),
+ test.response("0-0-0.vector.pbf"));
+ test.db.put(Resource::tile("http://127.0.0.1:3000/{z}-{x}-{y}.vector.pbf", 1, 0, 1, 1, Tileset::Scheme::XYZ),
+ test.response("0-0-0.vector.pbf"));
+ test.db.put(Resource::tile("http://127.0.0.1:3000/{z}-{x}-{y}.vector.pbf", 1, 1, 0, 1, Tileset::Scheme::XYZ),
+ test.response("0-0-0.vector.pbf"));
+ test.db.put(Resource::tile("http://127.0.0.1:3000/{z}-{x}-{y}.vector.pbf", 1, 1, 1, 1, Tileset::Scheme::XYZ),
+ test.response("0-0-0.vector.pbf"));
+
+ auto observer = std::make_unique<MockObserver>();
+ observer->statusChangedFn = [&](OfflineRegionStatus status) {
+ if (status.complete()) {
+ test.loop.stop();
+ }
+ };
+
+ download.setObserver(std::move(observer));
+ download.setState(OfflineRegionDownloadState::Active);
+
+ test.loop.run();
+ // Passes if does not freeze.
+} \ No newline at end of file