summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-02-05 16:52:07 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-02-10 15:40:20 -0800
commite9302c797f68c7e48b908b87b126045c8c5e5209 (patch)
tree044441cdb82ed8752401c43ead9e84018b067fbd /test
parent7eb1a91c4e5134ecfbfb91b61a6622be40478af5 (diff)
downloadqtlocation-mapboxgl-e9302c797f68c7e48b908b87b126045c8c5e5209.tar.gz
[all] Don't interpret 404s on non-tile resources as "no content"
Diffstat (limited to 'test')
-rw-r--r--test/storage/http_reading.cpp50
-rw-r--r--test/storage/offline_database.cpp14
-rwxr-xr-xtest/storage/server.js4
-rw-r--r--test/style/source.cpp58
4 files changed, 119 insertions, 7 deletions
diff --git a/test/storage/http_reading.cpp b/test/storage/http_reading.cpp
index d360ec0031..b8e474ee43 100644
--- a/test/storage/http_reading.cpp
+++ b/test/storage/http_reading.cpp
@@ -59,6 +59,56 @@ TEST_F(Storage, HTTP404) {
loop.run();
}
+TEST_F(Storage, HTTPTile404) {
+ SCOPED_TEST(HTTPTile404)
+
+ using namespace mbgl;
+
+ util::RunLoop loop;
+ OnlineFileSource fs;
+
+ std::unique_ptr<FileRequest> req2 = fs.request({ Resource::Tile, "http://127.0.0.1:3000/doesnotexist" },
+ [&](Response res) {
+ req2.reset();
+ EXPECT_TRUE(util::ThreadContext::currentlyOn(util::ThreadType::Main));
+ EXPECT_TRUE(res.noContent);
+ EXPECT_FALSE(bool(res.error));
+ EXPECT_FALSE(bool(res.data));
+ EXPECT_FALSE(bool(res.expires));
+ EXPECT_FALSE(bool(res.modified));
+ EXPECT_FALSE(bool(res.etag));
+ loop.stop();
+ HTTPTile404.finish();
+ });
+
+ loop.run();
+}
+
+TEST_F(Storage, HTTP204) {
+ SCOPED_TEST(HTTP204)
+
+ using namespace mbgl;
+
+ util::RunLoop loop;
+ OnlineFileSource fs;
+
+ std::unique_ptr<FileRequest> req2 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/no-content" },
+ [&](Response res) {
+ req2.reset();
+ EXPECT_TRUE(util::ThreadContext::currentlyOn(util::ThreadType::Main));
+ EXPECT_TRUE(res.noContent);
+ EXPECT_FALSE(bool(res.error));
+ EXPECT_FALSE(bool(res.data));
+ EXPECT_FALSE(bool(res.expires));
+ EXPECT_FALSE(bool(res.modified));
+ EXPECT_FALSE(bool(res.etag));
+ loop.stop();
+ HTTP204.finish();
+ });
+
+ loop.run();
+}
+
TEST_F(Storage, HTTP500) {
SCOPED_TEST(HTTP500)
diff --git a/test/storage/offline_database.cpp b/test/storage/offline_database.cpp
index e2e32ee36b..1c43506066 100644
--- a/test/storage/offline_database.cpp
+++ b/test/storage/offline_database.cpp
@@ -334,19 +334,19 @@ TEST(OfflineDatabase, PutTile) {
EXPECT_EQ("data", *res->data);
}
-TEST(OfflineDatabase, PutResourceNotFound) {
+TEST(OfflineDatabase, PutResourceNoContent) {
using namespace mbgl;
OfflineDatabase db(":memory:");
Resource resource { Resource::Style, "http://example.com/" };
Response response;
- response.error = std::make_unique<Response::Error>(Response::Error::Reason::NotFound);
+ response.noContent = true;
db.put(resource, response);
auto res = db.get(resource);
- EXPECT_NE(nullptr, res->error);
- EXPECT_EQ(Response::Error::Reason::NotFound, res->error->reason);
+ EXPECT_EQ(nullptr, res->error);
+ EXPECT_TRUE(res->noContent);
EXPECT_FALSE(res->data.get());
}
@@ -364,11 +364,11 @@ TEST(OfflineDatabase, PutTileNotFound) {
0
};
Response response;
- response.error = std::make_unique<Response::Error>(Response::Error::Reason::NotFound);
+ response.noContent = true;
db.put(resource, response);
auto res = db.get(resource);
- EXPECT_NE(nullptr, res->error);
- EXPECT_EQ(Response::Error::Reason::NotFound, res->error->reason);
+ EXPECT_EQ(nullptr, res->error);
+ EXPECT_TRUE(res->noContent);
EXPECT_FALSE(res->data.get());
}
diff --git a/test/storage/server.js b/test/storage/server.js
index 0024330037..16b507daa9 100755
--- a/test/storage/server.js
+++ b/test/storage/server.js
@@ -84,6 +84,10 @@ app.get('/revalidate-etag', function(req, res) {
revalidateEtagCounter++;
});
+app.get('/no-content', function(req, res) {
+ res.status(204).send();
+});
+
app.get('/not-found', function(req, res) {
res.status(404).send('Not Found!');
});
diff --git a/test/style/source.cpp b/test/style/source.cpp
index 528059ae9f..f5b46292ab 100644
--- a/test/style/source.cpp
+++ b/test/style/source.cpp
@@ -116,6 +116,64 @@ TEST(Source, LoadingCorrupt) {
test.run();
}
+TEST(Source, RasterTileEmpty) {
+ SourceTest test;
+
+ test.fileSource.tileResponse = [&] (const Resource&) {
+ Response response;
+ response.noContent = true;
+ return response;
+ };
+
+ test.observer.tileLoaded = [&] (Source& source, const TileID&, bool) {
+ EXPECT_EQ("source", source.id);
+ test.end();
+ };
+
+ test.observer.tileError = [&] (Source&, const TileID&, std::exception_ptr) {
+ FAIL() << "Should never be called";
+ };
+
+ auto info = std::make_unique<SourceInfo>();
+ info->tiles = { "tiles" };
+
+ Source source(SourceType::Raster, "source", "", 512, std::move(info), nullptr);
+ source.setObserver(&test.observer);
+ source.load();
+ source.update(test.updateParameters);
+
+ test.run();
+}
+
+TEST(Source, VectorTileEmpty) {
+ SourceTest test;
+
+ test.fileSource.tileResponse = [&] (const Resource&) {
+ Response response;
+ response.noContent = true;
+ return response;
+ };
+
+ test.observer.tileLoaded = [&] (Source& source, const TileID&, bool) {
+ EXPECT_EQ("source", source.id);
+ test.end();
+ };
+
+ test.observer.tileError = [&] (Source&, const TileID&, std::exception_ptr) {
+ FAIL() << "Should never be called";
+ };
+
+ auto info = std::make_unique<SourceInfo>();
+ info->tiles = { "tiles" };
+
+ Source source(SourceType::Vector, "source", "", 512, std::move(info), nullptr);
+ source.setObserver(&test.observer);
+ source.load();
+ source.update(test.updateParameters);
+
+ test.run();
+}
+
TEST(Source, RasterTileFail) {
SourceTest test;