diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-17 22:20:36 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-17 22:20:36 +0000 |
commit | ea776d0208899b770ea386b994216ef476197a46 (patch) | |
tree | cb614ced5bd6e764e01f244813d07b0a48870a0a /webkit/appcache/appcache_storage_impl_unittest.cc | |
parent | a3d3a7cf3b81cc8d00490bb7bfd92b57f0146d9c (diff) | |
download | chromium_src-ea776d0208899b770ea386b994216ef476197a46.zip chromium_src-ea776d0208899b770ea386b994216ef476197a46.tar.gz chromium_src-ea776d0208899b770ea386b994216ef476197a46.tar.bz2 |
Introduce an AppCachePolicy interface that allows the containing browser to determine appcache permissions. The policy can allow or deny loading existing manifests or the creation of new manifests. The policy check for creating new manifests can be async to allow for a user prompt.
BUG=none
TEST=new unit tests added
Review URL: http://codereview.chromium.org/565042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39280 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_storage_impl_unittest.cc')
-rw-r--r-- | webkit/appcache/appcache_storage_impl_unittest.cc | 72 |
1 files changed, 61 insertions, 11 deletions
diff --git a/webkit/appcache/appcache_storage_impl_unittest.cc b/webkit/appcache/appcache_storage_impl_unittest.cc index 9e207f8..ad6a8310 100644 --- a/webkit/appcache/appcache_storage_impl_unittest.cc +++ b/webkit/appcache/appcache_storage_impl_unittest.cc @@ -7,11 +7,13 @@ #include "base/message_loop.h" #include "base/thread.h" #include "base/waitable_event.h" +#include "net/base/net_errors.h" #include "testing/gtest/include/gtest/gtest.h" #include "webkit/appcache/appcache.h" #include "webkit/appcache/appcache_database.h" #include "webkit/appcache/appcache_entry.h" #include "webkit/appcache/appcache_group.h" +#include "webkit/appcache/appcache_policy.h" #include "webkit/appcache/appcache_service.h" #include "webkit/appcache/appcache_storage_impl.h" #include "webkit/tools/test_shell/simple_appcache_system.h" @@ -130,6 +132,34 @@ class AppCacheStorageImplTest : public testing::Test { AppCacheStorageImplTest* test_; }; + class MockAppCachePolicy : public AppCachePolicy { + public: + explicit MockAppCachePolicy(AppCacheStorageImplTest* test) + : can_load_return_value_(true), can_create_return_value_(0), + callback_(NULL), test_(test) { + } + + virtual bool CanLoadAppCache(const GURL& manifest_url) { + requested_manifest_url_ = manifest_url; + return can_load_return_value_; + } + + virtual int CanCreateAppCache(const GURL& manifest_url, + net::CompletionCallback* callback) { + requested_manifest_url_ = manifest_url; + callback_ = callback; + if (can_create_return_value_ == net::ERR_IO_PENDING) + test_->ScheduleNextTask(); + return can_create_return_value_; + } + + bool can_load_return_value_; + int can_create_return_value_; + GURL requested_manifest_url_; + net::CompletionCallback* callback_; + AppCacheStorageImplTest* test_; + }; + // Helper class run a test on our io_thread. The io_thread // is spun up once and reused for all tests. template <class Method> @@ -182,7 +212,8 @@ class AppCacheStorageImplTest : public testing::Test { // Test harness -------------------------------------------------- AppCacheStorageImplTest() - : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { + : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(policy_(this)) { } template <class Method> @@ -664,17 +695,25 @@ class AppCacheStorageImplTest : public testing::Test { // BasicFindMainResponse ------------------------------- void BasicFindMainResponseInDatabase() { - BasicFindMainResponse(true); + BasicFindMainResponse(true, false); } void BasicFindMainResponseInWorkingSet() { - BasicFindMainResponse(false); + BasicFindMainResponse(false, false); + } + + void BlockFindMainResponseWithPolicyCheck() { + BasicFindMainResponse(true, true); } - void BasicFindMainResponse(bool drop_from_working_set) { + void BasicFindMainResponse(bool drop_from_working_set, + bool block_with_policy_check) { PushNextTask(method_factory_.NewRunnableMethod( &AppCacheStorageImplTest::Verify_BasicFindMainResponse)); + policy_.can_load_return_value_ = !block_with_policy_check; + service()->set_appcache_policy(&policy_); + // Setup some preconditions. Create a complete cache with an entry // in storage. MakeCacheAndGroup(kManifestUrl, 1, 1, true); @@ -700,13 +739,18 @@ class AppCacheStorageImplTest : public testing::Test { } void Verify_BasicFindMainResponse() { - EXPECT_EQ(kEntryUrl, delegate()->found_url_); - EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_); - EXPECT_EQ(1, delegate()->found_cache_id_); - EXPECT_EQ(1, delegate()->found_entry_.response_id()); - EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); - EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); - TestFinished(); + EXPECT_EQ(kManifestUrl, policy_.requested_manifest_url_); + if (policy_.can_load_return_value_) { + EXPECT_EQ(kEntryUrl, delegate()->found_url_); + EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_); + EXPECT_EQ(1, delegate()->found_cache_id_); + EXPECT_EQ(1, delegate()->found_entry_.response_id()); + EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); + EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); + TestFinished(); + } else { + Verify_FindNoMainResponse(); + } } // BasicFindMainFallbackResponse ------------------------------- @@ -914,6 +958,7 @@ class AppCacheStorageImplTest : public testing::Test { ScopedRunnableMethodFactory<AppCacheStorageImplTest> method_factory_; scoped_ptr<base::WaitableEvent> test_finished_event_; std::stack<Task*> task_stack_; + MockAppCachePolicy policy_; scoped_ptr<AppCacheService> service_; scoped_ptr<MockStorageDelegate> delegate_; scoped_refptr<AppCacheGroup> group_; @@ -981,6 +1026,11 @@ TEST_F(AppCacheStorageImplTest, BasicFindMainResponseInWorkingSet) { &AppCacheStorageImplTest::BasicFindMainResponseInWorkingSet); } +TEST_F(AppCacheStorageImplTest, BlockFindMainResponseWithPolicyCheck) { + RunTestOnIOThread( + &AppCacheStorageImplTest::BlockFindMainResponseWithPolicyCheck); +} + TEST_F(AppCacheStorageImplTest, BasicFindMainFallbackResponseInDatabase) { RunTestOnIOThread( &AppCacheStorageImplTest::BasicFindMainFallbackResponseInDatabase); |