diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-20 20:51:06 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-20 20:51:06 +0000 |
commit | 15f9cdedac1784a85dca7867858c905f0ed90d2b (patch) | |
tree | bb001e718240c0fd86aa43a55f4a76e978b72880 /webkit/appcache/appcache_request_handler_unittest.cc | |
parent | b89f7e4d3f98fffe88bd07a57c735e28c37e692c (diff) | |
download | chromium_src-15f9cdedac1784a85dca7867858c905f0ed90d2b.zip chromium_src-15f9cdedac1784a85dca7867858c905f0ed90d2b.tar.gz chromium_src-15f9cdedac1784a85dca7867858c905f0ed90d2b.tar.bz2 |
Finally getting to the appcache parts instead of all of this webkitApi/ipc plumbing craziness.
BUG=39368
TEST=new unittests
Review URL: http://codereview.chromium.org/2121002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47844 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_request_handler_unittest.cc')
-rw-r--r-- | webkit/appcache/appcache_request_handler_unittest.cc | 113 |
1 files changed, 92 insertions, 21 deletions
diff --git a/webkit/appcache/appcache_request_handler_unittest.cc b/webkit/appcache/appcache_request_handler_unittest.cc index 83a0236..5ca8f4c1 100644 --- a/webkit/appcache/appcache_request_handler_unittest.cc +++ b/webkit/appcache/appcache_request_handler_unittest.cc @@ -10,12 +10,15 @@ #include "net/url_request/url_request_error_job.h" #include "testing/gtest/include/gtest/gtest.h" #include "webkit/appcache/appcache.h" +#include "webkit/appcache/appcache_backend_impl.h" #include "webkit/appcache/appcache_request_handler.h" #include "webkit/appcache/appcache_url_request_job.h" #include "webkit/appcache/mock_appcache_service.h" namespace appcache { +static const int kMockProcessId = 1; + class AppCacheRequestHandlerTest : public testing::Test { public: class MockFrontend : public AppCacheFrontend { @@ -103,7 +106,7 @@ class AppCacheRequestHandlerTest : public testing::Test { // Test harness -------------------------------------------------- AppCacheRequestHandlerTest() - : orig_http_factory_(NULL) { + : host_(NULL), orig_http_factory_(NULL) { } template <class Method> @@ -120,8 +123,12 @@ class AppCacheRequestHandlerTest : public testing::Test { "http", MockHttpJobFactory); mock_service_.reset(new MockAppCacheService); mock_frontend_.reset(new MockFrontend); - host_.reset( - new AppCacheHost(1, mock_frontend_.get(), mock_service_.get())); + backend_impl_.reset(new AppCacheBackendImpl); + backend_impl_->Initialize(mock_service_.get(), mock_frontend_.get(), + kMockProcessId); + const int kHostId = 1; + backend_impl_->RegisterHost(kHostId); + host_ = backend_impl_->GetHost(kHostId); } void TearDownTest() { @@ -132,9 +139,10 @@ class AppCacheRequestHandlerTest : public testing::Test { job_ = NULL; handler_.reset(); request_.reset(); - host_.reset(); + backend_impl_.reset(); mock_frontend_.reset(); mock_service_.reset(); + host_ = NULL; } void TestFinished() { @@ -171,7 +179,8 @@ class AppCacheRequestHandlerTest : public testing::Test { this, &AppCacheRequestHandlerTest::Verify_MainResource_Miss)); request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), true)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::MAIN_FRAME)); EXPECT_TRUE(handler_.get()); job_ = handler_->MaybeLoadResource(request_.get()); @@ -209,7 +218,8 @@ class AppCacheRequestHandlerTest : public testing::Test { this, &AppCacheRequestHandlerTest::Verify_MainResource_Hit)); request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), true)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::MAIN_FRAME)); EXPECT_TRUE(handler_.get()); mock_storage()->SimulateFindMainResource( @@ -248,7 +258,8 @@ class AppCacheRequestHandlerTest : public testing::Test { this, &AppCacheRequestHandlerTest::Verify_MainResource_Fallback)); request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), true)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::MAIN_FRAME)); EXPECT_TRUE(handler_.get()); mock_storage()->SimulateFindMainResource( @@ -293,7 +304,8 @@ class AppCacheRequestHandlerTest : public testing::Test { void SubResource_Miss_WithNoCacheSelected() { request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), false)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::SUB_RESOURCE)); // We avoid creating handler when possible, sub-resource requests are not // subject to retrieval from an appcache when there's no associated cache. @@ -310,7 +322,8 @@ class AppCacheRequestHandlerTest : public testing::Test { host_->AssociateCache(MakeNewCache()); request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), false)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); job_ = handler_->MaybeLoadResource(request_.get()); @@ -335,7 +348,8 @@ class AppCacheRequestHandlerTest : public testing::Test { host_->pending_selected_cache_id_ = cache->cache_id(); request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), false)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); job_ = handler_->MaybeLoadResource(request_.get()); EXPECT_TRUE(job_.get()); @@ -364,7 +378,8 @@ class AppCacheRequestHandlerTest : public testing::Test { AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), false)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); job_ = handler_->MaybeLoadResource(request_.get()); EXPECT_TRUE(job_.get()); @@ -391,7 +406,8 @@ class AppCacheRequestHandlerTest : public testing::Test { AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), false)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); job_ = handler_->MaybeLoadResource(request_.get()); EXPECT_FALSE(job_.get()); @@ -419,7 +435,8 @@ class AppCacheRequestHandlerTest : public testing::Test { AppCacheEntry(), AppCacheEntry(AppCacheEntry::EXPLICIT, 1), false); request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), false)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); job_ = handler_->MaybeLoadResource(request_.get()); EXPECT_FALSE(job_.get()); @@ -448,7 +465,8 @@ class AppCacheRequestHandlerTest : public testing::Test { AppCacheEntry(), AppCacheEntry(), true); request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), false)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); job_ = handler_->MaybeLoadResource(request_.get()); EXPECT_FALSE(job_.get()); @@ -472,10 +490,12 @@ class AppCacheRequestHandlerTest : public testing::Test { AppCacheEntry(AppCacheEntry::EXPLICIT, 1), AppCacheEntry(), false); request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), false)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); - host_.reset(); + backend_impl_->UnregisterHost(1); + host_ = NULL; EXPECT_FALSE(handler_->MaybeLoadResource(request_.get())); EXPECT_FALSE(handler_->MaybeLoadFallbackForRedirect( @@ -492,14 +512,16 @@ class AppCacheRequestHandlerTest : public testing::Test { host_->pending_selected_cache_id_ = 1; request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), false)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); job_ = handler_->MaybeLoadResource(request_.get()); EXPECT_TRUE(job_.get()); EXPECT_TRUE(job_->is_waiting()); - host_.reset(); + backend_impl_->UnregisterHost(1); + host_ = NULL; EXPECT_TRUE(job_->has_been_killed()); EXPECT_FALSE(handler_->MaybeLoadResource(request_.get())); @@ -517,7 +539,8 @@ class AppCacheRequestHandlerTest : public testing::Test { host_->pending_selected_cache_id_ = 1; request_.reset(new MockURLRequest(GURL("ftp://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), false)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::SUB_RESOURCE)); EXPECT_TRUE(handler_.get()); // we could redirect to http (conceivably) EXPECT_FALSE(handler_->MaybeLoadResource(request_.get())); @@ -532,7 +555,8 @@ class AppCacheRequestHandlerTest : public testing::Test { void CanceledRequest() { request_.reset(new MockURLRequest(GURL("http://blah/"))); - handler_.reset(host_->CreateRequestHandler(request_.get(), true)); + handler_.reset(host_->CreateRequestHandler(request_.get(), + ResourceType::MAIN_FRAME)); EXPECT_TRUE(handler_.get()); job_ = handler_->MaybeLoadResource(request_.get()); @@ -552,6 +576,48 @@ class AppCacheRequestHandlerTest : public testing::Test { TestFinished(); } + // WorkerRequest ----------------------------- + + void WorkerRequest() { + EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( + ResourceType::MAIN_FRAME)); + EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( + ResourceType::SUB_FRAME)); + EXPECT_TRUE(AppCacheRequestHandler::IsMainResourceType( + ResourceType::SHARED_WORKER)); + EXPECT_FALSE(AppCacheRequestHandler::IsMainResourceType( + ResourceType::WORKER)); + + request_.reset(new MockURLRequest(GURL("http://blah/"))); + + const int kParentHostId = host_->host_id(); + const int kWorkerHostId = 2; + const int kAbandonedWorkerHostId = 3; + const int kNonExsitingHostId = 700; + + backend_impl_->RegisterHost(kWorkerHostId); + AppCacheHost* worker_host = backend_impl_->GetHost(kWorkerHostId); + worker_host->SelectCacheForWorker(kParentHostId, kMockProcessId); + handler_.reset(worker_host->CreateRequestHandler( + request_.get(), ResourceType::SHARED_WORKER)); + EXPECT_TRUE(handler_.get()); + // Verify that the handler is associated with the parent host. + EXPECT_EQ(host_, handler_->host_); + + // Create a new worker host, but associate it with a parent host that + // does not exists to simulate the host having been torn down. + backend_impl_->UnregisterHost(kWorkerHostId); + backend_impl_->RegisterHost(kAbandonedWorkerHostId); + worker_host = backend_impl_->GetHost(kAbandonedWorkerHostId); + EXPECT_EQ(NULL, backend_impl_->GetHost(kNonExsitingHostId)); + worker_host->SelectCacheForWorker(kNonExsitingHostId, kMockProcessId); + handler_.reset(worker_host->CreateRequestHandler( + request_.get(), ResourceType::SHARED_WORKER)); + EXPECT_FALSE(handler_.get()); + + TestFinished(); + } + // Test case helpers -------------------------------------------------- AppCache* MakeNewCache() { @@ -574,8 +640,9 @@ class AppCacheRequestHandlerTest : public testing::Test { scoped_ptr<base::WaitableEvent> test_finished_event_; std::stack<Task*> task_stack_; scoped_ptr<MockAppCacheService> mock_service_; + scoped_ptr<AppCacheBackendImpl> backend_impl_; scoped_ptr<MockFrontend> mock_frontend_; - scoped_ptr<AppCacheHost> host_; + AppCacheHost* host_; scoped_ptr<MockURLRequest> request_; scoped_ptr<AppCacheRequestHandler> handler_; scoped_refptr<AppCacheURLRequestJob> job_; @@ -650,6 +717,10 @@ TEST_F(AppCacheRequestHandlerTest, CanceledRequest) { RunTestOnIOThread(&AppCacheRequestHandlerTest::CanceledRequest); } +TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { + RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); +} + } // namespace appcache // AppCacheRequestHandlerTest is expected to always live longer than the |