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

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

Issue 2512073002: [Offline Pages] Removes two-step expiration related. (Closed)
Patch Set: adding unit in histograms. Created 4 years 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.h" 5 #include "components/offline_pages/offline_page_metadata_store.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 "version INTEGER NOT NULL, " 142 "version INTEGER NOT NULL, "
143 "last_access_time INTEGER NOT NULL, " 143 "last_access_time INTEGER NOT NULL, "
144 "access_count INTEGER NOT NULL, " 144 "access_count INTEGER NOT NULL, "
145 "status INTEGER NOT NULL DEFAULT 0, " 145 "status INTEGER NOT NULL DEFAULT 0, "
146 "user_initiated INTEGER, " 146 "user_initiated INTEGER, "
147 "expiration_time INTEGER NOT NULL DEFAULT 0, " 147 "expiration_time INTEGER NOT NULL DEFAULT 0, "
148 "client_namespace VARCHAR NOT NULL, " 148 "client_namespace VARCHAR NOT NULL, "
149 "client_id VARCHAR NOT NULL, " 149 "client_id VARCHAR NOT NULL, "
150 "online_url VARCHAR NOT NULL, " 150 "online_url VARCHAR NOT NULL, "
151 "offline_url VARCHAR NOT NULL DEFAULT '', " 151 "offline_url VARCHAR NOT NULL DEFAULT '', "
152 "file_path VARCHAR NOT NULL " 152 "file_path VARCHAR NOT NULL, "
153 "title VARCHAR NOT NULL DEFAULT ''" 153 "title VARCHAR NOT NULL DEFAULT ''"
154 ")")); 154 ")"));
155 ASSERT_TRUE(connection.CommitTransaction()); 155 ASSERT_TRUE(connection.CommitTransaction());
156 sql::Statement statement(connection.GetUniqueStatement( 156 sql::Statement statement(connection.GetUniqueStatement(
157 "INSERT INTO " OFFLINE_PAGES_TABLE_V1 157 "INSERT INTO " OFFLINE_PAGES_TABLE_V1
158 "(offline_id, creation_time, file_size, version, " 158 "(offline_id, creation_time, file_size, version, "
159 "last_access_time, access_count, client_namespace, " 159 "last_access_time, access_count, client_namespace, "
160 "client_id, online_url, file_path, expiration_time, title) " 160 "client_id, online_url, file_path, expiration_time, title) "
161 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")); 161 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"));
162 statement.BindInt64(0, kOfflineId); 162 statement.BindInt64(0, kOfflineId);
163 statement.BindInt(1, 0); 163 statement.BindInt(1, 0);
164 statement.BindInt64(2, kFileSize); 164 statement.BindInt64(2, kFileSize);
165 statement.BindInt(3, 0); 165 statement.BindInt(3, 0);
166 statement.BindInt(4, 0); 166 statement.BindInt(4, 0);
167 statement.BindInt(5, 1); 167 statement.BindInt(5, 1);
168 statement.BindCString(6, kTestClientNamespace); 168 statement.BindCString(6, kTestClientNamespace);
169 statement.BindString(7, kTestClientId2.id); 169 statement.BindString(7, kTestClientId2.id);
170 statement.BindCString(8, kTestURL); 170 statement.BindCString(8, kTestURL);
171 statement.BindString(9, base::FilePath(kFilePath).MaybeAsASCII()); 171 statement.BindString(9, base::FilePath(kFilePath).MaybeAsASCII());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 statement.BindString(8, base::FilePath(kFilePath).MaybeAsASCII()); 218 statement.BindString(8, base::FilePath(kFilePath).MaybeAsASCII());
219 statement.BindInt64(9, base::Time::Now().ToInternalValue()); 219 statement.BindInt64(9, base::Time::Now().ToInternalValue());
220 statement.BindString16(10, base::UTF8ToUTF16("Test title")); 220 statement.BindString16(10, base::UTF8ToUTF16("Test title"));
221 ASSERT_TRUE(statement.Run()); 221 ASSERT_TRUE(statement.Run());
222 ASSERT_TRUE(connection.DoesTableExist(OFFLINE_PAGES_TABLE_V1)); 222 ASSERT_TRUE(connection.DoesTableExist(OFFLINE_PAGES_TABLE_V1));
223 ASSERT_TRUE(connection.DoesColumnExist(OFFLINE_PAGES_TABLE_V1, "title")); 223 ASSERT_TRUE(connection.DoesColumnExist(OFFLINE_PAGES_TABLE_V1, "title"));
224 ASSERT_FALSE( 224 ASSERT_FALSE(
225 connection.DoesColumnExist(OFFLINE_PAGES_TABLE_V1, "original_url")); 225 connection.DoesColumnExist(OFFLINE_PAGES_TABLE_V1, "original_url"));
226 } 226 }
227 227
228 void BuildTestStoreWithSchemaFromM56(const base::FilePath& file) {
229 sql::Connection connection;
230 ASSERT_TRUE(
231 connection.Open(file.Append(FILE_PATH_LITERAL("OfflinePages.db"))));
232 ASSERT_TRUE(connection.is_open());
233 ASSERT_TRUE(connection.BeginTransaction());
234 ASSERT_TRUE(connection.Execute("CREATE TABLE " OFFLINE_PAGES_TABLE_V1
235 "(offline_id INTEGER PRIMARY KEY NOT NULL, "
236 "creation_time INTEGER NOT NULL, "
237 "file_size INTEGER NOT NULL, "
238 "last_access_time INTEGER NOT NULL, "
239 "access_count INTEGER NOT NULL, "
240 "expiration_time INTEGER NOT NULL DEFAULT 0, "
241 "client_namespace VARCHAR NOT NULL, "
242 "client_id VARCHAR NOT NULL, "
243 "online_url VARCHAR NOT NULL, "
244 "file_path VARCHAR NOT NULL, "
245 "title VARCHAR NOT NULL DEFAULT '', "
246 "original_url VARCHAR NOT NULL DEFAULT ''"
247 ")"));
248 ASSERT_TRUE(connection.CommitTransaction());
249 sql::Statement statement(connection.GetUniqueStatement(
250 "INSERT INTO " OFFLINE_PAGES_TABLE_V1
251 "(offline_id, creation_time, file_size, "
252 "last_access_time, access_count, client_namespace, "
253 "client_id, online_url, file_path, expiration_time, title, original_url) "
254 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"));
255 statement.BindInt64(0, kOfflineId);
256 statement.BindInt(1, 0);
257 statement.BindInt64(2, kFileSize);
258 statement.BindInt(3, 0);
259 statement.BindInt(4, 1);
260 statement.BindCString(5, kTestClientNamespace);
261 statement.BindString(6, kTestClientId2.id);
262 statement.BindCString(7, kTestURL);
263 statement.BindString(8, base::FilePath(kFilePath).MaybeAsASCII());
264 statement.BindInt64(9, base::Time::Now().ToInternalValue());
265 statement.BindString16(10, base::UTF8ToUTF16("Test title"));
266 statement.BindCString(11, kOriginalTestURL);
267 ASSERT_TRUE(statement.Run());
268 ASSERT_TRUE(connection.DoesTableExist(OFFLINE_PAGES_TABLE_V1));
269 ASSERT_TRUE(
270 connection.DoesColumnExist(OFFLINE_PAGES_TABLE_V1, "expiration_time"));
271 }
272
228 class OfflinePageMetadataStoreFactory { 273 class OfflinePageMetadataStoreFactory {
229 public: 274 public:
230 OfflinePageMetadataStore* BuildStore(const base::FilePath& file_path) { 275 OfflinePageMetadataStore* BuildStore(const base::FilePath& file_path) {
231 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL( 276 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL(
232 base::ThreadTaskRunnerHandle::Get(), file_path); 277 base::ThreadTaskRunnerHandle::Get(), file_path);
233 return store; 278 return store;
234 } 279 }
235 280
236 OfflinePageMetadataStore* BuildStoreM52(const base::FilePath& file_path) { 281 OfflinePageMetadataStore* BuildStoreM52(const base::FilePath& file_path) {
237 BuildTestStoreWithSchemaFromM52(file_path); 282 BuildTestStoreWithSchemaFromM52(file_path);
(...skipping 15 matching lines...) Expand all
253 base::ThreadTaskRunnerHandle::Get(), file_path); 298 base::ThreadTaskRunnerHandle::Get(), file_path);
254 return store; 299 return store;
255 } 300 }
256 301
257 OfflinePageMetadataStore* BuildStoreM55(const base::FilePath& file_path) { 302 OfflinePageMetadataStore* BuildStoreM55(const base::FilePath& file_path) {
258 BuildTestStoreWithSchemaFromM55(file_path); 303 BuildTestStoreWithSchemaFromM55(file_path);
259 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL( 304 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL(
260 base::ThreadTaskRunnerHandle::Get(), file_path); 305 base::ThreadTaskRunnerHandle::Get(), file_path);
261 return store; 306 return store;
262 } 307 }
308
309 OfflinePageMetadataStore* BuildStoreM56(const base::FilePath& file_path) {
310 BuildTestStoreWithSchemaFromM56(file_path);
311 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL(
312 base::ThreadTaskRunnerHandle::Get(), file_path);
313 return store;
314 }
263 }; 315 };
264 316
265 enum CalledCallback { NONE, LOAD, ADD, UPDATE, REMOVE, RESET }; 317 enum CalledCallback { NONE, LOAD, ADD, UPDATE, REMOVE, RESET };
266 enum Status { STATUS_NONE, STATUS_TRUE, STATUS_FALSE }; 318 enum Status { STATUS_NONE, STATUS_TRUE, STATUS_FALSE };
267 319
268 class OfflinePageMetadataStoreTest : public testing::Test { 320 class OfflinePageMetadataStoreTest : public testing::Test {
269 public: 321 public:
270 OfflinePageMetadataStoreTest(); 322 OfflinePageMetadataStoreTest();
271 ~OfflinePageMetadataStoreTest() override; 323 ~OfflinePageMetadataStoreTest() override;
272 324
273 void TearDown() override { 325 void TearDown() override {
274 // Wait for all the pieces of the store to delete itself properly. 326 // Wait for all the pieces of the store to delete itself properly.
275 PumpLoop(); 327 PumpLoop();
276 } 328 }
277 329
278 std::unique_ptr<OfflinePageMetadataStore> BuildStore(); 330 std::unique_ptr<OfflinePageMetadataStore> BuildStore();
279 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM52(); 331 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM52();
280 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM53(); 332 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM53();
281 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM54(); 333 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM54();
282 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM55(); 334 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM55();
335 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM56();
283 336
284 void PumpLoop(); 337 void PumpLoop();
285 338
286 void InitializeCallback(bool success); 339 void InitializeCallback(bool success);
287 void GetOfflinePagesCallback( 340 void GetOfflinePagesCallback(
288 const std::vector<OfflinePageItem>& offline_pages); 341 const std::vector<OfflinePageItem>& offline_pages);
289 void AddCallback(ItemActionStatus status); 342 void AddCallback(ItemActionStatus status);
290 void UpdateCallback(CalledCallback called_callback, 343 void UpdateCallback(CalledCallback called_callback,
291 std::unique_ptr<OfflinePagesUpdateResult> result); 344 std::unique_ptr<OfflinePagesUpdateResult> result);
292 void ResetCallback(bool success); 345 void ResetCallback(bool success);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 425
373 return offline_pages_[0]; 426 return offline_pages_[0];
374 } 427 }
375 428
376 void OfflinePageMetadataStoreTest::CheckThatOfflinePageCanBeSaved( 429 void OfflinePageMetadataStoreTest::CheckThatOfflinePageCanBeSaved(
377 std::unique_ptr<OfflinePageMetadataStore> store) { 430 std::unique_ptr<OfflinePageMetadataStore> store) {
378 size_t store_size = offline_pages_.size(); 431 size_t store_size = offline_pages_.size();
379 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, 432 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1,
380 base::FilePath(kFilePath), kFileSize); 433 base::FilePath(kFilePath), kFileSize);
381 offline_page.title = base::UTF8ToUTF16("a title"); 434 offline_page.title = base::UTF8ToUTF16("a title");
382 base::Time expiration_time = base::Time::Now();
383 offline_page.expiration_time = expiration_time;
384 offline_page.original_url = GURL(kOriginalTestURL); 435 offline_page.original_url = GURL(kOriginalTestURL);
385 436
386 store->AddOfflinePage(offline_page, 437 store->AddOfflinePage(offline_page,
387 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, 438 base::Bind(&OfflinePageMetadataStoreTest::AddCallback,
388 base::Unretained(this))); 439 base::Unretained(this)));
389 PumpLoop(); 440 PumpLoop();
390 EXPECT_EQ(ADD, last_called_callback_); 441 EXPECT_EQ(ADD, last_called_callback_);
391 EXPECT_EQ(STATUS_TRUE, last_status_); 442 EXPECT_EQ(STATUS_TRUE, last_status_);
392 ClearResults(); 443 ClearResults();
393 444
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 store->GetOfflinePages( 501 store->GetOfflinePages(
451 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, 502 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback,
452 base::Unretained(this))); 503 base::Unretained(this)));
453 PumpLoop(); 504 PumpLoop();
454 return store; 505 return store;
455 } 506 }
456 507
457 std::unique_ptr<OfflinePageMetadataStore> 508 std::unique_ptr<OfflinePageMetadataStore>
458 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM54() { 509 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM54() {
459 std::unique_ptr<OfflinePageMetadataStore> store( 510 std::unique_ptr<OfflinePageMetadataStore> store(
460 factory_.BuildStoreM53(temp_directory_.GetPath())); 511 factory_.BuildStoreM54(temp_directory_.GetPath()));
461 PumpLoop(); 512 PumpLoop();
462 store->Initialize( 513 store->Initialize(
463 base::Bind(&OfflinePageMetadataStoreTest::InitializeCallback, 514 base::Bind(&OfflinePageMetadataStoreTest::InitializeCallback,
464 base::Unretained(this))); 515 base::Unretained(this)));
465 PumpLoop(); 516 PumpLoop();
466 store->GetOfflinePages( 517 store->GetOfflinePages(
467 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, 518 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback,
468 base::Unretained(this))); 519 base::Unretained(this)));
469 PumpLoop(); 520 PumpLoop();
470 return store; 521 return store;
471 } 522 }
472 523
473 std::unique_ptr<OfflinePageMetadataStore> 524 std::unique_ptr<OfflinePageMetadataStore>
474 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM55() { 525 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM55() {
475 std::unique_ptr<OfflinePageMetadataStore> store( 526 std::unique_ptr<OfflinePageMetadataStore> store(
476 factory_.BuildStoreM55(temp_directory_.GetPath())); 527 factory_.BuildStoreM55(temp_directory_.GetPath()));
477 PumpLoop(); 528 PumpLoop();
478 store->Initialize( 529 store->Initialize(
479 base::Bind(&OfflinePageMetadataStoreTest::InitializeCallback, 530 base::Bind(&OfflinePageMetadataStoreTest::InitializeCallback,
480 base::Unretained(this))); 531 base::Unretained(this)));
481 PumpLoop(); 532 PumpLoop();
482 store->GetOfflinePages( 533 store->GetOfflinePages(
483 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, 534 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback,
484 base::Unretained(this))); 535 base::Unretained(this)));
485 PumpLoop(); 536 PumpLoop();
486 return store; 537 return store;
487 } 538 }
488 539
540 std::unique_ptr<OfflinePageMetadataStore>
541 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM56() {
542 std::unique_ptr<OfflinePageMetadataStore> store(
543 factory_.BuildStoreM56(temp_directory_.GetPath()));
544 PumpLoop();
545 store->Initialize(
546 base::Bind(&OfflinePageMetadataStoreTest::InitializeCallback,
547 base::Unretained(this)));
548 PumpLoop();
549 store->GetOfflinePages(
550 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback,
551 base::Unretained(this)));
552 PumpLoop();
553 return store;
554 }
555
489 // Loads empty store and makes sure that there are no offline pages stored in 556 // Loads empty store and makes sure that there are no offline pages stored in
490 // it. 557 // it.
491 TEST_F(OfflinePageMetadataStoreTest, LoadEmptyStore) { 558 TEST_F(OfflinePageMetadataStoreTest, LoadEmptyStore) {
492 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); 559 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore());
493 EXPECT_EQ(LOAD, last_called_callback_); 560 EXPECT_EQ(LOAD, last_called_callback_);
494 EXPECT_EQ(STATUS_TRUE, last_status_); 561 EXPECT_EQ(STATUS_TRUE, last_status_);
495 EXPECT_EQ(0U, offline_pages_.size()); 562 EXPECT_EQ(0U, offline_pages_.size());
496 } 563 }
497 564
498 TEST_F(OfflinePageMetadataStoreTest, GetOfflinePagesFromInvalidStore) { 565 TEST_F(OfflinePageMetadataStoreTest, GetOfflinePagesFromInvalidStore) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 } 634 }
568 635
569 // Loads a store which has an outdated schema. 636 // Loads a store which has an outdated schema.
570 // This test case would crash if it's not handling correctly when we're loading 637 // This test case would crash if it's not handling correctly when we're loading
571 // old version stores. 638 // old version stores.
572 // TODO(romax): Move this to sql_unittest. 639 // TODO(romax): Move this to sql_unittest.
573 TEST_F(OfflinePageMetadataStoreTest, LoadVersion52Store) { 640 TEST_F(OfflinePageMetadataStoreTest, LoadVersion52Store) {
574 std::unique_ptr<OfflinePageMetadataStore> store( 641 std::unique_ptr<OfflinePageMetadataStore> store(
575 BuildStoreWithSchemaFromM52()); 642 BuildStoreWithSchemaFromM52());
576 643
577 CheckThatStoreHasOneItem(); 644 OfflinePageItem item = CheckThatStoreHasOneItem();
578 CheckThatOfflinePageCanBeSaved(std::move(store)); 645 CheckThatOfflinePageCanBeSaved(std::move(store));
579 } 646 }
580 647
581 // Loads a store which has an outdated schema. 648 // Loads a store which has an outdated schema.
582 // This test case would crash if it's not handling correctly when we're loading 649 // This test case would crash if it's not handling correctly when we're loading
583 // old version stores. 650 // old version stores.
584 // TODO(romax): Move this to sql_unittest. 651 // TODO(romax): Move this to sql_unittest.
585 TEST_F(OfflinePageMetadataStoreTest, LoadVersion53Store) { 652 TEST_F(OfflinePageMetadataStoreTest, LoadVersion53Store) {
586 std::unique_ptr<OfflinePageMetadataStore> store( 653 std::unique_ptr<OfflinePageMetadataStore> store(
587 BuildStoreWithSchemaFromM53()); 654 BuildStoreWithSchemaFromM53());
588 655
589 OfflinePageItem item = CheckThatStoreHasOneItem(); 656 OfflinePageItem item = CheckThatStoreHasOneItem();
590 // We should have a valid expiration time after upgrade.
591 EXPECT_NE(base::Time::FromInternalValue(0),
592 offline_pages_[0].expiration_time);
593
594 CheckThatOfflinePageCanBeSaved(std::move(store)); 657 CheckThatOfflinePageCanBeSaved(std::move(store));
595 } 658 }
596 659
597 // Loads a string with schema from M54. 660 // Loads a string with schema from M54.
598 // Because for now we only reduce the number of fields it just makes sure there 661 // This test case would crash if it's not handling correctly when we're loading
599 // are no crashes in the process. 662 // old version stores.
600 // TODO(romax): Move this to sql_unittest. 663 // TODO(romax): Move this to sql_unittest.
601 TEST_F(OfflinePageMetadataStoreTest, LoadVersion54Store) { 664 TEST_F(OfflinePageMetadataStoreTest, LoadVersion54Store) {
602 std::unique_ptr<OfflinePageMetadataStore> store( 665 std::unique_ptr<OfflinePageMetadataStore> store(
603 BuildStoreWithSchemaFromM54()); 666 BuildStoreWithSchemaFromM54());
604 667
605 OfflinePageItem item = CheckThatStoreHasOneItem(); 668 OfflinePageItem item = CheckThatStoreHasOneItem();
606
607 CheckThatOfflinePageCanBeSaved(std::move(store)); 669 CheckThatOfflinePageCanBeSaved(std::move(store));
608 } 670 }
609 671
610 // Loads a string with schema from M55. 672 // Loads a string with schema from M55.
611 // Because for now we only reduce the number of fields it just makes sure there 673 // This test case would crash if it's not handling correctly when we're loading
612 // are no crashes in the process. 674 // old version stores.
613 // TODO(romax): Move this to sql_unittest. 675 // TODO(romax): Move this to sql_unittest.
614 TEST_F(OfflinePageMetadataStoreTest, LoadVersion55Store) { 676 TEST_F(OfflinePageMetadataStoreTest, LoadVersion55Store) {
615 std::unique_ptr<OfflinePageMetadataStore> store( 677 std::unique_ptr<OfflinePageMetadataStore> store(
616 BuildStoreWithSchemaFromM55()); 678 BuildStoreWithSchemaFromM55());
617 679
618 OfflinePageItem item = CheckThatStoreHasOneItem(); 680 OfflinePageItem item = CheckThatStoreHasOneItem();
619
620 CheckThatOfflinePageCanBeSaved(std::move(store)); 681 CheckThatOfflinePageCanBeSaved(std::move(store));
621 } 682 }
622 683
684 // Loads a string with schema from M56.
685 // This test case would crash if it's not handling correctly when we're loading
686 // old version stores.
687 // TODO(romax): Move this to sql_unittest.
688 TEST_F(OfflinePageMetadataStoreTest, LoadVersion56Store) {
689 std::unique_ptr<OfflinePageMetadataStore> store(
690 BuildStoreWithSchemaFromM56());
691
692 OfflinePageItem item = CheckThatStoreHasOneItem();
693 CheckThatOfflinePageCanBeSaved(std::move(store));
694 }
695
623 // Adds metadata of an offline page into a store and then opens the store 696 // Adds metadata of an offline page into a store and then opens the store
624 // again to make sure that stored metadata survives store restarts. 697 // again to make sure that stored metadata survives store restarts.
625 TEST_F(OfflinePageMetadataStoreTest, AddOfflinePage) { 698 TEST_F(OfflinePageMetadataStoreTest, AddOfflinePage) {
626 CheckThatOfflinePageCanBeSaved(BuildStore()); 699 CheckThatOfflinePageCanBeSaved(BuildStore());
627 } 700 }
628 701
629 TEST_F(OfflinePageMetadataStoreTest, AddSameOfflinePageTwice) { 702 TEST_F(OfflinePageMetadataStoreTest, AddSameOfflinePageTwice) {
630 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); 703 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore());
631 704
632 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, 705 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1,
633 base::FilePath(kFilePath), kFileSize); 706 base::FilePath(kFilePath), kFileSize);
634 offline_page.title = base::UTF8ToUTF16("a title"); 707 offline_page.title = base::UTF8ToUTF16("a title");
635 base::Time expiration_time = base::Time::Now();
636 offline_page.expiration_time = expiration_time;
637 708
638 store->AddOfflinePage(offline_page, 709 store->AddOfflinePage(offline_page,
639 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, 710 base::Bind(&OfflinePageMetadataStoreTest::AddCallback,
640 base::Unretained(this))); 711 base::Unretained(this)));
641 PumpLoop(); 712 PumpLoop();
642 EXPECT_EQ(ADD, last_called_callback_); 713 EXPECT_EQ(ADD, last_called_callback_);
643 EXPECT_EQ(STATUS_TRUE, last_status_); 714 EXPECT_EQ(STATUS_TRUE, last_status_);
644 ClearResults(); 715 ClearResults();
645 716
646 store->AddOfflinePage(offline_page, 717 store->AddOfflinePage(offline_page,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 EXPECT_EQ(STATUS_TRUE, last_status_); 798 EXPECT_EQ(STATUS_TRUE, last_status_);
728 799
729 ClearResults(); 800 ClearResults();
730 801
731 // Add anther offline page. 802 // Add anther offline page.
732 base::FilePath file_path_2 = 803 base::FilePath file_path_2 =
733 base::FilePath(FILE_PATH_LITERAL("//other.page.com.mhtml")); 804 base::FilePath(FILE_PATH_LITERAL("//other.page.com.mhtml"));
734 OfflinePageItem offline_page_2(GURL("https://other.page.com"), 5678LL, 805 OfflinePageItem offline_page_2(GURL("https://other.page.com"), 5678LL,
735 kTestClientId2, file_path_2, 12345, 806 kTestClientId2, file_path_2, 12345,
736 base::Time::Now()); 807 base::Time::Now());
737 offline_page_2.expiration_time = base::Time::Now();
738 offline_page_2.original_url = GURL("https://example.com/bar"); 808 offline_page_2.original_url = GURL("https://example.com/bar");
739 store->AddOfflinePage(offline_page_2, 809 store->AddOfflinePage(offline_page_2,
740 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, 810 base::Bind(&OfflinePageMetadataStoreTest::AddCallback,
741 base::Unretained(this))); 811 base::Unretained(this)));
742 PumpLoop(); 812 PumpLoop();
743 EXPECT_EQ(ADD, last_called_callback_); 813 EXPECT_EQ(ADD, last_called_callback_);
744 EXPECT_EQ(STATUS_TRUE, last_status_); 814 EXPECT_EQ(STATUS_TRUE, last_status_);
745 815
746 ClearResults(); 816 ClearResults();
747 817
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 EXPECT_EQ(LOAD, last_called_callback_); 853 EXPECT_EQ(LOAD, last_called_callback_);
784 EXPECT_EQ(STATUS_TRUE, last_status_); 854 EXPECT_EQ(STATUS_TRUE, last_status_);
785 ASSERT_EQ(1U, offline_pages_.size()); 855 ASSERT_EQ(1U, offline_pages_.size());
786 EXPECT_EQ(offline_page_2.url, offline_pages_[0].url); 856 EXPECT_EQ(offline_page_2.url, offline_pages_[0].url);
787 EXPECT_EQ(offline_page_2.offline_id, offline_pages_[0].offline_id); 857 EXPECT_EQ(offline_page_2.offline_id, offline_pages_[0].offline_id);
788 EXPECT_EQ(offline_page_2.file_path, offline_pages_[0].file_path); 858 EXPECT_EQ(offline_page_2.file_path, offline_pages_[0].file_path);
789 EXPECT_EQ(offline_page_2.file_size, offline_pages_[0].file_size); 859 EXPECT_EQ(offline_page_2.file_size, offline_pages_[0].file_size);
790 EXPECT_EQ(offline_page_2.creation_time, offline_pages_[0].creation_time); 860 EXPECT_EQ(offline_page_2.creation_time, offline_pages_[0].creation_time);
791 EXPECT_EQ(offline_page_2.last_access_time, 861 EXPECT_EQ(offline_page_2.last_access_time,
792 offline_pages_[0].last_access_time); 862 offline_pages_[0].last_access_time);
793 EXPECT_EQ(offline_page_2.expiration_time, offline_pages_[0].expiration_time);
794 EXPECT_EQ(offline_page_2.access_count, offline_pages_[0].access_count); 863 EXPECT_EQ(offline_page_2.access_count, offline_pages_[0].access_count);
795 EXPECT_EQ(offline_page_2.client_id, offline_pages_[0].client_id); 864 EXPECT_EQ(offline_page_2.client_id, offline_pages_[0].client_id);
796 } 865 }
797 866
798 // Tests updating offline page metadata from the store. 867 // Tests updating offline page metadata from the store.
799 TEST_F(OfflinePageMetadataStoreTest, UpdateOfflinePage) { 868 TEST_F(OfflinePageMetadataStoreTest, UpdateOfflinePage) {
800 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); 869 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore());
801 870
802 // First, adds a fresh page. 871 // First, adds a fresh page.
803 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, 872 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1,
(...skipping 11 matching lines...) Expand all
815 base::Unretained(this))); 884 base::Unretained(this)));
816 PumpLoop(); 885 PumpLoop();
817 886
818 EXPECT_EQ(LOAD, last_called_callback_); 887 EXPECT_EQ(LOAD, last_called_callback_);
819 ASSERT_EQ(1U, offline_pages_.size()); 888 ASSERT_EQ(1U, offline_pages_.size());
820 EXPECT_EQ(offline_page, offline_pages_[0]); 889 EXPECT_EQ(offline_page, offline_pages_[0]);
821 890
822 // Then update some data. 891 // Then update some data.
823 offline_page.file_size = kFileSize + 1; 892 offline_page.file_size = kFileSize + 1;
824 offline_page.access_count++; 893 offline_page.access_count++;
825 offline_page.expiration_time = base::Time::Now();
826 offline_page.original_url = GURL("https://example.com/bar"); 894 offline_page.original_url = GURL("https://example.com/bar");
827 std::vector<OfflinePageItem> items_to_update; 895 std::vector<OfflinePageItem> items_to_update;
828 items_to_update.push_back(offline_page); 896 items_to_update.push_back(offline_page);
829 store->UpdateOfflinePages( 897 store->UpdateOfflinePages(
830 items_to_update, base::Bind(&OfflinePageMetadataStoreTest::UpdateCallback, 898 items_to_update, base::Bind(&OfflinePageMetadataStoreTest::UpdateCallback,
831 base::Unretained(this), UPDATE)); 899 base::Unretained(this), UPDATE));
832 PumpLoop(); 900 PumpLoop();
833 EXPECT_EQ(UPDATE, last_called_callback_); 901 EXPECT_EQ(UPDATE, last_called_callback_);
834 EXPECT_EQ(STATUS_TRUE, last_status_); 902 EXPECT_EQ(STATUS_TRUE, last_status_);
835 ASSERT_TRUE(last_update_result() != nullptr); 903 ASSERT_TRUE(last_update_result() != nullptr);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); 976 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore());
909 977
910 store->Reset(base::Bind(&OfflinePageMetadataStoreTest::ResetCallback, 978 store->Reset(base::Bind(&OfflinePageMetadataStoreTest::ResetCallback,
911 base::Unretained(this))); 979 base::Unretained(this)));
912 PumpLoop(); 980 PumpLoop();
913 EXPECT_EQ(STATUS_TRUE, last_status_); 981 EXPECT_EQ(STATUS_TRUE, last_status_);
914 } 982 }
915 983
916 } // namespace 984 } // namespace
917 } // namespace offline_pages 985 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_item.cc ('k') | components/offline_pages/offline_page_metadata_store_sql.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698