diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 02:29:14 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 02:29:14 +0000 |
commit | 6ed2a5a54b7bb8ccd33da7bc948fee169f128459 (patch) | |
tree | 3752c15899760eef346dc2c1f66768aa2f3e676a /webkit/appcache | |
parent | d6bb669008e0308f3ee6e04e77fe903698864e7b (diff) | |
download | chromium_src-6ed2a5a54b7bb8ccd33da7bc948fee169f128459.zip chromium_src-6ed2a5a54b7bb8ccd33da7bc948fee169f128459.tar.gz chromium_src-6ed2a5a54b7bb8ccd33da7bc948fee169f128459.tar.bz2 |
Fix for WKBug 47000: a failure mode given bad content (in an unlikely form). The error occurs when an html page is put in an appcache as a fallback resource (so it's listed in a fallback section), but it contains a manifest attribute that refers to a different manifest file. The system should mark the resource as foreign and exclude it from main resource loads, but it was failing to do so. The fix is to do that.
BUG=WK47000
TEST=http/tests/appcache/foreign-fallback.html
Review URL: http://codereview.chromium.org/3529009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64868 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r-- | webkit/appcache/appcache.cc | 10 | ||||
-rw-r--r-- | webkit/appcache/appcache.h | 3 | ||||
-rw-r--r-- | webkit/appcache/appcache_host.cc | 12 | ||||
-rw-r--r-- | webkit/appcache/appcache_host.h | 8 | ||||
-rw-r--r-- | webkit/appcache/appcache_host_unittest.cc | 36 | ||||
-rw-r--r-- | webkit/appcache/appcache_request_handler.cc | 25 | ||||
-rw-r--r-- | webkit/appcache/appcache_request_handler.h | 8 | ||||
-rw-r--r-- | webkit/appcache/appcache_request_handler_unittest.cc | 9 | ||||
-rw-r--r-- | webkit/appcache/appcache_service.h | 15 | ||||
-rw-r--r-- | webkit/appcache/appcache_storage.h | 2 | ||||
-rw-r--r-- | webkit/appcache/appcache_storage_impl.cc | 21 | ||||
-rw-r--r-- | webkit/appcache/appcache_storage_impl.h | 5 | ||||
-rw-r--r-- | webkit/appcache/appcache_storage_impl_unittest.cc | 6 | ||||
-rw-r--r-- | webkit/appcache/appcache_unittest.cc | 4 | ||||
-rw-r--r-- | webkit/appcache/mock_appcache_storage.cc | 15 | ||||
-rw-r--r-- | webkit/appcache/mock_appcache_storage.h | 3 | ||||
-rw-r--r-- | webkit/appcache/mock_appcache_storage_unittest.cc | 7 | ||||
-rw-r--r-- | webkit/appcache/webkit_appcache.gypi | 2 |
18 files changed, 149 insertions, 42 deletions
diff --git a/webkit/appcache/appcache.cc b/webkit/appcache/appcache.cc index de25b15..aeeeb0c 100644 --- a/webkit/appcache/appcache.cc +++ b/webkit/appcache/appcache.cc @@ -70,6 +70,16 @@ AppCacheEntry* AppCache::GetEntry(const GURL& url) { return (it != entries_.end()) ? &(it->second) : NULL; } +GURL AppCache::GetFallbackEntryUrl(const GURL& namespace_url) const { + size_t count = fallback_namespaces_.size(); + for (size_t i = 0; i < count; ++i) { + if (fallback_namespaces_[i].first == namespace_url) + return fallback_namespaces_[i].second; + } + NOTREACHED(); + return GURL(); +} + namespace { bool SortByLength( const FallbackNamespace& lhs, const FallbackNamespace& rhs) { diff --git a/webkit/appcache/appcache.h b/webkit/appcache/appcache.h index 00753ab..20298a4 100644 --- a/webkit/appcache/appcache.h +++ b/webkit/appcache/appcache.h @@ -58,6 +58,9 @@ class AppCache : public base::RefCounted<AppCache> { const EntryMap& entries() const { return entries_; } + // Returns the URL of the resource used as the fallback for 'namespace_url'. + GURL GetFallbackEntryUrl(const GURL& namespace_url) const; + AppCacheHosts& associated_hosts() { return associated_hosts_; } bool IsNewerThan(AppCache* cache) const { diff --git a/webkit/appcache/appcache_host.cc b/webkit/appcache/appcache_host.cc index f11293d..e954e80 100644 --- a/webkit/appcache/appcache_host.cc +++ b/webkit/appcache/appcache_host.cc @@ -39,7 +39,8 @@ AppCacheHost::AppCacheHost(int host_id, AppCacheFrontend* frontend, frontend_(frontend), service_(service), pending_get_status_callback_(NULL), pending_start_update_callback_(NULL), pending_swap_cache_callback_(NULL), pending_callback_param_(NULL), - main_resource_blocked_(false), associated_cache_info_pending_(false) { + main_resource_was_fallback_(false), main_resource_blocked_(false), + associated_cache_info_pending_(false) { } AppCacheHost::~AppCacheHost() { @@ -144,8 +145,10 @@ void AppCacheHost::SelectCacheForSharedWorker(int64 appcache_id) { // TODO(michaeln): change method name to MarkEntryAsForeign for consistency void AppCacheHost::MarkAsForeignEntry(const GURL& document_url, int64 cache_document_was_loaded_from) { + // The document url is not the resource url in the fallback case. service_->storage()->MarkEntryAsForeign( - document_url, cache_document_was_loaded_from); + main_resource_was_fallback_ ? fallback_url_ : document_url, + cache_document_was_loaded_from); SelectCache(document_url, kNoCacheId, GURL()); } @@ -452,6 +455,11 @@ void AppCacheHost::LoadMainResourceCache(int64 cache_id) { service_->storage()->LoadCache(cache_id, this); } +void AppCacheHost::NotifyMainResourceFallback(const GURL& fallback_url) { + main_resource_was_fallback_ = true; + fallback_url_ = fallback_url; +} + void AppCacheHost::NotifyMainResourceBlocked(const GURL& manifest_url) { main_resource_blocked_ = true; blocked_manifest_url_ = manifest_url; diff --git a/webkit/appcache/appcache_host.h b/webkit/appcache/appcache_host.h index a23be18..d3743b4 100644 --- a/webkit/appcache/appcache_host.h +++ b/webkit/appcache/appcache_host.h @@ -90,6 +90,10 @@ class AppCacheHost : public AppCacheStorage::Delegate, // Used to ensure that a loaded appcache survives a frame navigation. void LoadMainResourceCache(int64 cache_id); + // Used to notify the host that a fallback resource is being delivered as + // the main resource of the page and to provide its url. + void NotifyMainResourceFallback(const GURL& fallback_url); + // Used to notify the host that the main resource was blocked by a policy. To // work properly, this method needs to by invoked prior to cache selection. void NotifyMainResourceBlocked(const GURL& manifest_url); @@ -198,6 +202,10 @@ class AppCacheHost : public AppCacheStorage::Delegate, SwapCacheCallback* pending_swap_cache_callback_; void* pending_callback_param_; + // True if a fallback resource was delivered as the main resource. + bool main_resource_was_fallback_; + GURL fallback_url_; + // True if requests for this host were blocked by a policy. bool main_resource_blocked_; GURL blocked_manifest_url_; diff --git a/webkit/appcache/appcache_host_unittest.cc b/webkit/appcache/appcache_host_unittest.cc index 5d1f409..09fea0f 100644 --- a/webkit/appcache/appcache_host_unittest.cc +++ b/webkit/appcache/appcache_host_unittest.cc @@ -164,8 +164,14 @@ TEST_F(AppCacheHostTest, ForeignEntry) { mock_frontend_.last_host_id_ = -333; mock_frontend_.last_status_ = OBSOLETE; + // Precondition, a cache with an entry that is not marked as foreign. + const int kCacheId = 22; + const GURL kDocumentURL("http://origin/document"); + scoped_refptr<AppCache> cache = new AppCache(&service_, kCacheId); + cache->AddEntry(kDocumentURL, AppCacheEntry(AppCacheEntry::EXPLICIT)); + AppCacheHost host(1, &mock_frontend_, &service_); - host.MarkAsForeignEntry(GURL("http://whatever/"), 22); + host.MarkAsForeignEntry(kDocumentURL, kCacheId); // We should have received an OnCacheSelected msg for kNoCacheId. EXPECT_EQ(1, mock_frontend_.last_host_id_); @@ -178,6 +184,34 @@ TEST_F(AppCacheHostTest, ForeignEntry) { EXPECT_EQ(&mock_frontend_, host.frontend()); EXPECT_EQ(NULL, host.associated_cache()); EXPECT_FALSE(host.is_selection_pending()); + + // See that the entry was marked as foreign. + EXPECT_TRUE(cache->GetEntry(kDocumentURL)->IsForeign()); +} + +TEST_F(AppCacheHostTest, ForeignFallbackEntry) { + // Reset our mock frontend + mock_frontend_.last_cache_id_ = -333; + mock_frontend_.last_host_id_ = -333; + mock_frontend_.last_status_ = OBSOLETE; + + // Precondition, a cache with a fallback entry that is not marked as foreign. + const int kCacheId = 22; + const GURL kFallbackURL("http://origin/fallback_resource"); + scoped_refptr<AppCache> cache = new AppCache(&service_, kCacheId); + cache->AddEntry(kFallbackURL, AppCacheEntry(AppCacheEntry::FALLBACK)); + + AppCacheHost host(1, &mock_frontend_, &service_); + host.NotifyMainResourceFallback(kFallbackURL); + host.MarkAsForeignEntry(GURL("http://origin/missing_document"), kCacheId); + + // We should have received an OnCacheSelected msg for kNoCacheId. + EXPECT_EQ(1, mock_frontend_.last_host_id_); + EXPECT_EQ(kNoCacheId, mock_frontend_.last_cache_id_); + EXPECT_EQ(UNCACHED, mock_frontend_.last_status_); + + // See that the fallback entry was marked as foreign. + EXPECT_TRUE(cache->GetEntry(kFallbackURL)->IsForeign()); } TEST_F(AppCacheHostTest, FailedCacheLoad) { diff --git a/webkit/appcache/appcache_request_handler.cc b/webkit/appcache/appcache_request_handler.cc index f193139..8cbb805 100644 --- a/webkit/appcache/appcache_request_handler.cc +++ b/webkit/appcache/appcache_request_handler.cc @@ -101,7 +101,8 @@ AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( // get the resource of the fallback entry. job_ = new AppCacheURLRequestJob(request, storage()); DeliverAppCachedResponse( - found_fallback_entry_, found_cache_id_, found_manifest_url_, true); + found_fallback_entry_, found_cache_id_, found_manifest_url_, + true, found_fallback_url_); } else if (!found_network_namespace_) { // 6.9.6, step 6: Fail the resource load. job_ = new AppCacheURLRequestJob(request, storage()); @@ -142,7 +143,8 @@ AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( // or there were network errors, get the resource of the fallback entry. job_ = new AppCacheURLRequestJob(request, storage()); DeliverAppCachedResponse( - found_fallback_entry_, found_cache_id_, found_manifest_url_, true); + found_fallback_entry_, found_cache_id_, found_manifest_url_, + true, found_fallback_url_); return job_; } @@ -160,9 +162,15 @@ void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { void AppCacheRequestHandler::DeliverAppCachedResponse( const AppCacheEntry& entry, int64 cache_id, const GURL& manifest_url, - bool is_fallback) { - DCHECK(job_ && job_->is_waiting()); + bool is_fallback, const GURL& fallback_url) { + DCHECK(host_ && job_ && job_->is_waiting()); DCHECK(entry.has_response_id()); + + if (ResourceType::IsFrame(resource_type_) && is_fallback) { + DCHECK(!fallback_url.is_empty()); + host_->NotifyMainResourceFallback(fallback_url); + } + job_->DeliverAppCachedResponse(manifest_url, cache_id, entry, is_fallback); } @@ -189,7 +197,7 @@ void AppCacheRequestHandler::MaybeLoadMainResource(URLRequest* request) { void AppCacheRequestHandler::OnMainResponseFound( const GURL& url, const AppCacheEntry& entry, - const AppCacheEntry& fallback_entry, + const GURL& fallback_url, const AppCacheEntry& fallback_entry, int64 cache_id, const GURL& manifest_url, bool was_blocked_by_policy) { DCHECK(host_); @@ -218,6 +226,7 @@ void AppCacheRequestHandler::OnMainResponseFound( // 6.11.1 Navigating across documents, steps 10 and 14. found_entry_ = entry; + found_fallback_url_ = fallback_url; found_fallback_entry_ = fallback_entry; found_cache_id_ = cache_id; found_manifest_url_ = manifest_url; @@ -225,7 +234,8 @@ void AppCacheRequestHandler::OnMainResponseFound( if (found_entry_.has_response_id()) { DeliverAppCachedResponse( - found_entry_, found_cache_id_, found_manifest_url_, false); + found_entry_, found_cache_id_, found_manifest_url_, + false, GURL()); } else { DeliverNetworkResponse(); } @@ -275,7 +285,8 @@ void AppCacheRequestHandler::ContinueMaybeLoadSubResource() { found_cache_id_ = cache->cache_id(); found_manifest_url_ = cache->owning_group()->manifest_url(); DeliverAppCachedResponse( - found_entry_, found_cache_id_, found_manifest_url_, false); + found_entry_, found_cache_id_, found_manifest_url_, + false, GURL()); return; } diff --git a/webkit/appcache/appcache_request_handler.h b/webkit/appcache/appcache_request_handler.h index 3a19a8f..8577232 100644 --- a/webkit/appcache/appcache_request_handler.h +++ b/webkit/appcache/appcache_request_handler.h @@ -53,7 +53,8 @@ class AppCacheRequestHandler : public URLRequest::UserData, // Helpers to instruct a waiting job with what response to // deliver for the request we're handling. void DeliverAppCachedResponse(const AppCacheEntry& entry, int64 cache_id, - const GURL& manifest_url, bool is_fallback); + const GURL& manifest_url, bool is_fallback, + const GURL& fallback_url); void DeliverNetworkResponse(); void DeliverErrorResponse(); @@ -72,7 +73,7 @@ class AppCacheRequestHandler : public URLRequest::UserData, // AppCacheStorage::Delegate methods virtual void OnMainResponseFound( const GURL& url, const AppCacheEntry& entry, - const AppCacheEntry& fallback_entry, + const GURL& fallback_url, const AppCacheEntry& fallback_entry, int64 cache_id, const GURL& mainfest_url, bool was_blocked_by_policy); @@ -98,9 +99,10 @@ class AppCacheRequestHandler : public URLRequest::UserData, // Info about the type of response we found for delivery. // These are relevant for both main and subresource requests. + int64 found_cache_id_; AppCacheEntry found_entry_; AppCacheEntry found_fallback_entry_; - int64 found_cache_id_; + GURL found_fallback_url_; GURL found_manifest_url_; bool found_network_namespace_; diff --git a/webkit/appcache/appcache_request_handler_unittest.cc b/webkit/appcache/appcache_request_handler_unittest.cc index 8d22a49..ae0be75 100644 --- a/webkit/appcache/appcache_request_handler_unittest.cc +++ b/webkit/appcache/appcache_request_handler_unittest.cc @@ -237,7 +237,8 @@ class AppCacheRequestHandlerTest : public testing::Test { EXPECT_TRUE(handler_.get()); mock_storage()->SimulateFindMainResource( - AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), + AppCacheEntry(AppCacheEntry::EXPLICIT, 1), + GURL(), AppCacheEntry(), 1, GURL("http://blah/manifest/")); job_ = handler_->MaybeLoadResource(request_.get()); @@ -277,7 +278,9 @@ class AppCacheRequestHandlerTest : public testing::Test { EXPECT_TRUE(handler_.get()); mock_storage()->SimulateFindMainResource( - AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), + AppCacheEntry(), + GURL("http://blah/fallbackurl"), + AppCacheEntry(AppCacheEntry::EXPLICIT, 1), 1, GURL("http://blah/manifest/")); job_ = handler_->MaybeLoadResource(request_.get()); @@ -310,6 +313,8 @@ class AppCacheRequestHandlerTest : public testing::Test { handler_->GetExtraResponseInfo(&cache_id, &manifest_url); EXPECT_EQ(1, cache_id); EXPECT_EQ(GURL("http://blah/manifest/"), manifest_url); + EXPECT_TRUE(host_->main_resource_was_fallback_); + EXPECT_EQ(GURL("http://blah/fallbackurl"), host_->fallback_url_); TestFinished(); } diff --git a/webkit/appcache/appcache_service.h b/webkit/appcache/appcache_service.h index ebd8fb7..4e68341 100644 --- a/webkit/appcache/appcache_service.h +++ b/webkit/appcache/appcache_service.h @@ -104,22 +104,13 @@ class AppCacheService { class GetInfoHelper; typedef std::set<AsyncHelper*> PendingAsyncHelpers; + typedef std::map<int, AppCacheBackendImpl*> BackendMap; AppCachePolicy* appcache_policy_; - - // Deals with persistence. scoped_ptr<AppCacheStorage> storage_; - PendingAsyncHelpers pending_helpers_; - - // Track current processes. One 'backend' per child process. - typedef std::map<int, AppCacheBackendImpl*> BackendMap; - BackendMap backends_; - - // Context for use during cache updates. - URLRequestContext* request_context_; - - // TODO(jennb): service state: e.g. reached quota? + BackendMap backends_; // One 'backend' per child process. + URLRequestContext* request_context_; // Context for use during cache updates. DISALLOW_COPY_AND_ASSIGN(AppCacheService); }; diff --git a/webkit/appcache/appcache_storage.h b/webkit/appcache/appcache_storage.h index 20fbffe..1d64ef9 100644 --- a/webkit/appcache/appcache_storage.h +++ b/webkit/appcache/appcache_storage.h @@ -63,7 +63,7 @@ class AppCacheStorage { // containing cache and group are also returned. virtual void OnMainResponseFound( const GURL& url, const AppCacheEntry& entry, - const AppCacheEntry& fallback_entry, + const GURL& fallback_url, const AppCacheEntry& fallback_entry, int64 cache_id, const GURL& mainfest_url, bool was_blocked_by_policy) {} }; diff --git a/webkit/appcache/appcache_storage_impl.cc b/webkit/appcache/appcache_storage_impl.cc index c8f6e3a..b0aa25a 100644 --- a/webkit/appcache/appcache_storage_impl.cc +++ b/webkit/appcache/appcache_storage_impl.cc @@ -553,6 +553,7 @@ class AppCacheStorageImpl::FindMainResponseTask : public DatabaseTask { std::set<int64> cache_ids_in_use_; AppCacheEntry entry_; AppCacheEntry fallback_entry_; + GURL fallback_url_; int64 cache_id_; GURL manifest_url_; }; @@ -631,12 +632,15 @@ void AppCacheStorageImpl::FindMainResponseTask::Run() { if (take_new_candidate && database_->FindEntry(iter->cache_id, iter->fallback_entry_url, &entry_record)) { + if (entry_record.flags & AppCacheEntry::FOREIGN) + continue; AppCacheDatabase::GroupRecord group_record; if (!database_->FindGroupForCache(iter->cache_id, &group_record)) { NOTREACHED() << "A cache without a group is not expected."; continue; } cache_id_ = iter->cache_id; + fallback_url_ = iter->fallback_entry_url; manifest_url_ = group_record.manifest_url; fallback_entry_ = AppCacheEntry( entry_record.flags, entry_record.response_id); @@ -651,7 +655,8 @@ void AppCacheStorageImpl::FindMainResponseTask::Run() { void AppCacheStorageImpl::FindMainResponseTask::RunCompleted() { storage_->CheckPolicyAndCallOnMainResponseFound( - &delegates_, url_, entry_, fallback_entry_, cache_id_, manifest_url_); + &delegates_, url_, entry_, fallback_url_, fallback_entry_, + cache_id_, manifest_url_); } // MarkEntryAsForeignTask ------- @@ -1047,15 +1052,17 @@ void AppCacheStorageImpl::DeliverShortCircuitedFindMainResponse( if (delegate_ref->delegate) { DelegateReferenceVector delegates(1, delegate_ref); CheckPolicyAndCallOnMainResponseFound( - &delegates, url, found_entry, AppCacheEntry(), + &delegates, url, found_entry, + GURL(), AppCacheEntry(), cache.get() ? cache->cache_id() : kNoCacheId, group.get() ? group->manifest_url() : GURL()); } } void AppCacheStorageImpl::CheckPolicyAndCallOnMainResponseFound( - DelegateReferenceVector* delegates, const GURL& url, - const AppCacheEntry& entry, const AppCacheEntry& fallback_entry, + DelegateReferenceVector* delegates, + const GURL& url, const AppCacheEntry& entry, + const GURL& fallback_url, const AppCacheEntry& fallback_entry, int64 cache_id, const GURL& manifest_url) { if (!manifest_url.is_empty()) { // Check the policy prior to returning a main resource from the appcache. @@ -1063,7 +1070,8 @@ void AppCacheStorageImpl::CheckPolicyAndCallOnMainResponseFound( if (policy && !policy->CanLoadAppCache(manifest_url)) { FOR_EACH_DELEGATE( (*delegates), - OnMainResponseFound(url, AppCacheEntry(), AppCacheEntry(), + OnMainResponseFound(url, AppCacheEntry(), + GURL(), AppCacheEntry(), kNoCacheId, manifest_url, true)); return; } @@ -1071,7 +1079,8 @@ void AppCacheStorageImpl::CheckPolicyAndCallOnMainResponseFound( FOR_EACH_DELEGATE( (*delegates), - OnMainResponseFound(url, entry, fallback_entry, + OnMainResponseFound(url, entry, + fallback_url, fallback_entry, cache_id, manifest_url, false)); } diff --git a/webkit/appcache/appcache_storage_impl.h b/webkit/appcache/appcache_storage_impl.h index 93abfc64..584862a 100644 --- a/webkit/appcache/appcache_storage_impl.h +++ b/webkit/appcache/appcache_storage_impl.h @@ -107,8 +107,9 @@ class AppCacheStorageImpl : public AppCacheStorage { scoped_refptr<DelegateReference> delegate_ref); void CheckPolicyAndCallOnMainResponseFound( - DelegateReferenceVector* delegates, const GURL& url, - const AppCacheEntry& entry, const AppCacheEntry& fallback_entry, + DelegateReferenceVector* delegates, + const GURL& url, const AppCacheEntry& entry, + const GURL& fallback_url, const AppCacheEntry& fallback_entry, int64 cache_id, const GURL& manifest_url); AppCacheDiskCache* disk_cache(); diff --git a/webkit/appcache/appcache_storage_impl_unittest.cc b/webkit/appcache/appcache_storage_impl_unittest.cc index 6c153a5..116ce47 100644 --- a/webkit/appcache/appcache_storage_impl_unittest.cc +++ b/webkit/appcache/appcache_storage_impl_unittest.cc @@ -108,11 +108,13 @@ class AppCacheStorageImplTest : public testing::Test { } void OnMainResponseFound(const GURL& url, const AppCacheEntry& entry, + const GURL& fallback_url, const AppCacheEntry& fallback_entry, int64 cache_id, const GURL& manifest_url, bool was_blocked_by_policy) { found_url_ = url; found_entry_ = entry; + found_fallback_url_ = fallback_url; found_fallback_entry_ = fallback_entry; found_cache_id_ = cache_id; found_manifest_url_ = manifest_url; @@ -132,6 +134,7 @@ class AppCacheStorageImplTest : public testing::Test { bool obsoleted_success_; GURL found_url_; AppCacheEntry found_entry_; + GURL found_fallback_url_; AppCacheEntry found_fallback_entry_; int64 found_cache_id_; GURL found_manifest_url_; @@ -739,6 +742,7 @@ class AppCacheStorageImplTest : public testing::Test { EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); + EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); EXPECT_EQ(0, delegate()->found_entry_.types()); EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); TestFinished(); @@ -858,6 +862,7 @@ class AppCacheStorageImplTest : public testing::Test { EXPECT_EQ(1, delegate()->found_cache_id_); EXPECT_FALSE(delegate()->found_entry_.has_response_id()); EXPECT_EQ(2, delegate()->found_fallback_entry_.response_id()); + EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); TestFinished(); } @@ -954,6 +959,7 @@ class AppCacheStorageImplTest : public testing::Test { EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); + EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); EXPECT_EQ(0, delegate()->found_entry_.types()); EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); diff --git a/webkit/appcache/appcache_unittest.cc b/webkit/appcache/appcache_unittest.cc index d0583f8..bdeaa53 100644 --- a/webkit/appcache/appcache_unittest.cc +++ b/webkit/appcache/appcache_unittest.cc @@ -218,6 +218,8 @@ TEST(AppCacheTest, FindResponseForRequest) { EXPECT_TRUE(found); EXPECT_FALSE(entry.has_response_id()); EXPECT_EQ(kFallbackResponseId1, fallback_entry.response_id()); + EXPECT_EQ(kFallbackEntryUrl1, + cache->GetFallbackEntryUrl(fallback_namespace)); EXPECT_FALSE(network_namespace); fallback_entry = AppCacheEntry(); // reset @@ -227,6 +229,8 @@ TEST(AppCacheTest, FindResponseForRequest) { EXPECT_TRUE(found); EXPECT_FALSE(entry.has_response_id()); EXPECT_EQ(kFallbackResponseId2, fallback_entry.response_id()); + EXPECT_EQ(kFallbackEntryUrl2, + cache->GetFallbackEntryUrl(fallback_namespace)); EXPECT_FALSE(network_namespace); } diff --git a/webkit/appcache/mock_appcache_storage.cc b/webkit/appcache/mock_appcache_storage.cc index 13ae899..7cd3842 100644 --- a/webkit/appcache/mock_appcache_storage.cc +++ b/webkit/appcache/mock_appcache_storage.cc @@ -212,6 +212,7 @@ void MockAppCacheStorage::ProcessStoreGroupAndNewestCache( namespace { struct FoundCandidate { + GURL url; AppCacheEntry entry; int64 cache_id; GURL manifest_url; @@ -228,7 +229,8 @@ void MockAppCacheStorage::ProcessFindResponseForMainRequest( simulate_find_main_resource_ = false; if (delegate_ref->delegate) { delegate_ref->delegate->OnMainResponseFound( - url, simulated_found_entry_, simulated_found_fallback_entry_, + url, simulated_found_entry_, + simulated_found_fallback_url_, simulated_found_fallback_entry_, simulated_found_cache_id_, simulated_found_manifest_url_, false); } return; @@ -283,6 +285,7 @@ void MockAppCacheStorage::ProcessFindResponseForMainRequest( bool is_in_use = IsCacheStored(cache) && !cache->HasOneRef(); if (found_entry.has_response_id()) { + found_candidate.url = url; found_candidate.entry = found_entry; found_candidate.cache_id = cache->cache_id(); found_candidate.manifest_url = group->manifest_url(); @@ -313,6 +316,8 @@ void MockAppCacheStorage::ProcessFindResponseForMainRequest( } if (take_new_candidate) { + found_fallback_candidate.url = + cache->GetFallbackEntryUrl(found_fallback_namespace); found_fallback_candidate.entry = found_fallback_entry; found_fallback_candidate.cache_id = cache->cache_id(); found_fallback_candidate.manifest_url = group->manifest_url(); @@ -325,7 +330,7 @@ void MockAppCacheStorage::ProcessFindResponseForMainRequest( // Found a direct hit. if (found_candidate.entry.has_response_id()) { delegate_ref->delegate->OnMainResponseFound( - url, found_candidate.entry, AppCacheEntry(), + url, found_candidate.entry, GURL(), AppCacheEntry(), found_candidate.cache_id, found_candidate.manifest_url, false); return; } @@ -333,7 +338,9 @@ void MockAppCacheStorage::ProcessFindResponseForMainRequest( // Found a fallback namespace. if (found_fallback_candidate.entry.has_response_id()) { delegate_ref->delegate->OnMainResponseFound( - url, AppCacheEntry(), found_fallback_candidate.entry, + url, AppCacheEntry(), + found_fallback_candidate.url, + found_fallback_candidate.entry, found_fallback_candidate.cache_id, found_fallback_candidate.manifest_url, false); return; @@ -341,7 +348,7 @@ void MockAppCacheStorage::ProcessFindResponseForMainRequest( // Didn't find anything. delegate_ref->delegate->OnMainResponseFound( - url, AppCacheEntry(), AppCacheEntry(), kNoCacheId, GURL(), false); + url, AppCacheEntry(), GURL(), AppCacheEntry(), kNoCacheId, GURL(), false); } void MockAppCacheStorage::ProcessMakeGroupObsolete( diff --git a/webkit/appcache/mock_appcache_storage.h b/webkit/appcache/mock_appcache_storage.h index ad6ad65..70880aa 100644 --- a/webkit/appcache/mock_appcache_storage.h +++ b/webkit/appcache/mock_appcache_storage.h @@ -119,11 +119,13 @@ class MockAppCacheStorage : public AppCacheStorage { // unaffected. void SimulateFindMainResource( const AppCacheEntry& entry, + const GURL& fallback_url, const AppCacheEntry& fallback_entry, int64 cache_id, const GURL& manifest_url) { simulate_find_main_resource_ = true; simulate_find_sub_resource_ = false; simulated_found_entry_ = entry; + simulated_found_fallback_url_ = fallback_url; simulated_found_fallback_entry_ = fallback_entry; simulated_found_cache_id_ = cache_id; simulated_found_manifest_url_ = manifest_url, @@ -157,6 +159,7 @@ class MockAppCacheStorage : public AppCacheStorage { AppCacheEntry simulated_found_entry_; AppCacheEntry simulated_found_fallback_entry_; int64 simulated_found_cache_id_; + GURL simulated_found_fallback_url_; GURL simulated_found_manifest_url_; bool simulated_found_network_namespace_; diff --git a/webkit/appcache/mock_appcache_storage_unittest.cc b/webkit/appcache/mock_appcache_storage_unittest.cc index 3bd8ca6..2be8642 100644 --- a/webkit/appcache/mock_appcache_storage_unittest.cc +++ b/webkit/appcache/mock_appcache_storage_unittest.cc @@ -44,11 +44,13 @@ class MockAppCacheStorageTest : public testing::Test { } void OnMainResponseFound(const GURL& url, const AppCacheEntry& entry, + const GURL& fallback_url, const AppCacheEntry& fallback_entry, int64 cache_id, const GURL& manifest_url, bool was_blocked_by_policy) { found_url_ = url; found_entry_ = entry; + found_fallback_url_ = fallback_url; found_fallback_entry_ = fallback_entry; found_cache_id_ = cache_id; found_manifest_url_ = manifest_url; @@ -64,6 +66,7 @@ class MockAppCacheStorageTest : public testing::Test { bool obsoleted_success_; GURL found_url_; AppCacheEntry found_entry_; + GURL found_fallback_url_; AppCacheEntry found_fallback_entry_; int64 found_cache_id_; GURL found_manifest_url_; @@ -399,6 +402,7 @@ TEST_F(MockAppCacheStorageTest, FindNoMainResponse) { EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); + EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); EXPECT_EQ(0, delegate.found_entry_.types()); EXPECT_EQ(0, delegate.found_fallback_entry_.types()); } @@ -490,6 +494,7 @@ TEST_F(MockAppCacheStorageTest, BasicFindMainFallbackResponse) { EXPECT_EQ(kCacheId, delegate.found_cache_id_); EXPECT_FALSE(delegate.found_entry_.has_response_id()); EXPECT_EQ(kResponseId2, delegate.found_fallback_entry_.response_id()); + EXPECT_EQ(kFallbackEntryUrl2, delegate.found_fallback_url_); EXPECT_TRUE(delegate.found_fallback_entry_.IsFallback()); } @@ -592,6 +597,7 @@ TEST_F(MockAppCacheStorageTest, FindMainResponseExclusions) { EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); + EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); EXPECT_EQ(0, delegate.found_entry_.types()); EXPECT_EQ(0, delegate.found_fallback_entry_.types()); @@ -605,6 +611,7 @@ TEST_F(MockAppCacheStorageTest, FindMainResponseExclusions) { EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); + EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); EXPECT_EQ(0, delegate.found_entry_.types()); EXPECT_EQ(0, delegate.found_fallback_entry_.types()); } diff --git a/webkit/appcache/webkit_appcache.gypi b/webkit/appcache/webkit_appcache.gypi index e3d5d902..3d8e857 100644 --- a/webkit/appcache/webkit_appcache.gypi +++ b/webkit/appcache/webkit_appcache.gypi @@ -56,8 +56,6 @@ 'appcache_url_request_job.h', 'manifest_parser.cc', 'manifest_parser.h', - 'mock_appcache_storage.cc', - 'mock_appcache_storage.h', 'view_appcache_internals_job.h', 'view_appcache_internals_job.cc', 'web_application_cache_host_impl.cc', |