OLD | NEW |
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 <stack> | 5 #include <stack> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 response_code_(response_code), | 90 response_code_(response_code), |
91 has_response_info_(false) {} | 91 has_response_info_(false) {} |
92 MockURLRequestJob(net::URLRequest* request, | 92 MockURLRequestJob(net::URLRequest* request, |
93 net::NetworkDelegate* network_delegate, | 93 net::NetworkDelegate* network_delegate, |
94 const net::HttpResponseInfo& info) | 94 const net::HttpResponseInfo& info) |
95 : net::URLRequestJob(request, network_delegate), | 95 : net::URLRequestJob(request, network_delegate), |
96 response_code_(info.headers->response_code()), | 96 response_code_(info.headers->response_code()), |
97 has_response_info_(true), | 97 has_response_info_(true), |
98 response_info_(info) {} | 98 response_info_(info) {} |
99 | 99 |
100 protected: | 100 protected: |
101 virtual ~MockURLRequestJob() {} | 101 virtual ~MockURLRequestJob() {} |
102 virtual void Start() OVERRIDE { | 102 virtual void Start() OVERRIDE { |
103 NotifyHeadersComplete(); | 103 NotifyHeadersComplete(); |
104 } | 104 } |
105 virtual int GetResponseCode() const OVERRIDE { | 105 virtual int GetResponseCode() const OVERRIDE { |
106 return response_code_; | 106 return response_code_; |
107 } | 107 } |
108 virtual void GetResponseInfo( | 108 virtual void GetResponseInfo( |
109 net::HttpResponseInfo* info) OVERRIDE { | 109 net::HttpResponseInfo* info) OVERRIDE { |
110 if (!has_response_info_) | 110 if (!has_response_info_) |
111 return; | 111 return; |
112 *info = response_info_; | 112 *info = response_info_; |
113 } | 113 } |
114 | 114 |
115 private: | 115 private: |
116 int response_code_; | 116 int response_code_; |
117 bool has_response_info_; | 117 bool has_response_info_; |
118 net::HttpResponseInfo response_info_; | 118 net::HttpResponseInfo response_info_; |
119 }; | 119 }; |
120 | 120 |
121 class MockURLRequestJobFactory : public net::URLRequestJobFactory { | 121 class MockURLRequestJobFactory : public net::URLRequestJobFactory { |
122 public: | 122 public: |
123 MockURLRequestJobFactory() : job_(NULL) { | 123 MockURLRequestJobFactory() : job_(NULL) { |
124 } | 124 } |
125 | 125 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 157 } |
158 | 158 |
159 virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE { | 159 virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE { |
160 return false; | 160 return false; |
161 } | 161 } |
162 | 162 |
163 private: | 163 private: |
164 mutable net::URLRequestJob* job_; | 164 mutable net::URLRequestJob* job_; |
165 }; | 165 }; |
166 | 166 |
167 class MockURLRequest : public net::URLRequest { | |
168 public: | |
169 MockURLRequest(const GURL& url, net::URLRequestContext* context) | |
170 : net::URLRequest(url, net::DEFAULT_PRIORITY, NULL, context) {} | |
171 | |
172 | |
173 MockURLRequestDelegate delegate_; | |
174 }; | |
175 | |
176 static void SetUpTestCase() { | 167 static void SetUpTestCase() { |
177 io_thread_.reset(new base::Thread("AppCacheRequestHandlerTest Thread")); | 168 io_thread_.reset(new base::Thread("AppCacheRequestHandlerTest Thread")); |
178 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 169 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
179 io_thread_->StartWithOptions(options); | 170 io_thread_->StartWithOptions(options); |
180 } | 171 } |
181 | 172 |
182 static void TearDownTestCase() { | 173 static void TearDownTestCase() { |
183 io_thread_.reset(NULL); | 174 io_thread_.reset(NULL); |
184 } | 175 } |
185 | 176 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 task_stack_.pop(); | 247 task_stack_.pop(); |
257 } | 248 } |
258 | 249 |
259 // MainResource_Miss -------------------------------------------------- | 250 // MainResource_Miss -------------------------------------------------- |
260 | 251 |
261 void MainResource_Miss() { | 252 void MainResource_Miss() { |
262 PushNextTask( | 253 PushNextTask( |
263 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Miss, | 254 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Miss, |
264 base::Unretained(this))); | 255 base::Unretained(this))); |
265 | 256 |
266 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 257 request_ = empty_context_.CreateRequest( |
| 258 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
267 handler_.reset(host_->CreateRequestHandler(request_.get(), | 259 handler_.reset(host_->CreateRequestHandler(request_.get(), |
268 RESOURCE_TYPE_MAIN_FRAME)); | 260 RESOURCE_TYPE_MAIN_FRAME)); |
269 EXPECT_TRUE(handler_.get()); | 261 EXPECT_TRUE(handler_.get()); |
270 | 262 |
271 job_ = handler_->MaybeLoadResource(request_.get(), | 263 job_ = handler_->MaybeLoadResource(request_.get(), |
272 request_->context()->network_delegate()); | 264 request_->context()->network_delegate()); |
273 EXPECT_TRUE(job_.get()); | 265 EXPECT_TRUE(job_.get()); |
274 EXPECT_TRUE(job_->is_waiting()); | 266 EXPECT_TRUE(job_->is_waiting()); |
275 | 267 |
276 // We have to wait for completion of storage->FindResponseForMainRequest. | 268 // We have to wait for completion of storage->FindResponseForMainRequest. |
(...skipping 26 matching lines...) Expand all Loading... |
303 TestFinished(); | 295 TestFinished(); |
304 } | 296 } |
305 | 297 |
306 // MainResource_Hit -------------------------------------------------- | 298 // MainResource_Hit -------------------------------------------------- |
307 | 299 |
308 void MainResource_Hit() { | 300 void MainResource_Hit() { |
309 PushNextTask( | 301 PushNextTask( |
310 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Hit, | 302 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Hit, |
311 base::Unretained(this))); | 303 base::Unretained(this))); |
312 | 304 |
313 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 305 request_ = empty_context_.CreateRequest( |
| 306 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
314 handler_.reset(host_->CreateRequestHandler(request_.get(), | 307 handler_.reset(host_->CreateRequestHandler(request_.get(), |
315 RESOURCE_TYPE_MAIN_FRAME)); | 308 RESOURCE_TYPE_MAIN_FRAME)); |
316 EXPECT_TRUE(handler_.get()); | 309 EXPECT_TRUE(handler_.get()); |
317 | 310 |
318 mock_storage()->SimulateFindMainResource( | 311 mock_storage()->SimulateFindMainResource( |
319 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), | 312 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), |
320 GURL(), AppCacheEntry(), | 313 GURL(), AppCacheEntry(), |
321 1, 2, GURL("http://blah/manifest/")); | 314 1, 2, GURL("http://blah/manifest/")); |
322 | 315 |
323 job_ = handler_->MaybeLoadResource(request_.get(), | 316 job_ = handler_->MaybeLoadResource(request_.get(), |
(...skipping 27 matching lines...) Expand all Loading... |
351 TestFinished(); | 344 TestFinished(); |
352 } | 345 } |
353 | 346 |
354 // MainResource_Fallback -------------------------------------------------- | 347 // MainResource_Fallback -------------------------------------------------- |
355 | 348 |
356 void MainResource_Fallback() { | 349 void MainResource_Fallback() { |
357 PushNextTask( | 350 PushNextTask( |
358 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Fallback, | 351 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Fallback, |
359 base::Unretained(this))); | 352 base::Unretained(this))); |
360 | 353 |
361 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 354 request_ = empty_context_.CreateRequest( |
| 355 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
362 handler_.reset(host_->CreateRequestHandler(request_.get(), | 356 handler_.reset(host_->CreateRequestHandler(request_.get(), |
363 RESOURCE_TYPE_MAIN_FRAME)); | 357 RESOURCE_TYPE_MAIN_FRAME)); |
364 EXPECT_TRUE(handler_.get()); | 358 EXPECT_TRUE(handler_.get()); |
365 | 359 |
366 mock_storage()->SimulateFindMainResource( | 360 mock_storage()->SimulateFindMainResource( |
367 AppCacheEntry(), | 361 AppCacheEntry(), |
368 GURL("http://blah/fallbackurl"), | 362 GURL("http://blah/fallbackurl"), |
369 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), | 363 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), |
370 1, 2, GURL("http://blah/manifest/")); | 364 1, 2, GURL("http://blah/manifest/")); |
371 | 365 |
(...skipping 16 matching lines...) Expand all Loading... |
388 // All our simulation needs to satisfy are the following two DCHECKs | 382 // All our simulation needs to satisfy are the following two DCHECKs |
389 DCHECK(request_->status().is_success()); | 383 DCHECK(request_->status().is_success()); |
390 DCHECK_EQ(response_code, request_->GetResponseCode()); | 384 DCHECK_EQ(response_code, request_->GetResponseCode()); |
391 } | 385 } |
392 | 386 |
393 void SimulateResponseInfo(const net::HttpResponseInfo& info) { | 387 void SimulateResponseInfo(const net::HttpResponseInfo& info) { |
394 job_factory_->SetJob( | 388 job_factory_->SetJob( |
395 new MockURLRequestJob( | 389 new MockURLRequestJob( |
396 request_.get(), | 390 request_.get(), |
397 request_->context()->network_delegate(), info)); | 391 request_->context()->network_delegate(), info)); |
398 request_->set_delegate(&request_->delegate_); | |
399 request_->Start(); | 392 request_->Start(); |
400 } | 393 } |
401 | 394 |
402 void Verify_MainResource_Fallback() { | 395 void Verify_MainResource_Fallback() { |
403 EXPECT_FALSE(job_->is_waiting()); | 396 EXPECT_FALSE(job_->is_waiting()); |
404 EXPECT_TRUE(job_->is_delivering_network_response()); | 397 EXPECT_TRUE(job_->is_delivering_network_response()); |
405 | 398 |
406 // When the request is restarted, the existing job is dropped so a | 399 // When the request is restarted, the existing job is dropped so a |
407 // real network job gets created. We expect NULL here which will cause | 400 // real network job gets created. We expect NULL here which will cause |
408 // the net library to create a real job. | 401 // the net library to create a real job. |
(...skipping 23 matching lines...) Expand all Loading... |
432 TestFinished(); | 425 TestFinished(); |
433 } | 426 } |
434 | 427 |
435 // MainResource_FallbackOverride -------------------------------------------- | 428 // MainResource_FallbackOverride -------------------------------------------- |
436 | 429 |
437 void MainResource_FallbackOverride() { | 430 void MainResource_FallbackOverride() { |
438 PushNextTask(base::Bind( | 431 PushNextTask(base::Bind( |
439 &AppCacheRequestHandlerTest::Verify_MainResource_FallbackOverride, | 432 &AppCacheRequestHandlerTest::Verify_MainResource_FallbackOverride, |
440 base::Unretained(this))); | 433 base::Unretained(this))); |
441 | 434 |
442 request_.reset(new MockURLRequest(GURL("http://blah/fallback-override"), | 435 request_ = empty_context_.CreateRequest( |
443 &empty_context_)); | 436 GURL("http://blah/fallback-override"), net::DEFAULT_PRIORITY, |
| 437 &delegate_, NULL); |
444 handler_.reset(host_->CreateRequestHandler(request_.get(), | 438 handler_.reset(host_->CreateRequestHandler(request_.get(), |
445 RESOURCE_TYPE_MAIN_FRAME)); | 439 RESOURCE_TYPE_MAIN_FRAME)); |
446 EXPECT_TRUE(handler_.get()); | 440 EXPECT_TRUE(handler_.get()); |
447 | 441 |
448 mock_storage()->SimulateFindMainResource( | 442 mock_storage()->SimulateFindMainResource( |
449 AppCacheEntry(), | 443 AppCacheEntry(), |
450 GURL("http://blah/fallbackurl"), | 444 GURL("http://blah/fallbackurl"), |
451 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), | 445 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), |
452 1, 2, GURL("http://blah/manifest/")); | 446 1, 2, GURL("http://blah/manifest/")); |
453 | 447 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 job_ = handler_->MaybeLoadFallbackForResponse( | 479 job_ = handler_->MaybeLoadFallbackForResponse( |
486 request_.get(), request_->context()->network_delegate()); | 480 request_.get(), request_->context()->network_delegate()); |
487 EXPECT_FALSE(job_.get()); | 481 EXPECT_FALSE(job_.get()); |
488 | 482 |
489 TestFinished(); | 483 TestFinished(); |
490 } | 484 } |
491 | 485 |
492 // SubResource_Miss_WithNoCacheSelected ---------------------------------- | 486 // SubResource_Miss_WithNoCacheSelected ---------------------------------- |
493 | 487 |
494 void SubResource_Miss_WithNoCacheSelected() { | 488 void SubResource_Miss_WithNoCacheSelected() { |
495 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 489 request_ = empty_context_.CreateRequest( |
| 490 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
496 handler_.reset(host_->CreateRequestHandler(request_.get(), | 491 handler_.reset(host_->CreateRequestHandler(request_.get(), |
497 RESOURCE_TYPE_SUB_RESOURCE)); | 492 RESOURCE_TYPE_SUB_RESOURCE)); |
498 | 493 |
499 // We avoid creating handler when possible, sub-resource requests are not | 494 // We avoid creating handler when possible, sub-resource requests are not |
500 // subject to retrieval from an appcache when there's no associated cache. | 495 // subject to retrieval from an appcache when there's no associated cache. |
501 EXPECT_FALSE(handler_.get()); | 496 EXPECT_FALSE(handler_.get()); |
502 | 497 |
503 TestFinished(); | 498 TestFinished(); |
504 } | 499 } |
505 | 500 |
506 // SubResource_Miss_WithCacheSelected ---------------------------------- | 501 // SubResource_Miss_WithCacheSelected ---------------------------------- |
507 | 502 |
508 void SubResource_Miss_WithCacheSelected() { | 503 void SubResource_Miss_WithCacheSelected() { |
509 // A sub-resource load where the resource is not in an appcache, or | 504 // A sub-resource load where the resource is not in an appcache, or |
510 // in a network or fallback namespace, should result in a failed request. | 505 // in a network or fallback namespace, should result in a failed request. |
511 host_->AssociateCompleteCache(MakeNewCache()); | 506 host_->AssociateCompleteCache(MakeNewCache()); |
512 | 507 |
513 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 508 request_ = empty_context_.CreateRequest( |
| 509 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
514 handler_.reset(host_->CreateRequestHandler(request_.get(), | 510 handler_.reset(host_->CreateRequestHandler(request_.get(), |
515 RESOURCE_TYPE_SUB_RESOURCE)); | 511 RESOURCE_TYPE_SUB_RESOURCE)); |
516 EXPECT_TRUE(handler_.get()); | 512 EXPECT_TRUE(handler_.get()); |
517 | 513 |
518 job_ = handler_->MaybeLoadResource(request_.get(), | 514 job_ = handler_->MaybeLoadResource(request_.get(), |
519 request_->context()->network_delegate()); | 515 request_->context()->network_delegate()); |
520 EXPECT_TRUE(job_.get()); | 516 EXPECT_TRUE(job_.get()); |
521 EXPECT_TRUE(job_->is_delivering_error_response()); | 517 EXPECT_TRUE(job_->is_delivering_error_response()); |
522 | 518 |
523 AppCacheURLRequestJob* fallback_job; | 519 AppCacheURLRequestJob* fallback_job; |
(...skipping 10 matching lines...) Expand all Loading... |
534 } | 530 } |
535 | 531 |
536 // SubResource_Miss_WithWaitForCacheSelection ----------------------------- | 532 // SubResource_Miss_WithWaitForCacheSelection ----------------------------- |
537 | 533 |
538 void SubResource_Miss_WithWaitForCacheSelection() { | 534 void SubResource_Miss_WithWaitForCacheSelection() { |
539 // Precondition, the host is waiting on cache selection. | 535 // Precondition, the host is waiting on cache selection. |
540 scoped_refptr<AppCache> cache(MakeNewCache()); | 536 scoped_refptr<AppCache> cache(MakeNewCache()); |
541 host_->pending_selected_cache_id_ = cache->cache_id(); | 537 host_->pending_selected_cache_id_ = cache->cache_id(); |
542 host_->set_preferred_manifest_url(cache->owning_group()->manifest_url()); | 538 host_->set_preferred_manifest_url(cache->owning_group()->manifest_url()); |
543 | 539 |
544 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 540 request_ = empty_context_.CreateRequest( |
| 541 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
545 handler_.reset(host_->CreateRequestHandler(request_.get(), | 542 handler_.reset(host_->CreateRequestHandler(request_.get(), |
546 RESOURCE_TYPE_SUB_RESOURCE)); | 543 RESOURCE_TYPE_SUB_RESOURCE)); |
547 EXPECT_TRUE(handler_.get()); | 544 EXPECT_TRUE(handler_.get()); |
548 job_ = handler_->MaybeLoadResource(request_.get(), | 545 job_ = handler_->MaybeLoadResource(request_.get(), |
549 request_->context()->network_delegate()); | 546 request_->context()->network_delegate()); |
550 EXPECT_TRUE(job_.get()); | 547 EXPECT_TRUE(job_.get()); |
551 EXPECT_TRUE(job_->is_waiting()); | 548 EXPECT_TRUE(job_->is_waiting()); |
552 | 549 |
553 host_->FinishCacheSelection(cache.get(), NULL); | 550 host_->FinishCacheSelection(cache.get(), NULL); |
554 EXPECT_FALSE(job_->is_waiting()); | 551 EXPECT_FALSE(job_->is_waiting()); |
(...skipping 13 matching lines...) Expand all Loading... |
568 } | 565 } |
569 | 566 |
570 // SubResource_Hit ----------------------------- | 567 // SubResource_Hit ----------------------------- |
571 | 568 |
572 void SubResource_Hit() { | 569 void SubResource_Hit() { |
573 host_->AssociateCompleteCache(MakeNewCache()); | 570 host_->AssociateCompleteCache(MakeNewCache()); |
574 | 571 |
575 mock_storage()->SimulateFindSubResource( | 572 mock_storage()->SimulateFindSubResource( |
576 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); | 573 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); |
577 | 574 |
578 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 575 request_ = empty_context_.CreateRequest( |
| 576 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
579 handler_.reset(host_->CreateRequestHandler(request_.get(), | 577 handler_.reset(host_->CreateRequestHandler(request_.get(), |
580 RESOURCE_TYPE_SUB_RESOURCE)); | 578 RESOURCE_TYPE_SUB_RESOURCE)); |
581 EXPECT_TRUE(handler_.get()); | 579 EXPECT_TRUE(handler_.get()); |
582 job_ = handler_->MaybeLoadResource(request_.get(), | 580 job_ = handler_->MaybeLoadResource(request_.get(), |
583 request_->context()->network_delegate()); | 581 request_->context()->network_delegate()); |
584 EXPECT_TRUE(job_.get()); | 582 EXPECT_TRUE(job_.get()); |
585 EXPECT_TRUE(job_->is_delivering_appcache_response()); | 583 EXPECT_TRUE(job_->is_delivering_appcache_response()); |
586 | 584 |
587 AppCacheURLRequestJob* fallback_job; | 585 AppCacheURLRequestJob* fallback_job; |
588 fallback_job = handler_->MaybeLoadFallbackForRedirect( | 586 fallback_job = handler_->MaybeLoadFallbackForRedirect( |
(...skipping 11 matching lines...) Expand all Loading... |
600 // SubResource_RedirectFallback ----------------------------- | 598 // SubResource_RedirectFallback ----------------------------- |
601 | 599 |
602 void SubResource_RedirectFallback() { | 600 void SubResource_RedirectFallback() { |
603 // Redirects to resources in the a different origin are subject to | 601 // Redirects to resources in the a different origin are subject to |
604 // fallback namespaces. | 602 // fallback namespaces. |
605 host_->AssociateCompleteCache(MakeNewCache()); | 603 host_->AssociateCompleteCache(MakeNewCache()); |
606 | 604 |
607 mock_storage()->SimulateFindSubResource( | 605 mock_storage()->SimulateFindSubResource( |
608 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); | 606 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); |
609 | 607 |
610 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 608 request_ = empty_context_.CreateRequest( |
| 609 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
611 handler_.reset(host_->CreateRequestHandler(request_.get(), | 610 handler_.reset(host_->CreateRequestHandler(request_.get(), |
612 RESOURCE_TYPE_SUB_RESOURCE)); | 611 RESOURCE_TYPE_SUB_RESOURCE)); |
613 EXPECT_TRUE(handler_.get()); | 612 EXPECT_TRUE(handler_.get()); |
614 job_ = handler_->MaybeLoadResource(request_.get(), | 613 job_ = handler_->MaybeLoadResource(request_.get(), |
615 request_->context()->network_delegate()); | 614 request_->context()->network_delegate()); |
616 EXPECT_FALSE(job_.get()); | 615 EXPECT_FALSE(job_.get()); |
617 | 616 |
618 job_ = handler_->MaybeLoadFallbackForRedirect( | 617 job_ = handler_->MaybeLoadFallbackForRedirect( |
619 request_.get(), | 618 request_.get(), |
620 request_->context()->network_delegate(), | 619 request_->context()->network_delegate(), |
(...skipping 12 matching lines...) Expand all Loading... |
633 // SubResource_NoRedirectFallback ----------------------------- | 632 // SubResource_NoRedirectFallback ----------------------------- |
634 | 633 |
635 void SubResource_NoRedirectFallback() { | 634 void SubResource_NoRedirectFallback() { |
636 // Redirects to resources in the same-origin are not subject to | 635 // Redirects to resources in the same-origin are not subject to |
637 // fallback namespaces. | 636 // fallback namespaces. |
638 host_->AssociateCompleteCache(MakeNewCache()); | 637 host_->AssociateCompleteCache(MakeNewCache()); |
639 | 638 |
640 mock_storage()->SimulateFindSubResource( | 639 mock_storage()->SimulateFindSubResource( |
641 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); | 640 AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); |
642 | 641 |
643 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 642 request_ = empty_context_.CreateRequest( |
| 643 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
644 handler_.reset(host_->CreateRequestHandler(request_.get(), | 644 handler_.reset(host_->CreateRequestHandler(request_.get(), |
645 RESOURCE_TYPE_SUB_RESOURCE)); | 645 RESOURCE_TYPE_SUB_RESOURCE)); |
646 EXPECT_TRUE(handler_.get()); | 646 EXPECT_TRUE(handler_.get()); |
647 job_ = handler_->MaybeLoadResource(request_.get(), | 647 job_ = handler_->MaybeLoadResource(request_.get(), |
648 request_->context()->network_delegate()); | 648 request_->context()->network_delegate()); |
649 EXPECT_FALSE(job_.get()); | 649 EXPECT_FALSE(job_.get()); |
650 | 650 |
651 AppCacheURLRequestJob* fallback_job; | 651 AppCacheURLRequestJob* fallback_job; |
652 fallback_job = handler_->MaybeLoadFallbackForRedirect( | 652 fallback_job = handler_->MaybeLoadFallbackForRedirect( |
653 request_.get(), | 653 request_.get(), |
(...skipping 13 matching lines...) Expand all Loading... |
667 | 667 |
668 void SubResource_Network() { | 668 void SubResource_Network() { |
669 // A sub-resource load where the resource is in a network namespace, | 669 // A sub-resource load where the resource is in a network namespace, |
670 // should result in the system using a 'real' job to do the network | 670 // should result in the system using a 'real' job to do the network |
671 // retrieval. | 671 // retrieval. |
672 host_->AssociateCompleteCache(MakeNewCache()); | 672 host_->AssociateCompleteCache(MakeNewCache()); |
673 | 673 |
674 mock_storage()->SimulateFindSubResource( | 674 mock_storage()->SimulateFindSubResource( |
675 AppCacheEntry(), AppCacheEntry(), true); | 675 AppCacheEntry(), AppCacheEntry(), true); |
676 | 676 |
677 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 677 request_ = empty_context_.CreateRequest( |
| 678 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
678 handler_.reset(host_->CreateRequestHandler(request_.get(), | 679 handler_.reset(host_->CreateRequestHandler(request_.get(), |
679 RESOURCE_TYPE_SUB_RESOURCE)); | 680 RESOURCE_TYPE_SUB_RESOURCE)); |
680 EXPECT_TRUE(handler_.get()); | 681 EXPECT_TRUE(handler_.get()); |
681 job_ = handler_->MaybeLoadResource(request_.get(), | 682 job_ = handler_->MaybeLoadResource(request_.get(), |
682 request_->context()->network_delegate()); | 683 request_->context()->network_delegate()); |
683 EXPECT_FALSE(job_.get()); | 684 EXPECT_FALSE(job_.get()); |
684 | 685 |
685 AppCacheURLRequestJob* fallback_job; | 686 AppCacheURLRequestJob* fallback_job; |
686 fallback_job = handler_->MaybeLoadFallbackForRedirect( | 687 fallback_job = handler_->MaybeLoadFallbackForRedirect( |
687 request_.get(), | 688 request_.get(), |
688 request_->context()->network_delegate(), | 689 request_->context()->network_delegate(), |
689 GURL("http://blah/redirect")); | 690 GURL("http://blah/redirect")); |
690 EXPECT_FALSE(fallback_job); | 691 EXPECT_FALSE(fallback_job); |
691 fallback_job = handler_->MaybeLoadFallbackForResponse( | 692 fallback_job = handler_->MaybeLoadFallbackForResponse( |
692 request_.get(), request_->context()->network_delegate()); | 693 request_.get(), request_->context()->network_delegate()); |
693 EXPECT_FALSE(fallback_job); | 694 EXPECT_FALSE(fallback_job); |
694 | 695 |
695 TestFinished(); | 696 TestFinished(); |
696 } | 697 } |
697 | 698 |
698 // DestroyedHost ----------------------------- | 699 // DestroyedHost ----------------------------- |
699 | 700 |
700 void DestroyedHost() { | 701 void DestroyedHost() { |
701 host_->AssociateCompleteCache(MakeNewCache()); | 702 host_->AssociateCompleteCache(MakeNewCache()); |
702 | 703 |
703 mock_storage()->SimulateFindSubResource( | 704 mock_storage()->SimulateFindSubResource( |
704 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); | 705 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); |
705 | 706 |
706 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 707 request_ = empty_context_.CreateRequest( |
| 708 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
707 handler_.reset(host_->CreateRequestHandler(request_.get(), | 709 handler_.reset(host_->CreateRequestHandler(request_.get(), |
708 RESOURCE_TYPE_SUB_RESOURCE)); | 710 RESOURCE_TYPE_SUB_RESOURCE)); |
709 EXPECT_TRUE(handler_.get()); | 711 EXPECT_TRUE(handler_.get()); |
710 | 712 |
711 backend_impl_->UnregisterHost(1); | 713 backend_impl_->UnregisterHost(1); |
712 host_ = NULL; | 714 host_ = NULL; |
713 | 715 |
714 EXPECT_FALSE(handler_->MaybeLoadResource( | 716 EXPECT_FALSE(handler_->MaybeLoadResource( |
715 request_.get(), request_->context()->network_delegate())); | 717 request_.get(), request_->context()->network_delegate())); |
716 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( | 718 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( |
717 request_.get(), | 719 request_.get(), |
718 request_->context()->network_delegate(), | 720 request_->context()->network_delegate(), |
719 GURL("http://blah/redirect"))); | 721 GURL("http://blah/redirect"))); |
720 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( | 722 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( |
721 request_.get(), request_->context()->network_delegate())); | 723 request_.get(), request_->context()->network_delegate())); |
722 | 724 |
723 TestFinished(); | 725 TestFinished(); |
724 } | 726 } |
725 | 727 |
726 // DestroyedHostWithWaitingJob ----------------------------- | 728 // DestroyedHostWithWaitingJob ----------------------------- |
727 | 729 |
728 void DestroyedHostWithWaitingJob() { | 730 void DestroyedHostWithWaitingJob() { |
729 // Precondition, the host is waiting on cache selection. | 731 // Precondition, the host is waiting on cache selection. |
730 host_->pending_selected_cache_id_ = 1; | 732 host_->pending_selected_cache_id_ = 1; |
731 | 733 |
732 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 734 request_ = empty_context_.CreateRequest( |
| 735 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
733 handler_.reset(host_->CreateRequestHandler(request_.get(), | 736 handler_.reset(host_->CreateRequestHandler(request_.get(), |
734 RESOURCE_TYPE_SUB_RESOURCE)); | 737 RESOURCE_TYPE_SUB_RESOURCE)); |
735 EXPECT_TRUE(handler_.get()); | 738 EXPECT_TRUE(handler_.get()); |
736 | 739 |
737 job_ = handler_->MaybeLoadResource(request_.get(), | 740 job_ = handler_->MaybeLoadResource(request_.get(), |
738 request_->context()->network_delegate()); | 741 request_->context()->network_delegate()); |
739 EXPECT_TRUE(job_.get()); | 742 EXPECT_TRUE(job_.get()); |
740 EXPECT_TRUE(job_->is_waiting()); | 743 EXPECT_TRUE(job_->is_waiting()); |
741 | 744 |
742 backend_impl_->UnregisterHost(1); | 745 backend_impl_->UnregisterHost(1); |
(...skipping 11 matching lines...) Expand all Loading... |
754 | 757 |
755 TestFinished(); | 758 TestFinished(); |
756 } | 759 } |
757 | 760 |
758 // UnsupportedScheme ----------------------------- | 761 // UnsupportedScheme ----------------------------- |
759 | 762 |
760 void UnsupportedScheme() { | 763 void UnsupportedScheme() { |
761 // Precondition, the host is waiting on cache selection. | 764 // Precondition, the host is waiting on cache selection. |
762 host_->pending_selected_cache_id_ = 1; | 765 host_->pending_selected_cache_id_ = 1; |
763 | 766 |
764 request_.reset(new MockURLRequest(GURL("ftp://blah/"), &empty_context_)); | 767 request_ = empty_context_.CreateRequest( |
| 768 GURL("ftp://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
765 handler_.reset(host_->CreateRequestHandler(request_.get(), | 769 handler_.reset(host_->CreateRequestHandler(request_.get(), |
766 RESOURCE_TYPE_SUB_RESOURCE)); | 770 RESOURCE_TYPE_SUB_RESOURCE)); |
767 EXPECT_TRUE(handler_.get()); // we could redirect to http (conceivably) | 771 EXPECT_TRUE(handler_.get()); // we could redirect to http (conceivably) |
768 | 772 |
769 EXPECT_FALSE(handler_->MaybeLoadResource( | 773 EXPECT_FALSE(handler_->MaybeLoadResource( |
770 request_.get(), request_->context()->network_delegate())); | 774 request_.get(), request_->context()->network_delegate())); |
771 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( | 775 EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( |
772 request_.get(), | 776 request_.get(), |
773 request_->context()->network_delegate(), | 777 request_->context()->network_delegate(), |
774 GURL("ftp://blah/redirect"))); | 778 GURL("ftp://blah/redirect"))); |
775 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( | 779 EXPECT_FALSE(handler_->MaybeLoadFallbackForResponse( |
776 request_.get(), request_->context()->network_delegate())); | 780 request_.get(), request_->context()->network_delegate())); |
777 | 781 |
778 TestFinished(); | 782 TestFinished(); |
779 } | 783 } |
780 | 784 |
781 // CanceledRequest ----------------------------- | 785 // CanceledRequest ----------------------------- |
782 | 786 |
783 void CanceledRequest() { | 787 void CanceledRequest() { |
784 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 788 request_ = empty_context_.CreateRequest( |
| 789 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
785 handler_.reset(host_->CreateRequestHandler(request_.get(), | 790 handler_.reset(host_->CreateRequestHandler(request_.get(), |
786 RESOURCE_TYPE_MAIN_FRAME)); | 791 RESOURCE_TYPE_MAIN_FRAME)); |
787 EXPECT_TRUE(handler_.get()); | 792 EXPECT_TRUE(handler_.get()); |
788 | 793 |
789 job_ = handler_->MaybeLoadResource(request_.get(), | 794 job_ = handler_->MaybeLoadResource(request_.get(), |
790 request_->context()->network_delegate()); | 795 request_->context()->network_delegate()); |
791 EXPECT_TRUE(job_.get()); | 796 EXPECT_TRUE(job_.get()); |
792 EXPECT_TRUE(job_->is_waiting()); | 797 EXPECT_TRUE(job_->is_waiting()); |
793 EXPECT_FALSE(job_->has_been_started()); | 798 EXPECT_FALSE(job_->has_been_started()); |
794 | 799 |
(...skipping 15 matching lines...) Expand all Loading... |
810 void WorkerRequest() { | 815 void WorkerRequest() { |
811 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( | 816 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( |
812 RESOURCE_TYPE_MAIN_FRAME)); | 817 RESOURCE_TYPE_MAIN_FRAME)); |
813 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( | 818 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( |
814 RESOURCE_TYPE_SUB_FRAME)); | 819 RESOURCE_TYPE_SUB_FRAME)); |
815 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( | 820 EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( |
816 RESOURCE_TYPE_SHARED_WORKER)); | 821 RESOURCE_TYPE_SHARED_WORKER)); |
817 EXPECT_FALSE(AppCacheRequestHandler::IsMainResourceType( | 822 EXPECT_FALSE(AppCacheRequestHandler::IsMainResourceType( |
818 RESOURCE_TYPE_WORKER)); | 823 RESOURCE_TYPE_WORKER)); |
819 | 824 |
820 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 825 request_ = empty_context_.CreateRequest( |
| 826 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
821 | 827 |
822 const int kParentHostId = host_->host_id(); | 828 const int kParentHostId = host_->host_id(); |
823 const int kWorkerHostId = 2; | 829 const int kWorkerHostId = 2; |
824 const int kAbandonedWorkerHostId = 3; | 830 const int kAbandonedWorkerHostId = 3; |
825 const int kNonExsitingHostId = 700; | 831 const int kNonExsitingHostId = 700; |
826 | 832 |
827 backend_impl_->RegisterHost(kWorkerHostId); | 833 backend_impl_->RegisterHost(kWorkerHostId); |
828 AppCacheHost* worker_host = backend_impl_->GetHost(kWorkerHostId); | 834 AppCacheHost* worker_host = backend_impl_->GetHost(kWorkerHostId); |
829 worker_host->SelectCacheForWorker(kParentHostId, kMockProcessId); | 835 worker_host->SelectCacheForWorker(kParentHostId, kMockProcessId); |
830 handler_.reset(worker_host->CreateRequestHandler( | 836 handler_.reset(worker_host->CreateRequestHandler( |
(...skipping 16 matching lines...) Expand all Loading... |
847 TestFinished(); | 853 TestFinished(); |
848 } | 854 } |
849 | 855 |
850 // MainResource_Blocked -------------------------------------------------- | 856 // MainResource_Blocked -------------------------------------------------- |
851 | 857 |
852 void MainResource_Blocked() { | 858 void MainResource_Blocked() { |
853 PushNextTask( | 859 PushNextTask( |
854 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Blocked, | 860 base::Bind(&AppCacheRequestHandlerTest::Verify_MainResource_Blocked, |
855 base::Unretained(this))); | 861 base::Unretained(this))); |
856 | 862 |
857 request_.reset(new MockURLRequest(GURL("http://blah/"), &empty_context_)); | 863 request_ = empty_context_.CreateRequest( |
| 864 GURL("http://blah/"), net::DEFAULT_PRIORITY, &delegate_, NULL); |
858 handler_.reset(host_->CreateRequestHandler(request_.get(), | 865 handler_.reset(host_->CreateRequestHandler(request_.get(), |
859 RESOURCE_TYPE_MAIN_FRAME)); | 866 RESOURCE_TYPE_MAIN_FRAME)); |
860 EXPECT_TRUE(handler_.get()); | 867 EXPECT_TRUE(handler_.get()); |
861 | 868 |
862 mock_policy_->can_load_return_value_ = false; | 869 mock_policy_->can_load_return_value_ = false; |
863 mock_storage()->SimulateFindMainResource( | 870 mock_storage()->SimulateFindMainResource( |
864 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), | 871 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), |
865 GURL(), AppCacheEntry(), | 872 GURL(), AppCacheEntry(), |
866 1, 2, GURL("http://blah/manifest/")); | 873 1, 2, GURL("http://blah/manifest/")); |
867 | 874 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 | 916 |
910 scoped_ptr<base::WaitableEvent> test_finished_event_; | 917 scoped_ptr<base::WaitableEvent> test_finished_event_; |
911 std::stack<base::Closure> task_stack_; | 918 std::stack<base::Closure> task_stack_; |
912 scoped_ptr<MockAppCacheService> mock_service_; | 919 scoped_ptr<MockAppCacheService> mock_service_; |
913 scoped_ptr<AppCacheBackendImpl> backend_impl_; | 920 scoped_ptr<AppCacheBackendImpl> backend_impl_; |
914 scoped_ptr<MockFrontend> mock_frontend_; | 921 scoped_ptr<MockFrontend> mock_frontend_; |
915 scoped_ptr<MockAppCachePolicy> mock_policy_; | 922 scoped_ptr<MockAppCachePolicy> mock_policy_; |
916 AppCacheHost* host_; | 923 AppCacheHost* host_; |
917 net::URLRequestContext empty_context_; | 924 net::URLRequestContext empty_context_; |
918 scoped_ptr<MockURLRequestJobFactory> job_factory_; | 925 scoped_ptr<MockURLRequestJobFactory> job_factory_; |
919 scoped_ptr<MockURLRequest> request_; | 926 MockURLRequestDelegate delegate_; |
| 927 scoped_ptr<net::URLRequest> request_; |
920 scoped_ptr<AppCacheRequestHandler> handler_; | 928 scoped_ptr<AppCacheRequestHandler> handler_; |
921 scoped_refptr<AppCacheURLRequestJob> job_; | 929 scoped_refptr<AppCacheURLRequestJob> job_; |
922 | 930 |
923 static scoped_ptr<base::Thread> io_thread_; | 931 static scoped_ptr<base::Thread> io_thread_; |
924 }; | 932 }; |
925 | 933 |
926 // static | 934 // static |
927 scoped_ptr<base::Thread> AppCacheRequestHandlerTest::io_thread_; | 935 scoped_ptr<base::Thread> AppCacheRequestHandlerTest::io_thread_; |
928 | 936 |
929 TEST_F(AppCacheRequestHandlerTest, MainResource_Miss) { | 937 TEST_F(AppCacheRequestHandlerTest, MainResource_Miss) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 | 1002 |
995 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { | 1003 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { |
996 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); | 1004 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); |
997 } | 1005 } |
998 | 1006 |
999 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { | 1007 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { |
1000 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); | 1008 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); |
1001 } | 1009 } |
1002 | 1010 |
1003 } // namespace content | 1011 } // namespace content |
OLD | NEW |