Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "net/url_request/url_request.h" | 7 #include "net/url_request/url_request.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "webkit/appcache/appcache.h" | 9 #include "webkit/appcache/appcache.h" |
| 10 #include "webkit/appcache/appcache_backend_impl.h" | 10 #include "webkit/appcache/appcache_backend_impl.h" |
| 11 #include "webkit/appcache/appcache_group.h" | 11 #include "webkit/appcache/appcache_group.h" |
| 12 #include "webkit/appcache/appcache_host.h" | 12 #include "webkit/appcache/appcache_host.h" |
| 13 #include "webkit/appcache/mock_appcache_policy.h" | |
| 13 #include "webkit/appcache/mock_appcache_service.h" | 14 #include "webkit/appcache/mock_appcache_service.h" |
| 14 #include "webkit/quota/quota_manager.h" | 15 #include "webkit/quota/quota_manager.h" |
| 15 | 16 |
| 16 namespace appcache { | 17 namespace appcache { |
| 17 | 18 |
| 18 class AppCacheHostTest : public testing::Test { | 19 class AppCacheHostTest : public testing::Test { |
| 19 public: | 20 public: |
| 20 AppCacheHostTest() { | 21 AppCacheHostTest() { |
| 21 get_status_callback_.reset( | 22 get_status_callback_.reset( |
| 22 NewCallback(this, &AppCacheHostTest::GetStatusCallback)); | 23 NewCallback(this, &AppCacheHostTest::GetStatusCallback)); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 EXPECT_EQ(kNoCacheId, mock_frontend_.last_cache_id_); | 426 EXPECT_EQ(kNoCacheId, mock_frontend_.last_cache_id_); |
| 426 EXPECT_EQ(UNCACHED, mock_frontend_.last_status_); | 427 EXPECT_EQ(UNCACHED, mock_frontend_.last_status_); |
| 427 | 428 |
| 428 // Simulate the parent being torn down. | 429 // Simulate the parent being torn down. |
| 429 backend_impl.UnregisterHost(kParentHostId); | 430 backend_impl.UnregisterHost(kParentHostId); |
| 430 parent_host = NULL; | 431 parent_host = NULL; |
| 431 EXPECT_EQ(NULL, backend_impl.GetHost(kParentHostId)); | 432 EXPECT_EQ(NULL, backend_impl.GetHost(kParentHostId)); |
| 432 EXPECT_EQ(NULL, worker_host->GetParentAppCacheHost()); | 433 EXPECT_EQ(NULL, worker_host->GetParentAppCacheHost()); |
| 433 } | 434 } |
| 434 | 435 |
| 436 TEST_F(AppCacheHostTest, SelectCacheAllowed) { | |
| 437 scoped_refptr<MockQuotaManagerProxy> mock_quota_proxy( | |
| 438 new MockQuotaManagerProxy); | |
| 439 MockAppCachePolicy mock_appcache_policy; | |
| 440 mock_appcache_policy.can_create_return_value_ = true; | |
| 441 service_.set_quota_manager_proxy(mock_quota_proxy); | |
| 442 service_.set_appcache_policy(&mock_appcache_policy); | |
| 443 | |
| 444 // Reset our mock frontend | |
| 445 mock_frontend_.last_cache_id_ = -333; | |
| 446 mock_frontend_.last_host_id_ = -333; | |
| 447 mock_frontend_.last_status_ = OBSOLETE; | |
| 448 mock_frontend_.last_event_id_ = OBSOLETE_EVENT; | |
| 449 | |
| 450 const GURL kDocAndOriginUrl(GURL("http://whatever/").GetOrigin()); | |
| 451 const GURL kManifestUrl(GURL("http://whatever/cache.manifest")); | |
| 452 { | |
| 453 AppCacheHost host(1, &mock_frontend_, &service_); | |
| 454 host.first_party_url_ = kDocAndOriginUrl; | |
| 455 host.SelectCache(kDocAndOriginUrl, kNoCacheId, kManifestUrl); | |
| 456 EXPECT_EQ(1, mock_quota_proxy->GetInUseCount(kDocAndOriginUrl)); | |
| 457 | |
| 458 // MockAppCacheService::LoadOrCreateGroup is asynchronous, so we shouldn't | |
| 459 // have received an OnCacheSelected msg yet. | |
| 460 EXPECT_EQ(-333, mock_frontend_.last_host_id_); | |
| 461 EXPECT_EQ(-333, mock_frontend_.last_cache_id_); | |
| 462 EXPECT_EQ(OBSOLETE, mock_frontend_.last_status_); | |
| 463 // No error events either | |
| 464 EXPECT_EQ(OBSOLETE_EVENT, mock_frontend_.last_event_id_); | |
|
michaeln
2011/09/05 19:49:31
does it make sense to also verify that frontend.On
marja
2011/09/06 09:09:28
Done.
| |
| 465 | |
| 466 EXPECT_TRUE(host.is_selection_pending()); | |
| 467 } | |
| 468 EXPECT_EQ(0, mock_quota_proxy->GetInUseCount(kDocAndOriginUrl)); | |
| 469 service_.set_quota_manager_proxy(NULL); | |
| 470 } | |
| 471 | |
| 472 TEST_F(AppCacheHostTest, SelectCacheBlocked) { | |
| 473 scoped_refptr<MockQuotaManagerProxy> mock_quota_proxy( | |
| 474 new MockQuotaManagerProxy); | |
| 475 MockAppCachePolicy mock_appcache_policy; | |
| 476 mock_appcache_policy.can_create_return_value_ = false; | |
| 477 service_.set_quota_manager_proxy(mock_quota_proxy); | |
| 478 service_.set_appcache_policy(&mock_appcache_policy); | |
| 479 | |
| 480 // Reset our mock frontend | |
| 481 mock_frontend_.last_cache_id_ = -333; | |
| 482 mock_frontend_.last_host_id_ = -333; | |
| 483 mock_frontend_.last_status_ = OBSOLETE; | |
| 484 mock_frontend_.last_event_id_ = OBSOLETE_EVENT; | |
| 485 | |
| 486 const GURL kDocAndOriginUrl(GURL("http://whatever/").GetOrigin()); | |
| 487 const GURL kManifestUrl(GURL("http://whatever/cache.manifest")); | |
| 488 { | |
| 489 AppCacheHost host(1, &mock_frontend_, &service_); | |
| 490 host.first_party_url_ = kDocAndOriginUrl; | |
| 491 host.SelectCache(kDocAndOriginUrl, kNoCacheId, kManifestUrl); | |
| 492 EXPECT_EQ(1, mock_quota_proxy->GetInUseCount(kDocAndOriginUrl)); | |
| 493 | |
| 494 // We should have received an OnCacheSelected msg | |
| 495 EXPECT_EQ(1, mock_frontend_.last_host_id_); | |
| 496 EXPECT_EQ(kNoCacheId, mock_frontend_.last_cache_id_); | |
| 497 EXPECT_EQ(UNCACHED, mock_frontend_.last_status_); | |
| 498 | |
| 499 // Also, an error event was raised | |
| 500 EXPECT_EQ(ERROR_EVENT, mock_frontend_.last_event_id_); | |
|
michaeln
2011/09/05 19:49:31
similarly verify that frontend.OnContentBlocked ha
marja
2011/09/06 09:09:28
Done.
| |
| 501 | |
| 502 // Otherwise, see that it respond as if there is no cache selected. | |
| 503 EXPECT_EQ(1, host.host_id()); | |
| 504 EXPECT_EQ(&service_, host.service()); | |
| 505 EXPECT_EQ(&mock_frontend_, host.frontend()); | |
| 506 EXPECT_EQ(NULL, host.associated_cache()); | |
| 507 EXPECT_FALSE(host.is_selection_pending()); | |
| 508 EXPECT_TRUE(host.preferred_manifest_url().is_empty()); | |
| 509 } | |
| 510 EXPECT_EQ(0, mock_quota_proxy->GetInUseCount(kDocAndOriginUrl)); | |
| 511 service_.set_quota_manager_proxy(NULL); | |
| 512 } | |
| 513 | |
| 435 } // namespace appcache | 514 } // namespace appcache |
| 436 | |
| OLD | NEW |