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

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

Issue 4807001: AppCache: Alter the relative priorities of online vs fallback namespaces. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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
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 13 matching lines...) Expand all
24 24
25 const base::Time kZeroTime; 25 const base::Time kZeroTime;
26 const GURL kManifestUrl("http://blah/manifest"); 26 const GURL kManifestUrl("http://blah/manifest");
27 const GURL kManifestUrl2("http://blah/manifest2"); 27 const GURL kManifestUrl2("http://blah/manifest2");
28 const GURL kEntryUrl("http://blah/entry"); 28 const GURL kEntryUrl("http://blah/entry");
29 const GURL kEntryUrl2("http://blah/entry2"); 29 const GURL kEntryUrl2("http://blah/entry2");
30 const GURL kFallbackNamespace("http://blah/fallback_namespace/"); 30 const GURL kFallbackNamespace("http://blah/fallback_namespace/");
31 const GURL kFallbackNamespace2("http://blah/fallback_namespace/longer"); 31 const GURL kFallbackNamespace2("http://blah/fallback_namespace/longer");
32 const GURL kFallbackTestUrl("http://blah/fallback_namespace/longer/test"); 32 const GURL kFallbackTestUrl("http://blah/fallback_namespace/longer/test");
33 const GURL kOnlineNamespace("http://blah/online_namespace"); 33 const GURL kOnlineNamespace("http://blah/online_namespace");
34 const GURL kOnlineNamespaceWithinFallback(
35 "http://blah/fallback_namespace/online/");
34 36
35 // For the duration of this test case, we hijack the AppCacheThread API 37 // For the duration of this test case, we hijack the AppCacheThread API
36 // calls and implement them in terms of the io and db threads created here. 38 // calls and implement them in terms of the io and db threads created here.
37 39
38 scoped_ptr<base::Thread> io_thread; 40 scoped_ptr<base::Thread> io_thread;
39 scoped_ptr<base::Thread> db_thread; 41 scoped_ptr<base::Thread> db_thread;
40 42
41 class TestThreadProvider : public SimpleAppCacheSystem::ThreadProvider { 43 class TestThreadProvider : public SimpleAppCacheSystem::ThreadProvider {
42 public: 44 public:
43 virtual bool PostTask( 45 virtual bool PostTask(
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 void FindMainResponseExclusionsInDatabase() { 921 void FindMainResponseExclusionsInDatabase() {
920 FindMainResponseExclusions(true); 922 FindMainResponseExclusions(true);
921 } 923 }
922 924
923 void FindMainResponseExclusionsInWorkingSet() { 925 void FindMainResponseExclusionsInWorkingSet() {
924 FindMainResponseExclusions(false); 926 FindMainResponseExclusions(false);
925 } 927 }
926 928
927 void FindMainResponseExclusions(bool drop_from_working_set) { 929 void FindMainResponseExclusions(bool drop_from_working_set) {
928 // Setup some preconditions. Create a complete cache with a 930 // Setup some preconditions. Create a complete cache with a
929 // foreign entry and an online namespace. 931 // foreign entry, an online namespace, and a second online
932 // namespace nested within a fallback namespace.
930 MakeCacheAndGroup(kManifestUrl, 1, 1, true); 933 MakeCacheAndGroup(kManifestUrl, 1, 1, true);
931 cache_->AddEntry(kEntryUrl, 934 cache_->AddEntry(kEntryUrl,
932 AppCacheEntry(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN, 1)); 935 AppCacheEntry(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN, 1));
933 cache_->online_whitelist_namespaces_.push_back(kOnlineNamespace); 936 cache_->online_whitelist_namespaces_.push_back(kOnlineNamespace);
937 cache_->AddEntry(kEntryUrl2, AppCacheEntry(AppCacheEntry::FALLBACK, 2));
938 cache_->fallback_namespaces_.push_back(
939 FallbackNamespace(kFallbackNamespace, kEntryUrl2));
940 cache_->online_whitelist_namespaces_.push_back(kOnlineNamespace);
941 cache_->online_whitelist_namespaces_.push_back(
942 kOnlineNamespaceWithinFallback);
943
934 AppCacheDatabase::EntryRecord entry_record; 944 AppCacheDatabase::EntryRecord entry_record;
935 entry_record.cache_id = 1; 945 entry_record.cache_id = 1;
936 entry_record.url = kEntryUrl; 946 entry_record.url = kEntryUrl;
937 entry_record.flags = AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN; 947 entry_record.flags = AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN;
938 entry_record.response_id = 1; 948 entry_record.response_id = 1;
939 EXPECT_TRUE(database()->InsertEntry(&entry_record)); 949 EXPECT_TRUE(database()->InsertEntry(&entry_record));
940 AppCacheDatabase::OnlineWhiteListRecord whitelist_record; 950 AppCacheDatabase::OnlineWhiteListRecord whitelist_record;
941 whitelist_record.cache_id = 1; 951 whitelist_record.cache_id = 1;
942 whitelist_record.namespace_url = kOnlineNamespace; 952 whitelist_record.namespace_url = kOnlineNamespace;
943 EXPECT_TRUE(database()->InsertOnlineWhiteList(&whitelist_record)); 953 EXPECT_TRUE(database()->InsertOnlineWhiteList(&whitelist_record));
954 AppCacheDatabase::FallbackNameSpaceRecord fallback_namespace_record;
955 fallback_namespace_record.cache_id = 1;
956 fallback_namespace_record.fallback_entry_url = kEntryUrl2;
957 fallback_namespace_record.namespace_url = kFallbackNamespace;
958 fallback_namespace_record.origin = kManifestUrl.GetOrigin();
959 EXPECT_TRUE(
960 database()->InsertFallbackNameSpace(&fallback_namespace_record));
961 whitelist_record.cache_id = 1;
962 whitelist_record.namespace_url = kOnlineNamespaceWithinFallback;
963 EXPECT_TRUE(database()->InsertOnlineWhiteList(&whitelist_record));
944 if (drop_from_working_set) { 964 if (drop_from_working_set) {
945 cache_ = NULL; 965 cache_ = NULL;
946 group_ = NULL; 966 group_ = NULL;
947 } 967 }
948 968
949 // We should not find anything for the foreign entry. 969 // We should not find anything for the foreign entry.
950 PushNextTask(NewRunnableMethod( 970 PushNextTask(NewRunnableMethod(
951 this, &AppCacheStorageImplTest::Verify_NotFound, kEntryUrl, false)); 971 this, &AppCacheStorageImplTest::Verify_ExclusionNotFound,
972 kEntryUrl, 1));
952 storage()->FindResponseForMainRequest(kEntryUrl, delegate()); 973 storage()->FindResponseForMainRequest(kEntryUrl, delegate());
953 } 974 }
954 975
955 void Verify_NotFound(GURL expected_url, bool test_finished) { 976 void Verify_ExclusionNotFound(GURL expected_url, int phase) {
956 EXPECT_EQ(expected_url, delegate()->found_url_); 977 EXPECT_EQ(expected_url, delegate()->found_url_);
957 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty()); 978 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty());
958 EXPECT_FALSE(delegate()->found_blocked_by_policy_); 979 EXPECT_FALSE(delegate()->found_blocked_by_policy_);
959 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); 980 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_);
960 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); 981 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id());
961 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); 982 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id());
962 EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); 983 EXPECT_TRUE(delegate()->found_fallback_url_.is_empty());
963 EXPECT_EQ(0, delegate()->found_entry_.types()); 984 EXPECT_EQ(0, delegate()->found_entry_.types());
964 EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); 985 EXPECT_EQ(0, delegate()->found_fallback_entry_.types());
965 986
966 if (!test_finished) { 987 if (phase == 1) {
967 // We should not find anything for the online namespace. 988 // We should not find anything for the online namespace.
968 PushNextTask(NewRunnableMethod(this, 989 PushNextTask(NewRunnableMethod(this,
969 &AppCacheStorageImplTest::Verify_NotFound, kOnlineNamespace, true)); 990 &AppCacheStorageImplTest::Verify_ExclusionNotFound,
991 kOnlineNamespace, 2));
970 storage()->FindResponseForMainRequest(kOnlineNamespace, delegate()); 992 storage()->FindResponseForMainRequest(kOnlineNamespace, delegate());
971 return; 993 return;
972 } 994 }
995 if (phase == 2) {
996 // We should not find anything for the online namespace nested in the
997 // in the fallback namespace.
kinuko 2010/11/19 00:28:51 nit: 'in the' is duplicated?
998 PushNextTask(NewRunnableMethod(this,
999 &AppCacheStorageImplTest::Verify_ExclusionNotFound,
1000 kOnlineNamespaceWithinFallback, 3));
1001 storage()->FindResponseForMainRequest(
1002 kOnlineNamespaceWithinFallback, delegate());
1003 return;
1004 }
973 1005
974 TestFinished(); 1006 TestFinished();
975 } 1007 }
976 1008
977 // Test case helpers -------------------------------------------------- 1009 // Test case helpers --------------------------------------------------
978 1010
979 AppCacheService* service() { 1011 AppCacheService* service() {
980 return service_.get(); 1012 return service_.get();
981 } 1013 }
982 1014
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); 1153 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet);
1122 } 1154 }
1123 1155
1124 // That's all folks! 1156 // That's all folks!
1125 1157
1126 } // namespace appcache 1158 } // namespace appcache
1127 1159
1128 // AppCacheStorageImplTest is expected to always live longer than the 1160 // AppCacheStorageImplTest is expected to always live longer than the
1129 // runnable methods. This lets us call NewRunnableMethod on its instances. 1161 // runnable methods. This lets us call NewRunnableMethod on its instances.
1130 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest); 1162 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698