diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 22:07:15 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 22:07:15 +0000 |
commit | 97e3edc23314c476859c22c8db601f9b3dec552d (patch) | |
tree | 9c589f47545b88c1453c2481a7844a921636485c /webkit/appcache/appcache_group_unittest.cc | |
parent | 34fce2a5030cb53a1e2decb37b5f7517f98457f7 (diff) | |
download | chromium_src-97e3edc23314c476859c22c8db601f9b3dec552d.zip chromium_src-97e3edc23314c476859c22c8db601f9b3dec552d.tar.gz chromium_src-97e3edc23314c476859c22c8db601f9b3dec552d.tar.bz2 |
* Fleshed out AppCacheHost class a fair amount, in particular the cache selection algorithm.
* Added some AppCacheHost unit tests.
* Introduced AppCacheRequestHandler class, which replaces the clunkyApp
CacheInterceptor::ExtraInfo struct. This impl is entirely skeletal
stubs for now.
TEST=appcache_unittest.cc, but really needs more
BUG=none
Review URL: http://codereview.chromium.org/192043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26275 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_group_unittest.cc')
-rw-r--r-- | webkit/appcache/appcache_group_unittest.cc | 67 |
1 files changed, 52 insertions, 15 deletions
diff --git a/webkit/appcache/appcache_group_unittest.cc b/webkit/appcache/appcache_group_unittest.cc index c4e0cd1..bcfbce0 100644 --- a/webkit/appcache/appcache_group_unittest.cc +++ b/webkit/appcache/appcache_group_unittest.cc @@ -4,26 +4,50 @@ #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_host.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 { +class TestAppCacheFrontend : public appcache::AppCacheFrontend { + public: + TestAppCacheFrontend() + : last_host_id_(-1), last_cache_id_(-1), + last_status_(appcache::OBSOLETE) { + } + + virtual void OnCacheSelected(int host_id, int64 cache_id , + appcache::Status status) { + last_host_id_ = host_id; + last_cache_id_ = cache_id; + last_status_ = status; + } + + virtual void OnStatusChanged(const std::vector<int>& host_ids, + appcache::Status status) { + } + + virtual void OnEventRaised(const std::vector<int>& host_ids, + appcache::EventID event_id) { + } + + int last_host_id_; + int64 last_cache_id_; + appcache::Status last_status_; }; -} // namespace +} // namespace anon + +namespace appcache { + +class AppCacheGroupTest : public testing::Test { +}; TEST(AppCacheGroupTest, AddRemoveCache) { AppCacheService service; scoped_refptr<AppCacheGroup> group = - new AppCacheGroup(&service, GURL::EmptyGURL()); + new AppCacheGroup(&service, GURL::EmptyGURL()); base::TimeTicks ticks = base::TimeTicks::Now(); @@ -66,10 +90,11 @@ TEST(AppCacheGroupTest, AddRemoveCache) { TEST(AppCacheGroupTest, CleanupUnusedGroup) { AppCacheService service; + TestAppCacheFrontend frontend; AppCacheGroup* group = new AppCacheGroup(&service, GURL::EmptyGURL()); - AppCacheHost host1(1, NULL); - AppCacheHost host2(2, NULL); + AppCacheHost host1(1, &frontend, &service); + AppCacheHost host2(2, &frontend, &service); base::TimeTicks ticks = base::TimeTicks::Now(); @@ -80,8 +105,15 @@ TEST(AppCacheGroupTest, CleanupUnusedGroup) { group->AddCache(cache1); EXPECT_EQ(cache1, group->newest_complete_cache()); - host1.set_selected_cache(cache1); - host2.set_selected_cache(cache1); + host1.AssociateCache(cache1); + EXPECT_EQ(frontend.last_host_id_, host1.host_id()); + EXPECT_EQ(frontend.last_cache_id_, cache1->cache_id()); + EXPECT_EQ(frontend.last_status_, appcache::IDLE); + + host2.AssociateCache(cache1); + EXPECT_EQ(frontend.last_host_id_, host2.host_id()); + EXPECT_EQ(frontend.last_cache_id_, cache1->cache_id()); + EXPECT_EQ(frontend.last_status_, appcache::IDLE); AppCache* cache2 = new AppCache(&service, 222); cache2->set_complete(true); @@ -91,6 +123,11 @@ TEST(AppCacheGroupTest, CleanupUnusedGroup) { EXPECT_EQ(cache2, group->newest_complete_cache()); // Unassociate all hosts from older cache. - host1.set_selected_cache(NULL); - host2.set_selected_cache(NULL); + host1.AssociateCache(NULL); + host2.AssociateCache(NULL); + EXPECT_EQ(frontend.last_host_id_, host2.host_id()); + EXPECT_EQ(frontend.last_cache_id_, appcache::kNoCacheId); + EXPECT_EQ(frontend.last_status_, appcache::UNCACHED); } + +} // namespace appcache |