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 <stdint.h> |
| 6 |
5 #include <stack> | 7 #include <stack> |
6 #include <string> | 8 #include <string> |
7 #include <vector> | 9 #include <vector> |
8 | 10 |
9 #include "base/bind.h" | 11 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
11 #include "base/callback.h" | 13 #include "base/callback.h" |
12 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
14 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
15 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
16 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
17 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
18 #include "content/browser/appcache/appcache.h" | 21 #include "content/browser/appcache/appcache.h" |
19 #include "content/browser/appcache/appcache_backend_impl.h" | 22 #include "content/browser/appcache/appcache_backend_impl.h" |
20 #include "content/browser/appcache/appcache_request_handler.h" | 23 #include "content/browser/appcache/appcache_request_handler.h" |
21 #include "content/browser/appcache/appcache_url_request_job.h" | 24 #include "content/browser/appcache/appcache_url_request_job.h" |
22 #include "content/browser/appcache/mock_appcache_policy.h" | 25 #include "content/browser/appcache/mock_appcache_policy.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 EXPECT_TRUE(job_->is_waiting()); | 265 EXPECT_TRUE(job_->is_waiting()); |
263 | 266 |
264 // We have to wait for completion of storage->FindResponseForMainRequest. | 267 // We have to wait for completion of storage->FindResponseForMainRequest. |
265 ScheduleNextTask(); | 268 ScheduleNextTask(); |
266 } | 269 } |
267 | 270 |
268 void Verify_MainResource_Miss() { | 271 void Verify_MainResource_Miss() { |
269 EXPECT_FALSE(job_->is_waiting()); | 272 EXPECT_FALSE(job_->is_waiting()); |
270 EXPECT_TRUE(job_->is_delivering_network_response()); | 273 EXPECT_TRUE(job_->is_delivering_network_response()); |
271 | 274 |
272 int64 cache_id = kAppCacheNoCacheId; | 275 int64_t cache_id = kAppCacheNoCacheId; |
273 GURL manifest_url; | 276 GURL manifest_url; |
274 handler_->GetExtraResponseInfo(&cache_id, &manifest_url); | 277 handler_->GetExtraResponseInfo(&cache_id, &manifest_url); |
275 EXPECT_EQ(kAppCacheNoCacheId, cache_id); | 278 EXPECT_EQ(kAppCacheNoCacheId, cache_id); |
276 EXPECT_EQ(GURL(), manifest_url); | 279 EXPECT_EQ(GURL(), manifest_url); |
277 EXPECT_EQ(0, handler_->found_group_id_); | 280 EXPECT_EQ(0, handler_->found_group_id_); |
278 | 281 |
279 scoped_ptr<AppCacheURLRequestJob> fallback_job( | 282 scoped_ptr<AppCacheURLRequestJob> fallback_job( |
280 handler_->MaybeLoadFallbackForRedirect( | 283 handler_->MaybeLoadFallbackForRedirect( |
281 request_.get(), request_->context()->network_delegate(), | 284 request_.get(), request_->context()->network_delegate(), |
282 GURL("http://blah/redirect"))); | 285 GURL("http://blah/redirect"))); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 EXPECT_TRUE(job_->is_waiting()); | 318 EXPECT_TRUE(job_->is_waiting()); |
316 | 319 |
317 // We have to wait for completion of storage->FindResponseForMainRequest. | 320 // We have to wait for completion of storage->FindResponseForMainRequest. |
318 ScheduleNextTask(); | 321 ScheduleNextTask(); |
319 } | 322 } |
320 | 323 |
321 void Verify_MainResource_Hit() { | 324 void Verify_MainResource_Hit() { |
322 EXPECT_FALSE(job_->is_waiting()); | 325 EXPECT_FALSE(job_->is_waiting()); |
323 EXPECT_TRUE(job_->is_delivering_appcache_response()); | 326 EXPECT_TRUE(job_->is_delivering_appcache_response()); |
324 | 327 |
325 int64 cache_id = kAppCacheNoCacheId; | 328 int64_t cache_id = kAppCacheNoCacheId; |
326 GURL manifest_url; | 329 GURL manifest_url; |
327 handler_->GetExtraResponseInfo(&cache_id, &manifest_url); | 330 handler_->GetExtraResponseInfo(&cache_id, &manifest_url); |
328 EXPECT_EQ(1, cache_id); | 331 EXPECT_EQ(1, cache_id); |
329 EXPECT_EQ(GURL("http://blah/manifest/"), manifest_url); | 332 EXPECT_EQ(GURL("http://blah/manifest/"), manifest_url); |
330 EXPECT_EQ(2, handler_->found_group_id_); | 333 EXPECT_EQ(2, handler_->found_group_id_); |
331 | 334 |
332 scoped_ptr<AppCacheURLRequestJob> fallback_job( | 335 scoped_ptr<AppCacheURLRequestJob> fallback_job( |
333 handler_->MaybeLoadFallbackForResponse( | 336 handler_->MaybeLoadFallbackForResponse( |
334 request_.get(), request_->context()->network_delegate())); | 337 request_.get(), request_->context()->network_delegate())); |
335 EXPECT_FALSE(fallback_job); | 338 EXPECT_FALSE(fallback_job); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 EXPECT_FALSE(job_.get()); | 404 EXPECT_FALSE(job_.get()); |
402 | 405 |
403 // Simulate an http error of the real network job. | 406 // Simulate an http error of the real network job. |
404 SimulateResponseCode(500); | 407 SimulateResponseCode(500); |
405 | 408 |
406 job_.reset(handler_->MaybeLoadFallbackForResponse( | 409 job_.reset(handler_->MaybeLoadFallbackForResponse( |
407 request_.get(), request_->context()->network_delegate())); | 410 request_.get(), request_->context()->network_delegate())); |
408 EXPECT_TRUE(job_.get()); | 411 EXPECT_TRUE(job_.get()); |
409 EXPECT_TRUE(job_->is_delivering_appcache_response()); | 412 EXPECT_TRUE(job_->is_delivering_appcache_response()); |
410 | 413 |
411 int64 cache_id = kAppCacheNoCacheId; | 414 int64_t cache_id = kAppCacheNoCacheId; |
412 GURL manifest_url; | 415 GURL manifest_url; |
413 handler_->GetExtraResponseInfo(&cache_id, &manifest_url); | 416 handler_->GetExtraResponseInfo(&cache_id, &manifest_url); |
414 EXPECT_EQ(1, cache_id); | 417 EXPECT_EQ(1, cache_id); |
415 EXPECT_EQ(GURL("http://blah/manifest/"), manifest_url); | 418 EXPECT_EQ(GURL("http://blah/manifest/"), manifest_url); |
416 EXPECT_TRUE(host_->main_resource_was_namespace_entry_); | 419 EXPECT_TRUE(host_->main_resource_was_namespace_entry_); |
417 EXPECT_EQ(GURL("http://blah/fallbackurl"), host_->namespace_entry_url_); | 420 EXPECT_EQ(GURL("http://blah/fallbackurl"), host_->namespace_entry_url_); |
418 | 421 |
419 EXPECT_EQ(GURL("http://blah/manifest/"), | 422 EXPECT_EQ(GURL("http://blah/manifest/"), |
420 host_->preferred_manifest_url()); | 423 host_->preferred_manifest_url()); |
421 | 424 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 net::HttpResponseInfo info; | 479 net::HttpResponseInfo info; |
477 info.headers = new net::HttpResponseHeaders( | 480 info.headers = new net::HttpResponseHeaders( |
478 std::string(kOverrideHeaders, arraysize(kOverrideHeaders))); | 481 std::string(kOverrideHeaders, arraysize(kOverrideHeaders))); |
479 SimulateResponseInfo(info); | 482 SimulateResponseInfo(info); |
480 | 483 |
481 job_.reset(handler_->MaybeLoadFallbackForResponse( | 484 job_.reset(handler_->MaybeLoadFallbackForResponse( |
482 request_.get(), request_->context()->network_delegate())); | 485 request_.get(), request_->context()->network_delegate())); |
483 EXPECT_FALSE(job_.get()); | 486 EXPECT_FALSE(job_.get()); |
484 | 487 |
485 // GetExtraResponseInfo should return no information. | 488 // GetExtraResponseInfo should return no information. |
486 int64 cache_id = kAppCacheNoCacheId; | 489 int64_t cache_id = kAppCacheNoCacheId; |
487 GURL manifest_url; | 490 GURL manifest_url; |
488 handler_->GetExtraResponseInfo(&cache_id, &manifest_url); | 491 handler_->GetExtraResponseInfo(&cache_id, &manifest_url); |
489 EXPECT_EQ(kAppCacheNoCacheId, cache_id); | 492 EXPECT_EQ(kAppCacheNoCacheId, cache_id); |
490 EXPECT_TRUE(manifest_url.is_empty()); | 493 EXPECT_TRUE(manifest_url.is_empty()); |
491 | 494 |
492 TestFinished(); | 495 TestFinished(); |
493 } | 496 } |
494 | 497 |
495 // SubResource_Miss_WithNoCacheSelected ---------------------------------- | 498 // SubResource_Miss_WithNoCacheSelected ---------------------------------- |
496 | 499 |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 | 1023 |
1021 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { | 1024 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { |
1022 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); | 1025 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); |
1023 } | 1026 } |
1024 | 1027 |
1025 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { | 1028 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { |
1026 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); | 1029 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); |
1027 } | 1030 } |
1028 | 1031 |
1029 } // namespace content | 1032 } // namespace content |
OLD | NEW |