diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-25 21:15:31 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-25 21:15:31 +0000 |
commit | 697af4a94a9351f6994d9207356930f373cf3a6e (patch) | |
tree | 501a3d73683bf94694da5a540c5b6b88501ba961 /webkit | |
parent | 2a8132263c53c361e4a7618af889492407dbb8e2 (diff) | |
download | chromium_src-697af4a94a9351f6994d9207356930f373cf3a6e.zip chromium_src-697af4a94a9351f6994d9207356930f373cf3a6e.tar.gz chromium_src-697af4a94a9351f6994d9207356930f373cf3a6e.tar.bz2 |
Provide more info to the renderer process in appcache progress events.
BUG=39370
TEST= yes, updated unittests
Review URL: http://codereview.chromium.org/2166006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48197 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/appcache/appcache_frontend_impl.cc | 14 | ||||
-rw-r--r-- | webkit/appcache/appcache_frontend_impl.h | 3 | ||||
-rw-r--r-- | webkit/appcache/appcache_group_unittest.cc | 5 | ||||
-rw-r--r-- | webkit/appcache/appcache_host_unittest.cc | 6 | ||||
-rw-r--r-- | webkit/appcache/appcache_interfaces.h | 3 | ||||
-rw-r--r-- | webkit/appcache/appcache_request_handler_unittest.cc | 4 | ||||
-rw-r--r-- | webkit/appcache/appcache_update_job.cc | 49 | ||||
-rw-r--r-- | webkit/appcache/appcache_update_job.h | 4 | ||||
-rw-r--r-- | webkit/appcache/appcache_update_job_unittest.cc | 155 | ||||
-rw-r--r-- | webkit/appcache/web_application_cache_host_impl.cc | 17 | ||||
-rw-r--r-- | webkit/appcache/web_application_cache_host_impl.h | 1 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_appcache_system.cc | 16 |
12 files changed, 212 insertions, 65 deletions
diff --git a/webkit/appcache/appcache_frontend_impl.cc b/webkit/appcache/appcache_frontend_impl.cc index 7a9c1b8..3535bf1 100644 --- a/webkit/appcache/appcache_frontend_impl.cc +++ b/webkit/appcache/appcache_frontend_impl.cc @@ -3,6 +3,8 @@ // found in the LICENSE file. #include "webkit/appcache/appcache_frontend_impl.h" + +#include "base/logging.h" #include "webkit/appcache/web_application_cache_host_impl.h" namespace appcache { @@ -31,6 +33,7 @@ void AppCacheFrontendImpl::OnStatusChanged(const std::vector<int>& host_ids, void AppCacheFrontendImpl::OnEventRaised(const std::vector<int>& host_ids, EventID event_id) { + DCHECK(event_id != PROGRESS_EVENT); // See OnProgressEventRaised. for (std::vector<int>::const_iterator i = host_ids.begin(); i != host_ids.end(); ++i) { WebApplicationCacheHostImpl* host = GetHost(*i); @@ -39,6 +42,17 @@ void AppCacheFrontendImpl::OnEventRaised(const std::vector<int>& host_ids, } } +void AppCacheFrontendImpl::OnProgressEventRaised( + const std::vector<int>& host_ids, + const GURL& url, int num_total, int num_complete) { + for (std::vector<int>::const_iterator i = host_ids.begin(); + i != host_ids.end(); ++i) { + WebApplicationCacheHostImpl* host = GetHost(*i); + if (host) + host->OnProgressEventRaised(url, num_total, num_complete); + } +} + void AppCacheFrontendImpl::OnContentBlocked(int host_id) { WebApplicationCacheHostImpl* host = GetHost(host_id); if (host) diff --git a/webkit/appcache/appcache_frontend_impl.h b/webkit/appcache/appcache_frontend_impl.h index e8658a8..99e5c2c 100644 --- a/webkit/appcache/appcache_frontend_impl.h +++ b/webkit/appcache/appcache_frontend_impl.h @@ -18,6 +18,9 @@ class AppCacheFrontendImpl : public AppCacheFrontend { Status status); virtual void OnEventRaised(const std::vector<int>& host_ids, EventID event_id); + virtual void OnProgressEventRaised(const std::vector<int>& host_ids, + const GURL& url, + int num_total, int num_complete); virtual void OnContentBlocked(int host_id); }; diff --git a/webkit/appcache/appcache_group_unittest.cc b/webkit/appcache/appcache_group_unittest.cc index 9f86bc0b..b1c7425 100644 --- a/webkit/appcache/appcache_group_unittest.cc +++ b/webkit/appcache/appcache_group_unittest.cc @@ -33,6 +33,11 @@ class TestAppCacheFrontend : public appcache::AppCacheFrontend { appcache::EventID event_id) { } + virtual void OnProgressEventRaised(const std::vector<int>& host_ids, + const GURL& url, + int num_total, int num_complete) { + } + virtual void OnContentBlocked(int host_id) { } diff --git a/webkit/appcache/appcache_host_unittest.cc b/webkit/appcache/appcache_host_unittest.cc index 85cc4b4..b618ce9 100644 --- a/webkit/appcache/appcache_host_unittest.cc +++ b/webkit/appcache/appcache_host_unittest.cc @@ -51,6 +51,12 @@ class AppCacheHostTest : public testing::Test { last_event_id_ = event_id; } + virtual void OnProgressEventRaised(const std::vector<int>& host_ids, + const GURL& url, + int num_total, int num_complete) { + last_event_id_ = PROGRESS_EVENT; + } + virtual void OnContentBlocked(int host_id) { } diff --git a/webkit/appcache/appcache_interfaces.h b/webkit/appcache/appcache_interfaces.h index 84132e3..5f1c369 100644 --- a/webkit/appcache/appcache_interfaces.h +++ b/webkit/appcache/appcache_interfaces.h @@ -53,6 +53,9 @@ class AppCacheFrontend { Status status) = 0; virtual void OnEventRaised(const std::vector<int>& host_ids, EventID event_id) = 0; + virtual void OnProgressEventRaised(const std::vector<int>& host_ids, + const GURL& url, + int num_total, int num_complete) = 0; virtual void OnContentBlocked(int host_id) = 0; virtual ~AppCacheFrontend() {} diff --git a/webkit/appcache/appcache_request_handler_unittest.cc b/webkit/appcache/appcache_request_handler_unittest.cc index 5ca8f4c1..5dc5d729 100644 --- a/webkit/appcache/appcache_request_handler_unittest.cc +++ b/webkit/appcache/appcache_request_handler_unittest.cc @@ -32,6 +32,10 @@ class AppCacheRequestHandlerTest : public testing::Test { virtual void OnEventRaised(const std::vector<int>& host_ids, appcache::EventID event_id) {} + virtual void OnProgressEventRaised(const std::vector<int>& host_ids, + const GURL& url, + int num_total, int num_complete) {} + virtual void OnContentBlocked(int host_id) {} }; diff --git a/webkit/appcache/appcache_update_job.cc b/webkit/appcache/appcache_update_job.cc index dd2c79e..5bd7d42 100644 --- a/webkit/appcache/appcache_update_job.cc +++ b/webkit/appcache/appcache_update_job.cc @@ -96,6 +96,16 @@ class HostNotifier { } } + void SendProgressNotifications( + const GURL& url, int num_total, int num_complete) { + for (NotifyHostMap::iterator it = hosts_to_notify.begin(); + it != hosts_to_notify.end(); ++it) { + AppCacheFrontend* frontend = it->first; + frontend->OnProgressEventRaised(it->second, url, + num_total, num_complete); + } + } + private: NotifyHostMap hosts_to_notify; }; @@ -575,6 +585,7 @@ void AppCacheUpdateJob::HandleUrlFetchCompleted(URLRequest* request) { const GURL& url = request->original_url(); pending_url_fetches_.erase(url); + NotifyProgress(url); ++url_fetches_completed_; int response_code = request->status().is_success() @@ -817,28 +828,42 @@ void AppCacheUpdateJob::NotifyAllPendingMasterHosts(EventID event_id) { } void AppCacheUpdateJob::NotifyAllAssociatedHosts(EventID event_id) { + HostNotifier host_notifier; + AddAllAssociatedHostsToNotifier(&host_notifier); + host_notifier.SendNotifications(event_id); +} + +void AppCacheUpdateJob::NotifyProgress(const GURL& url) { + HostNotifier host_notifier; + AddAllAssociatedHostsToNotifier(&host_notifier); + host_notifier.SendProgressNotifications( + url, url_file_list_.size(), url_fetches_completed_); +} + +void AppCacheUpdateJob::NotifyFinalProgress() { + DCHECK(url_file_list_.size() == url_fetches_completed_); + NotifyProgress(GURL()); +} + +void AppCacheUpdateJob::AddAllAssociatedHostsToNotifier( + HostNotifier* host_notifier) { // Collect hosts so we only send one notification per frontend. // A host can only be associated with a single cache so no need to worry // about duplicate hosts being added to the notifier. - HostNotifier host_notifier; if (inprogress_cache_) { DCHECK(internal_state_ == DOWNLOADING || internal_state_ == CACHE_FAILURE); - host_notifier.AddHosts(inprogress_cache_->associated_hosts()); + host_notifier->AddHosts(inprogress_cache_->associated_hosts()); } AppCacheGroup::Caches old_caches = group_->old_caches(); for (AppCacheGroup::Caches::const_iterator it = old_caches.begin(); it != old_caches.end(); ++it) { - host_notifier.AddHosts((*it)->associated_hosts()); + host_notifier->AddHosts((*it)->associated_hosts()); } AppCache* newest_cache = group_->newest_complete_cache(); if (newest_cache) - host_notifier.AddHosts(newest_cache->associated_hosts()); - - // TODO(jennb): if progress event, also pass params lengthComputable=true, - // total = url_file_list_.size(), loaded=url_fetches_completed_. - host_notifier.SendNotifications(event_id); + host_notifier->AddHosts(newest_cache->associated_hosts()); } void AppCacheUpdateJob::OnDestructionImminent(AppCacheHost* host) { @@ -925,10 +950,6 @@ void AppCacheUpdateJob::FetchUrls() { // each fetch completes. while (pending_url_fetches_.size() < kMaxConcurrentUrlFetches && !urls_to_fetch_.empty()) { - // Notify about progress first to ensure it starts from 0% in case any - // entries are skipped. - NotifyAllAssociatedHosts(PROGRESS_EVENT); - const GURL url = urls_to_fetch_.front().first; bool storage_checked = urls_to_fetch_.front().second; urls_to_fetch_.pop_front(); @@ -937,8 +958,10 @@ void AppCacheUpdateJob::FetchUrls() { DCHECK(it != url_file_list_.end()); AppCacheEntry& entry = it->second; if (ShouldSkipUrlFetch(entry)) { + NotifyProgress(url); ++url_fetches_completed_; } else if (AlreadyFetchedEntry(url, entry.types())) { + NotifyProgress(url); ++url_fetches_completed_; // saved a URL request } else if (!storage_checked && MaybeLoadFromNewestCache(url, entry)) { // Continues asynchronously after data is loaded from newest cache. @@ -1164,6 +1187,7 @@ void AppCacheUpdateJob::OnResponseInfoLoaded( entry.set_response_id(response_id); entry.set_response_size(copy_me->response_size()); inprogress_cache_->AddOrModifyEntry(url, entry); + NotifyProgress(url); ++url_fetches_completed_; } } @@ -1213,6 +1237,7 @@ void AppCacheUpdateJob::MaybeCompleteUpdate() { break; case REFETCH_MANIFEST: DCHECK(stored_state_ == STORED); + NotifyFinalProgress(); if (update_type_ == CACHE_ATTEMPT) NotifyAllAssociatedHosts(CACHED_EVENT); else diff --git a/webkit/appcache/appcache_update_job.h b/webkit/appcache/appcache_update_job.h index c50f202..8dc7fb3 100644 --- a/webkit/appcache/appcache_update_job.h +++ b/webkit/appcache/appcache_update_job.h @@ -25,6 +25,7 @@ namespace appcache { class UpdateJobInfo; +class HostNotifier; // Application cache Update algorithm and state. class AppCacheUpdateJob : public URLRequest::Delegate, @@ -144,6 +145,9 @@ class AppCacheUpdateJob : public URLRequest::Delegate, void NotifySingleHost(AppCacheHost* host, EventID event_id); void NotifyAllPendingMasterHosts(EventID event_id); void NotifyAllAssociatedHosts(EventID event_id); + void NotifyProgress(const GURL& url); + void NotifyFinalProgress(); + void AddAllAssociatedHostsToNotifier(HostNotifier* notifier); // Checks if manifest is byte for byte identical with the manifest // in the newest application cache. diff --git a/webkit/appcache/appcache_update_job_unittest.cc b/webkit/appcache/appcache_update_job_unittest.cc index df63042..5b42fe4 100644 --- a/webkit/appcache/appcache_update_job_unittest.cc +++ b/webkit/appcache/appcache_update_job_unittest.cc @@ -24,7 +24,11 @@ const wchar_t kDocRoot[] = L"webkit/appcache/data/appcache_unittest"; class MockFrontend : public AppCacheFrontend { public: - MockFrontend() : start_update_trigger_(CHECKING_EVENT), update_(NULL) { } + MockFrontend() + : ignore_progress_events_(false), verify_progress_events_(false), + last_progress_total_(-1), last_progress_complete_(-1), + start_update_trigger_(CHECKING_EVENT), update_(NULL) { + } virtual void OnCacheSelected(int host_id, int64 cache_id, Status status) { @@ -50,13 +54,58 @@ class MockFrontend : public AppCacheFrontend { } } + virtual void OnProgressEventRaised(const std::vector<int>& host_ids, + const GURL& url, + int num_total, int num_complete) { + if (!ignore_progress_events_) + OnEventRaised(host_ids, PROGRESS_EVENT); + + if (verify_progress_events_) { + EXPECT_GE(num_total, num_complete); + EXPECT_GE(num_complete, 0); + + if (last_progress_total_ == -1) { + // Should start at zero. + EXPECT_EQ(0, num_complete); + } else { + // Total should be stable and complete should bump up by one at a time. + EXPECT_EQ(last_progress_total_, num_total); + EXPECT_EQ(last_progress_complete_ + 1, num_complete); + } + + // Url should be valid for all except the 'final' event. + if (num_total == num_complete) + EXPECT_TRUE(url.is_empty()); + else + EXPECT_TRUE(url.is_valid()); + + last_progress_total_ = num_total; + last_progress_complete_ = num_complete; + } + } + virtual void OnContentBlocked(int host_id) { } void AddExpectedEvent(const std::vector<int>& host_ids, EventID event_id) { + DCHECK(!ignore_progress_events_ || event_id != PROGRESS_EVENT); expected_events_.push_back(RaisedEvent(host_ids, event_id)); } + void SetIgnoreProgressEvents(bool ignore) { + // Some tests involve joining new hosts to an already running update job + // or intentionally failing. The timing and sequencing of the progress + // events generated by an update job are dependent on the behavior of + // an external HTTP server. For jobs that do not run fully till completion, + // due to either joining late or early exit, we skip monitoring the + // progress events to avoid flakiness. + ignore_progress_events_ = ignore; + } + + void SetVerifyProgressEvents(bool verify) { + verify_progress_events_ = verify; + } + void TriggerAdditionalUpdates(EventID trigger_event, AppCacheUpdateJob* update) { start_update_trigger_ = trigger_event; @@ -75,6 +124,12 @@ class MockFrontend : public AppCacheFrontend { // Set the expected events if verification needs to happen asynchronously. RaisedEvents expected_events_; + bool ignore_progress_events_; + + bool verify_progress_events_; + int last_progress_total_; + int last_progress_complete_; + // Add ability for frontend to add master entries to an inprogress update. EventID start_update_trigger_; AppCacheUpdateJob* update_; @@ -849,6 +904,8 @@ class AppCacheUpdateJobTest : public testing::Test, AppCacheHost* host2 = MakeHost(2, frontend2); host1->AssociateCache(cache); host2->AssociateCache(cache); + frontend1->SetVerifyProgressEvents(true); + frontend2->SetVerifyProgressEvents(true); // Set up checks for when update job finishes. do_checks_after_update_finished_ = true; @@ -861,12 +918,14 @@ class AppCacheUpdateJobTest : public testing::Test, frontend1->AddExpectedEvent(ids1, DOWNLOADING_EVENT); frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // final frontend1->AddExpectedEvent(ids1, UPDATE_READY_EVENT); MockFrontend::HostIds ids2(1, host2->host_id()); frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT); frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); + frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // final frontend2->AddExpectedEvent(ids2, UPDATE_READY_EVENT); // Seed storage with expected manifest data different from manifest1. @@ -919,6 +978,7 @@ class AppCacheUpdateJobTest : public testing::Test, frontend->AddExpectedEvent(ids, DOWNLOADING_EVENT); frontend->AddExpectedEvent(ids, PROGRESS_EVENT); frontend->AddExpectedEvent(ids, PROGRESS_EVENT); + frontend->AddExpectedEvent(ids, PROGRESS_EVENT); // final frontend->AddExpectedEvent(ids, UPDATE_READY_EVENT); // Seed storage with expected http response info for entry. Allow reuse. @@ -975,8 +1035,7 @@ class AppCacheUpdateJobTest : public testing::Test, frontend->AddExpectedEvent(ids, DOWNLOADING_EVENT); frontend->AddExpectedEvent(ids, PROGRESS_EVENT); frontend->AddExpectedEvent(ids, PROGRESS_EVENT); - // Extra progress event for re-attempt to fetch explicit1 from network. - frontend->AddExpectedEvent(ids, PROGRESS_EVENT); + frontend->AddExpectedEvent(ids, PROGRESS_EVENT); // final frontend->AddExpectedEvent(ids, UPDATE_READY_EVENT); // Seed storage with expected http response info for entry. Do NOT @@ -1034,8 +1093,7 @@ class AppCacheUpdateJobTest : public testing::Test, frontend->AddExpectedEvent(ids, DOWNLOADING_EVENT); frontend->AddExpectedEvent(ids, PROGRESS_EVENT); frontend->AddExpectedEvent(ids, PROGRESS_EVENT); - // Extra progress event for re-attempt to fetch explicit1 from network. - frontend->AddExpectedEvent(ids, PROGRESS_EVENT); + frontend->AddExpectedEvent(ids, PROGRESS_EVENT); // final frontend->AddExpectedEvent(ids, UPDATE_READY_EVENT); // Seed storage with expected http response info for entry: a vary header. @@ -1095,18 +1153,16 @@ class AppCacheUpdateJobTest : public testing::Test, MockFrontend::HostIds ids1(1, host1->host_id()); frontend1->AddExpectedEvent(ids1, CHECKING_EVENT); frontend1->AddExpectedEvent(ids1, DOWNLOADING_EVENT); - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // explicit1 (load) - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // manifest (load) - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // explicit1 (fetch) - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // manifest (fetch) + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // explicit1 + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // manifest + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // final frontend1->AddExpectedEvent(ids1, UPDATE_READY_EVENT); MockFrontend::HostIds ids2(1, host2->host_id()); frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT); frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); + frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // final frontend2->AddExpectedEvent(ids2, UPDATE_READY_EVENT); WaitForUpdateToFinish(); @@ -1150,6 +1206,8 @@ class AppCacheUpdateJobTest : public testing::Test, AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 99); MockFrontend* frontend1 = MakeMockFrontend(); MockFrontend* frontend2 = MakeMockFrontend(); + frontend1->SetIgnoreProgressEvents(true); + frontend2->SetIgnoreProgressEvents(true); AppCacheHost* host1 = MakeHost(1, frontend1); AppCacheHost* host2 = MakeHost(2, frontend2); host1->AssociateCache(cache); @@ -1166,16 +1224,10 @@ class AppCacheUpdateJobTest : public testing::Test, MockFrontend::HostIds ids1(1, host1->host_id()); frontend1->AddExpectedEvent(ids1, CHECKING_EVENT); frontend1->AddExpectedEvent(ids1, DOWNLOADING_EVENT); - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); frontend1->AddExpectedEvent(ids1, ERROR_EVENT); MockFrontend::HostIds ids2(1, host2->host_id()); frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); frontend2->AddExpectedEvent(ids2, ERROR_EVENT); WaitForUpdateToFinish(); @@ -1232,24 +1284,20 @@ class AppCacheUpdateJobTest : public testing::Test, frontend1->AddExpectedEvent(ids1, DOWNLOADING_EVENT); frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // explicit1 frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // fallback1a - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // notfound (load) - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // notfound (fetch) - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // explicit2 (load) - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // explicit2 (fetch) - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // servererror (load) - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // servererror (fetch) + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // notfound + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // explicit2 + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // servererror + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // final frontend1->AddExpectedEvent(ids1, UPDATE_READY_EVENT); MockFrontend::HostIds ids2(1, host2->host_id()); frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); + frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // explicit1 + frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // fallback1a + frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // notfound + frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // explicit2 + frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // servererror + frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // final frontend2->AddExpectedEvent(ids2, UPDATE_READY_EVENT); WaitForUpdateToFinish(); @@ -1273,6 +1321,8 @@ class AppCacheUpdateJobTest : public testing::Test, host1->AssociateCache(cache); host2->AssociateCache(cache); + frontend1->SetVerifyProgressEvents(true); + update->StartUpdate(NULL, GURL()); EXPECT_TRUE(update->manifest_url_request_ != NULL); @@ -1285,10 +1335,12 @@ class AppCacheUpdateJobTest : public testing::Test, MockFrontend::HostIds ids1(1, host1->host_id()); frontend1->AddExpectedEvent(ids1, CHECKING_EVENT); frontend1->AddExpectedEvent(ids1, DOWNLOADING_EVENT); + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // final frontend1->AddExpectedEvent(ids1, UPDATE_READY_EVENT); MockFrontend::HostIds ids2(1, host2->host_id()); frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT); + frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // final frontend2->AddExpectedEvent(ids2, UPDATE_READY_EVENT); WaitForUpdateToFinish(); @@ -1308,6 +1360,7 @@ class AppCacheUpdateJobTest : public testing::Test, MockFrontend* frontend = MakeMockFrontend(); AppCacheHost* host = MakeHost(1, frontend); host->AssociateCache(cache); + frontend->SetVerifyProgressEvents(true); update->StartUpdate(host, GURL()); EXPECT_TRUE(update->manifest_url_request_ != NULL); @@ -1321,6 +1374,7 @@ class AppCacheUpdateJobTest : public testing::Test, frontend->AddExpectedEvent(ids1, CHECKING_EVENT); frontend->AddExpectedEvent(ids1, DOWNLOADING_EVENT); frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); + frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); // final frontend->AddExpectedEvent(ids1, UPDATE_READY_EVENT); WaitForUpdateToFinish(); @@ -1714,6 +1768,7 @@ class AppCacheUpdateJobTest : public testing::Test, group_->update_job_ = update; MockFrontend* frontend = MakeMockFrontend(); + frontend->SetIgnoreProgressEvents(true); AppCacheHost* host = MakeHost(1, frontend); host->new_master_entry_url_ = http_server_->TestServerPage("files/explicit1"); @@ -1728,9 +1783,6 @@ class AppCacheUpdateJobTest : public testing::Test, MockFrontend::HostIds ids1(1, host->host_id()); frontend->AddExpectedEvent(ids1, CHECKING_EVENT); frontend->AddExpectedEvent(ids1, DOWNLOADING_EVENT); - frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); - frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); - frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); frontend->AddExpectedEvent(ids1, ERROR_EVENT); WaitForUpdateToFinish(); @@ -1746,12 +1798,14 @@ class AppCacheUpdateJobTest : public testing::Test, group_->update_job_ = update; MockFrontend* frontend1 = MakeMockFrontend(); + frontend1->SetIgnoreProgressEvents(true); AppCacheHost* host1 = MakeHost(1, frontend1); host1->new_master_entry_url_ = http_server_->TestServerPage("files/nosuchfile"); update->StartUpdate(host1, host1->new_master_entry_url_); MockFrontend* frontend2 = MakeMockFrontend(); + frontend2->SetIgnoreProgressEvents(true); AppCacheHost* host2 = MakeHost(2, frontend2); host2->new_master_entry_url_ = http_server_->TestServerPage("files/servererror"); @@ -1764,14 +1818,10 @@ class AppCacheUpdateJobTest : public testing::Test, MockFrontend::HostIds ids1(1, host1->host_id()); frontend1->AddExpectedEvent(ids1, CHECKING_EVENT); frontend1->AddExpectedEvent(ids1, DOWNLOADING_EVENT); - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); frontend1->AddExpectedEvent(ids1, ERROR_EVENT); MockFrontend::HostIds ids2(1, host2->host_id()); frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); frontend2->AddExpectedEvent(ids2, ERROR_EVENT); WaitForUpdateToFinish(); @@ -1792,12 +1842,14 @@ class AppCacheUpdateJobTest : public testing::Test, host1->AssociateCache(cache); MockFrontend* frontend2 = MakeMockFrontend(); + frontend2->SetIgnoreProgressEvents(true); AppCacheHost* host2 = MakeHost(2, frontend2); host2->new_master_entry_url_ = http_server_->TestServerPage("files/nosuchfile"); update->StartUpdate(host2, host2->new_master_entry_url_); MockFrontend* frontend3 = MakeMockFrontend(); + frontend3->SetIgnoreProgressEvents(true); AppCacheHost* host3 = MakeHost(3, frontend3); host3->new_master_entry_url_ = http_server_->TestServerPage("files/servererror"); @@ -1814,17 +1866,14 @@ class AppCacheUpdateJobTest : public testing::Test, frontend1->AddExpectedEvent(ids1, DOWNLOADING_EVENT); frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // final frontend1->AddExpectedEvent(ids1, UPDATE_READY_EVENT); MockFrontend::HostIds ids2(1, host2->host_id()); frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); frontend2->AddExpectedEvent(ids2, ERROR_EVENT); MockFrontend::HostIds ids3(1, host3->host_id()); frontend3->AddExpectedEvent(ids3, CHECKING_EVENT); frontend3->AddExpectedEvent(ids3, DOWNLOADING_EVENT); - frontend3->AddExpectedEvent(ids3, PROGRESS_EVENT); - frontend3->AddExpectedEvent(ids3, PROGRESS_EVENT); frontend3->AddExpectedEvent(ids3, ERROR_EVENT); WaitForUpdateToFinish(); @@ -1840,6 +1889,7 @@ class AppCacheUpdateJobTest : public testing::Test, group_->update_job_ = update; MockFrontend* frontend1 = MakeMockFrontend(); + frontend1->SetIgnoreProgressEvents(true); AppCacheHost* host1 = MakeHost(1, frontend1); host1->new_master_entry_url_ = http_server_->TestServerPage("files/nosuchfile"); @@ -1862,14 +1912,13 @@ class AppCacheUpdateJobTest : public testing::Test, MockFrontend::HostIds ids1(1, host1->host_id()); frontend1->AddExpectedEvent(ids1, CHECKING_EVENT); frontend1->AddExpectedEvent(ids1, DOWNLOADING_EVENT); - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); - frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); frontend1->AddExpectedEvent(ids1, ERROR_EVENT); MockFrontend::HostIds ids2(1, host2->host_id()); frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT); frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); + frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // final frontend2->AddExpectedEvent(ids2, CACHED_EVENT); WaitForUpdateToFinish(); @@ -1890,6 +1939,7 @@ class AppCacheUpdateJobTest : public testing::Test, host1->AssociateCache(cache); MockFrontend* frontend2 = MakeMockFrontend(); + frontend2->SetIgnoreProgressEvents(true); AppCacheHost* host2 = MakeHost(2, frontend2); host2->new_master_entry_url_ = http_server_->TestServerPage("files/nosuchfile"); @@ -1915,17 +1965,17 @@ class AppCacheUpdateJobTest : public testing::Test, frontend1->AddExpectedEvent(ids1, DOWNLOADING_EVENT); frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // final frontend1->AddExpectedEvent(ids1, UPDATE_READY_EVENT); MockFrontend::HostIds ids2(1, host2->host_id()); frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); frontend2->AddExpectedEvent(ids2, ERROR_EVENT); MockFrontend::HostIds ids3(1, host3->host_id()); frontend3->AddExpectedEvent(ids3, CHECKING_EVENT); frontend3->AddExpectedEvent(ids3, DOWNLOADING_EVENT); frontend3->AddExpectedEvent(ids3, PROGRESS_EVENT); frontend3->AddExpectedEvent(ids3, PROGRESS_EVENT); + frontend3->AddExpectedEvent(ids3, PROGRESS_EVENT); // final frontend3->AddExpectedEvent(ids3, UPDATE_READY_EVENT); WaitForUpdateToFinish(); @@ -2003,6 +2053,7 @@ class AppCacheUpdateJobTest : public testing::Test, // Set up additional updates to be started while update is in progress. MockFrontend* frontend2 = MakeMockFrontend(); + frontend2->SetIgnoreProgressEvents(true); AppCacheHost* host2 = MakeHost(2, frontend2); host2->new_master_entry_url_ = http_server_->TestServerPage("files/nosuchfile"); @@ -2040,24 +2091,25 @@ class AppCacheUpdateJobTest : public testing::Test, frontend1->AddExpectedEvent(ids1, DOWNLOADING_EVENT); frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // final frontend1->AddExpectedEvent(ids1, CACHED_EVENT); MockFrontend::HostIds ids2(1, host2->host_id()); frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); - frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); frontend2->AddExpectedEvent(ids2, ERROR_EVENT); MockFrontend::HostIds ids3(1, host3->host_id()); frontend3->AddExpectedEvent(ids3, CHECKING_EVENT); frontend3->AddExpectedEvent(ids3, DOWNLOADING_EVENT); frontend3->AddExpectedEvent(ids3, PROGRESS_EVENT); frontend3->AddExpectedEvent(ids3, PROGRESS_EVENT); + frontend3->AddExpectedEvent(ids3, PROGRESS_EVENT); // final frontend3->AddExpectedEvent(ids3, CACHED_EVENT); MockFrontend::HostIds ids4(1, host4->host_id()); frontend4->AddExpectedEvent(ids4, CHECKING_EVENT); frontend4->AddExpectedEvent(ids4, DOWNLOADING_EVENT); frontend4->AddExpectedEvent(ids4, PROGRESS_EVENT); frontend4->AddExpectedEvent(ids4, PROGRESS_EVENT); + frontend4->AddExpectedEvent(ids4, PROGRESS_EVENT); // final frontend4->AddExpectedEvent(ids4, CACHED_EVENT); // Host 5 is not associated with cache so no progress/cached events. @@ -2203,16 +2255,19 @@ class AppCacheUpdateJobTest : public testing::Test, frontend1->AddExpectedEvent(ids1, DOWNLOADING_EVENT); frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); + frontend1->AddExpectedEvent(ids1, PROGRESS_EVENT); // final frontend1->AddExpectedEvent(ids1, UPDATE_READY_EVENT); MockFrontend::HostIds ids2(1, host2->host_id()); frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT); frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); + frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // final frontend2->AddExpectedEvent(ids2, UPDATE_READY_EVENT); MockFrontend::HostIds ids3(1, host3->host_id()); frontend3->AddExpectedEvent(ids3, CHECKING_EVENT); frontend3->AddExpectedEvent(ids3, DOWNLOADING_EVENT); frontend3->AddExpectedEvent(ids3, PROGRESS_EVENT); + frontend3->AddExpectedEvent(ids3, PROGRESS_EVENT); // final frontend3->AddExpectedEvent(ids3, UPDATE_READY_EVENT); MockFrontend::HostIds ids4(1, host4->host_id()); // unassociated w/cache frontend4->AddExpectedEvent(ids4, CHECKING_EVENT); @@ -2221,6 +2276,7 @@ class AppCacheUpdateJobTest : public testing::Test, frontend5->AddExpectedEvent(ids5, CHECKING_EVENT); frontend5->AddExpectedEvent(ids5, DOWNLOADING_EVENT); frontend5->AddExpectedEvent(ids5, PROGRESS_EVENT); + frontend5->AddExpectedEvent(ids5, PROGRESS_EVENT); // final frontend5->AddExpectedEvent(ids5, UPDATE_READY_EVENT); WaitForUpdateToFinish(); @@ -2266,6 +2322,7 @@ class AppCacheUpdateJobTest : public testing::Test, frontend->AddExpectedEvent(ids1, DOWNLOADING_EVENT); frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); + frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); // final frontend->AddExpectedEvent(ids1, CACHED_EVENT); // Group status will be IDLE so cannot call WaitForUpdateToFinish. @@ -2372,6 +2429,7 @@ class AppCacheUpdateJobTest : public testing::Test, frontend->AddExpectedEvent(ids1, DOWNLOADING_EVENT); frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); + frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); // final frontend->AddExpectedEvent(ids1, UPDATE_READY_EVENT); // Seed storage with expected manifest response info that will cause @@ -2429,6 +2487,7 @@ class AppCacheUpdateJobTest : public testing::Test, frontend->AddExpectedEvent(ids1, DOWNLOADING_EVENT); frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); + frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); // final frontend->AddExpectedEvent(ids1, UPDATE_READY_EVENT); // Seed storage with expected manifest response info that will cause diff --git a/webkit/appcache/web_application_cache_host_impl.cc b/webkit/appcache/web_application_cache_host_impl.cc index 2aec43a..267f20b 100644 --- a/webkit/appcache/web_application_cache_host_impl.cc +++ b/webkit/appcache/web_application_cache_host_impl.cc @@ -75,16 +75,23 @@ void WebApplicationCacheHostImpl::OnStatusChanged(appcache::Status status) { } void WebApplicationCacheHostImpl::OnEventRaised(appcache::EventID event_id) { + DCHECK(event_id != PROGRESS_EVENT); // See OnProgressEventRaised. // Most events change the status. Clear out what we know so that the latest // status will be obtained from the backend. - if (PROGRESS_EVENT != event_id) { - has_status_ = false; - has_cached_status_ = false; - } - + has_status_ = false; + has_cached_status_ = false; client_->notifyEventListener(static_cast<EventID>(event_id)); } +void WebApplicationCacheHostImpl::OnProgressEventRaised( + const GURL& url, int num_total, int num_complete) { + // TODO(michaeln): Widen the webkit api to accept the additional data. + // Also send the 'final' event once webkit layout tests have been updated. + // See https://bugs.webkit.org/show_bug.cgi?id=37602 + if (num_complete < num_total) + client_->notifyEventListener(WebApplicationCacheHost::ProgressEvent); +} + void WebApplicationCacheHostImpl::willStartMainResourceRequest( WebURLRequest& request) { request.setAppCacheHostID(host_id_); diff --git a/webkit/appcache/web_application_cache_host_impl.h b/webkit/appcache/web_application_cache_host_impl.h index b2e1e53..7d7060c 100644 --- a/webkit/appcache/web_application_cache_host_impl.h +++ b/webkit/appcache/web_application_cache_host_impl.h @@ -33,6 +33,7 @@ class WebApplicationCacheHostImpl : public WebKit::WebApplicationCacheHost { void OnCacheSelected(int64 selected_cache_id, appcache::Status status); void OnStatusChanged(appcache::Status); void OnEventRaised(appcache::EventID); + void OnProgressEventRaised(const GURL& url, int num_total, int num_complete); virtual void OnContentBlocked() {} // WebApplicationCacheHost methods diff --git a/webkit/tools/test_shell/simple_appcache_system.cc b/webkit/tools/test_shell/simple_appcache_system.cc index 79bc557..eb32eb6 100644 --- a/webkit/tools/test_shell/simple_appcache_system.cc +++ b/webkit/tools/test_shell/simple_appcache_system.cc @@ -99,6 +99,22 @@ class SimpleFrontendProxy NOTREACHED(); } + virtual void OnProgressEventRaised(const std::vector<int>& host_ids, + const GURL& url, + int num_total, int num_complete) { + if (!system_) + return; + if (system_->is_io_thread()) + system_->ui_message_loop()->PostTask(FROM_HERE, NewRunnableMethod( + this, &SimpleFrontendProxy::OnProgressEventRaised, + host_ids, url, num_total, num_complete)); + else if (system_->is_ui_thread()) + system_->frontend_impl_.OnProgressEventRaised( + host_ids, url, num_total, num_complete); + else + NOTREACHED(); + } + virtual void OnContentBlocked(int host_id) {} private: |