1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#include "storage.hpp"
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
#include <cmath>
TEST_F(Storage, HTTPExpiresParsing) {
SCOPED_TEST(HTTPExpiresTest)
using namespace mbgl;
util::RunLoop loop;
OnlineFileSource fs(nullptr);
std::unique_ptr<FileRequest> req1 = fs.request({ Resource::Unknown,
"http://127.0.0.1:3000/test?modified=1420794326&expires=1420797926&etag=foo" },
[&](Response res) {
req1.reset();
EXPECT_EQ(nullptr, res.error);
ASSERT_TRUE(res.data.get());
EXPECT_EQ("Hello World!", *res.data);
EXPECT_EQ(SystemClock::from_time_t(1420797926), res.expires);
EXPECT_EQ(SystemClock::from_time_t(1420794326), res.modified);
EXPECT_EQ("foo", *res.etag);
loop.stop();
HTTPExpiresTest.finish();
});
loop.run();
}
TEST_F(Storage, HTTPCacheControlParsing) {
SCOPED_TEST(HTTPCacheControlTest)
using namespace mbgl;
util::RunLoop loop;
OnlineFileSource fs(nullptr);
const Seconds now = toSeconds(SystemClock::now());
std::unique_ptr<FileRequest> req2 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test?cachecontrol=max-age=120" },
[&](Response res) {
req2.reset();
EXPECT_EQ(nullptr, res.error);
ASSERT_TRUE(res.data.get());
EXPECT_EQ("Hello World!", *res.data);
EXPECT_GT(2, std::abs(toSeconds(*res.expires).count() - now.count() - 120)) << "Expiration date isn't about 120 seconds in the future";
EXPECT_FALSE(bool(res.modified));
EXPECT_FALSE(bool(res.etag));
loop.stop();
HTTPCacheControlTest.finish();
});
loop.run();
}
|