Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: webkit/appcache/appcache_group_unittest.cc

Issue 192043: AppCacheHost cache selection algorithm (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/appcache/appcache_group.cc ('k') | webkit/appcache/appcache_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authos. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authos. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "webkit/appcache/appcache.h" 6 #include "webkit/appcache/appcache.h"
7 #include "webkit/appcache/appcache_group.h"
7 #include "webkit/appcache/appcache_host.h" 8 #include "webkit/appcache/appcache_host.h"
8 #include "webkit/appcache/appcache_group.h"
9 #include "webkit/appcache/appcache_service.h" 9 #include "webkit/appcache/appcache_service.h"
10 10
11 using appcache::AppCache; 11 namespace {
12 using appcache::AppCacheHost;
13 using appcache::AppCacheGroup;
14 using appcache::AppCacheService;
15 12
16 namespace { 13 class TestAppCacheFrontend : public appcache::AppCacheFrontend {
14 public:
15 TestAppCacheFrontend()
16 : last_host_id_(-1), last_cache_id_(-1),
17 last_status_(appcache::OBSOLETE) {
18 }
19
20 virtual void OnCacheSelected(int host_id, int64 cache_id ,
21 appcache::Status status) {
22 last_host_id_ = host_id;
23 last_cache_id_ = cache_id;
24 last_status_ = status;
25 }
26
27 virtual void OnStatusChanged(const std::vector<int>& host_ids,
28 appcache::Status status) {
29 }
30
31 virtual void OnEventRaised(const std::vector<int>& host_ids,
32 appcache::EventID event_id) {
33 }
34
35 int last_host_id_;
36 int64 last_cache_id_;
37 appcache::Status last_status_;
38 };
39
40 } // namespace anon
41
42 namespace appcache {
17 43
18 class AppCacheGroupTest : public testing::Test { 44 class AppCacheGroupTest : public testing::Test {
19 }; 45 };
20 46
21 } // namespace
22
23 TEST(AppCacheGroupTest, AddRemoveCache) { 47 TEST(AppCacheGroupTest, AddRemoveCache) {
24 AppCacheService service; 48 AppCacheService service;
25 scoped_refptr<AppCacheGroup> group = 49 scoped_refptr<AppCacheGroup> group =
26 new AppCacheGroup(&service, GURL::EmptyGURL()); 50 new AppCacheGroup(&service, GURL::EmptyGURL());
27 51
28 base::TimeTicks ticks = base::TimeTicks::Now(); 52 base::TimeTicks ticks = base::TimeTicks::Now();
29 53
30 AppCache* cache1 = new AppCache(&service, 111); 54 AppCache* cache1 = new AppCache(&service, 111);
31 cache1->set_complete(true); 55 cache1->set_complete(true);
32 cache1->set_update_time(ticks); 56 cache1->set_update_time(ticks);
33 cache1->set_owning_group(group); 57 cache1->set_owning_group(group);
34 group->AddCache(cache1); 58 group->AddCache(cache1);
35 EXPECT_EQ(cache1, group->newest_complete_cache()); 59 EXPECT_EQ(cache1, group->newest_complete_cache());
36 60
(...skipping 22 matching lines...) Expand all
59 EXPECT_EQ(cache3, group->newest_complete_cache()); // newest unchanged 83 EXPECT_EQ(cache3, group->newest_complete_cache()); // newest unchanged
60 84
61 // Can remove newest cache after all older caches are removed. 85 // Can remove newest cache after all older caches are removed.
62 EXPECT_TRUE(group->RemoveCache(cache2)); 86 EXPECT_TRUE(group->RemoveCache(cache2));
63 EXPECT_EQ(cache3, group->newest_complete_cache()); // newest unchanged 87 EXPECT_EQ(cache3, group->newest_complete_cache()); // newest unchanged
64 EXPECT_TRUE(group->RemoveCache(cache3)); 88 EXPECT_TRUE(group->RemoveCache(cache3));
65 } 89 }
66 90
67 TEST(AppCacheGroupTest, CleanupUnusedGroup) { 91 TEST(AppCacheGroupTest, CleanupUnusedGroup) {
68 AppCacheService service; 92 AppCacheService service;
93 TestAppCacheFrontend frontend;
69 AppCacheGroup* group = new AppCacheGroup(&service, GURL::EmptyGURL()); 94 AppCacheGroup* group = new AppCacheGroup(&service, GURL::EmptyGURL());
70 95
71 AppCacheHost host1(1, NULL); 96 AppCacheHost host1(1, &frontend, &service);
72 AppCacheHost host2(2, NULL); 97 AppCacheHost host2(2, &frontend, &service);
73 98
74 base::TimeTicks ticks = base::TimeTicks::Now(); 99 base::TimeTicks ticks = base::TimeTicks::Now();
75 100
76 AppCache* cache1 = new AppCache(&service, 111); 101 AppCache* cache1 = new AppCache(&service, 111);
77 cache1->set_complete(true); 102 cache1->set_complete(true);
78 cache1->set_update_time(ticks); 103 cache1->set_update_time(ticks);
79 cache1->set_owning_group(group); 104 cache1->set_owning_group(group);
80 group->AddCache(cache1); 105 group->AddCache(cache1);
81 EXPECT_EQ(cache1, group->newest_complete_cache()); 106 EXPECT_EQ(cache1, group->newest_complete_cache());
82 107
83 host1.set_selected_cache(cache1); 108 host1.AssociateCache(cache1);
84 host2.set_selected_cache(cache1); 109 EXPECT_EQ(frontend.last_host_id_, host1.host_id());
110 EXPECT_EQ(frontend.last_cache_id_, cache1->cache_id());
111 EXPECT_EQ(frontend.last_status_, appcache::IDLE);
112
113 host2.AssociateCache(cache1);
114 EXPECT_EQ(frontend.last_host_id_, host2.host_id());
115 EXPECT_EQ(frontend.last_cache_id_, cache1->cache_id());
116 EXPECT_EQ(frontend.last_status_, appcache::IDLE);
85 117
86 AppCache* cache2 = new AppCache(&service, 222); 118 AppCache* cache2 = new AppCache(&service, 222);
87 cache2->set_complete(true); 119 cache2->set_complete(true);
88 cache2->set_update_time(ticks + base::TimeDelta::FromDays(1)); 120 cache2->set_update_time(ticks + base::TimeDelta::FromDays(1));
89 cache2->set_owning_group(group); 121 cache2->set_owning_group(group);
90 group->AddCache(cache2); 122 group->AddCache(cache2);
91 EXPECT_EQ(cache2, group->newest_complete_cache()); 123 EXPECT_EQ(cache2, group->newest_complete_cache());
92 124
93 // Unassociate all hosts from older cache. 125 // Unassociate all hosts from older cache.
94 host1.set_selected_cache(NULL); 126 host1.AssociateCache(NULL);
95 host2.set_selected_cache(NULL); 127 host2.AssociateCache(NULL);
128 EXPECT_EQ(frontend.last_host_id_, host2.host_id());
129 EXPECT_EQ(frontend.last_cache_id_, appcache::kNoCacheId);
130 EXPECT_EQ(frontend.last_status_, appcache::UNCACHED);
96 } 131 }
132
133 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_group.cc ('k') | webkit/appcache/appcache_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698