summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-03-04 14:26:58 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-03-04 15:15:09 -0800
commiteb9b4638417ddfb519cd278f25ad022500a9573a (patch)
tree996c51e79678510e2826bf93f3ff20a635cff9f2 /test
parent803adf42c9f8811598a2289c6b2773e968bebe30 (diff)
downloadqtlocation-mapboxgl-eb9b4638417ddfb519cd278f25ad022500a9573a.tar.gz
[core] Fix offline status reporting with pre-existing tiles (#4147)
Diffstat (limited to 'test')
-rw-r--r--test/storage/offline_download.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/storage/offline_download.cpp b/test/storage/offline_download.cpp
index fce081b8ab..15980e2fdc 100644
--- a/test/storage/offline_download.cpp
+++ b/test/storage/offline_download.cpp
@@ -380,3 +380,78 @@ TEST(OfflineDownload, TileCountLimitExceeded) {
test.loop.run();
}
+
+TEST(OfflineDownload, WithPreviouslyExistingTile) {
+ OfflineTest test;
+ OfflineRegion region = test.createRegion();
+ OfflineDownload download(
+ region.getID(),
+ OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/offline/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0),
+ test.db, test.fileSource);
+
+ test.fileSource.styleResponse = [&] (const Resource& resource) {
+ EXPECT_EQ("http://127.0.0.1:3000/offline/style.json", resource.url);
+ return test.response("offline/inline_source.style.json");
+ };
+
+ test.db.put(
+ Resource::tile("http://127.0.0.1:3000/offline/{z}-{x}-{y}.vector.pbf", 1, 0, 0, 0),
+ test.response("offline/0-0-0.vector.pbf"));
+
+ auto observer = std::make_unique<MockObserver>();
+
+ observer->statusChangedFn = [&] (OfflineRegionStatus status) {
+ if (status.complete()) {
+ EXPECT_EQ(2, status.completedResourceCount);
+ EXPECT_EQ(test.size, status.completedResourceSize);
+ EXPECT_TRUE(status.requiredResourceCountIsPrecise);
+ test.loop.stop();
+ }
+ };
+
+ download.setObserver(std::move(observer));
+ download.setState(OfflineRegionDownloadState::Active);
+
+ test.loop.run();
+}
+
+TEST(OfflineDownload, ReactivatePreviouslyCompletedDownload) {
+ OfflineTest test;
+ OfflineRegion region = test.createRegion();
+ OfflineDownload download(
+ region.getID(),
+ OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/offline/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0),
+ test.db, test.fileSource);
+
+ test.fileSource.styleResponse = [&] (const Resource& resource) {
+ EXPECT_EQ("http://127.0.0.1:3000/offline/style.json", resource.url);
+ return test.response("offline/inline_source.style.json");
+ };
+
+ test.db.put(
+ Resource::tile("http://127.0.0.1:3000/offline/{z}-{x}-{y}.vector.pbf", 1, 0, 0, 0),
+ test.response("offline/0-0-0.vector.pbf"));
+
+ auto observer = std::make_unique<MockObserver>();
+ bool completedOnce = false;
+
+ observer->statusChangedFn = [&] (OfflineRegionStatus status) {
+ if (!status.complete()) {
+ return;
+ } else if (!completedOnce) {
+ completedOnce = true;
+ download.setState(OfflineRegionDownloadState::Inactive);
+ download.setState(OfflineRegionDownloadState::Active);
+ } else {
+ EXPECT_EQ(2, status.completedResourceCount);
+ EXPECT_EQ(test.size, status.completedResourceSize);
+ EXPECT_TRUE(status.requiredResourceCountIsPrecise);
+ test.loop.stop();
+ }
+ };
+
+ download.setObserver(std::move(observer));
+ download.setState(OfflineRegionDownloadState::Active);
+
+ test.loop.run();
+}