summaryrefslogtreecommitdiffstats
path: root/webkit/appcache/appcache_group_unittest.cc
diff options
context:
space:
mode:
authorjennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-10 23:03:30 +0000
committerjennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-10 23:03:30 +0000
commitdc60e95adac80ad6c9a88cde612d37d5ecba3ebd (patch)
tree7b674dda57a5c149d093ce52d1ad67910f14d9ea /webkit/appcache/appcache_group_unittest.cc
parent8f0e7700181b5b69040fdd45ab775884c954461d (diff)
downloadchromium_src-dc60e95adac80ad6c9a88cde612d37d5ecba3ebd.zip
chromium_src-dc60e95adac80ad6c9a88cde612d37d5ecba3ebd.tar.gz
chromium_src-dc60e95adac80ad6c9a88cde612d37d5ecba3ebd.tar.bz2
Queue appcache update if current update process is terminating.
TEST=update and group unittests added BUG=none Review URL: http://codereview.chromium.org/465132 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34299 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_group_unittest.cc')
-rw-r--r--webkit/appcache/appcache_group_unittest.cc63
1 files changed, 63 insertions, 0 deletions
diff --git a/webkit/appcache/appcache_group_unittest.cc b/webkit/appcache/appcache_group_unittest.cc
index 81280e7..384a38b 100644
--- a/webkit/appcache/appcache_group_unittest.cc
+++ b/webkit/appcache/appcache_group_unittest.cc
@@ -56,6 +56,21 @@ class TestUpdateObserver : public AppCacheGroup::UpdateObserver {
bool group_has_cache_;
};
+class TestAppCacheHost : public AppCacheHost {
+ public:
+ TestAppCacheHost(int host_id, AppCacheFrontend* frontend,
+ AppCacheService* service)
+ : AppCacheHost(host_id, frontend, service),
+ update_completed_(false) {
+ }
+
+ virtual void OnUpdateComplete(AppCacheGroup* group) {
+ update_completed_ = true;
+ }
+
+ bool update_completed_;
+};
+
class AppCacheGroupTest : public testing::Test {
};
@@ -208,4 +223,52 @@ TEST(AppCacheGroupTest, CancelUpdate) {
EXPECT_FALSE(observer.group_has_cache_);
}
+TEST(AppCacheGroupTest, QueueUpdate) {
+ MockAppCacheService service;
+ scoped_refptr<AppCacheGroup> group =
+ new AppCacheGroup(&service, GURL("http://foo.com"), 111);
+
+ // Set state to checking to prevent update job from executing fetches.
+ group->update_status_ = AppCacheGroup::CHECKING;
+ group->StartUpdate();
+ EXPECT_TRUE(group->update_job_);
+
+ // Pretend group's update job is terminating so that next update is queued.
+ group->update_job_->internal_state_ = AppCacheUpdateJob::REFETCH_MANIFEST;
+ EXPECT_TRUE(group->update_job_->IsTerminating());
+
+ TestAppCacheFrontend frontend;
+ TestAppCacheHost host(1, &frontend, &service);
+ host.new_master_entry_url_ = GURL("http://foo.com/bar.txt");
+ group->StartUpdateWithNewMasterEntry(&host, host.new_master_entry_url_);
+ EXPECT_FALSE(group->queued_updates_.empty());
+
+ group->AddUpdateObserver(&host);
+ EXPECT_FALSE(group->FindObserver(&host, group->observers_));
+ EXPECT_TRUE(group->FindObserver(&host, group->queued_observers_));
+
+ // Delete update to cause it to complete. Verify no update complete notice
+ // sent to host.
+ delete group->update_job_;
+ EXPECT_EQ(AppCacheGroup::IDLE, group->update_status_);
+ EXPECT_TRUE(group->restart_update_task_);
+ EXPECT_FALSE(host.update_completed_);
+
+ // Start another update. Cancels task and will run queued updates.
+ group->update_status_ = AppCacheGroup::CHECKING; // prevent actual fetches
+ group->StartUpdate();
+ EXPECT_TRUE(group->update_job_);
+ EXPECT_FALSE(group->restart_update_task_);
+ EXPECT_TRUE(group->queued_updates_.empty());
+ EXPECT_FALSE(group->update_job_->pending_master_entries_.empty());
+ EXPECT_FALSE(group->FindObserver(&host, group->queued_observers_));
+ EXPECT_TRUE(group->FindObserver(&host, group->observers_));
+
+ // Delete update to cause it to complete. Verify host is notified.
+ delete group->update_job_;
+ EXPECT_EQ(AppCacheGroup::IDLE, group->update_status_);
+ EXPECT_FALSE(group->restart_update_task_);
+ EXPECT_TRUE(host.update_completed_);
+}
+
} // namespace appcache