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

Side by Side Diff: webkit/appcache/appcache_storage_impl_unittest.cc

Issue 3083014: AppCache: Provide a way to override the default quota for an origin. The inte... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/appcache/appcache_storage_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/thread.h" 8 #include "base/thread.h"
9 #include "base/waitable_event.h" 9 #include "base/waitable_event.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 TestThreadProvider thread_provider; 66 TestThreadProvider thread_provider;
67 67
68 } // namespace 68 } // namespace
69 69
70 class AppCacheStorageImplTest : public testing::Test { 70 class AppCacheStorageImplTest : public testing::Test {
71 public: 71 public:
72 class MockStorageDelegate : public AppCacheStorage::Delegate { 72 class MockStorageDelegate : public AppCacheStorage::Delegate {
73 public: 73 public:
74 explicit MockStorageDelegate(AppCacheStorageImplTest* test) 74 explicit MockStorageDelegate(AppCacheStorageImplTest* test)
75 : loaded_cache_id_(0), stored_group_success_(false), 75 : loaded_cache_id_(0), stored_group_success_(false),
76 obsoleted_success_(false), found_cache_id_(kNoCacheId), 76 would_exceed_quota_(false), obsoleted_success_(false),
77 found_blocked_by_policy_(false), test_(test) { 77 found_cache_id_(kNoCacheId), found_blocked_by_policy_(false),
78 test_(test) {
78 } 79 }
79 80
80 void OnCacheLoaded(AppCache* cache, int64 cache_id) { 81 void OnCacheLoaded(AppCache* cache, int64 cache_id) {
81 loaded_cache_ = cache; 82 loaded_cache_ = cache;
82 loaded_cache_id_ = cache_id; 83 loaded_cache_id_ = cache_id;
83 test_->ScheduleNextTask(); 84 test_->ScheduleNextTask();
84 } 85 }
85 86
86 void OnGroupLoaded(AppCacheGroup* group, const GURL& manifest_url) { 87 void OnGroupLoaded(AppCacheGroup* group, const GURL& manifest_url) {
87 loaded_group_ = group; 88 loaded_group_ = group;
88 loaded_manifest_url_ = manifest_url; 89 loaded_manifest_url_ = manifest_url;
89 loaded_groups_newest_cache_ = group ? group->newest_complete_cache() 90 loaded_groups_newest_cache_ = group ? group->newest_complete_cache()
90 : NULL; 91 : NULL;
91 test_->ScheduleNextTask(); 92 test_->ScheduleNextTask();
92 } 93 }
93 94
94 void OnGroupAndNewestCacheStored( 95 void OnGroupAndNewestCacheStored(
95 AppCacheGroup* group, AppCache* newest_cache, bool success, 96 AppCacheGroup* group, AppCache* newest_cache, bool success,
96 bool would_exceed_quota) { 97 bool would_exceed_quota) {
97 stored_group_ = group; 98 stored_group_ = group;
98 stored_group_success_ = success; 99 stored_group_success_ = success;
100 would_exceed_quota_ = would_exceed_quota;
99 test_->ScheduleNextTask(); 101 test_->ScheduleNextTask();
100 } 102 }
101 103
102 void OnGroupMadeObsolete(AppCacheGroup* group, bool success) { 104 void OnGroupMadeObsolete(AppCacheGroup* group, bool success) {
103 obsoleted_group_ = group; 105 obsoleted_group_ = group;
104 obsoleted_success_ = success; 106 obsoleted_success_ = success;
105 test_->ScheduleNextTask(); 107 test_->ScheduleNextTask();
106 } 108 }
107 109
108 void OnMainResponseFound(const GURL& url, const AppCacheEntry& entry, 110 void OnMainResponseFound(const GURL& url, const AppCacheEntry& entry,
109 const AppCacheEntry& fallback_entry, 111 const AppCacheEntry& fallback_entry,
110 int64 cache_id, const GURL& manifest_url, 112 int64 cache_id, const GURL& manifest_url,
111 bool was_blocked_by_policy) { 113 bool was_blocked_by_policy) {
112 found_url_ = url; 114 found_url_ = url;
113 found_entry_ = entry; 115 found_entry_ = entry;
114 found_fallback_entry_ = fallback_entry; 116 found_fallback_entry_ = fallback_entry;
115 found_cache_id_ = cache_id; 117 found_cache_id_ = cache_id;
116 found_manifest_url_ = manifest_url; 118 found_manifest_url_ = manifest_url;
117 found_blocked_by_policy_ = was_blocked_by_policy; 119 found_blocked_by_policy_ = was_blocked_by_policy;
118 test_->ScheduleNextTask(); 120 test_->ScheduleNextTask();
119 } 121 }
120 122
121 scoped_refptr<AppCache> loaded_cache_; 123 scoped_refptr<AppCache> loaded_cache_;
122 int64 loaded_cache_id_; 124 int64 loaded_cache_id_;
123 scoped_refptr<AppCacheGroup> loaded_group_; 125 scoped_refptr<AppCacheGroup> loaded_group_;
124 GURL loaded_manifest_url_; 126 GURL loaded_manifest_url_;
125 scoped_refptr<AppCache> loaded_groups_newest_cache_; 127 scoped_refptr<AppCache> loaded_groups_newest_cache_;
126 scoped_refptr<AppCacheGroup> stored_group_; 128 scoped_refptr<AppCacheGroup> stored_group_;
127 bool stored_group_success_; 129 bool stored_group_success_;
130 bool would_exceed_quota_;
128 scoped_refptr<AppCacheGroup> obsoleted_group_; 131 scoped_refptr<AppCacheGroup> obsoleted_group_;
129 bool obsoleted_success_; 132 bool obsoleted_success_;
130 GURL found_url_; 133 GURL found_url_;
131 AppCacheEntry found_entry_; 134 AppCacheEntry found_entry_;
132 AppCacheEntry found_fallback_entry_; 135 AppCacheEntry found_fallback_entry_;
133 int64 found_cache_id_; 136 int64 found_cache_id_;
134 GURL found_manifest_url_; 137 GURL found_manifest_url_;
135 bool found_blocked_by_policy_; 138 bool found_blocked_by_policy_;
136 AppCacheStorageImplTest* test_; 139 AppCacheStorageImplTest* test_;
137 }; 140 };
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 EXPECT_EQ(1U, entry_records.size()); 528 EXPECT_EQ(1U, entry_records.size());
526 EXPECT_EQ(1 , entry_records[0].cache_id); 529 EXPECT_EQ(1 , entry_records[0].cache_id);
527 EXPECT_EQ(kEntryUrl, entry_records[0].url); 530 EXPECT_EQ(kEntryUrl, entry_records[0].url);
528 EXPECT_EQ(AppCacheEntry::MASTER, entry_records[0].flags); 531 EXPECT_EQ(AppCacheEntry::MASTER, entry_records[0].flags);
529 EXPECT_EQ(1, entry_records[0].response_id); 532 EXPECT_EQ(1, entry_records[0].response_id);
530 EXPECT_EQ(100, entry_records[0].response_size); 533 EXPECT_EQ(100, entry_records[0].response_size);
531 534
532 TestFinished(); 535 TestFinished();
533 } 536 }
534 537
538 // FailStoreGroup --------------------------------------
539
540 void FailStoreGroup() {
541 // Store a group and its newest cache. Should complete asyncly.
542 PushNextTask(NewRunnableMethod(
543 this, &AppCacheStorageImplTest::Verify_FailStoreGroup));
544
545 // Set a low quota to force a failure.
546 const GURL kOrigin(kManifestUrl.GetOrigin());
547 EXPECT_EQ(-1L, storage()->GetOriginQuotaInMemory(kOrigin));
548 storage()->SetOriginQuotaInMemory(kManifestUrl.GetOrigin(), 0);
549 EXPECT_EQ(0L, storage()->GetOriginQuotaInMemory(kOrigin));
550
551 // Setup some preconditions. Create a group and newest cache that
552 // appear to be "unstored".
553 group_ = new AppCacheGroup(
554 service(), kManifestUrl, storage()->NewGroupId());
555 cache_ = new AppCache(service(), storage()->NewCacheId());
556 cache_->AddEntry(kManifestUrl,
557 AppCacheEntry(AppCacheEntry::MANIFEST, 1, 1024));
558 // Hold a ref to the cache simulate the UpdateJob holding that ref,
559 // and hold a ref to the group to simulate the CacheHost holding that ref.
560
561 // Conduct the store test.
562 storage()->StoreGroupAndNewestCache(group_, cache_, delegate());
563 EXPECT_FALSE(delegate()->stored_group_success_); // Expected to be async.
564 }
565
566 void Verify_FailStoreGroup() {
567 EXPECT_FALSE(delegate()->stored_group_success_);
568 EXPECT_TRUE(delegate()->would_exceed_quota_);
569
570 // Should not have been stored in the database.
571 AppCacheDatabase::GroupRecord group_record;
572 AppCacheDatabase::CacheRecord cache_record;
573 EXPECT_FALSE(database()->FindGroup(group_->group_id(), &group_record));
574 EXPECT_FALSE(database()->FindCache(cache_->cache_id(), &cache_record));
575
576 const GURL kOrigin(kManifestUrl.GetOrigin());
577 storage()->ResetOriginQuotaInMemory(kOrigin);
578 EXPECT_EQ(-1L, storage()->GetOriginQuotaInMemory(kOrigin));
579
580 TestFinished();
581 }
582
535 // MakeGroupObsolete ------------------------------- 583 // MakeGroupObsolete -------------------------------
536 584
537 void MakeGroupObsolete() { 585 void MakeGroupObsolete() {
538 // Make a group obsolete, should complete asyncly. 586 // Make a group obsolete, should complete asyncly.
539 PushNextTask(NewRunnableMethod( 587 PushNextTask(NewRunnableMethod(
540 this, &AppCacheStorageImplTest::Verify_MakeGroupObsolete)); 588 this, &AppCacheStorageImplTest::Verify_MakeGroupObsolete));
541 589
542 // Setup some preconditions. Create a group and newest cache that 590 // Setup some preconditions. Create a group and newest cache that
543 // appears to be "stored" and "currently in use". 591 // appears to be "stored" and "currently in use".
544 MakeCacheAndGroup(kManifestUrl, 1, 1, true); 592 MakeCacheAndGroup(kManifestUrl, 1, 1, true);
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 } 1047 }
1000 1048
1001 TEST_F(AppCacheStorageImplTest, StoreExistingGroup) { 1049 TEST_F(AppCacheStorageImplTest, StoreExistingGroup) {
1002 RunTestOnIOThread(&AppCacheStorageImplTest::StoreExistingGroup); 1050 RunTestOnIOThread(&AppCacheStorageImplTest::StoreExistingGroup);
1003 } 1051 }
1004 1052
1005 TEST_F(AppCacheStorageImplTest, StoreExistingGroupExistingCache) { 1053 TEST_F(AppCacheStorageImplTest, StoreExistingGroupExistingCache) {
1006 RunTestOnIOThread(&AppCacheStorageImplTest::StoreExistingGroupExistingCache); 1054 RunTestOnIOThread(&AppCacheStorageImplTest::StoreExistingGroupExistingCache);
1007 } 1055 }
1008 1056
1057 TEST_F(AppCacheStorageImplTest, FailStoreGroup) {
1058 RunTestOnIOThread(&AppCacheStorageImplTest::FailStoreGroup);
1059 }
1060
1009 TEST_F(AppCacheStorageImplTest, MakeGroupObsolete) { 1061 TEST_F(AppCacheStorageImplTest, MakeGroupObsolete) {
1010 RunTestOnIOThread(&AppCacheStorageImplTest::MakeGroupObsolete); 1062 RunTestOnIOThread(&AppCacheStorageImplTest::MakeGroupObsolete);
1011 } 1063 }
1012 1064
1013 TEST_F(AppCacheStorageImplTest, MarkEntryAsForeign) { 1065 TEST_F(AppCacheStorageImplTest, MarkEntryAsForeign) {
1014 RunTestOnIOThread(&AppCacheStorageImplTest::MarkEntryAsForeign); 1066 RunTestOnIOThread(&AppCacheStorageImplTest::MarkEntryAsForeign);
1015 } 1067 }
1016 1068
1017 TEST_F(AppCacheStorageImplTest, MarkEntryAsForeignWithLoadInProgress) { 1069 TEST_F(AppCacheStorageImplTest, MarkEntryAsForeignWithLoadInProgress) {
1018 RunTestOnIOThread( 1070 RunTestOnIOThread(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); 1115 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet);
1064 } 1116 }
1065 1117
1066 // That's all folks! 1118 // That's all folks!
1067 1119
1068 } // namespace appcache 1120 } // namespace appcache
1069 1121
1070 // AppCacheStorageImplTest is expected to always live longer than the 1122 // AppCacheStorageImplTest is expected to always live longer than the
1071 // runnable methods. This lets us call NewRunnableMethod on its instances. 1123 // runnable methods. This lets us call NewRunnableMethod on its instances.
1072 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest); 1124 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest);
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_storage_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698