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

Side by Side Diff: content/browser/appcache/appcache_group_unittest.cc

Issue 344493002: Move all remaining appcache-related code to content namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. 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 <string> 5 #include <string>
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "content/browser/appcache/appcache.h"
9 #include "content/browser/appcache/appcache_group.h"
10 #include "content/browser/appcache/appcache_host.h"
11 #include "content/browser/appcache/appcache_update_job.h"
8 #include "content/browser/appcache/mock_appcache_service.h" 12 #include "content/browser/appcache/mock_appcache_service.h"
13 #include "content/common/appcache_interfaces.h"
9 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
10 #include "webkit/browser/appcache/appcache.h"
11 #include "webkit/browser/appcache/appcache_group.h"
12 #include "webkit/browser/appcache/appcache_host.h"
13 #include "webkit/browser/appcache/appcache_update_job.h"
14 #include "webkit/common/appcache/appcache_interfaces.h"
15
16 using appcache::AppCache;
17 using appcache::AppCacheFrontend;
18 using appcache::AppCacheGroup;
19 using appcache::AppCacheHost;
20 using appcache::AppCacheServiceImpl;
21 using appcache::AppCacheUpdateJob;
22 15
23 namespace { 16 namespace {
24 17
25 class TestAppCacheFrontend : public appcache::AppCacheFrontend { 18 class TestAppCacheFrontend : public content::AppCacheFrontend {
26 public: 19 public:
27 TestAppCacheFrontend() 20 TestAppCacheFrontend()
28 : last_host_id_(-1), last_cache_id_(-1), 21 : last_host_id_(-1), last_cache_id_(-1),
29 last_status_(appcache::APPCACHE_STATUS_OBSOLETE) { 22 last_status_(content::APPCACHE_STATUS_OBSOLETE) {
30 } 23 }
31 24
32 virtual void OnCacheSelected( 25 virtual void OnCacheSelected(
33 int host_id, const appcache::AppCacheInfo& info) OVERRIDE { 26 int host_id, const content::AppCacheInfo& info) OVERRIDE {
34 last_host_id_ = host_id; 27 last_host_id_ = host_id;
35 last_cache_id_ = info.cache_id; 28 last_cache_id_ = info.cache_id;
36 last_status_ = info.status; 29 last_status_ = info.status;
37 } 30 }
38 31
39 virtual void OnStatusChanged(const std::vector<int>& host_ids, 32 virtual void OnStatusChanged(const std::vector<int>& host_ids,
40 appcache::AppCacheStatus status) OVERRIDE { 33 content::AppCacheStatus status) OVERRIDE {
41 } 34 }
42 35
43 virtual void OnEventRaised(const std::vector<int>& host_ids, 36 virtual void OnEventRaised(const std::vector<int>& host_ids,
44 appcache::AppCacheEventID event_id) OVERRIDE { 37 content::AppCacheEventID event_id) OVERRIDE {
45 } 38 }
46 39
47 virtual void OnErrorEventRaised(const std::vector<int>& host_ids, 40 virtual void OnErrorEventRaised(const std::vector<int>& host_ids,
48 const appcache::AppCacheErrorDetails& details) 41 const content::AppCacheErrorDetails& details)
49 OVERRIDE {} 42 OVERRIDE {}
50 43
51 virtual void OnProgressEventRaised(const std::vector<int>& host_ids, 44 virtual void OnProgressEventRaised(const std::vector<int>& host_ids,
52 const GURL& url, 45 const GURL& url,
53 int num_total, int num_complete) OVERRIDE { 46 int num_total, int num_complete) OVERRIDE {
54 } 47 }
55 48
56 virtual void OnLogMessage(int host_id, appcache::AppCacheLogLevel log_level, 49 virtual void OnLogMessage(int host_id, content::AppCacheLogLevel log_level,
57 const std::string& message) OVERRIDE { 50 const std::string& message) OVERRIDE {
58 } 51 }
59 52
60 virtual void OnContentBlocked(int host_id, 53 virtual void OnContentBlocked(int host_id,
61 const GURL& manifest_url) OVERRIDE { 54 const GURL& manifest_url) OVERRIDE {
62 } 55 }
63 56
64 int last_host_id_; 57 int last_host_id_;
65 int64 last_cache_id_; 58 int64 last_cache_id_;
66 appcache::AppCacheStatus last_status_; 59 content::AppCacheStatus last_status_;
67 }; 60 };
68 61
69 } // namespace anon 62 } // namespace anon
70 63
71 namespace content { 64 namespace content {
72 65
73 class TestUpdateObserver : public AppCacheGroup::UpdateObserver { 66 class TestUpdateObserver : public AppCacheGroup::UpdateObserver {
74 public: 67 public:
75 TestUpdateObserver() : update_completed_(false), group_has_cache_(false) { 68 TestUpdateObserver() : update_completed_(false), group_has_cache_(false) {
76 } 69 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 183
191 AppCache* cache1 = new AppCache(service.storage(), 111); 184 AppCache* cache1 = new AppCache(service.storage(), 111);
192 cache1->set_complete(true); 185 cache1->set_complete(true);
193 cache1->set_update_time(now); 186 cache1->set_update_time(now);
194 group->AddCache(cache1); 187 group->AddCache(cache1);
195 EXPECT_EQ(cache1, group->newest_complete_cache()); 188 EXPECT_EQ(cache1, group->newest_complete_cache());
196 189
197 host1.AssociateCompleteCache(cache1); 190 host1.AssociateCompleteCache(cache1);
198 EXPECT_EQ(frontend.last_host_id_, host1.host_id()); 191 EXPECT_EQ(frontend.last_host_id_, host1.host_id());
199 EXPECT_EQ(frontend.last_cache_id_, cache1->cache_id()); 192 EXPECT_EQ(frontend.last_cache_id_, cache1->cache_id());
200 EXPECT_EQ(frontend.last_status_, appcache::APPCACHE_STATUS_IDLE); 193 EXPECT_EQ(frontend.last_status_, APPCACHE_STATUS_IDLE);
201 194
202 host2.AssociateCompleteCache(cache1); 195 host2.AssociateCompleteCache(cache1);
203 EXPECT_EQ(frontend.last_host_id_, host2.host_id()); 196 EXPECT_EQ(frontend.last_host_id_, host2.host_id());
204 EXPECT_EQ(frontend.last_cache_id_, cache1->cache_id()); 197 EXPECT_EQ(frontend.last_cache_id_, cache1->cache_id());
205 EXPECT_EQ(frontend.last_status_, appcache::APPCACHE_STATUS_IDLE); 198 EXPECT_EQ(frontend.last_status_, APPCACHE_STATUS_IDLE);
206 199
207 AppCache* cache2 = new AppCache(service.storage(), 222); 200 AppCache* cache2 = new AppCache(service.storage(), 222);
208 cache2->set_complete(true); 201 cache2->set_complete(true);
209 cache2->set_update_time(now + base::TimeDelta::FromDays(1)); 202 cache2->set_update_time(now + base::TimeDelta::FromDays(1));
210 group->AddCache(cache2); 203 group->AddCache(cache2);
211 EXPECT_EQ(cache2, group->newest_complete_cache()); 204 EXPECT_EQ(cache2, group->newest_complete_cache());
212 205
213 // Unassociate all hosts from older cache. 206 // Unassociate all hosts from older cache.
214 host1.AssociateNoCache(GURL()); 207 host1.AssociateNoCache(GURL());
215 host2.AssociateNoCache(GURL()); 208 host2.AssociateNoCache(GURL());
216 EXPECT_EQ(frontend.last_host_id_, host2.host_id()); 209 EXPECT_EQ(frontend.last_host_id_, host2.host_id());
217 EXPECT_EQ(frontend.last_cache_id_, appcache::kAppCacheNoCacheId); 210 EXPECT_EQ(frontend.last_cache_id_, kAppCacheNoCacheId);
218 EXPECT_EQ(frontend.last_status_, appcache::APPCACHE_STATUS_UNCACHED); 211 EXPECT_EQ(frontend.last_status_, APPCACHE_STATUS_UNCACHED);
219 } 212 }
220 213
221 TEST_F(AppCacheGroupTest, StartUpdate) { 214 TEST_F(AppCacheGroupTest, StartUpdate) {
222 MockAppCacheService service; 215 MockAppCacheService service;
223 scoped_refptr<AppCacheGroup> group( 216 scoped_refptr<AppCacheGroup> group(
224 new AppCacheGroup(service.storage(), GURL("http://foo.com"), 111)); 217 new AppCacheGroup(service.storage(), GURL("http://foo.com"), 111));
225 218
226 // Set state to checking to prevent update job from executing fetches. 219 // Set state to checking to prevent update job from executing fetches.
227 group->update_status_ = AppCacheGroup::CHECKING; 220 group->update_status_ = AppCacheGroup::CHECKING;
228 group->StartUpdate(); 221 group->StartUpdate();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 EXPECT_TRUE(group->FindObserver(&host, group->observers_)); 293 EXPECT_TRUE(group->FindObserver(&host, group->observers_));
301 294
302 // Delete update to cause it to complete. Verify host is notified. 295 // Delete update to cause it to complete. Verify host is notified.
303 delete group->update_job_; 296 delete group->update_job_;
304 EXPECT_EQ(AppCacheGroup::IDLE, group->update_status_); 297 EXPECT_EQ(AppCacheGroup::IDLE, group->update_status_);
305 EXPECT_TRUE(group->restart_update_task_.IsCancelled()); 298 EXPECT_TRUE(group->restart_update_task_.IsCancelled());
306 EXPECT_TRUE(host.update_completed_); 299 EXPECT_TRUE(host.update_completed_);
307 } 300 }
308 301
309 } // namespace content 302 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698