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

Unified Diff: webkit/appcache/appcache_storage_impl_unittest.cc

Issue 8396013: AppCache INTERCEPT namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/appcache/appcache_storage_impl.cc ('k') | webkit/appcache/appcache_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/appcache/appcache_storage_impl_unittest.cc
===================================================================
--- webkit/appcache/appcache_storage_impl_unittest.cc (revision 113546)
+++ webkit/appcache/appcache_storage_impl_unittest.cc (working copy)
@@ -36,6 +36,9 @@
const GURL kOnlineNamespace("http://blah/online_namespace");
const GURL kOnlineNamespaceWithinFallback(
"http://blah/fallback_namespace/online/");
+const GURL kInterceptNamespace("http://blah/intercept_namespace/");
+const GURL kInterceptNamespace2("http://blah/intercept_namespace/longer/");
+const GURL kInterceptTestUrl("http://blah/intercept_namespace/longer/test");
const GURL kOrigin(kManifestUrl.GetOrigin());
const int kManifestEntryIdOffset = 100;
@@ -668,13 +671,12 @@
entry_record.url = kEntryUrl;
EXPECT_TRUE(database()->InsertEntry(&entry_record));
- AppCacheDatabase::FallbackNameSpaceRecord fallback_namespace_record;
+ AppCacheDatabase::NamespaceRecord fallback_namespace_record;
fallback_namespace_record.cache_id = 1;
- fallback_namespace_record.fallback_entry_url = kEntryUrl;
+ fallback_namespace_record.target_url = kEntryUrl;
fallback_namespace_record.namespace_url = kFallbackNamespace;
fallback_namespace_record.origin = kManifestUrl.GetOrigin();
- EXPECT_TRUE(
- database()->InsertFallbackNameSpace(&fallback_namespace_record));
+ EXPECT_TRUE(database()->InsertNamespace(&fallback_namespace_record));
AppCacheDatabase::OnlineWhiteListRecord online_whitelist_record;
online_whitelist_record.cache_id = 1;
@@ -702,8 +704,10 @@
std::vector<AppCacheDatabase::EntryRecord> entry_records;
database()->FindEntriesForCache(1, &entry_records);
EXPECT_TRUE(entry_records.empty());
- std::vector<AppCacheDatabase::FallbackNameSpaceRecord> fallback_records;
- database()->FindFallbackNameSpacesForCache(1, &fallback_records);
+ std::vector<AppCacheDatabase::NamespaceRecord> intercept_records;
+ std::vector<AppCacheDatabase::NamespaceRecord> fallback_records;
+ database()->FindNamespacesForCache(
+ 1, &intercept_records, &fallback_records);
EXPECT_TRUE(fallback_records.empty());
std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelist_records;
database()->FindOnlineWhiteListForCache(1, &whitelist_records);
@@ -889,15 +893,16 @@
cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::FALLBACK, 1));
cache_->AddEntry(kEntryUrl2, AppCacheEntry(AppCacheEntry::FALLBACK, 2));
cache_->fallback_namespaces_.push_back(
- FallbackNamespace(kFallbackNamespace2, kEntryUrl2));
+ Namespace(FALLBACK_NAMESPACE, kFallbackNamespace2, kEntryUrl2));
cache_->fallback_namespaces_.push_back(
- FallbackNamespace(kFallbackNamespace, kEntryUrl));
+ Namespace(FALLBACK_NAMESPACE, kFallbackNamespace, kEntryUrl));
AppCacheDatabase::CacheRecord cache_record;
std::vector<AppCacheDatabase::EntryRecord> entries;
- std::vector<AppCacheDatabase::FallbackNameSpaceRecord> fallbacks;
+ std::vector<AppCacheDatabase::NamespaceRecord> intercepts;
+ std::vector<AppCacheDatabase::NamespaceRecord> fallbacks;
std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelists;
cache_->ToDatabaseRecords(group_,
- &cache_record, &entries, &fallbacks, &whitelists);
+ &cache_record, &entries, &intercepts, &fallbacks, &whitelists);
std::vector<AppCacheDatabase::EntryRecord>::const_iterator iter =
entries.begin();
@@ -908,7 +913,7 @@
++iter;
}
- EXPECT_TRUE(database()->InsertFallbackNameSpaceRecords(fallbacks));
+ EXPECT_TRUE(database()->InsertNamespaceRecords(fallbacks));
EXPECT_TRUE(database()->InsertOnlineWhiteListRecords(whitelists));
if (drop_from_working_set) {
EXPECT_TRUE(cache_->HasOneRef());
@@ -935,6 +940,73 @@
TestFinished();
}
+ // BasicFindMainInterceptResponse -------------------------------
+
+ void BasicFindMainInterceptResponseInDatabase() {
+ BasicFindMainInterceptResponse(true);
+ }
+
+ void BasicFindMainInterceptResponseInWorkingSet() {
+ BasicFindMainInterceptResponse(false);
+ }
+
+ void BasicFindMainInterceptResponse(bool drop_from_working_set) {
+ PushNextTask(base::Bind(
+ &AppCacheStorageImplTest::Verify_BasicFindMainInterceptResponse,
+ base::Unretained(this)));
+
+ // Setup some preconditions. Create a complete cache with an
+ // intercept namespace and entry.
+ MakeCacheAndGroup(kManifestUrl, 2, 1, true);
+ cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::INTERCEPT, 1));
+ cache_->AddEntry(kEntryUrl2, AppCacheEntry(AppCacheEntry::INTERCEPT, 2));
+ cache_->intercept_namespaces_.push_back(
+ Namespace(INTERCEPT_NAMESPACE, kInterceptNamespace2, kEntryUrl2));
+ cache_->intercept_namespaces_.push_back(
+ Namespace(INTERCEPT_NAMESPACE, kInterceptNamespace, kEntryUrl));
+ AppCacheDatabase::CacheRecord cache_record;
+ std::vector<AppCacheDatabase::EntryRecord> entries;
+ std::vector<AppCacheDatabase::NamespaceRecord> intercepts;
+ std::vector<AppCacheDatabase::NamespaceRecord> fallbacks;
+ std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelists;
+ cache_->ToDatabaseRecords(group_,
+ &cache_record, &entries, &intercepts, &fallbacks, &whitelists);
+
+ std::vector<AppCacheDatabase::EntryRecord>::const_iterator iter =
+ entries.begin();
+ while (iter != entries.end()) {
+ // MakeCacheAndGroup has inserted the default entry record already
jennb 2011/12/13 00:33:09 extra space in sentence
+ if (iter->url != kDefaultEntryUrl)
+ EXPECT_TRUE(database()->InsertEntry(&(*iter)));
+ ++iter;
+ }
+
+ EXPECT_TRUE(database()->InsertNamespaceRecords(intercepts));
+ EXPECT_TRUE(database()->InsertOnlineWhiteListRecords(whitelists));
+ if (drop_from_working_set) {
+ EXPECT_TRUE(cache_->HasOneRef());
+ cache_ = NULL;
+ EXPECT_TRUE(group_->HasOneRef());
+ group_ = NULL;
+ }
+
+ // Conduct the test. The test url is in both intercept namespaces,
+ // but should match the longer of the two.
+ storage()->FindResponseForMainRequest(
+ kInterceptTestUrl, GURL(), delegate());
+ EXPECT_NE(kInterceptTestUrl, delegate()->found_url_);
+ }
+
+ void Verify_BasicFindMainInterceptResponse() {
+ EXPECT_EQ(kInterceptTestUrl, delegate()->found_url_);
+ EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_);
+ EXPECT_EQ(1, delegate()->found_cache_id_);
+ EXPECT_EQ(2, delegate()->found_group_id_);
+ EXPECT_EQ(2, delegate()->found_entry_.response_id());
+ EXPECT_TRUE(delegate()->found_entry_.IsIntercept());
+ EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id());
+ TestFinished();
+ }
// FindMainResponseWithMultipleHits -------------------------------
void FindMainResponseWithMultipleHits() {
@@ -988,15 +1060,14 @@
cache_->AddEntry(
entry_record.url,
AppCacheEntry(entry_record.flags, entry_record.response_id));
- AppCacheDatabase::FallbackNameSpaceRecord fallback_namespace_record;
+ AppCacheDatabase::NamespaceRecord fallback_namespace_record;
fallback_namespace_record.cache_id = id;
- fallback_namespace_record.fallback_entry_url = entry_record.url;
+ fallback_namespace_record.target_url = entry_record.url;
fallback_namespace_record.namespace_url = kFallbackNamespace;
fallback_namespace_record.origin = manifest_url.GetOrigin();
- EXPECT_TRUE(
- database()->InsertFallbackNameSpace(&fallback_namespace_record));
+ EXPECT_TRUE(database()->InsertNamespace(&fallback_namespace_record));
cache_->fallback_namespaces_.push_back(
- FallbackNamespace(kFallbackNamespace, kEntryUrl2));
+ Namespace(FALLBACK_NAMESPACE, kFallbackNamespace, kEntryUrl2));
}
void Verify_FindMainResponseWithMultipleHits() {
@@ -1109,7 +1180,7 @@
cache_->online_whitelist_namespaces_.push_back(kOnlineNamespace);
cache_->AddEntry(kEntryUrl2, AppCacheEntry(AppCacheEntry::FALLBACK, 2));
cache_->fallback_namespaces_.push_back(
- FallbackNamespace(kFallbackNamespace, kEntryUrl2));
+ Namespace(FALLBACK_NAMESPACE, kFallbackNamespace, kEntryUrl2));
cache_->online_whitelist_namespaces_.push_back(kOnlineNamespace);
cache_->online_whitelist_namespaces_.push_back(
kOnlineNamespaceWithinFallback);
@@ -1124,13 +1195,12 @@
whitelist_record.cache_id = 1;
whitelist_record.namespace_url = kOnlineNamespace;
EXPECT_TRUE(database()->InsertOnlineWhiteList(&whitelist_record));
- AppCacheDatabase::FallbackNameSpaceRecord fallback_namespace_record;
+ AppCacheDatabase::NamespaceRecord fallback_namespace_record;
fallback_namespace_record.cache_id = 1;
- fallback_namespace_record.fallback_entry_url = kEntryUrl2;
+ fallback_namespace_record.target_url = kEntryUrl2;
fallback_namespace_record.namespace_url = kFallbackNamespace;
fallback_namespace_record.origin = kManifestUrl.GetOrigin();
- EXPECT_TRUE(
- database()->InsertFallbackNameSpace(&fallback_namespace_record));
+ EXPECT_TRUE(database()->InsertNamespace(&fallback_namespace_record));
whitelist_record.cache_id = 1;
whitelist_record.namespace_url = kOnlineNamespaceWithinFallback;
EXPECT_TRUE(database()->InsertOnlineWhiteList(&whitelist_record));
@@ -1320,6 +1390,16 @@
&AppCacheStorageImplTest::BasicFindMainFallbackResponseInWorkingSet);
}
+TEST_F(AppCacheStorageImplTest, BasicFindMainInterceptResponseInDatabase) {
+ RunTestOnIOThread(
+ &AppCacheStorageImplTest::BasicFindMainInterceptResponseInDatabase);
+}
+
+TEST_F(AppCacheStorageImplTest, BasicFindMainInterceptResponseInWorkingSet) {
+ RunTestOnIOThread(
+ &AppCacheStorageImplTest::BasicFindMainInterceptResponseInWorkingSet);
+}
+
TEST_F(AppCacheStorageImplTest, FindMainResponseWithMultipleHits) {
RunTestOnIOThread(
&AppCacheStorageImplTest::FindMainResponseWithMultipleHits);
« no previous file with comments | « webkit/appcache/appcache_storage_impl.cc ('k') | webkit/appcache/appcache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698