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" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "webkit/appcache/appcache.h" | 12 #include "webkit/appcache/appcache.h" |
13 #include "webkit/appcache/appcache_database.h" | 13 #include "webkit/appcache/appcache_database.h" |
14 #include "webkit/appcache/appcache_entry.h" | 14 #include "webkit/appcache/appcache_entry.h" |
15 #include "webkit/appcache/appcache_group.h" | 15 #include "webkit/appcache/appcache_group.h" |
16 #include "webkit/appcache/appcache_policy.h" | |
17 #include "webkit/appcache/appcache_service.h" | 16 #include "webkit/appcache/appcache_service.h" |
18 #include "webkit/appcache/appcache_storage_impl.h" | 17 #include "webkit/appcache/appcache_storage_impl.h" |
19 #include "webkit/quota/quota_manager.h" | 18 #include "webkit/quota/quota_manager.h" |
20 #include "webkit/tools/test_shell/simple_appcache_system.h" | 19 #include "webkit/tools/test_shell/simple_appcache_system.h" |
21 | 20 |
22 namespace appcache { | 21 namespace appcache { |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 const base::Time kZeroTime; | 25 const base::Time kZeroTime; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 80 |
82 } // namespace | 81 } // namespace |
83 | 82 |
84 class AppCacheStorageImplTest : public testing::Test { | 83 class AppCacheStorageImplTest : public testing::Test { |
85 public: | 84 public: |
86 class MockStorageDelegate : public AppCacheStorage::Delegate { | 85 class MockStorageDelegate : public AppCacheStorage::Delegate { |
87 public: | 86 public: |
88 explicit MockStorageDelegate(AppCacheStorageImplTest* test) | 87 explicit MockStorageDelegate(AppCacheStorageImplTest* test) |
89 : loaded_cache_id_(0), stored_group_success_(false), | 88 : loaded_cache_id_(0), stored_group_success_(false), |
90 would_exceed_quota_(false), obsoleted_success_(false), | 89 would_exceed_quota_(false), obsoleted_success_(false), |
91 found_cache_id_(kNoCacheId), found_blocked_by_policy_(false), | 90 found_cache_id_(kNoCacheId), test_(test) { |
92 test_(test) { | |
93 } | 91 } |
94 | 92 |
95 void OnCacheLoaded(AppCache* cache, int64 cache_id) { | 93 void OnCacheLoaded(AppCache* cache, int64 cache_id) { |
96 loaded_cache_ = cache; | 94 loaded_cache_ = cache; |
97 loaded_cache_id_ = cache_id; | 95 loaded_cache_id_ = cache_id; |
98 test_->ScheduleNextTask(); | 96 test_->ScheduleNextTask(); |
99 } | 97 } |
100 | 98 |
101 void OnGroupLoaded(AppCacheGroup* group, const GURL& manifest_url) { | 99 void OnGroupLoaded(AppCacheGroup* group, const GURL& manifest_url) { |
102 loaded_group_ = group; | 100 loaded_group_ = group; |
(...skipping 14 matching lines...) Expand all Loading... |
117 | 115 |
118 void OnGroupMadeObsolete(AppCacheGroup* group, bool success) { | 116 void OnGroupMadeObsolete(AppCacheGroup* group, bool success) { |
119 obsoleted_group_ = group; | 117 obsoleted_group_ = group; |
120 obsoleted_success_ = success; | 118 obsoleted_success_ = success; |
121 test_->ScheduleNextTask(); | 119 test_->ScheduleNextTask(); |
122 } | 120 } |
123 | 121 |
124 void OnMainResponseFound(const GURL& url, const AppCacheEntry& entry, | 122 void OnMainResponseFound(const GURL& url, const AppCacheEntry& entry, |
125 const GURL& fallback_url, | 123 const GURL& fallback_url, |
126 const AppCacheEntry& fallback_entry, | 124 const AppCacheEntry& fallback_entry, |
127 int64 cache_id, const GURL& manifest_url, | 125 int64 cache_id, const GURL& manifest_url) { |
128 bool was_blocked_by_policy) { | |
129 found_url_ = url; | 126 found_url_ = url; |
130 found_entry_ = entry; | 127 found_entry_ = entry; |
131 found_fallback_url_ = fallback_url; | 128 found_fallback_url_ = fallback_url; |
132 found_fallback_entry_ = fallback_entry; | 129 found_fallback_entry_ = fallback_entry; |
133 found_cache_id_ = cache_id; | 130 found_cache_id_ = cache_id; |
134 found_manifest_url_ = manifest_url; | 131 found_manifest_url_ = manifest_url; |
135 found_blocked_by_policy_ = was_blocked_by_policy; | |
136 test_->ScheduleNextTask(); | 132 test_->ScheduleNextTask(); |
137 } | 133 } |
138 | 134 |
139 scoped_refptr<AppCache> loaded_cache_; | 135 scoped_refptr<AppCache> loaded_cache_; |
140 int64 loaded_cache_id_; | 136 int64 loaded_cache_id_; |
141 scoped_refptr<AppCacheGroup> loaded_group_; | 137 scoped_refptr<AppCacheGroup> loaded_group_; |
142 GURL loaded_manifest_url_; | 138 GURL loaded_manifest_url_; |
143 scoped_refptr<AppCache> loaded_groups_newest_cache_; | 139 scoped_refptr<AppCache> loaded_groups_newest_cache_; |
144 scoped_refptr<AppCacheGroup> stored_group_; | 140 scoped_refptr<AppCacheGroup> stored_group_; |
145 bool stored_group_success_; | 141 bool stored_group_success_; |
146 bool would_exceed_quota_; | 142 bool would_exceed_quota_; |
147 scoped_refptr<AppCacheGroup> obsoleted_group_; | 143 scoped_refptr<AppCacheGroup> obsoleted_group_; |
148 bool obsoleted_success_; | 144 bool obsoleted_success_; |
149 GURL found_url_; | 145 GURL found_url_; |
150 AppCacheEntry found_entry_; | 146 AppCacheEntry found_entry_; |
151 GURL found_fallback_url_; | 147 GURL found_fallback_url_; |
152 AppCacheEntry found_fallback_entry_; | 148 AppCacheEntry found_fallback_entry_; |
153 int64 found_cache_id_; | 149 int64 found_cache_id_; |
154 GURL found_manifest_url_; | 150 GURL found_manifest_url_; |
155 bool found_blocked_by_policy_; | |
156 AppCacheStorageImplTest* test_; | 151 AppCacheStorageImplTest* test_; |
157 }; | 152 }; |
158 | 153 |
159 class MockAppCachePolicy : public AppCachePolicy { | |
160 public: | |
161 explicit MockAppCachePolicy(AppCacheStorageImplTest* test) | |
162 : can_load_return_value_(true), can_create_return_value_(0), | |
163 callback_(NULL), test_(test) { | |
164 } | |
165 | |
166 virtual bool CanLoadAppCache(const GURL& manifest_url) { | |
167 requested_manifest_url_ = manifest_url; | |
168 return can_load_return_value_; | |
169 } | |
170 | |
171 virtual int CanCreateAppCache(const GURL& manifest_url, | |
172 net::CompletionCallback* callback) { | |
173 requested_manifest_url_ = manifest_url; | |
174 callback_ = callback; | |
175 if (can_create_return_value_ == net::ERR_IO_PENDING) | |
176 test_->ScheduleNextTask(); | |
177 return can_create_return_value_; | |
178 } | |
179 | |
180 bool can_load_return_value_; | |
181 int can_create_return_value_; | |
182 GURL requested_manifest_url_; | |
183 net::CompletionCallback* callback_; | |
184 AppCacheStorageImplTest* test_; | |
185 }; | |
186 | |
187 class MockQuotaManager : public quota::QuotaManager { | 154 class MockQuotaManager : public quota::QuotaManager { |
188 public: | 155 public: |
189 MockQuotaManager() | 156 MockQuotaManager() |
190 : QuotaManager(true /* is_incognito */, FilePath(), | 157 : QuotaManager(true /* is_incognito */, FilePath(), |
191 io_thread->message_loop_proxy(), | 158 io_thread->message_loop_proxy(), |
192 db_thread->message_loop_proxy(), | 159 db_thread->message_loop_proxy(), |
193 NULL), | 160 NULL), |
194 async_(false) {} | 161 async_(false) {} |
195 | 162 |
196 virtual void GetUsageAndQuota( | 163 virtual void GetUsageAndQuota( |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 } | 269 } |
303 | 270 |
304 static void TearDownTestCase() { | 271 static void TearDownTestCase() { |
305 SimpleAppCacheSystem::set_thread_provider(NULL); | 272 SimpleAppCacheSystem::set_thread_provider(NULL); |
306 io_thread.reset(NULL); | 273 io_thread.reset(NULL); |
307 db_thread.reset(NULL); | 274 db_thread.reset(NULL); |
308 } | 275 } |
309 | 276 |
310 // Test harness -------------------------------------------------- | 277 // Test harness -------------------------------------------------- |
311 | 278 |
312 AppCacheStorageImplTest() | 279 AppCacheStorageImplTest() { |
313 : ALLOW_THIS_IN_INITIALIZER_LIST(policy_(this)) { | |
314 } | 280 } |
315 | 281 |
316 template <class Method> | 282 template <class Method> |
317 void RunTestOnIOThread(Method method) { | 283 void RunTestOnIOThread(Method method) { |
318 test_finished_event_ .reset(new base::WaitableEvent(false, false)); | 284 test_finished_event_ .reset(new base::WaitableEvent(false, false)); |
319 io_thread->message_loop()->PostTask( | 285 io_thread->message_loop()->PostTask( |
320 FROM_HERE, new WrapperTask<Method>(this, method)); | 286 FROM_HERE, new WrapperTask<Method>(this, method)); |
321 test_finished_event_->Wait(); | 287 test_finished_event_->Wait(); |
322 } | 288 } |
323 | 289 |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 PushNextTask(NewRunnableMethod( | 829 PushNextTask(NewRunnableMethod( |
864 this, &AppCacheStorageImplTest::Verify_FindNoMainResponse)); | 830 this, &AppCacheStorageImplTest::Verify_FindNoMainResponse)); |
865 | 831 |
866 // Conduct the test. | 832 // Conduct the test. |
867 storage()->FindResponseForMainRequest(kEntryUrl, GURL(), delegate()); | 833 storage()->FindResponseForMainRequest(kEntryUrl, GURL(), delegate()); |
868 EXPECT_NE(kEntryUrl, delegate()->found_url_); | 834 EXPECT_NE(kEntryUrl, delegate()->found_url_); |
869 } | 835 } |
870 | 836 |
871 void Verify_FindNoMainResponse() { | 837 void Verify_FindNoMainResponse() { |
872 EXPECT_EQ(kEntryUrl, delegate()->found_url_); | 838 EXPECT_EQ(kEntryUrl, delegate()->found_url_); |
873 // If the request was blocked by a policy, the manifest url is still valid. | 839 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty()); |
874 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty() || | |
875 delegate()->found_blocked_by_policy_); | |
876 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); | 840 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); |
877 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); | 841 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); |
878 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); | 842 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); |
879 EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); | 843 EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); |
880 EXPECT_EQ(0, delegate()->found_entry_.types()); | 844 EXPECT_EQ(0, delegate()->found_entry_.types()); |
881 EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); | 845 EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); |
882 TestFinished(); | 846 TestFinished(); |
883 } | 847 } |
884 | 848 |
885 // BasicFindMainResponse ------------------------------- | 849 // BasicFindMainResponse ------------------------------- |
886 | 850 |
887 void BasicFindMainResponseInDatabase() { | 851 void BasicFindMainResponseInDatabase() { |
888 BasicFindMainResponse(true, false); | 852 BasicFindMainResponse(true); |
889 } | 853 } |
890 | 854 |
891 void BasicFindMainResponseInWorkingSet() { | 855 void BasicFindMainResponseInWorkingSet() { |
892 BasicFindMainResponse(false, false); | 856 BasicFindMainResponse(false); |
893 } | 857 } |
894 | 858 |
895 void BlockFindMainResponseWithPolicyCheck() { | 859 void BasicFindMainResponse(bool drop_from_working_set) { |
896 BasicFindMainResponse(true, true); | |
897 } | |
898 | |
899 void BasicFindMainResponse(bool drop_from_working_set, | |
900 bool block_with_policy_check) { | |
901 PushNextTask(NewRunnableMethod( | 860 PushNextTask(NewRunnableMethod( |
902 this, &AppCacheStorageImplTest::Verify_BasicFindMainResponse)); | 861 this, &AppCacheStorageImplTest::Verify_BasicFindMainResponse)); |
903 | 862 |
904 policy_.can_load_return_value_ = !block_with_policy_check; | |
905 service()->set_appcache_policy(&policy_); | |
906 | |
907 // Setup some preconditions. Create a complete cache with an entry | 863 // Setup some preconditions. Create a complete cache with an entry |
908 // in storage. | 864 // in storage. |
909 MakeCacheAndGroup(kManifestUrl, 1, 1, true); | 865 MakeCacheAndGroup(kManifestUrl, 1, 1, true); |
910 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, 1)); | 866 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, 1)); |
911 AppCacheDatabase::EntryRecord entry_record; | 867 AppCacheDatabase::EntryRecord entry_record; |
912 entry_record.cache_id = 1; | 868 entry_record.cache_id = 1; |
913 entry_record.url = kEntryUrl; | 869 entry_record.url = kEntryUrl; |
914 entry_record.flags = AppCacheEntry::EXPLICIT; | 870 entry_record.flags = AppCacheEntry::EXPLICIT; |
915 entry_record.response_id = 1; | 871 entry_record.response_id = 1; |
916 EXPECT_TRUE(database()->InsertEntry(&entry_record)); | 872 EXPECT_TRUE(database()->InsertEntry(&entry_record)); |
917 | 873 |
918 // Optionally drop the cache/group pair from the working set. | 874 // Optionally drop the cache/group pair from the working set. |
919 if (drop_from_working_set) { | 875 if (drop_from_working_set) { |
920 EXPECT_TRUE(cache_->HasOneRef()); | 876 EXPECT_TRUE(cache_->HasOneRef()); |
921 cache_ = NULL; | 877 cache_ = NULL; |
922 EXPECT_TRUE(group_->HasOneRef()); | 878 EXPECT_TRUE(group_->HasOneRef()); |
923 group_ = NULL; | 879 group_ = NULL; |
924 } | 880 } |
925 | 881 |
926 // Conduct the test. | 882 // Conduct the test. |
927 storage()->FindResponseForMainRequest(kEntryUrl, GURL(), delegate()); | 883 storage()->FindResponseForMainRequest(kEntryUrl, GURL(), delegate()); |
928 EXPECT_NE(kEntryUrl, delegate()->found_url_); | 884 EXPECT_NE(kEntryUrl, delegate()->found_url_); |
929 } | 885 } |
930 | 886 |
931 void Verify_BasicFindMainResponse() { | 887 void Verify_BasicFindMainResponse() { |
932 EXPECT_EQ(kManifestUrl, policy_.requested_manifest_url_); | 888 EXPECT_EQ(kEntryUrl, delegate()->found_url_); |
933 if (policy_.can_load_return_value_) { | 889 EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_); |
934 EXPECT_EQ(kEntryUrl, delegate()->found_url_); | 890 EXPECT_EQ(1, delegate()->found_cache_id_); |
935 EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_); | 891 EXPECT_EQ(1, delegate()->found_entry_.response_id()); |
936 EXPECT_FALSE(delegate()->found_blocked_by_policy_); | 892 EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); |
937 EXPECT_EQ(1, delegate()->found_cache_id_); | 893 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); |
938 EXPECT_EQ(1, delegate()->found_entry_.response_id()); | 894 TestFinished(); |
939 EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); | |
940 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); | |
941 TestFinished(); | |
942 } else { | |
943 Verify_FindNoMainResponse(); | |
944 } | |
945 } | 895 } |
946 | 896 |
947 // BasicFindMainFallbackResponse ------------------------------- | 897 // BasicFindMainFallbackResponse ------------------------------- |
948 | 898 |
949 void BasicFindMainFallbackResponseInDatabase() { | 899 void BasicFindMainFallbackResponseInDatabase() { |
950 BasicFindMainFallbackResponse(true); | 900 BasicFindMainFallbackResponse(true); |
951 } | 901 } |
952 | 902 |
953 void BasicFindMainFallbackResponseInWorkingSet() { | 903 void BasicFindMainFallbackResponseInWorkingSet() { |
954 BasicFindMainFallbackResponse(false); | 904 BasicFindMainFallbackResponse(false); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 | 944 |
995 // Conduct the test. The test url is in both fallback namespace urls, | 945 // Conduct the test. The test url is in both fallback namespace urls, |
996 // but should match the longer of the two. | 946 // but should match the longer of the two. |
997 storage()->FindResponseForMainRequest(kFallbackTestUrl, GURL(), delegate()); | 947 storage()->FindResponseForMainRequest(kFallbackTestUrl, GURL(), delegate()); |
998 EXPECT_NE(kFallbackTestUrl, delegate()->found_url_); | 948 EXPECT_NE(kFallbackTestUrl, delegate()->found_url_); |
999 } | 949 } |
1000 | 950 |
1001 void Verify_BasicFindMainFallbackResponse() { | 951 void Verify_BasicFindMainFallbackResponse() { |
1002 EXPECT_EQ(kFallbackTestUrl, delegate()->found_url_); | 952 EXPECT_EQ(kFallbackTestUrl, delegate()->found_url_); |
1003 EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_); | 953 EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_); |
1004 EXPECT_FALSE(delegate()->found_blocked_by_policy_); | |
1005 EXPECT_EQ(1, delegate()->found_cache_id_); | 954 EXPECT_EQ(1, delegate()->found_cache_id_); |
1006 EXPECT_FALSE(delegate()->found_entry_.has_response_id()); | 955 EXPECT_FALSE(delegate()->found_entry_.has_response_id()); |
1007 EXPECT_EQ(2, delegate()->found_fallback_entry_.response_id()); | 956 EXPECT_EQ(2, delegate()->found_fallback_entry_.response_id()); |
1008 EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); | 957 EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); |
1009 EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); | 958 EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); |
1010 TestFinished(); | 959 TestFinished(); |
1011 } | 960 } |
1012 | 961 |
1013 // FindMainResponseWithMultipleHits ------------------------------- | 962 // FindMainResponseWithMultipleHits ------------------------------- |
1014 | 963 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 fallback_namespace_record.origin = manifest_url.GetOrigin(); | 1018 fallback_namespace_record.origin = manifest_url.GetOrigin(); |
1070 EXPECT_TRUE( | 1019 EXPECT_TRUE( |
1071 database()->InsertFallbackNameSpace(&fallback_namespace_record)); | 1020 database()->InsertFallbackNameSpace(&fallback_namespace_record)); |
1072 cache_->fallback_namespaces_.push_back( | 1021 cache_->fallback_namespaces_.push_back( |
1073 FallbackNamespace(kFallbackNamespace, kEntryUrl2)); | 1022 FallbackNamespace(kFallbackNamespace, kEntryUrl2)); |
1074 } | 1023 } |
1075 | 1024 |
1076 void Verify_FindMainResponseWithMultipleHits() { | 1025 void Verify_FindMainResponseWithMultipleHits() { |
1077 EXPECT_EQ(kEntryUrl, delegate()->found_url_); | 1026 EXPECT_EQ(kEntryUrl, delegate()->found_url_); |
1078 EXPECT_EQ(kManifestUrl3, delegate()->found_manifest_url_); | 1027 EXPECT_EQ(kManifestUrl3, delegate()->found_manifest_url_); |
1079 EXPECT_FALSE(delegate()->found_blocked_by_policy_); | |
1080 EXPECT_EQ(3, delegate()->found_cache_id_); | 1028 EXPECT_EQ(3, delegate()->found_cache_id_); |
1081 EXPECT_EQ(3, delegate()->found_entry_.response_id()); | 1029 EXPECT_EQ(3, delegate()->found_entry_.response_id()); |
1082 EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); | 1030 EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); |
1083 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); | 1031 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); |
1084 | 1032 |
1085 // Conduct another test perferring kManifestUrl | 1033 // Conduct another test perferring kManifestUrl |
1086 delegate_.reset(new MockStorageDelegate(this)); | 1034 delegate_.reset(new MockStorageDelegate(this)); |
1087 PushNextTask(NewRunnableMethod(this, | 1035 PushNextTask(NewRunnableMethod(this, |
1088 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits2)); | 1036 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits2)); |
1089 storage()->FindResponseForMainRequest(kEntryUrl, kManifestUrl, delegate()); | 1037 storage()->FindResponseForMainRequest(kEntryUrl, kManifestUrl, delegate()); |
1090 EXPECT_NE(kEntryUrl, delegate()->found_url_); | 1038 EXPECT_NE(kEntryUrl, delegate()->found_url_); |
1091 } | 1039 } |
1092 | 1040 |
1093 void Verify_FindMainResponseWithMultipleHits2() { | 1041 void Verify_FindMainResponseWithMultipleHits2() { |
1094 EXPECT_EQ(kEntryUrl, delegate()->found_url_); | 1042 EXPECT_EQ(kEntryUrl, delegate()->found_url_); |
1095 EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_); | 1043 EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_); |
1096 EXPECT_FALSE(delegate()->found_blocked_by_policy_); | |
1097 EXPECT_EQ(1, delegate()->found_cache_id_); | 1044 EXPECT_EQ(1, delegate()->found_cache_id_); |
1098 EXPECT_EQ(1, delegate()->found_entry_.response_id()); | 1045 EXPECT_EQ(1, delegate()->found_entry_.response_id()); |
1099 EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); | 1046 EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); |
1100 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); | 1047 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); |
1101 | 1048 |
1102 // Conduct the another test perferring kManifestUrl2 | 1049 // Conduct the another test perferring kManifestUrl2 |
1103 delegate_.reset(new MockStorageDelegate(this)); | 1050 delegate_.reset(new MockStorageDelegate(this)); |
1104 PushNextTask(NewRunnableMethod(this, | 1051 PushNextTask(NewRunnableMethod(this, |
1105 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits3)); | 1052 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits3)); |
1106 storage()->FindResponseForMainRequest(kEntryUrl, kManifestUrl2, delegate()); | 1053 storage()->FindResponseForMainRequest(kEntryUrl, kManifestUrl2, delegate()); |
1107 EXPECT_NE(kEntryUrl, delegate()->found_url_); | 1054 EXPECT_NE(kEntryUrl, delegate()->found_url_); |
1108 } | 1055 } |
1109 | 1056 |
1110 void Verify_FindMainResponseWithMultipleHits3() { | 1057 void Verify_FindMainResponseWithMultipleHits3() { |
1111 EXPECT_EQ(kEntryUrl, delegate()->found_url_); | 1058 EXPECT_EQ(kEntryUrl, delegate()->found_url_); |
1112 EXPECT_EQ(kManifestUrl2, delegate()->found_manifest_url_); | 1059 EXPECT_EQ(kManifestUrl2, delegate()->found_manifest_url_); |
1113 EXPECT_FALSE(delegate()->found_blocked_by_policy_); | |
1114 EXPECT_EQ(2, delegate()->found_cache_id_); | 1060 EXPECT_EQ(2, delegate()->found_cache_id_); |
1115 EXPECT_EQ(2, delegate()->found_entry_.response_id()); | 1061 EXPECT_EQ(2, delegate()->found_entry_.response_id()); |
1116 EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); | 1062 EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); |
1117 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); | 1063 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); |
1118 | 1064 |
1119 // Conduct another test with no preferred manifest that hits the fallback. | 1065 // Conduct another test with no preferred manifest that hits the fallback. |
1120 delegate_.reset(new MockStorageDelegate(this)); | 1066 delegate_.reset(new MockStorageDelegate(this)); |
1121 PushNextTask(NewRunnableMethod(this, | 1067 PushNextTask(NewRunnableMethod(this, |
1122 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits4)); | 1068 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits4)); |
1123 storage()->FindResponseForMainRequest( | 1069 storage()->FindResponseForMainRequest( |
1124 kFallbackTestUrl, GURL(), delegate()); | 1070 kFallbackTestUrl, GURL(), delegate()); |
1125 EXPECT_NE(kFallbackTestUrl, delegate()->found_url_); | 1071 EXPECT_NE(kFallbackTestUrl, delegate()->found_url_); |
1126 } | 1072 } |
1127 | 1073 |
1128 void Verify_FindMainResponseWithMultipleHits4() { | 1074 void Verify_FindMainResponseWithMultipleHits4() { |
1129 EXPECT_EQ(kFallbackTestUrl, delegate()->found_url_); | 1075 EXPECT_EQ(kFallbackTestUrl, delegate()->found_url_); |
1130 EXPECT_EQ(kManifestUrl3, delegate()->found_manifest_url_); | 1076 EXPECT_EQ(kManifestUrl3, delegate()->found_manifest_url_); |
1131 EXPECT_FALSE(delegate()->found_blocked_by_policy_); | |
1132 EXPECT_EQ(3, delegate()->found_cache_id_); | 1077 EXPECT_EQ(3, delegate()->found_cache_id_); |
1133 EXPECT_FALSE(delegate()->found_entry_.has_response_id()); | 1078 EXPECT_FALSE(delegate()->found_entry_.has_response_id()); |
1134 EXPECT_EQ(3 + kFallbackEntryIdOffset, | 1079 EXPECT_EQ(3 + kFallbackEntryIdOffset, |
1135 delegate()->found_fallback_entry_.response_id()); | 1080 delegate()->found_fallback_entry_.response_id()); |
1136 EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); | 1081 EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); |
1137 EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); | 1082 EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); |
1138 | 1083 |
1139 // Conduct another test preferring kManifestUrl2 that hits the fallback. | 1084 // Conduct another test preferring kManifestUrl2 that hits the fallback. |
1140 delegate_.reset(new MockStorageDelegate(this)); | 1085 delegate_.reset(new MockStorageDelegate(this)); |
1141 PushNextTask(NewRunnableMethod(this, | 1086 PushNextTask(NewRunnableMethod(this, |
1142 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits5)); | 1087 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits5)); |
1143 storage()->FindResponseForMainRequest( | 1088 storage()->FindResponseForMainRequest( |
1144 kFallbackTestUrl, kManifestUrl2, delegate()); | 1089 kFallbackTestUrl, kManifestUrl2, delegate()); |
1145 EXPECT_NE(kFallbackTestUrl, delegate()->found_url_); | 1090 EXPECT_NE(kFallbackTestUrl, delegate()->found_url_); |
1146 } | 1091 } |
1147 | 1092 |
1148 void Verify_FindMainResponseWithMultipleHits5() { | 1093 void Verify_FindMainResponseWithMultipleHits5() { |
1149 EXPECT_EQ(kFallbackTestUrl, delegate()->found_url_); | 1094 EXPECT_EQ(kFallbackTestUrl, delegate()->found_url_); |
1150 EXPECT_EQ(kManifestUrl2, delegate()->found_manifest_url_); | 1095 EXPECT_EQ(kManifestUrl2, delegate()->found_manifest_url_); |
1151 EXPECT_FALSE(delegate()->found_blocked_by_policy_); | |
1152 EXPECT_EQ(2, delegate()->found_cache_id_); | 1096 EXPECT_EQ(2, delegate()->found_cache_id_); |
1153 EXPECT_FALSE(delegate()->found_entry_.has_response_id()); | 1097 EXPECT_FALSE(delegate()->found_entry_.has_response_id()); |
1154 EXPECT_EQ(2 + kFallbackEntryIdOffset, | 1098 EXPECT_EQ(2 + kFallbackEntryIdOffset, |
1155 delegate()->found_fallback_entry_.response_id()); | 1099 delegate()->found_fallback_entry_.response_id()); |
1156 EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); | 1100 EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); |
1157 EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); | 1101 EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); |
1158 | 1102 |
1159 TestFinished(); | 1103 TestFinished(); |
1160 } | 1104 } |
1161 | 1105 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 // We should not find anything for the foreign entry. | 1156 // We should not find anything for the foreign entry. |
1213 PushNextTask(NewRunnableMethod( | 1157 PushNextTask(NewRunnableMethod( |
1214 this, &AppCacheStorageImplTest::Verify_ExclusionNotFound, | 1158 this, &AppCacheStorageImplTest::Verify_ExclusionNotFound, |
1215 kEntryUrl, 1)); | 1159 kEntryUrl, 1)); |
1216 storage()->FindResponseForMainRequest(kEntryUrl, GURL(), delegate()); | 1160 storage()->FindResponseForMainRequest(kEntryUrl, GURL(), delegate()); |
1217 } | 1161 } |
1218 | 1162 |
1219 void Verify_ExclusionNotFound(GURL expected_url, int phase) { | 1163 void Verify_ExclusionNotFound(GURL expected_url, int phase) { |
1220 EXPECT_EQ(expected_url, delegate()->found_url_); | 1164 EXPECT_EQ(expected_url, delegate()->found_url_); |
1221 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty()); | 1165 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty()); |
1222 EXPECT_FALSE(delegate()->found_blocked_by_policy_); | |
1223 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); | 1166 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); |
1224 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); | 1167 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); |
1225 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); | 1168 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); |
1226 EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); | 1169 EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); |
1227 EXPECT_EQ(0, delegate()->found_entry_.types()); | 1170 EXPECT_EQ(0, delegate()->found_entry_.types()); |
1228 EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); | 1171 EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); |
1229 | 1172 |
1230 if (phase == 1) { | 1173 if (phase == 1) { |
1231 // We should not find anything for the online namespace. | 1174 // We should not find anything for the online namespace. |
1232 PushNextTask(NewRunnableMethod(this, | 1175 PushNextTask(NewRunnableMethod(this, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 | 1245 |
1303 storage()->usage_map_[manifest_url.GetOrigin()] = | 1246 storage()->usage_map_[manifest_url.GetOrigin()] = |
1304 default_entry.response_size(); | 1247 default_entry.response_size(); |
1305 } | 1248 } |
1306 } | 1249 } |
1307 | 1250 |
1308 // Data members -------------------------------------------------- | 1251 // Data members -------------------------------------------------- |
1309 | 1252 |
1310 scoped_ptr<base::WaitableEvent> test_finished_event_; | 1253 scoped_ptr<base::WaitableEvent> test_finished_event_; |
1311 std::stack<Task*> task_stack_; | 1254 std::stack<Task*> task_stack_; |
1312 MockAppCachePolicy policy_; | |
1313 scoped_ptr<AppCacheService> service_; | 1255 scoped_ptr<AppCacheService> service_; |
1314 scoped_ptr<MockStorageDelegate> delegate_; | 1256 scoped_ptr<MockStorageDelegate> delegate_; |
1315 scoped_refptr<MockQuotaManagerProxy> mock_quota_manager_proxy_; | 1257 scoped_refptr<MockQuotaManagerProxy> mock_quota_manager_proxy_; |
1316 scoped_refptr<AppCacheGroup> group_; | 1258 scoped_refptr<AppCacheGroup> group_; |
1317 scoped_refptr<AppCache> cache_; | 1259 scoped_refptr<AppCache> cache_; |
1318 scoped_refptr<AppCache> cache2_; | 1260 scoped_refptr<AppCache> cache2_; |
1319 }; | 1261 }; |
1320 | 1262 |
1321 | 1263 |
1322 TEST_F(AppCacheStorageImplTest, LoadCache_Miss) { | 1264 TEST_F(AppCacheStorageImplTest, LoadCache_Miss) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 TEST_F(AppCacheStorageImplTest, BasicFindMainResponseInDatabase) { | 1317 TEST_F(AppCacheStorageImplTest, BasicFindMainResponseInDatabase) { |
1376 RunTestOnIOThread( | 1318 RunTestOnIOThread( |
1377 &AppCacheStorageImplTest::BasicFindMainResponseInDatabase); | 1319 &AppCacheStorageImplTest::BasicFindMainResponseInDatabase); |
1378 } | 1320 } |
1379 | 1321 |
1380 TEST_F(AppCacheStorageImplTest, BasicFindMainResponseInWorkingSet) { | 1322 TEST_F(AppCacheStorageImplTest, BasicFindMainResponseInWorkingSet) { |
1381 RunTestOnIOThread( | 1323 RunTestOnIOThread( |
1382 &AppCacheStorageImplTest::BasicFindMainResponseInWorkingSet); | 1324 &AppCacheStorageImplTest::BasicFindMainResponseInWorkingSet); |
1383 } | 1325 } |
1384 | 1326 |
1385 TEST_F(AppCacheStorageImplTest, BlockFindMainResponseWithPolicyCheck) { | |
1386 RunTestOnIOThread( | |
1387 &AppCacheStorageImplTest::BlockFindMainResponseWithPolicyCheck); | |
1388 } | |
1389 | |
1390 TEST_F(AppCacheStorageImplTest, BasicFindMainFallbackResponseInDatabase) { | 1327 TEST_F(AppCacheStorageImplTest, BasicFindMainFallbackResponseInDatabase) { |
1391 RunTestOnIOThread( | 1328 RunTestOnIOThread( |
1392 &AppCacheStorageImplTest::BasicFindMainFallbackResponseInDatabase); | 1329 &AppCacheStorageImplTest::BasicFindMainFallbackResponseInDatabase); |
1393 } | 1330 } |
1394 | 1331 |
1395 TEST_F(AppCacheStorageImplTest, BasicFindMainFallbackResponseInWorkingSet) { | 1332 TEST_F(AppCacheStorageImplTest, BasicFindMainFallbackResponseInWorkingSet) { |
1396 RunTestOnIOThread( | 1333 RunTestOnIOThread( |
1397 &AppCacheStorageImplTest::BasicFindMainFallbackResponseInWorkingSet); | 1334 &AppCacheStorageImplTest::BasicFindMainFallbackResponseInWorkingSet); |
1398 } | 1335 } |
1399 | 1336 |
(...skipping 12 matching lines...) Expand all Loading... |
1412 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); | 1349 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); |
1413 } | 1350 } |
1414 | 1351 |
1415 // That's all folks! | 1352 // That's all folks! |
1416 | 1353 |
1417 } // namespace appcache | 1354 } // namespace appcache |
1418 | 1355 |
1419 // AppCacheStorageImplTest is expected to always live longer than the | 1356 // AppCacheStorageImplTest is expected to always live longer than the |
1420 // runnable methods. This lets us call NewRunnableMethod on its instances. | 1357 // runnable methods. This lets us call NewRunnableMethod on its instances. |
1421 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest); | 1358 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest); |
OLD | NEW |