summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-03-11 08:24:52 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-03-11 11:43:32 -0800
commit4748973c04329adaafa9c8c614bd5b377729b726 (patch)
tree8464c4b72aaa7e565276c8a7fc2d76b18b5d0b6d
parent694a064cdd7c32177eafd858aaa7e3f20cde8478 (diff)
downloadqtlocation-mapboxgl-4748973c04329adaafa9c8c614bd5b377729b726.tar.gz
[core] Deactivate offline region upon completion
-rw-r--r--platform/default/mbgl/storage/offline_download.cpp8
-rw-r--r--test/storage/offline_download.cpp21
2 files changed, 23 insertions, 6 deletions
diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp
index dc16ab10fd..36b6f5d502 100644
--- a/platform/default/mbgl/storage/offline_download.cpp
+++ b/platform/default/mbgl/storage/offline_download.cpp
@@ -222,6 +222,10 @@ void OfflineDownload::ensureResource(const Resource& resource, std::function<voi
status.completedResourceCount++;
status.completedResourceSize += offlineResponse->second;
observer->statusChanged(status);
+
+ if (status.complete()) {
+ setState(OfflineRegionDownloadState::Inactive);
+ }
return;
}
@@ -251,6 +255,10 @@ void OfflineDownload::ensureResource(const Resource& resource, std::function<voi
status.completedResourceSize += offlineDatabase.putRegionResource(id, resource, onlineResponse);
observer->statusChanged(status);
+
+ if (status.complete()) {
+ setState(OfflineRegionDownloadState::Inactive);
+ }
});
});
}
diff --git a/test/storage/offline_download.cpp b/test/storage/offline_download.cpp
index 1b35d561be..26d0fb29e5 100644
--- a/test/storage/offline_download.cpp
+++ b/test/storage/offline_download.cpp
@@ -71,13 +71,22 @@ TEST(OfflineDownload, NoSubresources) {
auto observer = std::make_unique<MockObserver>();
+ bool expectsInactiveStatus = false;
observer->statusChangedFn = [&] (OfflineRegionStatus status) {
if (status.complete()) {
- EXPECT_EQ(OfflineRegionDownloadState::Active, status.downloadState);
- EXPECT_EQ(1, status.completedResourceCount);
- EXPECT_EQ(test.size, status.completedResourceSize);
- EXPECT_TRUE(status.requiredResourceCountIsPrecise);
- test.loop.stop();
+ if (!expectsInactiveStatus) {
+ expectsInactiveStatus = true;
+ EXPECT_EQ(OfflineRegionDownloadState::Active, status.downloadState);
+ EXPECT_EQ(1, status.completedResourceCount);
+ EXPECT_EQ(test.size, status.completedResourceSize);
+ EXPECT_TRUE(status.requiredResourceCountIsPrecise);
+ } else {
+ EXPECT_EQ(OfflineRegionDownloadState::Inactive, status.downloadState);
+ EXPECT_EQ(1, status.completedResourceCount);
+ EXPECT_EQ(test.size, status.completedResourceSize);
+ EXPECT_TRUE(status.requiredResourceCountIsPrecise);
+ test.loop.stop();
+ }
}
};
@@ -478,7 +487,7 @@ TEST(OfflineDownload, ReactivatePreviouslyCompletedDownload) {
test.loop.run();
- ASSERT_EQ(3, statusesAfterReactivate.size());
+ ASSERT_EQ(4, statusesAfterReactivate.size());
EXPECT_EQ(OfflineRegionDownloadState::Active, statusesAfterReactivate[0].downloadState);
EXPECT_FALSE(statusesAfterReactivate[0].requiredResourceCountIsPrecise);