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-09-02 23:17:33 +0000
committerjennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-02 23:17:33 +0000
commiteaa0885f7f32060ea7313e25dc1104d5a9b6b3ba (patch)
treee81482931ebf2e92e2e3302d45c6b5470820752b /webkit/appcache/appcache_group_unittest.cc
parent900950e1a35c75ad3089e1f78c03e8c497cdb6f0 (diff)
downloadchromium_src-eaa0885f7f32060ea7313e25dc1104d5a9b6b3ba.zip
chromium_src-eaa0885f7f32060ea7313e25dc1104d5a9b6b3ba.tar.gz
chromium_src-eaa0885f7f32060ea7313e25dc1104d5a9b6b3ba.tar.bz2
Change AppCache and AppCacheGroup to be ref counted classes.Adjusted API of framework classes accordingly.Added unittests for appcache framework classes.TEST=verify objects are cleaned up properly, verify api implBUG=none
Review URL: http://codereview.chromium.org/179071 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25264 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_group_unittest.cc')
-rw-r--r--webkit/appcache/appcache_group_unittest.cc96
1 files changed, 96 insertions, 0 deletions
diff --git a/webkit/appcache/appcache_group_unittest.cc b/webkit/appcache/appcache_group_unittest.cc
new file mode 100644
index 0000000..c4e0cd1
--- /dev/null
+++ b/webkit/appcache/appcache_group_unittest.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2009 The Chromium Authos. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/appcache/appcache.h"
+#include "webkit/appcache/appcache_host.h"
+#include "webkit/appcache/appcache_group.h"
+#include "webkit/appcache/appcache_service.h"
+
+using appcache::AppCache;
+using appcache::AppCacheHost;
+using appcache::AppCacheGroup;
+using appcache::AppCacheService;
+
+namespace {
+
+class AppCacheGroupTest : public testing::Test {
+};
+
+} // namespace
+
+TEST(AppCacheGroupTest, AddRemoveCache) {
+ AppCacheService service;
+ scoped_refptr<AppCacheGroup> group =
+ new AppCacheGroup(&service, GURL::EmptyGURL());
+
+ base::TimeTicks ticks = base::TimeTicks::Now();
+
+ AppCache* cache1 = new AppCache(&service, 111);
+ cache1->set_complete(true);
+ cache1->set_update_time(ticks);
+ cache1->set_owning_group(group);
+ group->AddCache(cache1);
+ EXPECT_EQ(cache1, group->newest_complete_cache());
+
+ // Adding older cache does not change newest complete cache.
+ AppCache* cache2 = new AppCache(&service, 222);
+ cache2->set_complete(true);
+ cache2->set_update_time(ticks - base::TimeDelta::FromDays(1));
+ cache2->set_owning_group(group);
+ group->AddCache(cache2);
+ EXPECT_EQ(cache1, group->newest_complete_cache());
+
+ // Adding newer cache does change newest complete cache.
+ AppCache* cache3 = new AppCache(&service, 333);
+ cache3->set_complete(true);
+ cache3->set_update_time(ticks + base::TimeDelta::FromDays(1));
+ cache3->set_owning_group(group);
+ group->AddCache(cache3);
+ EXPECT_EQ(cache3, group->newest_complete_cache());
+
+ // Old caches can always be removed.
+ EXPECT_TRUE(group->RemoveCache(cache1));
+ EXPECT_EQ(cache3, group->newest_complete_cache()); // newest unchanged
+
+ // Cannot remove newest cache if there are older caches.
+ EXPECT_FALSE(group->RemoveCache(cache3));
+ EXPECT_EQ(cache3, group->newest_complete_cache()); // newest unchanged
+
+ // Can remove newest cache after all older caches are removed.
+ EXPECT_TRUE(group->RemoveCache(cache2));
+ EXPECT_EQ(cache3, group->newest_complete_cache()); // newest unchanged
+ EXPECT_TRUE(group->RemoveCache(cache3));
+}
+
+TEST(AppCacheGroupTest, CleanupUnusedGroup) {
+ AppCacheService service;
+ AppCacheGroup* group = new AppCacheGroup(&service, GURL::EmptyGURL());
+
+ AppCacheHost host1(1, NULL);
+ AppCacheHost host2(2, NULL);
+
+ base::TimeTicks ticks = base::TimeTicks::Now();
+
+ AppCache* cache1 = new AppCache(&service, 111);
+ cache1->set_complete(true);
+ cache1->set_update_time(ticks);
+ cache1->set_owning_group(group);
+ group->AddCache(cache1);
+ EXPECT_EQ(cache1, group->newest_complete_cache());
+
+ host1.set_selected_cache(cache1);
+ host2.set_selected_cache(cache1);
+
+ AppCache* cache2 = new AppCache(&service, 222);
+ cache2->set_complete(true);
+ cache2->set_update_time(ticks + base::TimeDelta::FromDays(1));
+ cache2->set_owning_group(group);
+ group->AddCache(cache2);
+ EXPECT_EQ(cache2, group->newest_complete_cache());
+
+ // Unassociate all hosts from older cache.
+ host1.set_selected_cache(NULL);
+ host2.set_selected_cache(NULL);
+}