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

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

Issue 330053004: Rename some appcache types in preparation for moving 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/mock_appcache_service.h" 10 #include "content/browser/appcache/mock_appcache_service.h"
(...skipping 14 matching lines...) Expand all
25 using appcache::AppCacheFrontend; 25 using appcache::AppCacheFrontend;
26 using appcache::AppCacheHost; 26 using appcache::AppCacheHost;
27 using appcache::AppCacheGroup; 27 using appcache::AppCacheGroup;
28 using appcache::AppCacheResponseInfo; 28 using appcache::AppCacheResponseInfo;
29 using appcache::AppCacheUpdateJob; 29 using appcache::AppCacheUpdateJob;
30 using appcache::AppCacheResponseWriter; 30 using appcache::AppCacheResponseWriter;
31 using appcache::CACHED_EVENT; 31 using appcache::CACHED_EVENT;
32 using appcache::CHECKING_EVENT; 32 using appcache::CHECKING_EVENT;
33 using appcache::DOWNLOADING_EVENT; 33 using appcache::DOWNLOADING_EVENT;
34 using appcache::ERROR_EVENT; 34 using appcache::ERROR_EVENT;
35 using appcache::EventID; 35 using appcache::AppCacheEventID;
36 using appcache::FALLBACK_NAMESPACE; 36 using appcache::FALLBACK_NAMESPACE;
37 using appcache::HttpResponseInfoIOBuffer; 37 using appcache::HttpResponseInfoIOBuffer;
38 using appcache::kNoCacheId; 38 using appcache::kNoCacheId;
39 using appcache::kNoResponseId; 39 using appcache::kNoResponseId;
40 using appcache::Namespace; 40 using appcache::Namespace;
41 using appcache::NETWORK_NAMESPACE; 41 using appcache::NETWORK_NAMESPACE;
42 using appcache::NO_UPDATE_EVENT; 42 using appcache::NO_UPDATE_EVENT;
43 using appcache::OBSOLETE_EVENT; 43 using appcache::OBSOLETE_EVENT;
44 using appcache::PROGRESS_EVENT; 44 using appcache::PROGRESS_EVENT;
45 using appcache::UPDATE_READY_EVENT; 45 using appcache::UPDATE_READY_EVENT;
46 using appcache::Status; 46 using appcache::AppCacheStatus;
47 47
48 namespace content { 48 namespace content {
49 class AppCacheUpdateJobTest; 49 class AppCacheUpdateJobTest;
50 50
51 namespace { 51 namespace {
52 52
53 const char kManifest1Contents[] = 53 const char kManifest1Contents[] =
54 "CACHE MANIFEST\n" 54 "CACHE MANIFEST\n"
55 "explicit1\n" 55 "explicit1\n"
56 "FALLBACK:\n" 56 "FALLBACK:\n"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 : ignore_progress_events_(false), verify_progress_events_(false), 241 : ignore_progress_events_(false), verify_progress_events_(false),
242 last_progress_total_(-1), last_progress_complete_(-1), 242 last_progress_total_(-1), last_progress_complete_(-1),
243 start_update_trigger_(CHECKING_EVENT), update_(NULL) { 243 start_update_trigger_(CHECKING_EVENT), update_(NULL) {
244 } 244 }
245 245
246 virtual void OnCacheSelected( 246 virtual void OnCacheSelected(
247 int host_id, const appcache::AppCacheInfo& info) OVERRIDE { 247 int host_id, const appcache::AppCacheInfo& info) OVERRIDE {
248 } 248 }
249 249
250 virtual void OnStatusChanged(const std::vector<int>& host_ids, 250 virtual void OnStatusChanged(const std::vector<int>& host_ids,
251 Status status) OVERRIDE { 251 AppCacheStatus status) OVERRIDE {
252 } 252 }
253 253
254 virtual void OnEventRaised(const std::vector<int>& host_ids, 254 virtual void OnEventRaised(const std::vector<int>& host_ids,
255 EventID event_id) OVERRIDE { 255 AppCacheEventID event_id) OVERRIDE {
256 raised_events_.push_back(RaisedEvent(host_ids, event_id)); 256 raised_events_.push_back(RaisedEvent(host_ids, event_id));
257 257
258 // Trigger additional updates if requested. 258 // Trigger additional updates if requested.
259 if (event_id == start_update_trigger_ && update_) { 259 if (event_id == start_update_trigger_ && update_) {
260 for (std::vector<AppCacheHost*>::iterator it = update_hosts_.begin(); 260 for (std::vector<AppCacheHost*>::iterator it = update_hosts_.begin();
261 it != update_hosts_.end(); ++it) { 261 it != update_hosts_.end(); ++it) {
262 AppCacheHost* host = *it; 262 AppCacheHost* host = *it;
263 update_->StartUpdate(host, 263 update_->StartUpdate(host,
264 (host ? host->pending_master_entry_url() : GURL())); 264 (host ? host->pending_master_entry_url() : GURL()));
265 } 265 }
266 update_hosts_.clear(); // only trigger once 266 update_hosts_.clear(); // only trigger once
267 } 267 }
268 } 268 }
269 269
270 virtual void OnErrorEventRaised(const std::vector<int>& host_ids, 270 virtual void OnErrorEventRaised(const std::vector<int>& host_ids,
271 const appcache::ErrorDetails& details) 271 const appcache::AppCacheErrorDetails& details)
272 OVERRIDE { 272 OVERRIDE {
273 error_message_ = details.message; 273 error_message_ = details.message;
274 OnEventRaised(host_ids, ERROR_EVENT); 274 OnEventRaised(host_ids, ERROR_EVENT);
275 } 275 }
276 276
277 virtual void OnProgressEventRaised(const std::vector<int>& host_ids, 277 virtual void OnProgressEventRaised(const std::vector<int>& host_ids,
278 const GURL& url, 278 const GURL& url,
279 int num_total, 279 int num_total,
280 int num_complete) OVERRIDE { 280 int num_complete) OVERRIDE {
281 if (!ignore_progress_events_) 281 if (!ignore_progress_events_)
(...skipping 17 matching lines...) Expand all
299 EXPECT_TRUE(url.is_empty()); 299 EXPECT_TRUE(url.is_empty());
300 else 300 else
301 EXPECT_TRUE(url.is_valid()); 301 EXPECT_TRUE(url.is_valid());
302 302
303 last_progress_total_ = num_total; 303 last_progress_total_ = num_total;
304 last_progress_complete_ = num_complete; 304 last_progress_complete_ = num_complete;
305 } 305 }
306 } 306 }
307 307
308 virtual void OnLogMessage(int host_id, 308 virtual void OnLogMessage(int host_id,
309 appcache::LogLevel log_level, 309 appcache::AppCacheLogLevel log_level,
310 const std::string& message) OVERRIDE { 310 const std::string& message) OVERRIDE {
311 } 311 }
312 312
313 virtual void OnContentBlocked(int host_id, 313 virtual void OnContentBlocked(int host_id,
314 const GURL& manifest_url) OVERRIDE { 314 const GURL& manifest_url) OVERRIDE {
315 } 315 }
316 316
317 void AddExpectedEvent(const std::vector<int>& host_ids, EventID event_id) { 317 void AddExpectedEvent(const std::vector<int>& host_ids,
318 AppCacheEventID event_id) {
318 DCHECK(!ignore_progress_events_ || event_id != PROGRESS_EVENT); 319 DCHECK(!ignore_progress_events_ || event_id != PROGRESS_EVENT);
319 expected_events_.push_back(RaisedEvent(host_ids, event_id)); 320 expected_events_.push_back(RaisedEvent(host_ids, event_id));
320 } 321 }
321 322
322 void SetIgnoreProgressEvents(bool ignore) { 323 void SetIgnoreProgressEvents(bool ignore) {
323 // Some tests involve joining new hosts to an already running update job 324 // Some tests involve joining new hosts to an already running update job
324 // or intentionally failing. The timing and sequencing of the progress 325 // or intentionally failing. The timing and sequencing of the progress
325 // events generated by an update job are dependent on the behavior of 326 // events generated by an update job are dependent on the behavior of
326 // an external HTTP server. For jobs that do not run fully till completion, 327 // an external HTTP server. For jobs that do not run fully till completion,
327 // due to either joining late or early exit, we skip monitoring the 328 // due to either joining late or early exit, we skip monitoring the
328 // progress events to avoid flakiness. 329 // progress events to avoid flakiness.
329 ignore_progress_events_ = ignore; 330 ignore_progress_events_ = ignore;
330 } 331 }
331 332
332 void SetVerifyProgressEvents(bool verify) { 333 void SetVerifyProgressEvents(bool verify) {
333 verify_progress_events_ = verify; 334 verify_progress_events_ = verify;
334 } 335 }
335 336
336 void TriggerAdditionalUpdates(EventID trigger_event, 337 void TriggerAdditionalUpdates(AppCacheEventID trigger_event,
337 AppCacheUpdateJob* update) { 338 AppCacheUpdateJob* update) {
338 start_update_trigger_ = trigger_event; 339 start_update_trigger_ = trigger_event;
339 update_ = update; 340 update_ = update;
340 } 341 }
341 342
342 void AdditionalUpdateHost(AppCacheHost* host) { 343 void AdditionalUpdateHost(AppCacheHost* host) {
343 update_hosts_.push_back(host); 344 update_hosts_.push_back(host);
344 } 345 }
345 346
346 typedef std::vector<int> HostIds; 347 typedef std::vector<int> HostIds;
347 typedef std::pair<HostIds, EventID> RaisedEvent; 348 typedef std::pair<HostIds, AppCacheEventID> RaisedEvent;
348 typedef std::vector<RaisedEvent> RaisedEvents; 349 typedef std::vector<RaisedEvent> RaisedEvents;
349 RaisedEvents raised_events_; 350 RaisedEvents raised_events_;
350 std::string error_message_; 351 std::string error_message_;
351 352
352 // Set the expected events if verification needs to happen asynchronously. 353 // Set the expected events if verification needs to happen asynchronously.
353 RaisedEvents expected_events_; 354 RaisedEvents expected_events_;
354 std::string expected_error_message_; 355 std::string expected_error_message_;
355 356
356 bool ignore_progress_events_; 357 bool ignore_progress_events_;
357 358
358 bool verify_progress_events_; 359 bool verify_progress_events_;
359 int last_progress_total_; 360 int last_progress_total_;
360 int last_progress_complete_; 361 int last_progress_complete_;
361 362
362 // Add ability for frontend to add master entries to an inprogress update. 363 // Add ability for frontend to add master entries to an inprogress update.
363 EventID start_update_trigger_; 364 AppCacheEventID start_update_trigger_;
364 AppCacheUpdateJob* update_; 365 AppCacheUpdateJob* update_;
365 std::vector<AppCacheHost*> update_hosts_; 366 std::vector<AppCacheHost*> update_hosts_;
366 }; 367 };
367 368
368 // Helper factories to simulate redirected URL responses for tests. 369 // Helper factories to simulate redirected URL responses for tests.
369 class RedirectFactory : public net::URLRequestJobFactory::ProtocolHandler { 370 class RedirectFactory : public net::URLRequestJobFactory::ProtocolHandler {
370 public: 371 public:
371 virtual net::URLRequestJob* MaybeCreateJob( 372 virtual net::URLRequestJob* MaybeCreateJob(
372 net::URLRequest* request, 373 net::URLRequest* request,
373 net::NetworkDelegate* network_delegate) const OVERRIDE { 374 net::NetworkDelegate* network_delegate) const OVERRIDE {
(...skipping 3335 matching lines...) Expand 10 before | Expand all | Expand 10 after
3709 3710
3710 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { 3711 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) {
3711 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); 3712 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest);
3712 } 3713 }
3713 3714
3714 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { 3715 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) {
3715 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); 3716 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest);
3716 } 3717 }
3717 3718
3718 } // namespace content 3719 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698