Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: components/precache/core/precache_session_tables_unittest.cc

Issue 1961153003: Add pause/resume functionality to precache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/precache/core/precache_session_tables.h"
6
7 #include <stdint.h>
8
9 #include <list>
10 #include <map>
11
12 #include "base/compiler_specific.h"
13 #include "base/time/time.h"
14 #include "sql/connection.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h"
17
18 namespace precache {
19
20 namespace {
21
22 class PrecacheSessionTablesTest : public testing::Test {
23 public:
24 PrecacheSessionTablesTest() {}
25 ~PrecacheSessionTablesTest() override {}
26
27 protected:
28 void SetUp() override {
29 precache_session_tables_.reset(new PrecacheSessionTables());
30 db_.reset(new sql::Connection());
31 ASSERT_TRUE(db_->OpenInMemory());
32 precache_session_tables_->Init(db_.get());
33 }
34
35 std::unique_ptr<PrecacheSessionTables> precache_session_tables_;
36 std::unique_ptr<sql::Connection> db_;
37 };
38
39 TEST_F(PrecacheSessionTablesTest, StoreAndGetURLs) {
40 std::list<GURL> manifests, manifests2;
41 std::list<GURL> resources, resources2;
42 manifests.push_back(GURL("http://www.m1.com/"));
43 manifests.push_back(GURL("http://www.m2.com/"));
44 resources.push_back(GURL("http://www.r1.com/"));
45 resources.push_back(GURL("http://www.r2.com/"));
46 precache_session_tables_->StoreURLs(manifests, resources);
47 precache_session_tables_->GetURLs(&manifests2, &resources2);
48 EXPECT_EQ(manifests, manifests2);
49 EXPECT_EQ(resources, resources2);
50 }
51
52 TEST_F(PrecacheSessionTablesTest, StoreAndGetStatistics) {
53 int64_t total_response_bytes = 100;
54 int64_t network_response_bytes = 50;
55 int64_t num_manifest_urls_to_fetch = 2;
56 base::TimeTicks start_time = base::TimeTicks::FromInternalValue(50);
57 int64_t total_response_bytes2;
58 int64_t network_response_bytes2;
59 int64_t num_manifest_urls_to_fetch2;
60 base::TimeTicks start_time2;
61 precache_session_tables_->StoreStatistics(
62 total_response_bytes, network_response_bytes, num_manifest_urls_to_fetch,
63 start_time);
64 precache_session_tables_->GetStatistics(
65 &total_response_bytes2, &network_response_bytes2,
66 &num_manifest_urls_to_fetch2, &start_time2);
67 EXPECT_EQ(total_response_bytes, total_response_bytes2);
68 EXPECT_EQ(network_response_bytes, network_response_bytes2);
69 EXPECT_EQ(network_response_bytes, network_response_bytes2);
70 EXPECT_EQ(start_time, start_time2);
71 }
72
73 TEST_F(PrecacheSessionTablesTest, GetEmptyURLs) {
74 std::list<GURL> manifests;
75 std::list<GURL> resources;
76 precache_session_tables_->GetURLs(&manifests, &resources);
77 EXPECT_TRUE(manifests.empty());
78 EXPECT_TRUE(resources.empty());
79 }
80
81 TEST_F(PrecacheSessionTablesTest, GetEmptyStatistics) {
82 int64_t total_response_bytes;
83 int64_t network_response_bytes;
84 int64_t num_manifest_urls_to_fetch;
85 base::TimeTicks start_time;
86 precache_session_tables_->GetStatistics(
87 &total_response_bytes, &network_response_bytes,
88 &num_manifest_urls_to_fetch, &start_time);
89 EXPECT_EQ(0, total_response_bytes);
90 EXPECT_EQ(0, network_response_bytes);
91 EXPECT_EQ(0, network_response_bytes);
92 EXPECT_EQ(0, start_time.ToInternalValue());
93 }
94
95 TEST_F(PrecacheSessionTablesTest, StoreTwiceAndGetURLs) {
96 std::list<GURL> manifests, manifests2, manifests3;
97 std::list<GURL> resources, resources2, resources3;
98 manifests.push_back(GURL("http://www.m1.com/"));
99 manifests.push_back(GURL("http://www.m2.com/"));
100 resources.push_back(GURL("http://www.r1.com/"));
101 resources.push_back(GURL("http://www.r2.com/"));
102 manifests2.push_back(GURL("http://www.m3.com/"));
103 resources2.push_back(GURL("http://www.r3.com/"));
104 precache_session_tables_->StoreURLs(manifests, resources);
105 precache_session_tables_->StoreURLs(manifests2, resources2);
106 precache_session_tables_->GetURLs(&manifests3, &resources3);
107 EXPECT_EQ(manifests2, manifests2);
108 EXPECT_EQ(resources2, resources2);
109 }
110
111 TEST_F(PrecacheSessionTablesTest, StoreTwiceAndGetStatistics) {
112 int64_t total_response_bytes = 100;
113 int64_t network_response_bytes = 50;
114 int64_t num_manifest_urls_to_fetch = 2;
115 base::TimeTicks start_time = base::TimeTicks::FromInternalValue(50);
116 int64_t total_response_bytes2 = 101;
117 int64_t network_response_bytes2 = 51;
118 int64_t num_manifest_urls_to_fetch2 = 3;
119 base::TimeTicks start_time2 = base::TimeTicks::FromInternalValue(51);
120 int64_t total_response_bytes3;
121 int64_t network_response_bytes3;
122 int64_t num_manifest_urls_to_fetch3;
123 base::TimeTicks start_time3;
124 precache_session_tables_->StoreStatistics(
125 total_response_bytes, network_response_bytes, num_manifest_urls_to_fetch,
126 start_time);
127 precache_session_tables_->StoreStatistics(
128 total_response_bytes2, network_response_bytes2,
129 num_manifest_urls_to_fetch2, start_time2);
130 precache_session_tables_->GetStatistics(
131 &total_response_bytes3, &network_response_bytes3,
132 &num_manifest_urls_to_fetch3, &start_time3);
133 EXPECT_EQ(total_response_bytes2, total_response_bytes3);
134 EXPECT_EQ(network_response_bytes2, network_response_bytes3);
135 EXPECT_EQ(network_response_bytes2, network_response_bytes3);
136 EXPECT_EQ(start_time2, start_time3);
137 }
138
139 TEST_F(PrecacheSessionTablesTest, StoreAndGetURLsTwice) {
140 std::list<GURL> manifests, manifests2, manifests3;
141 std::list<GURL> resources, resources2, resources3;
142 manifests.push_back(GURL("http://www.m1.com/"));
143 manifests.push_back(GURL("http://www.m2.com/"));
144 resources.push_back(GURL("http://www.r1.com/"));
145 resources.push_back(GURL("http://www.r2.com/"));
146 precache_session_tables_->StoreURLs(manifests, resources);
147 precache_session_tables_->GetURLs(&manifests2, &resources2);
148 precache_session_tables_->GetURLs(&manifests3, &resources3);
149 EXPECT_EQ(manifests, manifests2);
150 EXPECT_EQ(resources, resources2);
151 EXPECT_EQ(manifests, manifests3);
152 EXPECT_EQ(resources, resources3);
153 }
154
155 TEST_F(PrecacheSessionTablesTest, StoreAndGetStatisticsTwice) {
156 int64_t total_response_bytes = 100;
157 int64_t network_response_bytes = 50;
158 int64_t num_manifest_urls_to_fetch = 2;
159 base::TimeTicks start_time = base::TimeTicks::FromInternalValue(50);
160 int64_t total_response_bytes2, total_response_bytes3;
161 int64_t network_response_bytes2, network_response_bytes3;
162 int64_t num_manifest_urls_to_fetch2, num_manifest_urls_to_fetch3;
163 base::TimeTicks start_time2, start_time3;
164 precache_session_tables_->StoreStatistics(
165 total_response_bytes, network_response_bytes, num_manifest_urls_to_fetch,
166 start_time);
167 precache_session_tables_->GetStatistics(
168 &total_response_bytes2, &network_response_bytes2,
169 &num_manifest_urls_to_fetch2, &start_time2);
170 precache_session_tables_->GetStatistics(
171 &total_response_bytes3, &network_response_bytes3,
172 &num_manifest_urls_to_fetch3, &start_time3);
173 EXPECT_EQ(total_response_bytes, total_response_bytes2);
174 EXPECT_EQ(network_response_bytes, network_response_bytes2);
175 EXPECT_EQ(network_response_bytes, network_response_bytes2);
176 EXPECT_EQ(start_time, start_time2);
177 EXPECT_EQ(total_response_bytes, total_response_bytes3);
178 EXPECT_EQ(network_response_bytes, network_response_bytes3);
179 EXPECT_EQ(network_response_bytes, network_response_bytes3);
180 EXPECT_EQ(start_time, start_time3);
181 }
182
183 } // namespace
184
185 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698