Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 statement.BindInt(4, 1); | 214 statement.BindInt(4, 1); |
| 215 statement.BindCString(5, kTestClientNamespace); | 215 statement.BindCString(5, kTestClientNamespace); |
| 216 statement.BindString(6, kTestClientId2.id); | 216 statement.BindString(6, kTestClientId2.id); |
| 217 statement.BindCString(7, kTestURL); | 217 statement.BindCString(7, kTestURL); |
| 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(connection.DoesColumnExist(OFFLINE_PAGES_TABLE_V1, "version")); | |
|
fgorski
2016/11/18 00:13:04
don't touch M55 code, Jian has appropriate fix in
romax
2016/11/18 20:50:48
Done.
| |
| 225 ASSERT_FALSE(connection.DoesColumnExist(OFFLINE_PAGES_TABLE_V1, "status")); | |
| 226 ASSERT_FALSE( | |
| 227 connection.DoesColumnExist(OFFLINE_PAGES_TABLE_V1, "user_initiated")); | |
| 228 ASSERT_FALSE( | |
| 229 connection.DoesColumnExist(OFFLINE_PAGES_TABLE_V1, "offline_url")); | |
| 224 } | 230 } |
| 225 | 231 |
| 226 class OfflinePageMetadataStoreFactory { | 232 class OfflinePageMetadataStoreFactory { |
| 227 public: | 233 public: |
| 228 OfflinePageMetadataStore* BuildStore(const base::FilePath& file_path) { | 234 OfflinePageMetadataStore* BuildStore(const base::FilePath& file_path) { |
| 229 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL( | 235 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL( |
| 230 base::ThreadTaskRunnerHandle::Get(), file_path); | 236 base::ThreadTaskRunnerHandle::Get(), file_path); |
| 231 return store; | 237 return store; |
| 232 } | 238 } |
| 233 | 239 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 | 375 |
| 370 return offline_pages_[0]; | 376 return offline_pages_[0]; |
| 371 } | 377 } |
| 372 | 378 |
| 373 void OfflinePageMetadataStoreTest::CheckThatOfflinePageCanBeSaved( | 379 void OfflinePageMetadataStoreTest::CheckThatOfflinePageCanBeSaved( |
| 374 std::unique_ptr<OfflinePageMetadataStore> store) { | 380 std::unique_ptr<OfflinePageMetadataStore> store) { |
| 375 size_t store_size = offline_pages_.size(); | 381 size_t store_size = offline_pages_.size(); |
| 376 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, | 382 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, |
| 377 base::FilePath(kFilePath), kFileSize); | 383 base::FilePath(kFilePath), kFileSize); |
| 378 offline_page.title = base::UTF8ToUTF16("a title"); | 384 offline_page.title = base::UTF8ToUTF16("a title"); |
| 379 base::Time expiration_time = base::Time::Now(); | |
| 380 offline_page.expiration_time = expiration_time; | |
| 381 offline_page.original_url = GURL(kOriginalTestURL); | |
|
fgorski
2016/11/18 00:13:04
be careful about what you are removing. original_u
romax
2016/11/18 20:50:49
Done.
| |
| 382 | 385 |
| 383 store->AddOfflinePage(offline_page, | 386 store->AddOfflinePage(offline_page, |
| 384 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, | 387 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, |
| 385 base::Unretained(this))); | 388 base::Unretained(this))); |
| 386 PumpLoop(); | 389 PumpLoop(); |
| 387 EXPECT_EQ(ADD, last_called_callback_); | 390 EXPECT_EQ(ADD, last_called_callback_); |
| 388 EXPECT_EQ(STATUS_TRUE, last_status_); | 391 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 389 ClearResults(); | 392 ClearResults(); |
| 390 | 393 |
| 391 // Close the store first to ensure file lock is removed. | 394 // Close the store first to ensure file lock is removed. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 store->GetOfflinePages( | 438 store->GetOfflinePages( |
| 436 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, | 439 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, |
| 437 base::Unretained(this))); | 440 base::Unretained(this))); |
| 438 PumpLoop(); | 441 PumpLoop(); |
| 439 return store; | 442 return store; |
| 440 } | 443 } |
| 441 | 444 |
| 442 std::unique_ptr<OfflinePageMetadataStore> | 445 std::unique_ptr<OfflinePageMetadataStore> |
| 443 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM54() { | 446 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM54() { |
| 444 std::unique_ptr<OfflinePageMetadataStore> store( | 447 std::unique_ptr<OfflinePageMetadataStore> store( |
| 445 factory_.BuildStoreM53(temp_directory_.GetPath())); | 448 factory_.BuildStoreM54(temp_directory_.GetPath())); |
| 446 PumpLoop(); | 449 PumpLoop(); |
| 447 store->GetOfflinePages( | 450 store->GetOfflinePages( |
| 448 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, | 451 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, |
| 449 base::Unretained(this))); | 452 base::Unretained(this))); |
| 450 PumpLoop(); | 453 PumpLoop(); |
| 451 return store; | 454 return store; |
| 452 } | 455 } |
| 453 | 456 |
| 454 std::unique_ptr<OfflinePageMetadataStore> | 457 std::unique_ptr<OfflinePageMetadataStore> |
| 455 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM55() { | 458 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM55() { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 } | 546 } |
| 544 | 547 |
| 545 // Loads a store which has an outdated schema. | 548 // Loads a store which has an outdated schema. |
| 546 // This test case would crash if it's not handling correctly when we're loading | 549 // This test case would crash if it's not handling correctly when we're loading |
| 547 // old version stores. | 550 // old version stores. |
| 548 // TODO(romax): Move this to sql_unittest. | 551 // TODO(romax): Move this to sql_unittest. |
| 549 TEST_F(OfflinePageMetadataStoreTest, LoadVersion52Store) { | 552 TEST_F(OfflinePageMetadataStoreTest, LoadVersion52Store) { |
| 550 std::unique_ptr<OfflinePageMetadataStore> store( | 553 std::unique_ptr<OfflinePageMetadataStore> store( |
| 551 BuildStoreWithSchemaFromM52()); | 554 BuildStoreWithSchemaFromM52()); |
| 552 | 555 |
| 553 CheckThatStoreHasOneItem(); | 556 OfflinePageItem item = CheckThatStoreHasOneItem(); |
| 554 CheckThatOfflinePageCanBeSaved(std::move(store)); | 557 CheckThatOfflinePageCanBeSaved(std::move(store)); |
| 555 } | 558 } |
| 556 | 559 |
| 557 // Loads a store which has an outdated schema. | 560 // Loads a store which has an outdated schema. |
| 558 // This test case would crash if it's not handling correctly when we're loading | 561 // This test case would crash if it's not handling correctly when we're loading |
| 559 // old version stores. | 562 // old version stores. |
| 560 // TODO(romax): Move this to sql_unittest. | 563 // TODO(romax): Move this to sql_unittest. |
| 561 TEST_F(OfflinePageMetadataStoreTest, LoadVersion53Store) { | 564 TEST_F(OfflinePageMetadataStoreTest, LoadVersion53Store) { |
| 562 std::unique_ptr<OfflinePageMetadataStore> store( | 565 std::unique_ptr<OfflinePageMetadataStore> store( |
| 563 BuildStoreWithSchemaFromM53()); | 566 BuildStoreWithSchemaFromM53()); |
| 564 | 567 |
| 565 OfflinePageItem item = CheckThatStoreHasOneItem(); | 568 OfflinePageItem item = CheckThatStoreHasOneItem(); |
| 566 // We should have a valid expiration time after upgrade. | |
| 567 EXPECT_NE(base::Time::FromInternalValue(0), | |
| 568 offline_pages_[0].expiration_time); | |
| 569 | |
| 570 CheckThatOfflinePageCanBeSaved(std::move(store)); | 569 CheckThatOfflinePageCanBeSaved(std::move(store)); |
| 571 } | 570 } |
| 572 | 571 |
| 573 // Loads a string with schema from M54. | 572 // Loads a string with schema from M54. |
| 574 // Because for now we only reduce the number of fields it just makes sure there | 573 // Because for now we only reduce the number of fields it just makes sure there |
| 575 // are no crashes in the process. | 574 // are no crashes in the process. |
| 576 // TODO(romax): Move this to sql_unittest. | 575 // TODO(romax): Move this to sql_unittest. |
| 577 TEST_F(OfflinePageMetadataStoreTest, LoadVersion54Store) { | 576 TEST_F(OfflinePageMetadataStoreTest, LoadVersion54Store) { |
| 578 std::unique_ptr<OfflinePageMetadataStore> store( | 577 std::unique_ptr<OfflinePageMetadataStore> store( |
| 579 BuildStoreWithSchemaFromM54()); | 578 BuildStoreWithSchemaFromM54()); |
| 580 | 579 |
| 581 OfflinePageItem item = CheckThatStoreHasOneItem(); | 580 OfflinePageItem item = CheckThatStoreHasOneItem(); |
| 582 | |
| 583 CheckThatOfflinePageCanBeSaved(std::move(store)); | 581 CheckThatOfflinePageCanBeSaved(std::move(store)); |
| 584 } | 582 } |
| 585 | 583 |
| 586 // Loads a string with schema from M55. | 584 // Loads a string with schema from M55. |
| 587 // Because for now we only reduce the number of fields it just makes sure there | 585 // Because for now we only removed 'title' and added 'original_url' , it just |
| 588 // are no crashes in the process. | 586 // makes sure there are no crashes in the process. |
| 589 // TODO(romax): Move this to sql_unittest. | 587 // TODO(romax): Move this to sql_unittest. |
| 590 TEST_F(OfflinePageMetadataStoreTest, LoadVersion55Store) { | 588 TEST_F(OfflinePageMetadataStoreTest, LoadVersion55Store) { |
| 591 std::unique_ptr<OfflinePageMetadataStore> store( | 589 std::unique_ptr<OfflinePageMetadataStore> store( |
| 592 BuildStoreWithSchemaFromM55()); | 590 BuildStoreWithSchemaFromM55()); |
| 593 | 591 |
| 594 OfflinePageItem item = CheckThatStoreHasOneItem(); | 592 OfflinePageItem item = CheckThatStoreHasOneItem(); |
| 595 | |
| 596 CheckThatOfflinePageCanBeSaved(std::move(store)); | 593 CheckThatOfflinePageCanBeSaved(std::move(store)); |
| 597 } | 594 } |
| 598 | 595 |
| 599 // Adds metadata of an offline page into a store and then opens the store | 596 // Adds metadata of an offline page into a store and then opens the store |
| 600 // again to make sure that stored metadata survives store restarts. | 597 // again to make sure that stored metadata survives store restarts. |
| 601 TEST_F(OfflinePageMetadataStoreTest, AddOfflinePage) { | 598 TEST_F(OfflinePageMetadataStoreTest, AddOfflinePage) { |
| 602 CheckThatOfflinePageCanBeSaved(BuildStore()); | 599 CheckThatOfflinePageCanBeSaved(BuildStore()); |
| 603 } | 600 } |
| 604 | 601 |
| 605 TEST_F(OfflinePageMetadataStoreTest, AddSameOfflinePageTwice) { | 602 TEST_F(OfflinePageMetadataStoreTest, AddSameOfflinePageTwice) { |
| 606 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); | 603 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); |
| 607 | 604 |
| 608 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, | 605 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, |
| 609 base::FilePath(kFilePath), kFileSize); | 606 base::FilePath(kFilePath), kFileSize); |
| 610 offline_page.title = base::UTF8ToUTF16("a title"); | 607 offline_page.title = base::UTF8ToUTF16("a title"); |
| 611 base::Time expiration_time = base::Time::Now(); | |
| 612 offline_page.expiration_time = expiration_time; | |
| 613 | 608 |
| 614 store->AddOfflinePage(offline_page, | 609 store->AddOfflinePage(offline_page, |
| 615 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, | 610 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, |
| 616 base::Unretained(this))); | 611 base::Unretained(this))); |
| 617 PumpLoop(); | 612 PumpLoop(); |
| 618 EXPECT_EQ(ADD, last_called_callback_); | 613 EXPECT_EQ(ADD, last_called_callback_); |
| 619 EXPECT_EQ(STATUS_TRUE, last_status_); | 614 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 620 ClearResults(); | 615 ClearResults(); |
| 621 | 616 |
| 622 store->AddOfflinePage(offline_page, | 617 store->AddOfflinePage(offline_page, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 EXPECT_EQ(0U, offline_pages_.size()); | 683 EXPECT_EQ(0U, offline_pages_.size()); |
| 689 } | 684 } |
| 690 | 685 |
| 691 // Adds metadata of multiple offline pages into a store and removes some. | 686 // Adds metadata of multiple offline pages into a store and removes some. |
| 692 TEST_F(OfflinePageMetadataStoreTest, AddRemoveMultipleOfflinePages) { | 687 TEST_F(OfflinePageMetadataStoreTest, AddRemoveMultipleOfflinePages) { |
| 693 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); | 688 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); |
| 694 | 689 |
| 695 // Add an offline page. | 690 // Add an offline page. |
| 696 OfflinePageItem offline_page_1(GURL(kTestURL), 12345LL, kTestClientId1, | 691 OfflinePageItem offline_page_1(GURL(kTestURL), 12345LL, kTestClientId1, |
| 697 base::FilePath(kFilePath), kFileSize); | 692 base::FilePath(kFilePath), kFileSize); |
| 693 base::FilePath file_path_2 = | |
| 694 base::FilePath(FILE_PATH_LITERAL("//other.page.com.mhtml")); | |
| 695 OfflinePageItem offline_page_2(GURL("https://other.page.com"), 5678LL, | |
|
fgorski
2016/11/18 00:13:04
given line 710, does this compile?
romax
2016/11/18 20:50:49
Done.
| |
| 696 kTestClientId2, file_path_2, 12345, | |
| 697 base::Time::Now()); | |
| 698 store->AddOfflinePage(offline_page_1, | 698 store->AddOfflinePage(offline_page_1, |
| 699 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, | 699 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, |
| 700 base::Unretained(this))); | 700 base::Unretained(this))); |
| 701 PumpLoop(); | 701 PumpLoop(); |
| 702 EXPECT_EQ(ADD, last_called_callback_); | 702 EXPECT_EQ(ADD, last_called_callback_); |
| 703 EXPECT_EQ(STATUS_TRUE, last_status_); | 703 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 704 | 704 |
| 705 ClearResults(); | 705 ClearResults(); |
| 706 | 706 |
| 707 // Add anther offline page. | 707 // Add anther offline page. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 EXPECT_EQ(LOAD, last_called_callback_); | 760 EXPECT_EQ(LOAD, last_called_callback_); |
| 761 EXPECT_EQ(STATUS_TRUE, last_status_); | 761 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 762 ASSERT_EQ(1U, offline_pages_.size()); | 762 ASSERT_EQ(1U, offline_pages_.size()); |
| 763 EXPECT_EQ(offline_page_2.url, offline_pages_[0].url); | 763 EXPECT_EQ(offline_page_2.url, offline_pages_[0].url); |
| 764 EXPECT_EQ(offline_page_2.offline_id, offline_pages_[0].offline_id); | 764 EXPECT_EQ(offline_page_2.offline_id, offline_pages_[0].offline_id); |
| 765 EXPECT_EQ(offline_page_2.file_path, offline_pages_[0].file_path); | 765 EXPECT_EQ(offline_page_2.file_path, offline_pages_[0].file_path); |
| 766 EXPECT_EQ(offline_page_2.file_size, offline_pages_[0].file_size); | 766 EXPECT_EQ(offline_page_2.file_size, offline_pages_[0].file_size); |
| 767 EXPECT_EQ(offline_page_2.creation_time, offline_pages_[0].creation_time); | 767 EXPECT_EQ(offline_page_2.creation_time, offline_pages_[0].creation_time); |
| 768 EXPECT_EQ(offline_page_2.last_access_time, | 768 EXPECT_EQ(offline_page_2.last_access_time, |
| 769 offline_pages_[0].last_access_time); | 769 offline_pages_[0].last_access_time); |
| 770 EXPECT_EQ(offline_page_2.expiration_time, offline_pages_[0].expiration_time); | |
| 771 EXPECT_EQ(offline_page_2.access_count, offline_pages_[0].access_count); | 770 EXPECT_EQ(offline_page_2.access_count, offline_pages_[0].access_count); |
| 772 EXPECT_EQ(offline_page_2.client_id, offline_pages_[0].client_id); | 771 EXPECT_EQ(offline_page_2.client_id, offline_pages_[0].client_id); |
| 773 } | 772 } |
| 774 | 773 |
| 775 // Tests updating offline page metadata from the store. | 774 // Tests updating offline page metadata from the store. |
| 776 TEST_F(OfflinePageMetadataStoreTest, UpdateOfflinePage) { | 775 TEST_F(OfflinePageMetadataStoreTest, UpdateOfflinePage) { |
| 777 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); | 776 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); |
| 778 | 777 |
| 779 // First, adds a fresh page. | 778 // First, adds a fresh page. |
| 780 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, | 779 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 793 PumpLoop(); | 792 PumpLoop(); |
| 794 | 793 |
| 795 EXPECT_EQ(LOAD, last_called_callback_); | 794 EXPECT_EQ(LOAD, last_called_callback_); |
| 796 EXPECT_EQ(STATUS_TRUE, last_status_); | 795 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 797 ASSERT_EQ(1U, offline_pages_.size()); | 796 ASSERT_EQ(1U, offline_pages_.size()); |
| 798 EXPECT_EQ(offline_page, offline_pages_[0]); | 797 EXPECT_EQ(offline_page, offline_pages_[0]); |
| 799 | 798 |
| 800 // Then update some data. | 799 // Then update some data. |
| 801 offline_page.file_size = kFileSize + 1; | 800 offline_page.file_size = kFileSize + 1; |
| 802 offline_page.access_count++; | 801 offline_page.access_count++; |
| 803 offline_page.expiration_time = base::Time::Now(); | |
| 804 offline_page.original_url = GURL("https://example.com/bar"); | 802 offline_page.original_url = GURL("https://example.com/bar"); |
| 805 std::vector<OfflinePageItem> items_to_update; | 803 std::vector<OfflinePageItem> items_to_update; |
| 806 items_to_update.push_back(offline_page); | 804 items_to_update.push_back(offline_page); |
| 807 store->UpdateOfflinePages( | 805 store->UpdateOfflinePages( |
| 808 items_to_update, base::Bind(&OfflinePageMetadataStoreTest::UpdateCallback, | 806 items_to_update, base::Bind(&OfflinePageMetadataStoreTest::UpdateCallback, |
| 809 base::Unretained(this), UPDATE)); | 807 base::Unretained(this), UPDATE)); |
| 810 PumpLoop(); | 808 PumpLoop(); |
| 811 EXPECT_EQ(UPDATE, last_called_callback_); | 809 EXPECT_EQ(UPDATE, last_called_callback_); |
| 812 EXPECT_EQ(STATUS_TRUE, last_status_); | 810 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 813 ASSERT_TRUE(last_update_result() != nullptr); | 811 ASSERT_TRUE(last_update_result() != nullptr); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 878 base::Unretained(this))); | 876 base::Unretained(this))); |
| 879 PumpLoop(); | 877 PumpLoop(); |
| 880 | 878 |
| 881 EXPECT_EQ(LOAD, last_called_callback_); | 879 EXPECT_EQ(LOAD, last_called_callback_); |
| 882 EXPECT_EQ(STATUS_TRUE, last_status_); | 880 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 883 ASSERT_EQ(0U, offline_pages_.size()); | 881 ASSERT_EQ(0U, offline_pages_.size()); |
| 884 } | 882 } |
| 885 | 883 |
| 886 } // namespace | 884 } // namespace |
| 887 } // namespace offline_pages | 885 } // namespace offline_pages |
| OLD | NEW |