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

Side by Side Diff: components/offline_pages/offline_page_metadata_store_impl_unittest.cc

Issue 1694863003: Refactor the offline page storage to include client namespace and id. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address changes Created 4 years, 9 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/offline_pages/offline_page_metadata_store_impl.h" 5 #include "components/offline_pages/offline_page_metadata_store_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/test/test_simple_task_runner.h" 14 #include "base/test/test_simple_task_runner.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "components/leveldb_proto/proto_database_impl.h" 16 #include "components/leveldb_proto/proto_database_impl.h"
17 #include "components/offline_pages/offline_page_item.h" 17 #include "components/offline_pages/offline_page_item.h"
18 #include "components/offline_pages/offline_page_model.h"
18 #include "components/offline_pages/proto/offline_pages.pb.h" 19 #include "components/offline_pages/proto/offline_pages.pb.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 using leveldb_proto::ProtoDatabaseImpl; 22 using leveldb_proto::ProtoDatabaseImpl;
22 23
23 namespace offline_pages { 24 namespace offline_pages {
24 25
25 namespace { 26 namespace {
26 27
27 const char kTestURL[] = "https://example.com"; 28 const char kTestURL[] = "https://example.com";
28 const int64_t kTestBookmarkId = 1234LL; 29 const ClientId kTestBookmarkId(BOOKMARK_NAMESPACE, "1234");
30 const ClientId kTestBookmarkId2(BOOKMARK_NAMESPACE, "5678");
29 const base::FilePath::CharType kFilePath[] = 31 const base::FilePath::CharType kFilePath[] =
30 FILE_PATH_LITERAL("/offline_pages/example_com.mhtml"); 32 FILE_PATH_LITERAL("/offline_pages/example_com.mhtml");
31 int64_t kFileSize = 234567; 33 int64_t kFileSize = 234567;
32 34
33 class OfflinePageMetadataStoreImplTest : public testing::Test { 35 class OfflinePageMetadataStoreImplTest : public testing::Test {
34 public: 36 public:
35 enum CalledCallback { NONE, LOAD, ADD, REMOVE, DESTROY }; 37 enum CalledCallback { NONE, LOAD, ADD, REMOVE, DESTROY };
36 enum Status { STATUS_NONE, STATUS_TRUE, STATUS_FALSE }; 38 enum Status { STATUS_NONE, STATUS_TRUE, STATUS_FALSE };
37 39
38 OfflinePageMetadataStoreImplTest(); 40 OfflinePageMetadataStoreImplTest();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 EXPECT_EQ(LOAD, last_called_callback_); 119 EXPECT_EQ(LOAD, last_called_callback_);
118 EXPECT_EQ(STATUS_TRUE, last_status_); 120 EXPECT_EQ(STATUS_TRUE, last_status_);
119 EXPECT_EQ(0U, offline_pages_.size()); 121 EXPECT_EQ(0U, offline_pages_.size());
120 } 122 }
121 123
122 // Adds metadata of an offline page into a store and then opens the store 124 // Adds metadata of an offline page into a store and then opens the store
123 // again to make sure that stored metadata survives store restarts. 125 // again to make sure that stored metadata survives store restarts.
124 TEST_F(OfflinePageMetadataStoreImplTest, AddOfflinePage) { 126 TEST_F(OfflinePageMetadataStoreImplTest, AddOfflinePage) {
125 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); 127 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore());
126 128
127 OfflinePageItem offline_page(GURL(kTestURL), kTestBookmarkId, 129 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestBookmarkId,
128 base::FilePath(kFilePath), kFileSize); 130 base::FilePath(kFilePath), kFileSize);
129 store->AddOrUpdateOfflinePage( 131 store->AddOrUpdateOfflinePage(
130 offline_page, 132 offline_page,
131 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, 133 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback,
132 base::Unretained(this), ADD)); 134 base::Unretained(this), ADD));
133 PumpLoop(); 135 PumpLoop();
134 EXPECT_EQ(ADD, last_called_callback_); 136 EXPECT_EQ(ADD, last_called_callback_);
135 EXPECT_EQ(STATUS_TRUE, last_status_); 137 EXPECT_EQ(STATUS_TRUE, last_status_);
136 138
137 ClearResults(); 139 ClearResults();
138 140
139 // Close the store first to ensure file lock is removed. 141 // Close the store first to ensure file lock is removed.
140 store.reset(); 142 store.reset();
141 store = BuildStore(); 143 store = BuildStore();
142 PumpLoop(); 144 PumpLoop();
143 145
144 EXPECT_EQ(LOAD, last_called_callback_); 146 EXPECT_EQ(LOAD, last_called_callback_);
145 EXPECT_EQ(STATUS_TRUE, last_status_); 147 EXPECT_EQ(STATUS_TRUE, last_status_);
146 EXPECT_EQ(1U, offline_pages_.size()); 148 EXPECT_EQ(1U, offline_pages_.size());
147 EXPECT_EQ(offline_page.url, offline_pages_[0].url); 149 EXPECT_EQ(offline_page.url, offline_pages_[0].url);
148 EXPECT_EQ(offline_page.bookmark_id, offline_pages_[0].bookmark_id); 150 EXPECT_EQ(offline_page.offline_id, offline_pages_[0].offline_id);
149 EXPECT_EQ(offline_page.version, offline_pages_[0].version); 151 EXPECT_EQ(offline_page.version, offline_pages_[0].version);
150 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path); 152 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path);
151 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size); 153 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size);
152 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time); 154 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time);
153 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time); 155 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time);
154 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count); 156 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count);
157 EXPECT_EQ(offline_page.client_id, offline_pages_[0].client_id);
155 } 158 }
156 159
157 // Tests removing offline page metadata from the store, for which it first adds 160 // Tests removing offline page metadata from the store, for which it first adds
158 // metadata of an offline page. 161 // metadata of an offline page.
159 TEST_F(OfflinePageMetadataStoreImplTest, RemoveOfflinePage) { 162 TEST_F(OfflinePageMetadataStoreImplTest, RemoveOfflinePage) {
160 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); 163 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore());
161 164
162 // Add an offline page. 165 // Add an offline page.
163 OfflinePageItem offline_page(GURL(kTestURL), kTestBookmarkId, 166 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestBookmarkId,
164 base::FilePath(kFilePath), kFileSize); 167 base::FilePath(kFilePath), kFileSize);
165 store->AddOrUpdateOfflinePage( 168 store->AddOrUpdateOfflinePage(
166 offline_page, 169 offline_page,
167 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, 170 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback,
168 base::Unretained(this), ADD)); 171 base::Unretained(this), ADD));
169 PumpLoop(); 172 PumpLoop();
170 EXPECT_EQ(ADD, last_called_callback_); 173 EXPECT_EQ(ADD, last_called_callback_);
171 EXPECT_EQ(STATUS_TRUE, last_status_); 174 EXPECT_EQ(STATUS_TRUE, last_status_);
172 175
173 ClearResults(); 176 ClearResults();
174 177
175 // Load the store. 178 // Load the store.
176 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, 179 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback,
177 base::Unretained(this))); 180 base::Unretained(this)));
178 PumpLoop(); 181 PumpLoop();
179 EXPECT_EQ(LOAD, last_called_callback_); 182 EXPECT_EQ(LOAD, last_called_callback_);
180 EXPECT_EQ(1U, offline_pages_.size()); 183 EXPECT_EQ(1U, offline_pages_.size());
181 184
182 // Remove the offline page. 185 // Remove the offline page.
183 std::vector<int64_t> ids_to_remove; 186 std::vector<int64_t> ids_to_remove;
184 ids_to_remove.push_back(offline_page.bookmark_id); 187 ids_to_remove.push_back(offline_page.offline_id);
185 store->RemoveOfflinePages( 188 store->RemoveOfflinePages(
186 ids_to_remove, 189 ids_to_remove,
187 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, 190 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback,
188 base::Unretained(this), REMOVE)); 191 base::Unretained(this), REMOVE));
189 PumpLoop(); 192 PumpLoop();
190 EXPECT_EQ(REMOVE, last_called_callback_); 193 EXPECT_EQ(REMOVE, last_called_callback_);
191 EXPECT_EQ(STATUS_TRUE, last_status_); 194 EXPECT_EQ(STATUS_TRUE, last_status_);
192 195
193 ClearResults(); 196 ClearResults();
194 197
(...skipping 12 matching lines...) Expand all
207 EXPECT_EQ(LOAD, last_called_callback_); 210 EXPECT_EQ(LOAD, last_called_callback_);
208 EXPECT_EQ(STATUS_TRUE, last_status_); 211 EXPECT_EQ(STATUS_TRUE, last_status_);
209 EXPECT_EQ(0U, offline_pages_.size()); 212 EXPECT_EQ(0U, offline_pages_.size());
210 } 213 }
211 214
212 // Adds metadata of multiple offline pages into a store and removes some. 215 // Adds metadata of multiple offline pages into a store and removes some.
213 TEST_F(OfflinePageMetadataStoreImplTest, AddRemoveMultipleOfflinePages) { 216 TEST_F(OfflinePageMetadataStoreImplTest, AddRemoveMultipleOfflinePages) {
214 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); 217 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore());
215 218
216 // Add an offline page. 219 // Add an offline page.
217 OfflinePageItem offline_page_1(GURL(kTestURL), kTestBookmarkId, 220 OfflinePageItem offline_page_1(GURL(kTestURL), 12345LL, kTestBookmarkId,
218 base::FilePath(kFilePath), kFileSize); 221 base::FilePath(kFilePath), kFileSize);
219 base::FilePath file_path_2 = 222 base::FilePath file_path_2 =
220 base::FilePath(FILE_PATH_LITERAL("//other.page.com.mhtml")); 223 base::FilePath(FILE_PATH_LITERAL("//other.page.com.mhtml"));
221 OfflinePageItem offline_page_2(GURL("https://other.page.com"), 5678LL, 224 OfflinePageItem offline_page_2(GURL("https://other.page.com"), 5678LL,
222 file_path_2, 12345, base::Time::Now()); 225 kTestBookmarkId2, file_path_2, 12345,
226 base::Time::Now());
223 store->AddOrUpdateOfflinePage( 227 store->AddOrUpdateOfflinePage(
224 offline_page_1, 228 offline_page_1,
225 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, 229 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback,
226 base::Unretained(this), ADD)); 230 base::Unretained(this), ADD));
227 PumpLoop(); 231 PumpLoop();
228 EXPECT_EQ(ADD, last_called_callback_); 232 EXPECT_EQ(ADD, last_called_callback_);
229 EXPECT_EQ(STATUS_TRUE, last_status_); 233 EXPECT_EQ(STATUS_TRUE, last_status_);
230 234
231 ClearResults(); 235 ClearResults();
232 236
(...skipping 12 matching lines...) Expand all
245 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, 249 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback,
246 base::Unretained(this))); 250 base::Unretained(this)));
247 PumpLoop(); 251 PumpLoop();
248 252
249 EXPECT_EQ(LOAD, last_called_callback_); 253 EXPECT_EQ(LOAD, last_called_callback_);
250 EXPECT_EQ(STATUS_TRUE, last_status_); 254 EXPECT_EQ(STATUS_TRUE, last_status_);
251 EXPECT_EQ(2U, offline_pages_.size()); 255 EXPECT_EQ(2U, offline_pages_.size());
252 256
253 // Remove the offline page. 257 // Remove the offline page.
254 std::vector<int64_t> ids_to_remove; 258 std::vector<int64_t> ids_to_remove;
255 ids_to_remove.push_back(offline_page_1.bookmark_id); 259 ids_to_remove.push_back(offline_page_1.offline_id);
256 store->RemoveOfflinePages( 260 store->RemoveOfflinePages(
257 ids_to_remove, 261 ids_to_remove,
258 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, 262 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback,
259 base::Unretained(this), REMOVE)); 263 base::Unretained(this), REMOVE));
260 PumpLoop(); 264 PumpLoop();
261 EXPECT_EQ(REMOVE, last_called_callback_); 265 EXPECT_EQ(REMOVE, last_called_callback_);
262 EXPECT_EQ(STATUS_TRUE, last_status_); 266 EXPECT_EQ(STATUS_TRUE, last_status_);
263 267
264 ClearResults(); 268 ClearResults();
265 269
266 // Close and reload the store. 270 // Close and reload the store.
267 store.reset(); 271 store.reset();
268 store = BuildStore(); 272 store = BuildStore();
269 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, 273 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback,
270 base::Unretained(this))); 274 base::Unretained(this)));
271 PumpLoop(); 275 PumpLoop();
272 276
273 EXPECT_EQ(LOAD, last_called_callback_); 277 EXPECT_EQ(LOAD, last_called_callback_);
274 EXPECT_EQ(STATUS_TRUE, last_status_); 278 EXPECT_EQ(STATUS_TRUE, last_status_);
275 EXPECT_EQ(1U, offline_pages_.size()); 279 EXPECT_EQ(1U, offline_pages_.size());
276 EXPECT_EQ(offline_page_2.url, offline_pages_[0].url); 280 EXPECT_EQ(offline_page_2.url, offline_pages_[0].url);
277 EXPECT_EQ(offline_page_2.bookmark_id, offline_pages_[0].bookmark_id); 281 EXPECT_EQ(offline_page_2.offline_id, offline_pages_[0].offline_id);
278 EXPECT_EQ(offline_page_2.version, offline_pages_[0].version); 282 EXPECT_EQ(offline_page_2.version, offline_pages_[0].version);
279 EXPECT_EQ(offline_page_2.file_path, offline_pages_[0].file_path); 283 EXPECT_EQ(offline_page_2.file_path, offline_pages_[0].file_path);
280 EXPECT_EQ(offline_page_2.file_size, offline_pages_[0].file_size); 284 EXPECT_EQ(offline_page_2.file_size, offline_pages_[0].file_size);
281 EXPECT_EQ(offline_page_2.creation_time, offline_pages_[0].creation_time); 285 EXPECT_EQ(offline_page_2.creation_time, offline_pages_[0].creation_time);
282 EXPECT_EQ(offline_page_2.last_access_time, 286 EXPECT_EQ(offline_page_2.last_access_time,
283 offline_pages_[0].last_access_time); 287 offline_pages_[0].last_access_time);
284 EXPECT_EQ(offline_page_2.access_count, offline_pages_[0].access_count); 288 EXPECT_EQ(offline_page_2.access_count, offline_pages_[0].access_count);
289 EXPECT_EQ(offline_page_2.client_id, offline_pages_[0].client_id);
285 } 290 }
286 291
287 // Tests updating offline page metadata from the store. 292 // Tests updating offline page metadata from the store.
288 TEST_F(OfflinePageMetadataStoreImplTest, UpdateOfflinePage) { 293 TEST_F(OfflinePageMetadataStoreImplTest, UpdateOfflinePage) {
289 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); 294 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore());
290 295
291 // First, adds a fresh page. 296 // First, adds a fresh page.
292 OfflinePageItem offline_page(GURL(kTestURL), kTestBookmarkId, 297 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestBookmarkId,
293 base::FilePath(kFilePath), kFileSize); 298 base::FilePath(kFilePath), kFileSize);
294 store->AddOrUpdateOfflinePage( 299 store->AddOrUpdateOfflinePage(
295 offline_page, 300 offline_page,
296 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, 301 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback,
297 base::Unretained(this), ADD)); 302 base::Unretained(this), ADD));
298 PumpLoop(); 303 PumpLoop();
299 EXPECT_EQ(ADD, last_called_callback_); 304 EXPECT_EQ(ADD, last_called_callback_);
300 EXPECT_EQ(STATUS_TRUE, last_status_); 305 EXPECT_EQ(STATUS_TRUE, last_status_);
301 306
302 ClearResults(); 307 ClearResults();
303 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, 308 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback,
304 base::Unretained(this))); 309 base::Unretained(this)));
305 PumpLoop(); 310 PumpLoop();
306 311
307 EXPECT_EQ(LOAD, last_called_callback_); 312 EXPECT_EQ(LOAD, last_called_callback_);
308 EXPECT_EQ(STATUS_TRUE, last_status_); 313 EXPECT_EQ(STATUS_TRUE, last_status_);
309 EXPECT_EQ(1U, offline_pages_.size()); 314 EXPECT_EQ(1U, offline_pages_.size());
310 EXPECT_EQ(offline_page.url, offline_pages_[0].url); 315 EXPECT_EQ(offline_page.url, offline_pages_[0].url);
311 EXPECT_EQ(offline_page.bookmark_id, offline_pages_[0].bookmark_id); 316 EXPECT_EQ(offline_page.offline_id, offline_pages_[0].offline_id);
312 EXPECT_EQ(offline_page.version, offline_pages_[0].version); 317 EXPECT_EQ(offline_page.version, offline_pages_[0].version);
313 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path); 318 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path);
314 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size); 319 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size);
315 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time); 320 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time);
316 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time); 321 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time);
317 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count); 322 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count);
323 EXPECT_EQ(offline_page.client_id, offline_pages_[0].client_id);
318 324
319 // Then updates some data. 325 // Then updates some data.
320 offline_page.file_size = kFileSize + 1; 326 offline_page.file_size = kFileSize + 1;
321 offline_page.access_count++; 327 offline_page.access_count++;
322 store->AddOrUpdateOfflinePage( 328 store->AddOrUpdateOfflinePage(
323 offline_page, 329 offline_page,
324 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, 330 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback,
325 base::Unretained(this), ADD)); 331 base::Unretained(this), ADD));
326 PumpLoop(); 332 PumpLoop();
327 EXPECT_EQ(ADD, last_called_callback_); 333 EXPECT_EQ(ADD, last_called_callback_);
328 EXPECT_EQ(STATUS_TRUE, last_status_); 334 EXPECT_EQ(STATUS_TRUE, last_status_);
329 335
330 ClearResults(); 336 ClearResults();
331 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, 337 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback,
332 base::Unretained(this))); 338 base::Unretained(this)));
333 PumpLoop(); 339 PumpLoop();
334 340
335 EXPECT_EQ(LOAD, last_called_callback_); 341 EXPECT_EQ(LOAD, last_called_callback_);
336 EXPECT_EQ(STATUS_TRUE, last_status_); 342 EXPECT_EQ(STATUS_TRUE, last_status_);
337 EXPECT_EQ(1U, offline_pages_.size()); 343 EXPECT_EQ(1U, offline_pages_.size());
338 EXPECT_EQ(offline_page.url, offline_pages_[0].url); 344 EXPECT_EQ(offline_page.url, offline_pages_[0].url);
339 EXPECT_EQ(offline_page.bookmark_id, offline_pages_[0].bookmark_id); 345 EXPECT_EQ(offline_page.offline_id, offline_pages_[0].offline_id);
340 EXPECT_EQ(offline_page.version, offline_pages_[0].version); 346 EXPECT_EQ(offline_page.version, offline_pages_[0].version);
341 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path); 347 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path);
342 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size); 348 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size);
343 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time); 349 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time);
344 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time); 350 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time);
345 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count); 351 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count);
352 EXPECT_EQ(offline_page.client_id, offline_pages_[0].client_id);
346 } 353 }
347 354
348 } // namespace 355 } // namespace
349 356
350 // Test that loading a store with a bad value still loads. 357 // Test that loading a store with a bad value still loads.
351 // Needs to be outside of the anonymous namespace in order for FRIEND_TEST 358 // Needs to be outside of the anonymous namespace in order for FRIEND_TEST
352 // to work. 359 // to work.
353 TEST_F(OfflinePageMetadataStoreImplTest, LoadCorruptedStore) { 360 TEST_F(OfflinePageMetadataStoreImplTest, LoadCorruptedStore) {
354 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); 361 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore());
355 362
356 // Write one ok page. 363 // Write one ok page.
357 OfflinePageItem offline_page(GURL(kTestURL), kTestBookmarkId, 364 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestBookmarkId,
358 base::FilePath(kFilePath), kFileSize); 365 base::FilePath(kFilePath), kFileSize);
359 store->AddOrUpdateOfflinePage( 366 store->AddOrUpdateOfflinePage(
360 offline_page, 367 offline_page,
361 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, 368 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback,
362 base::Unretained(this), ADD)); 369 base::Unretained(this), ADD));
363 PumpLoop(); 370 PumpLoop();
364 EXPECT_EQ(ADD, last_called_callback_); 371 EXPECT_EQ(ADD, last_called_callback_);
365 EXPECT_EQ(STATUS_TRUE, last_status_); 372 EXPECT_EQ(STATUS_TRUE, last_status_);
366 373
367 // Manually write one broken page (no id) 374 // Manually write one broken page (no id)
(...skipping 20 matching lines...) Expand all
388 // Close the store first to ensure file lock is removed. 395 // Close the store first to ensure file lock is removed.
389 store.reset(); 396 store.reset();
390 store = BuildStore(); 397 store = BuildStore();
391 PumpLoop(); 398 PumpLoop();
392 399
393 // One of the pages was busted, so only expect one page. 400 // One of the pages was busted, so only expect one page.
394 EXPECT_EQ(LOAD, last_called_callback_); 401 EXPECT_EQ(LOAD, last_called_callback_);
395 EXPECT_EQ(STATUS_TRUE, last_status_); 402 EXPECT_EQ(STATUS_TRUE, last_status_);
396 EXPECT_EQ(1U, offline_pages_.size()); 403 EXPECT_EQ(1U, offline_pages_.size());
397 EXPECT_EQ(offline_page.url, offline_pages_[0].url); 404 EXPECT_EQ(offline_page.url, offline_pages_[0].url);
398 EXPECT_EQ(offline_page.bookmark_id, offline_pages_[0].bookmark_id); 405 EXPECT_EQ(offline_page.offline_id, offline_pages_[0].offline_id);
399 EXPECT_EQ(offline_page.version, offline_pages_[0].version); 406 EXPECT_EQ(offline_page.version, offline_pages_[0].version);
400 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path); 407 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path);
401 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size); 408 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size);
402 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time); 409 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time);
403 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time); 410 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time);
404 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count); 411 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count);
405 } 412 }
406 413
407 // Test that loading a store with nothing but bad values errors. 414 // Test that loading a store with nothing but bad values errors.
408 // Needs to be outside of the anonymous namespace in order for FRIEND_TEST 415 // Needs to be outside of the anonymous namespace in order for FRIEND_TEST
(...skipping 27 matching lines...) Expand all
436 store.reset(); 443 store.reset();
437 store = BuildStore(); 444 store = BuildStore();
438 PumpLoop(); 445 PumpLoop();
439 446
440 // One of the pages was busted, so only expect one page. 447 // One of the pages was busted, so only expect one page.
441 EXPECT_EQ(LOAD, last_called_callback_); 448 EXPECT_EQ(LOAD, last_called_callback_);
442 EXPECT_EQ(STATUS_FALSE, last_status_); 449 EXPECT_EQ(STATUS_FALSE, last_status_);
443 } 450 }
444 451
445 } // namespace offline_pages 452 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698