summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-09-23 15:26:31 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-09-26 14:55:49 -0700
commit570bafcfecf2ec9e87eaf280599b9e239bd5c2d4 (patch)
tree2e02fd417768ff1b972daecb25583d4e680a082a /test
parentf34ba23d85c2b034458363c8b3b7f2995a7ea09e (diff)
downloadqtlocation-mapboxgl-570bafcfecf2ec9e87eaf280599b9e239bd5c2d4.tar.gz
[core] Don't allow OfflineDownload to flood the request queue
Diffstat (limited to 'test')
-rw-r--r--test/src/mbgl/test/fake_file_source.hpp1
-rw-r--r--test/storage/offline_download.cpp25
2 files changed, 26 insertions, 0 deletions
diff --git a/test/src/mbgl/test/fake_file_source.hpp b/test/src/mbgl/test/fake_file_source.hpp
index 7ebb4cf0cb..3ed3f90a17 100644
--- a/test/src/mbgl/test/fake_file_source.hpp
+++ b/test/src/mbgl/test/fake_file_source.hpp
@@ -2,6 +2,7 @@
#include <mbgl/storage/file_source.hpp>
+#include <algorithm>
#include <list>
namespace mbgl {
diff --git a/test/storage/offline_download.cpp b/test/storage/offline_download.cpp
index 76a772dd1b..27e57771c8 100644
--- a/test/storage/offline_download.cpp
+++ b/test/storage/offline_download.cpp
@@ -1,8 +1,10 @@
#include <mbgl/test/stub_file_source.hpp>
+#include <mbgl/test/fake_file_source.hpp>
#include <mbgl/storage/offline.hpp>
#include <mbgl/storage/offline_database.hpp>
#include <mbgl/storage/offline_download.hpp>
+#include <mbgl/storage/http_file_source.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/compression.hpp>
@@ -240,6 +242,29 @@ TEST(OfflineDownload, Activate) {
test.loop.run();
}
+TEST(OfflineDownload, DoesNotFloodTheFileSourceWithRequests) {
+ FakeFileSource fileSource;
+ OfflineTest test;
+ OfflineRegion region = test.createRegion();
+ OfflineDownload download(
+ region.getID(),
+ OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0),
+ test.db, fileSource);
+
+ auto observer = std::make_unique<MockObserver>();
+
+ download.setObserver(std::move(observer));
+ download.setState(OfflineRegionDownloadState::Active);
+ test.loop.runOnce();
+
+ EXPECT_EQ(1u, fileSource.requests.size());
+
+ fileSource.respond(Resource::Kind::Style, test.response("style.json"));
+ test.loop.runOnce();
+
+ EXPECT_EQ(HTTPFileSource::maximumConcurrentRequests(), fileSource.requests.size());
+}
+
TEST(OfflineDownload, GetStatusNoResources) {
OfflineTest test;
OfflineRegion region = test.createRegion();