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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(connection.DoesColumnExist(OFFLINE_PAGES_TABLE_V1, "title")); | |
|
fgorski
2016/11/22 00:02:59
just the expiration time is what you care about in
romax
2016/11/23 23:32:02
Done.
| |
| 270 ASSERT_TRUE( | |
| 271 connection.DoesColumnExist(OFFLINE_PAGES_TABLE_V1, "original_url")); | |
| 272 ASSERT_TRUE( | |
| 273 connection.DoesColumnExist(OFFLINE_PAGES_TABLE_V1, "expiration_time")); | |
| 274 } | |
| 275 | |
| 228 class OfflinePageMetadataStoreFactory { | 276 class OfflinePageMetadataStoreFactory { |
| 229 public: | 277 public: |
| 230 OfflinePageMetadataStore* BuildStore(const base::FilePath& file_path) { | 278 OfflinePageMetadataStore* BuildStore(const base::FilePath& file_path) { |
| 231 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL( | 279 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL( |
| 232 base::ThreadTaskRunnerHandle::Get(), file_path); | 280 base::ThreadTaskRunnerHandle::Get(), file_path); |
| 233 return store; | 281 return store; |
| 234 } | 282 } |
| 235 | 283 |
| 236 OfflinePageMetadataStore* BuildStoreM52(const base::FilePath& file_path) { | 284 OfflinePageMetadataStore* BuildStoreM52(const base::FilePath& file_path) { |
| 237 BuildTestStoreWithSchemaFromM52(file_path); | 285 BuildTestStoreWithSchemaFromM52(file_path); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 253 base::ThreadTaskRunnerHandle::Get(), file_path); | 301 base::ThreadTaskRunnerHandle::Get(), file_path); |
| 254 return store; | 302 return store; |
| 255 } | 303 } |
| 256 | 304 |
| 257 OfflinePageMetadataStore* BuildStoreM55(const base::FilePath& file_path) { | 305 OfflinePageMetadataStore* BuildStoreM55(const base::FilePath& file_path) { |
| 258 BuildTestStoreWithSchemaFromM55(file_path); | 306 BuildTestStoreWithSchemaFromM55(file_path); |
| 259 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL( | 307 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL( |
| 260 base::ThreadTaskRunnerHandle::Get(), file_path); | 308 base::ThreadTaskRunnerHandle::Get(), file_path); |
| 261 return store; | 309 return store; |
| 262 } | 310 } |
| 311 | |
| 312 OfflinePageMetadataStore* BuildStoreM56(const base::FilePath& file_path) { | |
| 313 BuildTestStoreWithSchemaFromM56(file_path); | |
| 314 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL( | |
| 315 base::ThreadTaskRunnerHandle::Get(), file_path); | |
| 316 return store; | |
| 317 } | |
| 263 }; | 318 }; |
| 264 | 319 |
| 265 enum CalledCallback { NONE, LOAD, ADD, UPDATE, REMOVE, RESET }; | 320 enum CalledCallback { NONE, LOAD, ADD, UPDATE, REMOVE, RESET }; |
| 266 enum Status { STATUS_NONE, STATUS_TRUE, STATUS_FALSE }; | 321 enum Status { STATUS_NONE, STATUS_TRUE, STATUS_FALSE }; |
| 267 | 322 |
| 268 class OfflinePageMetadataStoreTest : public testing::Test { | 323 class OfflinePageMetadataStoreTest : public testing::Test { |
| 269 public: | 324 public: |
| 270 OfflinePageMetadataStoreTest(); | 325 OfflinePageMetadataStoreTest(); |
| 271 ~OfflinePageMetadataStoreTest() override; | 326 ~OfflinePageMetadataStoreTest() override; |
| 272 | 327 |
| 273 void TearDown() override { | 328 void TearDown() override { |
| 274 // Wait for all the pieces of the store to delete itself properly. | 329 // Wait for all the pieces of the store to delete itself properly. |
| 275 PumpLoop(); | 330 PumpLoop(); |
| 276 } | 331 } |
| 277 | 332 |
| 278 std::unique_ptr<OfflinePageMetadataStore> BuildStore(); | 333 std::unique_ptr<OfflinePageMetadataStore> BuildStore(); |
| 279 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM52(); | 334 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM52(); |
| 280 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM53(); | 335 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM53(); |
| 281 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM54(); | 336 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM54(); |
| 282 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM55(); | 337 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM55(); |
| 338 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM56(); | |
| 283 | 339 |
| 284 void PumpLoop(); | 340 void PumpLoop(); |
| 285 | 341 |
| 286 void InitializeCallback(bool success); | 342 void InitializeCallback(bool success); |
| 287 void GetOfflinePagesCallback( | 343 void GetOfflinePagesCallback( |
| 288 const std::vector<OfflinePageItem>& offline_pages); | 344 const std::vector<OfflinePageItem>& offline_pages); |
| 289 void AddCallback(ItemActionStatus status); | 345 void AddCallback(ItemActionStatus status); |
| 290 void UpdateCallback(CalledCallback called_callback, | 346 void UpdateCallback(CalledCallback called_callback, |
| 291 std::unique_ptr<OfflinePagesUpdateResult> result); | 347 std::unique_ptr<OfflinePagesUpdateResult> result); |
| 292 void ResetCallback(bool success); | 348 void ResetCallback(bool success); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 | 428 |
| 373 return offline_pages_[0]; | 429 return offline_pages_[0]; |
| 374 } | 430 } |
| 375 | 431 |
| 376 void OfflinePageMetadataStoreTest::CheckThatOfflinePageCanBeSaved( | 432 void OfflinePageMetadataStoreTest::CheckThatOfflinePageCanBeSaved( |
| 377 std::unique_ptr<OfflinePageMetadataStore> store) { | 433 std::unique_ptr<OfflinePageMetadataStore> store) { |
| 378 size_t store_size = offline_pages_.size(); | 434 size_t store_size = offline_pages_.size(); |
| 379 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, | 435 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, |
| 380 base::FilePath(kFilePath), kFileSize); | 436 base::FilePath(kFilePath), kFileSize); |
| 381 offline_page.title = base::UTF8ToUTF16("a title"); | 437 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); | 438 offline_page.original_url = GURL(kOriginalTestURL); |
| 385 | 439 |
| 386 store->AddOfflinePage(offline_page, | 440 store->AddOfflinePage(offline_page, |
| 387 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, | 441 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, |
| 388 base::Unretained(this))); | 442 base::Unretained(this))); |
| 389 PumpLoop(); | 443 PumpLoop(); |
| 390 EXPECT_EQ(ADD, last_called_callback_); | 444 EXPECT_EQ(ADD, last_called_callback_); |
| 391 EXPECT_EQ(STATUS_TRUE, last_status_); | 445 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 392 ClearResults(); | 446 ClearResults(); |
| 393 | 447 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 store->GetOfflinePages( | 504 store->GetOfflinePages( |
| 451 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, | 505 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, |
| 452 base::Unretained(this))); | 506 base::Unretained(this))); |
| 453 PumpLoop(); | 507 PumpLoop(); |
| 454 return store; | 508 return store; |
| 455 } | 509 } |
| 456 | 510 |
| 457 std::unique_ptr<OfflinePageMetadataStore> | 511 std::unique_ptr<OfflinePageMetadataStore> |
| 458 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM54() { | 512 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM54() { |
| 459 std::unique_ptr<OfflinePageMetadataStore> store( | 513 std::unique_ptr<OfflinePageMetadataStore> store( |
| 460 factory_.BuildStoreM53(temp_directory_.GetPath())); | 514 factory_.BuildStoreM54(temp_directory_.GetPath())); |
| 461 PumpLoop(); | 515 PumpLoop(); |
| 462 store->Initialize( | 516 store->Initialize( |
| 463 base::Bind(&OfflinePageMetadataStoreTest::InitializeCallback, | 517 base::Bind(&OfflinePageMetadataStoreTest::InitializeCallback, |
| 464 base::Unretained(this))); | 518 base::Unretained(this))); |
| 465 PumpLoop(); | 519 PumpLoop(); |
| 466 store->GetOfflinePages( | 520 store->GetOfflinePages( |
| 467 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, | 521 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, |
| 468 base::Unretained(this))); | 522 base::Unretained(this))); |
| 469 PumpLoop(); | 523 PumpLoop(); |
| 470 return store; | 524 return store; |
| 471 } | 525 } |
| 472 | 526 |
| 473 std::unique_ptr<OfflinePageMetadataStore> | 527 std::unique_ptr<OfflinePageMetadataStore> |
| 474 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM55() { | 528 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM55() { |
| 475 std::unique_ptr<OfflinePageMetadataStore> store( | 529 std::unique_ptr<OfflinePageMetadataStore> store( |
| 476 factory_.BuildStoreM55(temp_directory_.GetPath())); | 530 factory_.BuildStoreM55(temp_directory_.GetPath())); |
| 477 PumpLoop(); | 531 PumpLoop(); |
| 478 store->Initialize( | 532 store->Initialize( |
| 479 base::Bind(&OfflinePageMetadataStoreTest::InitializeCallback, | 533 base::Bind(&OfflinePageMetadataStoreTest::InitializeCallback, |
| 480 base::Unretained(this))); | 534 base::Unretained(this))); |
| 481 PumpLoop(); | 535 PumpLoop(); |
| 482 store->GetOfflinePages( | 536 store->GetOfflinePages( |
| 483 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, | 537 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, |
| 484 base::Unretained(this))); | 538 base::Unretained(this))); |
| 485 PumpLoop(); | 539 PumpLoop(); |
| 486 return store; | 540 return store; |
| 487 } | 541 } |
| 488 | 542 |
| 543 std::unique_ptr<OfflinePageMetadataStore> | |
| 544 OfflinePageMetadataStoreTest::BuildStoreWithSchemaFromM56() { | |
| 545 std::unique_ptr<OfflinePageMetadataStore> store( | |
| 546 factory_.BuildStoreM56(temp_directory_.GetPath())); | |
| 547 PumpLoop(); | |
| 548 store->Initialize( | |
| 549 base::Bind(&OfflinePageMetadataStoreTest::InitializeCallback, | |
| 550 base::Unretained(this))); | |
| 551 PumpLoop(); | |
| 552 store->GetOfflinePages( | |
| 553 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, | |
| 554 base::Unretained(this))); | |
| 555 PumpLoop(); | |
| 556 return store; | |
| 557 } | |
| 558 | |
| 489 // Loads empty store and makes sure that there are no offline pages stored in | 559 // Loads empty store and makes sure that there are no offline pages stored in |
| 490 // it. | 560 // it. |
| 491 TEST_F(OfflinePageMetadataStoreTest, LoadEmptyStore) { | 561 TEST_F(OfflinePageMetadataStoreTest, LoadEmptyStore) { |
| 492 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); | 562 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); |
| 493 EXPECT_EQ(LOAD, last_called_callback_); | 563 EXPECT_EQ(LOAD, last_called_callback_); |
| 494 EXPECT_EQ(STATUS_TRUE, last_status_); | 564 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 495 EXPECT_EQ(0U, offline_pages_.size()); | 565 EXPECT_EQ(0U, offline_pages_.size()); |
| 496 } | 566 } |
| 497 | 567 |
| 498 TEST_F(OfflinePageMetadataStoreTest, GetOfflinePagesFromInvalidStore) { | 568 TEST_F(OfflinePageMetadataStoreTest, GetOfflinePagesFromInvalidStore) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 } | 637 } |
| 568 | 638 |
| 569 // Loads a store which has an outdated schema. | 639 // Loads a store which has an outdated schema. |
| 570 // This test case would crash if it's not handling correctly when we're loading | 640 // This test case would crash if it's not handling correctly when we're loading |
| 571 // old version stores. | 641 // old version stores. |
| 572 // TODO(romax): Move this to sql_unittest. | 642 // TODO(romax): Move this to sql_unittest. |
| 573 TEST_F(OfflinePageMetadataStoreTest, LoadVersion52Store) { | 643 TEST_F(OfflinePageMetadataStoreTest, LoadVersion52Store) { |
| 574 std::unique_ptr<OfflinePageMetadataStore> store( | 644 std::unique_ptr<OfflinePageMetadataStore> store( |
| 575 BuildStoreWithSchemaFromM52()); | 645 BuildStoreWithSchemaFromM52()); |
| 576 | 646 |
| 577 CheckThatStoreHasOneItem(); | 647 OfflinePageItem item = CheckThatStoreHasOneItem(); |
| 578 CheckThatOfflinePageCanBeSaved(std::move(store)); | 648 CheckThatOfflinePageCanBeSaved(std::move(store)); |
| 579 } | 649 } |
| 580 | 650 |
| 581 // Loads a store which has an outdated schema. | 651 // Loads a store which has an outdated schema. |
| 582 // This test case would crash if it's not handling correctly when we're loading | 652 // This test case would crash if it's not handling correctly when we're loading |
| 583 // old version stores. | 653 // old version stores. |
| 584 // TODO(romax): Move this to sql_unittest. | 654 // TODO(romax): Move this to sql_unittest. |
| 585 TEST_F(OfflinePageMetadataStoreTest, LoadVersion53Store) { | 655 TEST_F(OfflinePageMetadataStoreTest, LoadVersion53Store) { |
| 586 std::unique_ptr<OfflinePageMetadataStore> store( | 656 std::unique_ptr<OfflinePageMetadataStore> store( |
| 587 BuildStoreWithSchemaFromM53()); | 657 BuildStoreWithSchemaFromM53()); |
| 588 | 658 |
| 589 OfflinePageItem item = CheckThatStoreHasOneItem(); | 659 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)); | 660 CheckThatOfflinePageCanBeSaved(std::move(store)); |
| 595 } | 661 } |
| 596 | 662 |
| 597 // Loads a string with schema from M54. | 663 // Loads a string with schema from M54. |
| 598 // Because for now we only reduce the number of fields it just makes sure there | 664 // This test case would crash if it's not handling correctly when we're loading |
| 599 // are no crashes in the process. | 665 // old version stores. |
| 600 // TODO(romax): Move this to sql_unittest. | 666 // TODO(romax): Move this to sql_unittest. |
| 601 TEST_F(OfflinePageMetadataStoreTest, LoadVersion54Store) { | 667 TEST_F(OfflinePageMetadataStoreTest, LoadVersion54Store) { |
| 602 std::unique_ptr<OfflinePageMetadataStore> store( | 668 std::unique_ptr<OfflinePageMetadataStore> store( |
| 603 BuildStoreWithSchemaFromM54()); | 669 BuildStoreWithSchemaFromM54()); |
| 604 | 670 |
| 605 OfflinePageItem item = CheckThatStoreHasOneItem(); | 671 OfflinePageItem item = CheckThatStoreHasOneItem(); |
| 606 | |
| 607 CheckThatOfflinePageCanBeSaved(std::move(store)); | 672 CheckThatOfflinePageCanBeSaved(std::move(store)); |
| 608 } | 673 } |
| 609 | 674 |
| 610 // Loads a string with schema from M55. | 675 // Loads a string with schema from M55. |
| 611 // Because for now we only reduce the number of fields it just makes sure there | 676 // This test case would crash if it's not handling correctly when we're loading |
| 612 // are no crashes in the process. | 677 // old version stores. |
| 613 // TODO(romax): Move this to sql_unittest. | 678 // TODO(romax): Move this to sql_unittest. |
| 614 TEST_F(OfflinePageMetadataStoreTest, LoadVersion55Store) { | 679 TEST_F(OfflinePageMetadataStoreTest, LoadVersion55Store) { |
| 615 std::unique_ptr<OfflinePageMetadataStore> store( | 680 std::unique_ptr<OfflinePageMetadataStore> store( |
| 616 BuildStoreWithSchemaFromM55()); | 681 BuildStoreWithSchemaFromM55()); |
| 617 | 682 |
| 618 OfflinePageItem item = CheckThatStoreHasOneItem(); | 683 OfflinePageItem item = CheckThatStoreHasOneItem(); |
| 619 | |
| 620 CheckThatOfflinePageCanBeSaved(std::move(store)); | 684 CheckThatOfflinePageCanBeSaved(std::move(store)); |
| 621 } | 685 } |
| 622 | 686 |
| 687 // Loads a string with schema from M56. | |
| 688 // This test case would crash if it's not handling correctly when we're loading | |
| 689 // old version stores. | |
| 690 // TODO(romax): Move this to sql_unittest. | |
| 691 TEST_F(OfflinePageMetadataStoreTest, LoadVersion56Store) { | |
| 692 std::unique_ptr<OfflinePageMetadataStore> store( | |
| 693 BuildStoreWithSchemaFromM56()); | |
| 694 | |
| 695 OfflinePageItem item = CheckThatStoreHasOneItem(); | |
| 696 CheckThatOfflinePageCanBeSaved(std::move(store)); | |
| 697 } | |
| 698 | |
| 623 // Adds metadata of an offline page into a store and then opens the store | 699 // 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. | 700 // again to make sure that stored metadata survives store restarts. |
| 625 TEST_F(OfflinePageMetadataStoreTest, AddOfflinePage) { | 701 TEST_F(OfflinePageMetadataStoreTest, AddOfflinePage) { |
| 626 CheckThatOfflinePageCanBeSaved(BuildStore()); | 702 CheckThatOfflinePageCanBeSaved(BuildStore()); |
| 627 } | 703 } |
| 628 | 704 |
| 629 TEST_F(OfflinePageMetadataStoreTest, AddSameOfflinePageTwice) { | 705 TEST_F(OfflinePageMetadataStoreTest, AddSameOfflinePageTwice) { |
| 630 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); | 706 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); |
| 631 | 707 |
| 632 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, | 708 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, |
| 633 base::FilePath(kFilePath), kFileSize); | 709 base::FilePath(kFilePath), kFileSize); |
| 634 offline_page.title = base::UTF8ToUTF16("a title"); | 710 offline_page.title = base::UTF8ToUTF16("a title"); |
| 635 base::Time expiration_time = base::Time::Now(); | |
| 636 offline_page.expiration_time = expiration_time; | |
| 637 | 711 |
| 638 store->AddOfflinePage(offline_page, | 712 store->AddOfflinePage(offline_page, |
| 639 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, | 713 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, |
| 640 base::Unretained(this))); | 714 base::Unretained(this))); |
| 641 PumpLoop(); | 715 PumpLoop(); |
| 642 EXPECT_EQ(ADD, last_called_callback_); | 716 EXPECT_EQ(ADD, last_called_callback_); |
| 643 EXPECT_EQ(STATUS_TRUE, last_status_); | 717 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 644 ClearResults(); | 718 ClearResults(); |
| 645 | 719 |
| 646 store->AddOfflinePage(offline_page, | 720 store->AddOfflinePage(offline_page, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 EXPECT_EQ(STATUS_TRUE, last_status_); | 801 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 728 | 802 |
| 729 ClearResults(); | 803 ClearResults(); |
| 730 | 804 |
| 731 // Add anther offline page. | 805 // Add anther offline page. |
| 732 base::FilePath file_path_2 = | 806 base::FilePath file_path_2 = |
| 733 base::FilePath(FILE_PATH_LITERAL("//other.page.com.mhtml")); | 807 base::FilePath(FILE_PATH_LITERAL("//other.page.com.mhtml")); |
| 734 OfflinePageItem offline_page_2(GURL("https://other.page.com"), 5678LL, | 808 OfflinePageItem offline_page_2(GURL("https://other.page.com"), 5678LL, |
| 735 kTestClientId2, file_path_2, 12345, | 809 kTestClientId2, file_path_2, 12345, |
| 736 base::Time::Now()); | 810 base::Time::Now()); |
| 737 offline_page_2.expiration_time = base::Time::Now(); | |
| 738 offline_page_2.original_url = GURL("https://example.com/bar"); | 811 offline_page_2.original_url = GURL("https://example.com/bar"); |
| 739 store->AddOfflinePage(offline_page_2, | 812 store->AddOfflinePage(offline_page_2, |
| 740 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, | 813 base::Bind(&OfflinePageMetadataStoreTest::AddCallback, |
| 741 base::Unretained(this))); | 814 base::Unretained(this))); |
| 742 PumpLoop(); | 815 PumpLoop(); |
| 743 EXPECT_EQ(ADD, last_called_callback_); | 816 EXPECT_EQ(ADD, last_called_callback_); |
| 744 EXPECT_EQ(STATUS_TRUE, last_status_); | 817 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 745 | 818 |
| 746 ClearResults(); | 819 ClearResults(); |
| 747 | 820 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 EXPECT_EQ(LOAD, last_called_callback_); | 856 EXPECT_EQ(LOAD, last_called_callback_); |
| 784 EXPECT_EQ(STATUS_TRUE, last_status_); | 857 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 785 ASSERT_EQ(1U, offline_pages_.size()); | 858 ASSERT_EQ(1U, offline_pages_.size()); |
| 786 EXPECT_EQ(offline_page_2.url, offline_pages_[0].url); | 859 EXPECT_EQ(offline_page_2.url, offline_pages_[0].url); |
| 787 EXPECT_EQ(offline_page_2.offline_id, offline_pages_[0].offline_id); | 860 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); | 861 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); | 862 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); | 863 EXPECT_EQ(offline_page_2.creation_time, offline_pages_[0].creation_time); |
| 791 EXPECT_EQ(offline_page_2.last_access_time, | 864 EXPECT_EQ(offline_page_2.last_access_time, |
| 792 offline_pages_[0].last_access_time); | 865 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); | 866 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); | 867 EXPECT_EQ(offline_page_2.client_id, offline_pages_[0].client_id); |
| 796 } | 868 } |
| 797 | 869 |
| 798 // Tests updating offline page metadata from the store. | 870 // Tests updating offline page metadata from the store. |
| 799 TEST_F(OfflinePageMetadataStoreTest, UpdateOfflinePage) { | 871 TEST_F(OfflinePageMetadataStoreTest, UpdateOfflinePage) { |
| 800 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); | 872 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); |
| 801 | 873 |
| 802 // First, adds a fresh page. | 874 // First, adds a fresh page. |
| 803 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, | 875 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestClientId1, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 815 base::Unretained(this))); | 887 base::Unretained(this))); |
| 816 PumpLoop(); | 888 PumpLoop(); |
| 817 | 889 |
| 818 EXPECT_EQ(LOAD, last_called_callback_); | 890 EXPECT_EQ(LOAD, last_called_callback_); |
| 819 ASSERT_EQ(1U, offline_pages_.size()); | 891 ASSERT_EQ(1U, offline_pages_.size()); |
| 820 EXPECT_EQ(offline_page, offline_pages_[0]); | 892 EXPECT_EQ(offline_page, offline_pages_[0]); |
| 821 | 893 |
| 822 // Then update some data. | 894 // Then update some data. |
| 823 offline_page.file_size = kFileSize + 1; | 895 offline_page.file_size = kFileSize + 1; |
| 824 offline_page.access_count++; | 896 offline_page.access_count++; |
| 825 offline_page.expiration_time = base::Time::Now(); | |
| 826 offline_page.original_url = GURL("https://example.com/bar"); | 897 offline_page.original_url = GURL("https://example.com/bar"); |
| 827 std::vector<OfflinePageItem> items_to_update; | 898 std::vector<OfflinePageItem> items_to_update; |
| 828 items_to_update.push_back(offline_page); | 899 items_to_update.push_back(offline_page); |
| 829 store->UpdateOfflinePages( | 900 store->UpdateOfflinePages( |
| 830 items_to_update, base::Bind(&OfflinePageMetadataStoreTest::UpdateCallback, | 901 items_to_update, base::Bind(&OfflinePageMetadataStoreTest::UpdateCallback, |
| 831 base::Unretained(this), UPDATE)); | 902 base::Unretained(this), UPDATE)); |
| 832 PumpLoop(); | 903 PumpLoop(); |
| 833 EXPECT_EQ(UPDATE, last_called_callback_); | 904 EXPECT_EQ(UPDATE, last_called_callback_); |
| 834 EXPECT_EQ(STATUS_TRUE, last_status_); | 905 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 835 ASSERT_TRUE(last_update_result() != nullptr); | 906 ASSERT_TRUE(last_update_result() != nullptr); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 908 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); | 979 std::unique_ptr<OfflinePageMetadataStore> store(BuildStore()); |
| 909 | 980 |
| 910 store->Reset(base::Bind(&OfflinePageMetadataStoreTest::ResetCallback, | 981 store->Reset(base::Bind(&OfflinePageMetadataStoreTest::ResetCallback, |
| 911 base::Unretained(this))); | 982 base::Unretained(this))); |
| 912 PumpLoop(); | 983 PumpLoop(); |
| 913 EXPECT_EQ(STATUS_TRUE, last_status_); | 984 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 914 } | 985 } |
| 915 | 986 |
| 916 } // namespace | 987 } // namespace |
| 917 } // namespace offline_pages | 988 } // namespace offline_pages |
| OLD | NEW |