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

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

Issue 1993953002: [Offline pages] Adding expiration capability to OfflinePageModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing feedback 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
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 <memory> 9 #include <memory>
10 10
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 EXPECT_EQ(STATUS_TRUE, this->last_status_); 187 EXPECT_EQ(STATUS_TRUE, this->last_status_);
188 EXPECT_EQ(1U, this->offline_pages_.size()); 188 EXPECT_EQ(1U, this->offline_pages_.size());
189 EXPECT_EQ(offline_page.url, this->offline_pages_[0].url); 189 EXPECT_EQ(offline_page.url, this->offline_pages_[0].url);
190 EXPECT_EQ(offline_page.offline_id, this->offline_pages_[0].offline_id); 190 EXPECT_EQ(offline_page.offline_id, this->offline_pages_[0].offline_id);
191 EXPECT_EQ(offline_page.version, this->offline_pages_[0].version); 191 EXPECT_EQ(offline_page.version, this->offline_pages_[0].version);
192 EXPECT_EQ(offline_page.file_path, this->offline_pages_[0].file_path); 192 EXPECT_EQ(offline_page.file_path, this->offline_pages_[0].file_path);
193 EXPECT_EQ(offline_page.file_size, this->offline_pages_[0].file_size); 193 EXPECT_EQ(offline_page.file_size, this->offline_pages_[0].file_size);
194 EXPECT_EQ(offline_page.creation_time, this->offline_pages_[0].creation_time); 194 EXPECT_EQ(offline_page.creation_time, this->offline_pages_[0].creation_time);
195 EXPECT_EQ(offline_page.last_access_time, 195 EXPECT_EQ(offline_page.last_access_time,
196 this->offline_pages_[0].last_access_time); 196 this->offline_pages_[0].last_access_time);
197 EXPECT_EQ(offline_page.expiration_time,
198 this->offline_pages_[0].expiration_time);
197 EXPECT_EQ(offline_page.access_count, this->offline_pages_[0].access_count); 199 EXPECT_EQ(offline_page.access_count, this->offline_pages_[0].access_count);
198 EXPECT_EQ(offline_page.client_id, this->offline_pages_[0].client_id); 200 EXPECT_EQ(offline_page.client_id, this->offline_pages_[0].client_id);
199 } 201 }
200 202
201 // Tests removing offline page metadata from the store, for which it first adds 203 // Tests removing offline page metadata from the store, for which it first adds
202 // metadata of an offline page. 204 // metadata of an offline page.
203 TYPED_TEST(OfflinePageMetadataStoreTest, RemoveOfflinePage) { 205 TYPED_TEST(OfflinePageMetadataStoreTest, RemoveOfflinePage) {
204 std::unique_ptr<OfflinePageMetadataStore> store(this->BuildStore()); 206 std::unique_ptr<OfflinePageMetadataStore> store(this->BuildStore());
205 207
206 // Add an offline page. 208 // Add an offline page.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 std::unique_ptr<OfflinePageMetadataStore> store(this->BuildStore()); 260 std::unique_ptr<OfflinePageMetadataStore> store(this->BuildStore());
259 261
260 // Add an offline page. 262 // Add an offline page.
261 OfflinePageItem offline_page_1(GURL(kTestURL), 12345LL, kTestClientId1, 263 OfflinePageItem offline_page_1(GURL(kTestURL), 12345LL, kTestClientId1,
262 base::FilePath(kFilePath), kFileSize); 264 base::FilePath(kFilePath), kFileSize);
263 base::FilePath file_path_2 = 265 base::FilePath file_path_2 =
264 base::FilePath(FILE_PATH_LITERAL("//other.page.com.mhtml")); 266 base::FilePath(FILE_PATH_LITERAL("//other.page.com.mhtml"));
265 OfflinePageItem offline_page_2(GURL("https://other.page.com"), 5678LL, 267 OfflinePageItem offline_page_2(GURL("https://other.page.com"), 5678LL,
266 kTestClientId2, file_path_2, 12345, 268 kTestClientId2, file_path_2, 12345,
267 base::Time::Now()); 269 base::Time::Now());
270 offline_page_2.expiration_time = base::Time::Now();
268 store->AddOrUpdateOfflinePage( 271 store->AddOrUpdateOfflinePage(
269 offline_page_1, 272 offline_page_1,
270 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback, 273 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback,
271 base::Unretained(this), ADD)); 274 base::Unretained(this), ADD));
272 this->PumpLoop(); 275 this->PumpLoop();
273 EXPECT_EQ(ADD, this->last_called_callback_); 276 EXPECT_EQ(ADD, this->last_called_callback_);
274 EXPECT_EQ(STATUS_TRUE, this->last_status_); 277 EXPECT_EQ(STATUS_TRUE, this->last_status_);
275 278
276 this->ClearResults(); 279 this->ClearResults();
277 280
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 EXPECT_EQ(1U, this->offline_pages_.size()); 323 EXPECT_EQ(1U, this->offline_pages_.size());
321 EXPECT_EQ(offline_page_2.url, this->offline_pages_[0].url); 324 EXPECT_EQ(offline_page_2.url, this->offline_pages_[0].url);
322 EXPECT_EQ(offline_page_2.offline_id, this->offline_pages_[0].offline_id); 325 EXPECT_EQ(offline_page_2.offline_id, this->offline_pages_[0].offline_id);
323 EXPECT_EQ(offline_page_2.version, this->offline_pages_[0].version); 326 EXPECT_EQ(offline_page_2.version, this->offline_pages_[0].version);
324 EXPECT_EQ(offline_page_2.file_path, this->offline_pages_[0].file_path); 327 EXPECT_EQ(offline_page_2.file_path, this->offline_pages_[0].file_path);
325 EXPECT_EQ(offline_page_2.file_size, this->offline_pages_[0].file_size); 328 EXPECT_EQ(offline_page_2.file_size, this->offline_pages_[0].file_size);
326 EXPECT_EQ(offline_page_2.creation_time, 329 EXPECT_EQ(offline_page_2.creation_time,
327 this->offline_pages_[0].creation_time); 330 this->offline_pages_[0].creation_time);
328 EXPECT_EQ(offline_page_2.last_access_time, 331 EXPECT_EQ(offline_page_2.last_access_time,
329 this->offline_pages_[0].last_access_time); 332 this->offline_pages_[0].last_access_time);
333 EXPECT_EQ(offline_page_2.expiration_time,
334 this->offline_pages_[0].expiration_time);
330 EXPECT_EQ(offline_page_2.access_count, this->offline_pages_[0].access_count); 335 EXPECT_EQ(offline_page_2.access_count, this->offline_pages_[0].access_count);
331 EXPECT_EQ(offline_page_2.client_id, this->offline_pages_[0].client_id); 336 EXPECT_EQ(offline_page_2.client_id, this->offline_pages_[0].client_id);
332 } 337 }
333 338
334 // Tests updating offline page metadata from the store. 339 // Tests updating offline page metadata from the store.
335 TYPED_TEST(OfflinePageMetadataStoreTest, UpdateOfflinePage) { 340 TYPED_TEST(OfflinePageMetadataStoreTest, UpdateOfflinePage) {
336 std::unique_ptr<OfflinePageMetadataStore> store(this->BuildStore()); 341 std::unique_ptr<OfflinePageMetadataStore> store(this->BuildStore());
337 342
338 // First, adds a fresh page. 343 // First, adds a fresh page.
339 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, 344 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1,
(...skipping 15 matching lines...) Expand all
355 EXPECT_EQ(STATUS_TRUE, this->last_status_); 360 EXPECT_EQ(STATUS_TRUE, this->last_status_);
356 EXPECT_EQ(1U, this->offline_pages_.size()); 361 EXPECT_EQ(1U, this->offline_pages_.size());
357 EXPECT_EQ(offline_page.url, this->offline_pages_[0].url); 362 EXPECT_EQ(offline_page.url, this->offline_pages_[0].url);
358 EXPECT_EQ(offline_page.offline_id, this->offline_pages_[0].offline_id); 363 EXPECT_EQ(offline_page.offline_id, this->offline_pages_[0].offline_id);
359 EXPECT_EQ(offline_page.version, this->offline_pages_[0].version); 364 EXPECT_EQ(offline_page.version, this->offline_pages_[0].version);
360 EXPECT_EQ(offline_page.file_path, this->offline_pages_[0].file_path); 365 EXPECT_EQ(offline_page.file_path, this->offline_pages_[0].file_path);
361 EXPECT_EQ(offline_page.file_size, this->offline_pages_[0].file_size); 366 EXPECT_EQ(offline_page.file_size, this->offline_pages_[0].file_size);
362 EXPECT_EQ(offline_page.creation_time, this->offline_pages_[0].creation_time); 367 EXPECT_EQ(offline_page.creation_time, this->offline_pages_[0].creation_time);
363 EXPECT_EQ(offline_page.last_access_time, 368 EXPECT_EQ(offline_page.last_access_time,
364 this->offline_pages_[0].last_access_time); 369 this->offline_pages_[0].last_access_time);
370 EXPECT_EQ(offline_page.expiration_time,
371 this->offline_pages_[0].expiration_time);
365 EXPECT_EQ(offline_page.access_count, this->offline_pages_[0].access_count); 372 EXPECT_EQ(offline_page.access_count, this->offline_pages_[0].access_count);
366 EXPECT_EQ(offline_page.client_id, this->offline_pages_[0].client_id); 373 EXPECT_EQ(offline_page.client_id, this->offline_pages_[0].client_id);
367 374
368 // Then update some data. 375 // Then update some data.
369 offline_page.file_size = kFileSize + 1; 376 offline_page.file_size = kFileSize + 1;
370 offline_page.access_count++; 377 offline_page.access_count++;
378 offline_page.expiration_time = base::Time::Now();
371 store->AddOrUpdateOfflinePage( 379 store->AddOrUpdateOfflinePage(
372 offline_page, 380 offline_page,
373 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback, 381 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback,
374 base::Unretained(this), ADD)); 382 base::Unretained(this), ADD));
375 this->PumpLoop(); 383 this->PumpLoop();
376 EXPECT_EQ(ADD, this->last_called_callback_); 384 EXPECT_EQ(ADD, this->last_called_callback_);
377 EXPECT_EQ(STATUS_TRUE, this->last_status_); 385 EXPECT_EQ(STATUS_TRUE, this->last_status_);
378 386
379 this->ClearResults(); 387 this->ClearResults();
380 store->Load(base::Bind(&OfflinePageMetadataStoreTestBase::LoadCallback, 388 store->Load(base::Bind(&OfflinePageMetadataStoreTestBase::LoadCallback,
381 base::Unretained(this))); 389 base::Unretained(this)));
382 this->PumpLoop(); 390 this->PumpLoop();
383 391
384 EXPECT_EQ(LOAD, this->last_called_callback_); 392 EXPECT_EQ(LOAD, this->last_called_callback_);
385 EXPECT_EQ(STATUS_TRUE, this->last_status_); 393 EXPECT_EQ(STATUS_TRUE, this->last_status_);
386 EXPECT_EQ(1U, this->offline_pages_.size()); 394 EXPECT_EQ(1U, this->offline_pages_.size());
387 EXPECT_EQ(offline_page.url, this->offline_pages_[0].url); 395 EXPECT_EQ(offline_page.url, this->offline_pages_[0].url);
388 EXPECT_EQ(offline_page.offline_id, this->offline_pages_[0].offline_id); 396 EXPECT_EQ(offline_page.offline_id, this->offline_pages_[0].offline_id);
389 EXPECT_EQ(offline_page.version, this->offline_pages_[0].version); 397 EXPECT_EQ(offline_page.version, this->offline_pages_[0].version);
390 EXPECT_EQ(offline_page.file_path, this->offline_pages_[0].file_path); 398 EXPECT_EQ(offline_page.file_path, this->offline_pages_[0].file_path);
391 EXPECT_EQ(offline_page.file_size, this->offline_pages_[0].file_size); 399 EXPECT_EQ(offline_page.file_size, this->offline_pages_[0].file_size);
392 EXPECT_EQ(offline_page.creation_time, this->offline_pages_[0].creation_time); 400 EXPECT_EQ(offline_page.creation_time, this->offline_pages_[0].creation_time);
393 EXPECT_EQ(offline_page.last_access_time, 401 EXPECT_EQ(offline_page.last_access_time,
394 this->offline_pages_[0].last_access_time); 402 this->offline_pages_[0].last_access_time);
403 EXPECT_EQ(offline_page.expiration_time,
404 this->offline_pages_[0].expiration_time);
395 EXPECT_EQ(offline_page.access_count, this->offline_pages_[0].access_count); 405 EXPECT_EQ(offline_page.access_count, this->offline_pages_[0].access_count);
396 EXPECT_EQ(offline_page.client_id, this->offline_pages_[0].client_id); 406 EXPECT_EQ(offline_page.client_id, this->offline_pages_[0].client_id);
397 } 407 }
398 408
399 } // namespace 409 } // namespace
400 410
401 class OfflinePageMetadataStoreImplTest 411 class OfflinePageMetadataStoreImplTest
402 : public OfflinePageMetadataStoreTest<OfflinePageMetadataStoreImplFactory> { 412 : public OfflinePageMetadataStoreTest<OfflinePageMetadataStoreImplFactory> {
403 public: 413 public:
404 void UpdateStoreEntries( 414 void UpdateStoreEntries(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 EXPECT_EQ(STATUS_TRUE, this->last_status_); 474 EXPECT_EQ(STATUS_TRUE, this->last_status_);
465 EXPECT_EQ(1U, this->offline_pages_.size()); 475 EXPECT_EQ(1U, this->offline_pages_.size());
466 EXPECT_EQ(offline_page.url, this->offline_pages_[0].url); 476 EXPECT_EQ(offline_page.url, this->offline_pages_[0].url);
467 EXPECT_EQ(offline_page.offline_id, this->offline_pages_[0].offline_id); 477 EXPECT_EQ(offline_page.offline_id, this->offline_pages_[0].offline_id);
468 EXPECT_EQ(offline_page.version, this->offline_pages_[0].version); 478 EXPECT_EQ(offline_page.version, this->offline_pages_[0].version);
469 EXPECT_EQ(offline_page.file_path, this->offline_pages_[0].file_path); 479 EXPECT_EQ(offline_page.file_path, this->offline_pages_[0].file_path);
470 EXPECT_EQ(offline_page.file_size, this->offline_pages_[0].file_size); 480 EXPECT_EQ(offline_page.file_size, this->offline_pages_[0].file_size);
471 EXPECT_EQ(offline_page.creation_time, this->offline_pages_[0].creation_time); 481 EXPECT_EQ(offline_page.creation_time, this->offline_pages_[0].creation_time);
472 EXPECT_EQ(offline_page.last_access_time, 482 EXPECT_EQ(offline_page.last_access_time,
473 this->offline_pages_[0].last_access_time); 483 this->offline_pages_[0].last_access_time);
484 EXPECT_EQ(offline_page.expiration_time,
485 this->offline_pages_[0].expiration_time);
474 EXPECT_EQ(offline_page.access_count, this->offline_pages_[0].access_count); 486 EXPECT_EQ(offline_page.access_count, this->offline_pages_[0].access_count);
475 } 487 }
476 488
477 // Test that loading a store with nothing but bad values errors. 489 // Test that loading a store with nothing but bad values errors.
478 // Needs to be outside of the anonymous namespace in order for FRIEND_TEST 490 // Needs to be outside of the anonymous namespace in order for FRIEND_TEST
479 // to work. 491 // to work.
480 TEST_F(OfflinePageMetadataStoreImplTest, LoadTotallyCorruptedStore) { 492 TEST_F(OfflinePageMetadataStoreImplTest, LoadTotallyCorruptedStore) {
481 std::unique_ptr<OfflinePageMetadataStore> store(this->BuildStore()); 493 std::unique_ptr<OfflinePageMetadataStore> store(this->BuildStore());
482 494
483 // Manually write two broken pages (no id) 495 // Manually write two broken pages (no id)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 offline_pages_[0].client_id.name_space); 561 offline_pages_[0].client_id.name_space);
550 EXPECT_EQ(base::Int64ToString(offline_page_proto.deprecated_bookmark_id()), 562 EXPECT_EQ(base::Int64ToString(offline_page_proto.deprecated_bookmark_id()),
551 offline_pages_[0].client_id.id); 563 offline_pages_[0].client_id.id);
552 EXPECT_EQ(GURL(kTestURL), offline_pages_[0].url); 564 EXPECT_EQ(GURL(kTestURL), offline_pages_[0].url);
553 EXPECT_EQ(offline_page_proto.version(), offline_pages_[0].version); 565 EXPECT_EQ(offline_page_proto.version(), offline_pages_[0].version);
554 EXPECT_EQ(offline_page_proto.file_path(), 566 EXPECT_EQ(offline_page_proto.file_path(),
555 offline_pages_[0].file_path.MaybeAsASCII()); 567 offline_pages_[0].file_path.MaybeAsASCII());
556 } 568 }
557 569
558 } // namespace offline_pages 570 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698