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

Side by Side Diff: content/browser/appcache/appcache_update_job_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: Created 6 years, 6 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "content/browser/appcache/appcache_group.h"
11 #include "content/browser/appcache/appcache_host.h"
12 #include "content/browser/appcache/appcache_response.h"
13 #include "content/browser/appcache/appcache_update_job.h"
10 #include "content/browser/appcache/mock_appcache_service.h" 14 #include "content/browser/appcache/mock_appcache_service.h"
11 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
12 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
13 #include "net/url_request/url_request_error_job.h" 17 #include "net/url_request/url_request_error_job.h"
14 #include "net/url_request/url_request_job_factory_impl.h" 18 #include "net/url_request/url_request_job_factory_impl.h"
15 #include "net/url_request/url_request_test_job.h" 19 #include "net/url_request/url_request_test_job.h"
16 #include "net/url_request/url_request_test_util.h" 20 #include "net/url_request/url_request_test_util.h"
17 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webkit/browser/appcache/appcache_group.h"
19 #include "webkit/browser/appcache/appcache_host.h"
20 #include "webkit/browser/appcache/appcache_response.h"
21 #include "webkit/browser/appcache/appcache_update_job.h"
22
23 using appcache::AppCache;
24 using appcache::AppCacheEntry;
25 using appcache::AppCacheFrontend;
26 using appcache::AppCacheHost;
27 using appcache::AppCacheGroup;
28 using appcache::AppCacheResponseInfo;
29 using appcache::AppCacheUpdateJob;
30 using appcache::AppCacheResponseWriter;
31 using appcache::APPCACHE_CACHED_EVENT;
32 using appcache::APPCACHE_CHECKING_EVENT;
33 using appcache::APPCACHE_DOWNLOADING_EVENT;
34 using appcache::APPCACHE_ERROR_EVENT;
35 using appcache::AppCacheEventID;
36 using appcache::APPCACHE_FALLBACK_NAMESPACE;
37 using appcache::HttpResponseInfoIOBuffer;
38 using appcache::kAppCacheNoCacheId;
39 using appcache::kAppCacheNoResponseId;
40 using appcache::Namespace;
41 using appcache::APPCACHE_NETWORK_NAMESPACE;
42 using appcache::APPCACHE_NO_UPDATE_EVENT;
43 using appcache::APPCACHE_OBSOLETE_EVENT;
44 using appcache::APPCACHE_PROGRESS_EVENT;
45 using appcache::APPCACHE_UPDATE_READY_EVENT;
46 using appcache::AppCacheStatus;
47 22
48 namespace content { 23 namespace content {
49 class AppCacheUpdateJobTest; 24 class AppCacheUpdateJobTest;
50 25
51 namespace { 26 namespace {
52 27
53 const char kManifest1Contents[] = 28 const char kManifest1Contents[] =
54 "CACHE MANIFEST\n" 29 "CACHE MANIFEST\n"
55 "explicit1\n" 30 "explicit1\n"
56 "FALLBACK:\n" 31 "FALLBACK:\n"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 212
238 class MockFrontend : public AppCacheFrontend { 213 class MockFrontend : public AppCacheFrontend {
239 public: 214 public:
240 MockFrontend() 215 MockFrontend()
241 : ignore_progress_events_(false), verify_progress_events_(false), 216 : ignore_progress_events_(false), verify_progress_events_(false),
242 last_progress_total_(-1), last_progress_complete_(-1), 217 last_progress_total_(-1), last_progress_complete_(-1),
243 start_update_trigger_(APPCACHE_CHECKING_EVENT), update_(NULL) { 218 start_update_trigger_(APPCACHE_CHECKING_EVENT), update_(NULL) {
244 } 219 }
245 220
246 virtual void OnCacheSelected( 221 virtual void OnCacheSelected(
247 int host_id, const appcache::AppCacheInfo& info) OVERRIDE { 222 int host_id, const AppCacheInfo& info) OVERRIDE {
248 } 223 }
249 224
250 virtual void OnStatusChanged(const std::vector<int>& host_ids, 225 virtual void OnStatusChanged(const std::vector<int>& host_ids,
251 AppCacheStatus status) OVERRIDE { 226 AppCacheStatus status) OVERRIDE {
252 } 227 }
253 228
254 virtual void OnEventRaised(const std::vector<int>& host_ids, 229 virtual void OnEventRaised(const std::vector<int>& host_ids,
255 AppCacheEventID event_id) OVERRIDE { 230 AppCacheEventID event_id) OVERRIDE {
256 raised_events_.push_back(RaisedEvent(host_ids, event_id)); 231 raised_events_.push_back(RaisedEvent(host_ids, event_id));
257 232
258 // Trigger additional updates if requested. 233 // Trigger additional updates if requested.
259 if (event_id == start_update_trigger_ && update_) { 234 if (event_id == start_update_trigger_ && update_) {
260 for (std::vector<AppCacheHost*>::iterator it = update_hosts_.begin(); 235 for (std::vector<AppCacheHost*>::iterator it = update_hosts_.begin();
261 it != update_hosts_.end(); ++it) { 236 it != update_hosts_.end(); ++it) {
262 AppCacheHost* host = *it; 237 AppCacheHost* host = *it;
263 update_->StartUpdate(host, 238 update_->StartUpdate(host,
264 (host ? host->pending_master_entry_url() : GURL())); 239 (host ? host->pending_master_entry_url() : GURL()));
265 } 240 }
266 update_hosts_.clear(); // only trigger once 241 update_hosts_.clear(); // only trigger once
267 } 242 }
268 } 243 }
269 244
270 virtual void OnErrorEventRaised(const std::vector<int>& host_ids, 245 virtual void OnErrorEventRaised(const std::vector<int>& host_ids,
271 const appcache::AppCacheErrorDetails& details) 246 const AppCacheErrorDetails& details)
272 OVERRIDE { 247 OVERRIDE {
273 error_message_ = details.message; 248 error_message_ = details.message;
274 OnEventRaised(host_ids, APPCACHE_ERROR_EVENT); 249 OnEventRaised(host_ids, APPCACHE_ERROR_EVENT);
275 } 250 }
276 251
277 virtual void OnProgressEventRaised(const std::vector<int>& host_ids, 252 virtual void OnProgressEventRaised(const std::vector<int>& host_ids,
278 const GURL& url, 253 const GURL& url,
279 int num_total, 254 int num_total,
280 int num_complete) OVERRIDE { 255 int num_complete) OVERRIDE {
281 if (!ignore_progress_events_) 256 if (!ignore_progress_events_)
(...skipping 17 matching lines...) Expand all
299 EXPECT_TRUE(url.is_empty()); 274 EXPECT_TRUE(url.is_empty());
300 else 275 else
301 EXPECT_TRUE(url.is_valid()); 276 EXPECT_TRUE(url.is_valid());
302 277
303 last_progress_total_ = num_total; 278 last_progress_total_ = num_total;
304 last_progress_complete_ = num_complete; 279 last_progress_complete_ = num_complete;
305 } 280 }
306 } 281 }
307 282
308 virtual void OnLogMessage(int host_id, 283 virtual void OnLogMessage(int host_id,
309 appcache::AppCacheLogLevel log_level, 284 AppCacheLogLevel log_level,
310 const std::string& message) OVERRIDE { 285 const std::string& message) OVERRIDE {
311 } 286 }
312 287
313 virtual void OnContentBlocked(int host_id, 288 virtual void OnContentBlocked(int host_id,
314 const GURL& manifest_url) OVERRIDE { 289 const GURL& manifest_url) OVERRIDE {
315 } 290 }
316 291
317 void AddExpectedEvent(const std::vector<int>& host_ids, 292 void AddExpectedEvent(const std::vector<int>& host_ids,
318 AppCacheEventID event_id) { 293 AppCacheEventID event_id) {
319 DCHECK(!ignore_progress_events_ || event_id != APPCACHE_PROGRESS_EVENT); 294 DCHECK(!ignore_progress_events_ || event_id != APPCACHE_PROGRESS_EVENT);
(...skipping 3171 matching lines...) Expand 10 before | Expand all | Expand 10 after
3491 MockFrontend::RaisedEvents events = mock_frontend.raised_events_; 3466 MockFrontend::RaisedEvents events = mock_frontend.raised_events_;
3492 size_t expected = 2; 3467 size_t expected = 2;
3493 EXPECT_EQ(expected, events.size()); 3468 EXPECT_EQ(expected, events.size());
3494 expected = 1; 3469 expected = 1;
3495 EXPECT_EQ(expected, events[0].first.size()); 3470 EXPECT_EQ(expected, events[0].first.size());
3496 EXPECT_EQ(host.host_id(), events[0].first[0]); 3471 EXPECT_EQ(host.host_id(), events[0].first[0]);
3497 EXPECT_EQ(APPCACHE_CHECKING_EVENT, events[0].second); 3472 EXPECT_EQ(APPCACHE_CHECKING_EVENT, events[0].second);
3498 3473
3499 EXPECT_EQ(expected, events[1].first.size()); 3474 EXPECT_EQ(expected, events[1].first.size());
3500 EXPECT_EQ(host.host_id(), events[1].first[0]); 3475 EXPECT_EQ(host.host_id(), events[1].first[0]);
3501 EXPECT_EQ(appcache::APPCACHE_DOWNLOADING_EVENT, events[1].second); 3476 EXPECT_EQ(APPCACHE_DOWNLOADING_EVENT, events[1].second);
3502 3477
3503 EXPECT_EQ(AppCacheGroup::DOWNLOADING, group->update_status()); 3478 EXPECT_EQ(AppCacheGroup::DOWNLOADING, group->update_status());
3504 } 3479 }
3505 3480
3506 TEST_F(AppCacheUpdateJobTest, StartCacheAttempt) { 3481 TEST_F(AppCacheUpdateJobTest, StartCacheAttempt) {
3507 RunTestOnIOThread(&AppCacheUpdateJobTest::StartCacheAttemptTest); 3482 RunTestOnIOThread(&AppCacheUpdateJobTest::StartCacheAttemptTest);
3508 } 3483 }
3509 3484
3510 TEST_F(AppCacheUpdateJobTest, StartUpgradeAttempt) { 3485 TEST_F(AppCacheUpdateJobTest, StartUpgradeAttempt) {
3511 RunTestOnIOThread(&AppCacheUpdateJobTest::StartUpgradeAttemptTest); 3486 RunTestOnIOThread(&AppCacheUpdateJobTest::StartUpgradeAttemptTest);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
3711 3686
3712 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { 3687 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) {
3713 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); 3688 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest);
3714 } 3689 }
3715 3690
3716 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { 3691 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) {
3717 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); 3692 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest);
3718 } 3693 }
3719 3694
3720 } // namespace content 3695 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698