Add OfflineDownload.NoFreezingOnCachedTilesAndNewStyle unit test
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
Reference in New Issue
Block a user