| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stack> | 5 #include <stack> |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 AppCacheDatabase::GroupRecord record; | 459 AppCacheDatabase::GroupRecord record; |
| 460 EXPECT_FALSE(database()->FindGroup( | 460 EXPECT_FALSE(database()->FindGroup( |
| 461 delegate()->loaded_group_->group_id(), &record)); | 461 delegate()->loaded_group_->group_id(), &record)); |
| 462 | 462 |
| 463 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_accessed_count_); | 463 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_accessed_count_); |
| 464 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); | 464 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); |
| 465 | 465 |
| 466 TestFinished(); | 466 TestFinished(); |
| 467 } | 467 } |
| 468 | 468 |
| 469 void CreateGroupSyncInPopulatedOrigin() { |
| 470 storage()->usage_map_[kOrigin] = kDefaultEntrySize; |
| 471 |
| 472 storage()->SyncLoadOrCreateGroup(kManifestUrl, delegate()); |
| 473 Verify_CreateGroup(); |
| 474 } |
| 475 |
| 469 // LoadGroupAndCache_FarHit -------------------------------------- | 476 // LoadGroupAndCache_FarHit -------------------------------------- |
| 470 | 477 |
| 471 void LoadGroupAndCache_FarHit() { | 478 void LoadGroupAndCache_FarHit() { |
| 472 // Attempt to load a cache that is not currently in use | 479 // Attempt to load a cache that is not currently in use |
| 473 // and does require loading from disk. This | 480 // and does require loading from disk. This |
| 474 // load should complete asyncly. | 481 // load should complete asyncly. |
| 475 PushNextTask(NewRunnableMethod( | 482 PushNextTask(NewRunnableMethod( |
| 476 this, &AppCacheStorageImplTest::Verify_LoadCache_Far_Hit)); | 483 this, &AppCacheStorageImplTest::Verify_LoadCache_Far_Hit)); |
| 477 | 484 |
| 478 // Setup some preconditions. Create a group and newest cache that | 485 // Setup some preconditions. Create a group and newest cache that |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 EXPECT_FALSE(database()->FindCache(cache_->cache_id(), &cache_record)); | 713 EXPECT_FALSE(database()->FindCache(cache_->cache_id(), &cache_record)); |
| 707 | 714 |
| 708 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_accessed_count_); | 715 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_accessed_count_); |
| 709 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); | 716 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); |
| 710 | 717 |
| 711 TestFinished(); | 718 TestFinished(); |
| 712 } | 719 } |
| 713 | 720 |
| 714 // MakeGroupObsolete ------------------------------- | 721 // MakeGroupObsolete ------------------------------- |
| 715 | 722 |
| 716 void MakeGroupObsolete() { | 723 void Setup_MakeGroupObsolete() { |
| 717 // Make a group obsolete, should complete asyncly. | |
| 718 PushNextTask(NewRunnableMethod( | |
| 719 this, &AppCacheStorageImplTest::Verify_MakeGroupObsolete)); | |
| 720 | |
| 721 // Setup some preconditions. Create a group and newest cache that | 724 // Setup some preconditions. Create a group and newest cache that |
| 722 // appears to be "stored" and "currently in use". | 725 // appears to be "stored" and "currently in use". |
| 723 MakeCacheAndGroup(kManifestUrl, 1, 1, true); | 726 MakeCacheAndGroup(kManifestUrl, 1, 1, true); |
| 724 EXPECT_EQ(kDefaultEntrySize, storage()->usage_map_[kOrigin]); | 727 EXPECT_EQ(kDefaultEntrySize, storage()->usage_map_[kOrigin]); |
| 725 | 728 |
| 726 // Also insert some related records. | 729 // Also insert some related records. |
| 727 AppCacheDatabase::EntryRecord entry_record; | 730 AppCacheDatabase::EntryRecord entry_record; |
| 728 entry_record.cache_id = 1; | 731 entry_record.cache_id = 1; |
| 729 entry_record.flags = AppCacheEntry::FALLBACK; | 732 entry_record.flags = AppCacheEntry::FALLBACK; |
| 730 entry_record.response_id = 1; | 733 entry_record.response_id = 1; |
| 731 entry_record.url = kEntryUrl; | 734 entry_record.url = kEntryUrl; |
| 732 EXPECT_TRUE(database()->InsertEntry(&entry_record)); | 735 EXPECT_TRUE(database()->InsertEntry(&entry_record)); |
| 733 | 736 |
| 734 AppCacheDatabase::FallbackNameSpaceRecord fallback_namespace_record; | 737 AppCacheDatabase::FallbackNameSpaceRecord fallback_namespace_record; |
| 735 fallback_namespace_record.cache_id = 1; | 738 fallback_namespace_record.cache_id = 1; |
| 736 fallback_namespace_record.fallback_entry_url = kEntryUrl; | 739 fallback_namespace_record.fallback_entry_url = kEntryUrl; |
| 737 fallback_namespace_record.namespace_url = kFallbackNamespace; | 740 fallback_namespace_record.namespace_url = kFallbackNamespace; |
| 738 fallback_namespace_record.origin = kManifestUrl.GetOrigin(); | 741 fallback_namespace_record.origin = kManifestUrl.GetOrigin(); |
| 739 EXPECT_TRUE( | 742 EXPECT_TRUE( |
| 740 database()->InsertFallbackNameSpace(&fallback_namespace_record)); | 743 database()->InsertFallbackNameSpace(&fallback_namespace_record)); |
| 741 | 744 |
| 742 AppCacheDatabase::OnlineWhiteListRecord online_whitelist_record; | 745 AppCacheDatabase::OnlineWhiteListRecord online_whitelist_record; |
| 743 online_whitelist_record.cache_id = 1; | 746 online_whitelist_record.cache_id = 1; |
| 744 online_whitelist_record.namespace_url = kOnlineNamespace; | 747 online_whitelist_record.namespace_url = kOnlineNamespace; |
| 745 EXPECT_TRUE(database()->InsertOnlineWhiteList(&online_whitelist_record)); | 748 EXPECT_TRUE(database()->InsertOnlineWhiteList(&online_whitelist_record)); |
| 749 } |
| 750 |
| 751 void MakeGroupObsolete() { |
| 752 // Make a group obsolete, should complete asyncly. |
| 753 PushNextTask(NewRunnableMethod( |
| 754 this, &AppCacheStorageImplTest::Verify_MakeGroupObsolete)); |
| 755 Setup_MakeGroupObsolete(); |
| 746 | 756 |
| 747 // Conduct the test. | 757 // Conduct the test. |
| 748 storage()->MakeGroupObsolete(group_, delegate()); | 758 storage()->MakeGroupObsolete(group_, delegate()); |
| 749 EXPECT_FALSE(group_->is_obsolete()); | 759 EXPECT_FALSE(group_->is_obsolete()); |
| 750 } | 760 } |
| 751 | 761 |
| 762 void SyncMakeGroupObsolete() { |
| 763 Setup_MakeGroupObsolete(); |
| 764 // Conduct the test. |
| 765 storage()->SyncMakeGroupObsolete(group_, delegate()); |
| 766 Verify_MakeGroupObsolete(); |
| 767 } |
| 768 |
| 752 void Verify_MakeGroupObsolete() { | 769 void Verify_MakeGroupObsolete() { |
| 753 EXPECT_TRUE(delegate()->obsoleted_success_); | 770 EXPECT_TRUE(delegate()->obsoleted_success_); |
| 754 EXPECT_EQ(group_.get(), delegate()->obsoleted_group_.get()); | 771 EXPECT_EQ(group_.get(), delegate()->obsoleted_group_.get()); |
| 755 EXPECT_TRUE(group_->is_obsolete()); | 772 EXPECT_TRUE(group_->is_obsolete()); |
| 756 EXPECT_TRUE(storage()->usage_map_.empty()); | 773 EXPECT_TRUE(storage()->usage_map_.empty()); |
| 757 | 774 |
| 758 // The cache and group have been deleted from the database. | 775 // The cache and group have been deleted from the database. |
| 759 AppCacheDatabase::GroupRecord group_record; | 776 AppCacheDatabase::GroupRecord group_record; |
| 760 AppCacheDatabase::CacheRecord cache_record; | 777 AppCacheDatabase::CacheRecord cache_record; |
| 761 EXPECT_FALSE(database()->FindGroup(1, &group_record)); | 778 EXPECT_FALSE(database()->FindGroup(1, &group_record)); |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 } | 1345 } |
| 1329 | 1346 |
| 1330 TEST_F(AppCacheStorageImplTest, CreateGroupInEmptyOrigin) { | 1347 TEST_F(AppCacheStorageImplTest, CreateGroupInEmptyOrigin) { |
| 1331 RunTestOnIOThread(&AppCacheStorageImplTest::CreateGroupInEmptyOrigin); | 1348 RunTestOnIOThread(&AppCacheStorageImplTest::CreateGroupInEmptyOrigin); |
| 1332 } | 1349 } |
| 1333 | 1350 |
| 1334 TEST_F(AppCacheStorageImplTest, CreateGroupInPopulatedOrigin) { | 1351 TEST_F(AppCacheStorageImplTest, CreateGroupInPopulatedOrigin) { |
| 1335 RunTestOnIOThread(&AppCacheStorageImplTest::CreateGroupInPopulatedOrigin); | 1352 RunTestOnIOThread(&AppCacheStorageImplTest::CreateGroupInPopulatedOrigin); |
| 1336 } | 1353 } |
| 1337 | 1354 |
| 1355 TEST_F(AppCacheStorageImplTest, CreateGroupSyncInPopulatedOrigin) { |
| 1356 RunTestOnIOThread(&AppCacheStorageImplTest::CreateGroupSyncInPopulatedOrigin); |
| 1357 } |
| 1358 |
| 1338 TEST_F(AppCacheStorageImplTest, LoadGroupAndCache_FarHit) { | 1359 TEST_F(AppCacheStorageImplTest, LoadGroupAndCache_FarHit) { |
| 1339 RunTestOnIOThread(&AppCacheStorageImplTest::LoadGroupAndCache_FarHit); | 1360 RunTestOnIOThread(&AppCacheStorageImplTest::LoadGroupAndCache_FarHit); |
| 1340 } | 1361 } |
| 1341 | 1362 |
| 1342 TEST_F(AppCacheStorageImplTest, StoreNewGroup) { | 1363 TEST_F(AppCacheStorageImplTest, StoreNewGroup) { |
| 1343 RunTestOnIOThread(&AppCacheStorageImplTest::StoreNewGroup); | 1364 RunTestOnIOThread(&AppCacheStorageImplTest::StoreNewGroup); |
| 1344 } | 1365 } |
| 1345 | 1366 |
| 1346 TEST_F(AppCacheStorageImplTest, StoreExistingGroup) { | 1367 TEST_F(AppCacheStorageImplTest, StoreExistingGroup) { |
| 1347 RunTestOnIOThread(&AppCacheStorageImplTest::StoreExistingGroup); | 1368 RunTestOnIOThread(&AppCacheStorageImplTest::StoreExistingGroup); |
| 1348 } | 1369 } |
| 1349 | 1370 |
| 1350 TEST_F(AppCacheStorageImplTest, StoreExistingGroupExistingCache) { | 1371 TEST_F(AppCacheStorageImplTest, StoreExistingGroupExistingCache) { |
| 1351 RunTestOnIOThread(&AppCacheStorageImplTest::StoreExistingGroupExistingCache); | 1372 RunTestOnIOThread(&AppCacheStorageImplTest::StoreExistingGroupExistingCache); |
| 1352 } | 1373 } |
| 1353 | 1374 |
| 1354 TEST_F(AppCacheStorageImplTest, FailStoreGroup) { | 1375 TEST_F(AppCacheStorageImplTest, FailStoreGroup) { |
| 1355 RunTestOnIOThread(&AppCacheStorageImplTest::FailStoreGroup); | 1376 RunTestOnIOThread(&AppCacheStorageImplTest::FailStoreGroup); |
| 1356 } | 1377 } |
| 1357 | 1378 |
| 1358 TEST_F(AppCacheStorageImplTest, MakeGroupObsolete) { | 1379 TEST_F(AppCacheStorageImplTest, MakeGroupObsolete) { |
| 1359 RunTestOnIOThread(&AppCacheStorageImplTest::MakeGroupObsolete); | 1380 RunTestOnIOThread(&AppCacheStorageImplTest::MakeGroupObsolete); |
| 1360 } | 1381 } |
| 1361 | 1382 |
| 1383 TEST_F(AppCacheStorageImplTest, SyncMakeGroupObsolete) { |
| 1384 RunTestOnIOThread(&AppCacheStorageImplTest::SyncMakeGroupObsolete); |
| 1385 } |
| 1386 |
| 1362 TEST_F(AppCacheStorageImplTest, MarkEntryAsForeign) { | 1387 TEST_F(AppCacheStorageImplTest, MarkEntryAsForeign) { |
| 1363 RunTestOnIOThread(&AppCacheStorageImplTest::MarkEntryAsForeign); | 1388 RunTestOnIOThread(&AppCacheStorageImplTest::MarkEntryAsForeign); |
| 1364 } | 1389 } |
| 1365 | 1390 |
| 1366 TEST_F(AppCacheStorageImplTest, MarkEntryAsForeignWithLoadInProgress) { | 1391 TEST_F(AppCacheStorageImplTest, MarkEntryAsForeignWithLoadInProgress) { |
| 1367 RunTestOnIOThread( | 1392 RunTestOnIOThread( |
| 1368 &AppCacheStorageImplTest::MarkEntryAsForeignWithLoadInProgress); | 1393 &AppCacheStorageImplTest::MarkEntryAsForeignWithLoadInProgress); |
| 1369 } | 1394 } |
| 1370 | 1395 |
| 1371 TEST_F(AppCacheStorageImplTest, FindNoMainResponse) { | 1396 TEST_F(AppCacheStorageImplTest, FindNoMainResponse) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1412 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); | 1437 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); |
| 1413 } | 1438 } |
| 1414 | 1439 |
| 1415 // That's all folks! | 1440 // That's all folks! |
| 1416 | 1441 |
| 1417 } // namespace appcache | 1442 } // namespace appcache |
| 1418 | 1443 |
| 1419 // AppCacheStorageImplTest is expected to always live longer than the | 1444 // AppCacheStorageImplTest is expected to always live longer than the |
| 1420 // runnable methods. This lets us call NewRunnableMethod on its instances. | 1445 // runnable methods. This lets us call NewRunnableMethod on its instances. |
| 1421 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest); | 1446 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest); |
| OLD | NEW |