summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-03-09 10:44:30 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-03-09 13:40:00 -0800
commit7cceca4b4576c21c315b445889bad770e7dc4e53 (patch)
treeb0e749be86ed3e56081d44e05f0516574bb0ebdd
parentbe00dfd3679902870ada89d606e2eed88ce586b1 (diff)
downloadqtlocation-mapboxgl-7cceca4b4576c21c315b445889bad770e7dc4e53.tar.gz
[core] Deactivate OfflineDownload when the tile count limit is hit
This is a better behavior than sending hundreds or thousands of tileCountLimitExceeded notifications.
-rw-r--r--platform/default/mbgl/storage/offline_download.cpp1
-rw-r--r--test/storage/offline_download.cpp14
2 files changed, 14 insertions, 1 deletions
diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp
index 8aacc29c56..dc16ab10fd 100644
--- a/platform/default/mbgl/storage/offline_download.cpp
+++ b/platform/default/mbgl/storage/offline_download.cpp
@@ -230,6 +230,7 @@ void OfflineDownload::ensureResource(const Resource& resource, std::function<voi
&& util::mapbox::isMapboxURL(resource.url)
&& offlineDatabase.offlineMapboxTileCountLimitExceeded()) {
observer->mapboxTileCountLimitExceeded(offlineDatabase.getOfflineMapboxTileCountLimit());
+ setState(OfflineRegionDownloadState::Inactive);
return;
}
diff --git a/test/storage/offline_download.cpp b/test/storage/offline_download.cpp
index da0b1ac0ee..1b35d561be 100644
--- a/test/storage/offline_download.cpp
+++ b/test/storage/offline_download.cpp
@@ -371,10 +371,22 @@ TEST(OfflineDownload, TileCountLimitExceeded) {
};
auto observer = std::make_unique<MockObserver>();
+ bool mapboxTileCountLimitExceededCalled = false;
observer->mapboxTileCountLimitExceededFn = [&] (uint64_t limit) {
+ EXPECT_FALSE(mapboxTileCountLimitExceededCalled);
EXPECT_EQ(0, limit);
- test.loop.stop();
+ mapboxTileCountLimitExceededCalled = true;
+ };
+
+ observer->statusChangedFn = [&] (OfflineRegionStatus status) {
+ EXPECT_FALSE(status.complete());
+ if (!mapboxTileCountLimitExceededCalled) {
+ EXPECT_EQ(OfflineRegionDownloadState::Active, status.downloadState);
+ } else {
+ EXPECT_EQ(OfflineRegionDownloadState::Inactive, status.downloadState);
+ test.loop.stop();
+ }
};
download.setObserver(std::move(observer));