From 7cceca4b4576c21c315b445889bad770e7dc4e53 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 9 Mar 2016 10:44:30 -0800 Subject: [PATCH] [core] Deactivate OfflineDownload when the tile count limit is hit This is a better behavior than sending hundreds or thousands of tileCountLimitExceeded notifications. --- platform/default/mbgl/storage/offline_download.cpp | 1 + test/storage/offline_download.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp index 8aacc29c5..dc16ab10f 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::functionmapboxTileCountLimitExceeded(offlineDatabase.getOfflineMapboxTileCountLimit()); + setState(OfflineRegionDownloadState::Inactive); return; } diff --git a/test/storage/offline_download.cpp b/test/storage/offline_download.cpp index da0b1ac0e..1b35d561b 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(); + 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));