| Index: content/browser/service_worker/service_worker_context_request_handler_unittest.cc
|
| diff --git a/content/browser/service_worker/service_worker_controllee_request_handler_unittest.cc b/content/browser/service_worker/service_worker_context_request_handler_unittest.cc
|
| similarity index 53%
|
| copy from content/browser/service_worker/service_worker_controllee_request_handler_unittest.cc
|
| copy to content/browser/service_worker/service_worker_context_request_handler_unittest.cc
|
| index 708d00083aea301cf01efb9a5c688a0e899f61d9..939fdd05468fc07100ce7083ab31a5e8e5d2acb0 100644
|
| --- a/content/browser/service_worker/service_worker_controllee_request_handler_unittest.cc
|
| +++ b/content/browser/service_worker/service_worker_context_request_handler_unittest.cc
|
| @@ -9,13 +9,13 @@
|
| #include "content/browser/fileapi/mock_url_request_delegate.h"
|
| #include "content/browser/service_worker/embedded_worker_test_helper.h"
|
| #include "content/browser/service_worker/service_worker_context_core.h"
|
| -#include "content/browser/service_worker/service_worker_controllee_request_handler.h"
|
| +#include "content/browser/service_worker/service_worker_context_request_handler.h"
|
| #include "content/browser/service_worker/service_worker_provider_host.h"
|
| #include "content/browser/service_worker/service_worker_registration.h"
|
| -#include "content/browser/service_worker/service_worker_registration.h"
|
| -#include "content/browser/service_worker/service_worker_url_request_job.h"
|
| #include "content/browser/service_worker/service_worker_utils.h"
|
| +#include "content/browser/service_worker/service_worker_write_to_cache_job.h"
|
| #include "content/public/test/test_browser_thread_bundle.h"
|
| +#include "net/base/load_flags.h"
|
| #include "net/url_request/url_request_context.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -29,9 +29,9 @@ void EmptyCallback() {}
|
|
|
| }
|
|
|
| -class ServiceWorkerControlleeRequestHandlerTest : public testing::Test {
|
| +class ServiceWorkerContextRequestHandlerTest : public testing::Test {
|
| public:
|
| - ServiceWorkerControlleeRequestHandlerTest()
|
| + ServiceWorkerContextRequestHandlerTest()
|
| : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
|
|
|
| virtual void SetUp() OVERRIDE {
|
| @@ -51,7 +51,7 @@ class ServiceWorkerControlleeRequestHandlerTest : public testing::Test {
|
| kMockRenderProcessId, 1 /* provider_id */,
|
| context()->AsWeakPtr(), NULL));
|
| provider_host_ = host->AsWeakPtr();
|
| - context()->AddProviderHost(make_scoped_ptr(host.release()));
|
| + context()->AddProviderHost(host.Pass());
|
|
|
| context()->storage()->LazyInitialize(base::Bind(&EmptyCallback));
|
| base::RunLoop().RunUntilIdle();
|
| @@ -77,48 +77,66 @@ class ServiceWorkerControlleeRequestHandlerTest : public testing::Test {
|
| GURL script_url_;
|
| };
|
|
|
| -TEST_F(ServiceWorkerControlleeRequestHandlerTest, ActivateWaitingVersion) {
|
| - // Store a registration that is installed but not activated yet.
|
| - version_->SetStatus(ServiceWorkerVersion::INSTALLED);
|
| - registration_->SetWaitingVersion(version_);
|
| - context()->storage()->StoreRegistration(
|
| - registration_, version_,
|
| - base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
|
| - base::RunLoop().RunUntilIdle();
|
| -
|
| - // Conduct a main resource load.
|
| - const GURL kDocUrl("http://host/scope/doc");
|
| +TEST_F(ServiceWorkerContextRequestHandlerTest, SoftUpdateBefore24Hours) {
|
| + // Give the registration an very recent last update time and pretend
|
| + // we're installing a new version.
|
| + registration_->set_last_update_check(base::Time::Now());
|
| + version_->SetStatus(ServiceWorkerVersion::NEW);
|
| + provider_host_->running_hosted_version_ = version_;
|
| +
|
| + // Conduct a resource fetch for the main script.
|
| + const GURL kScriptUrl("http://host/script.js");
|
| scoped_ptr<net::URLRequest> request = url_request_context_.CreateRequest(
|
| - kDocUrl,
|
| + kScriptUrl,
|
| net::DEFAULT_PRIORITY,
|
| &url_request_delegate_,
|
| NULL);
|
| - scoped_ptr<ServiceWorkerControlleeRequestHandler> handler(
|
| - new ServiceWorkerControlleeRequestHandler(
|
| + scoped_ptr<ServiceWorkerContextRequestHandler> handler(
|
| + new ServiceWorkerContextRequestHandler(
|
| context()->AsWeakPtr(),
|
| provider_host_,
|
| base::WeakPtr<webkit_blob::BlobStorageContext>(),
|
| - RESOURCE_TYPE_MAIN_FRAME));
|
| + RESOURCE_TYPE_SERVICE_WORKER));
|
| scoped_refptr<net::URLRequestJob> job =
|
| handler->MaybeCreateJob(request.get(), NULL);
|
| - ServiceWorkerURLRequestJob* sw_job =
|
| - static_cast<ServiceWorkerURLRequestJob*>(job.get());
|
| + ASSERT_TRUE(job);
|
| + ServiceWorkerWriteToCacheJob* sw_job =
|
| + static_cast<ServiceWorkerWriteToCacheJob*>(job.get());
|
|
|
| - EXPECT_FALSE(sw_job->ShouldFallbackToNetwork());
|
| - EXPECT_FALSE(sw_job->ShouldForwardToServiceWorker());
|
| - EXPECT_FALSE(version_->HasControllee());
|
| + // Verify the net request is not initialized to bypass the browser cache.
|
| + EXPECT_FALSE(sw_job->net_request_->load_flags() & net::LOAD_BYPASS_CACHE);
|
| +}
|
|
|
| - base::RunLoop().RunUntilIdle();
|
| +TEST_F(ServiceWorkerContextRequestHandlerTest, HardUpdateAfter24Hours) {
|
| + // Give the registration a old update time and pretend
|
| + // we're installing a new version.
|
| + registration_->set_last_update_check(
|
| + base::Time::Now() - base::TimeDelta::FromDays(7));
|
| + version_->SetStatus(ServiceWorkerVersion::NEW);
|
| + provider_host_->running_hosted_version_ = version_;
|
|
|
| - EXPECT_EQ(ServiceWorkerVersion::ACTIVATED,
|
| - version_->status());
|
| - EXPECT_FALSE(sw_job->ShouldFallbackToNetwork());
|
| - EXPECT_TRUE(sw_job->ShouldForwardToServiceWorker());
|
| - EXPECT_TRUE(version_->HasControllee());
|
| + // Conduct a resource fetch for the main script.
|
| + const GURL kScriptUrl("http://host/script.js");
|
| + scoped_ptr<net::URLRequest> request = url_request_context_.CreateRequest(
|
| + kScriptUrl,
|
| + net::DEFAULT_PRIORITY,
|
| + &url_request_delegate_,
|
| + NULL);
|
| + scoped_ptr<ServiceWorkerContextRequestHandler> handler(
|
| + new ServiceWorkerContextRequestHandler(
|
| + context()->AsWeakPtr(),
|
| + provider_host_,
|
| + base::WeakPtr<webkit_blob::BlobStorageContext>(),
|
| + RESOURCE_TYPE_SERVICE_WORKER));
|
| + scoped_refptr<net::URLRequestJob> job =
|
| + handler->MaybeCreateJob(request.get(), NULL);
|
| + ASSERT_TRUE(job);
|
| + ServiceWorkerWriteToCacheJob* sw_job =
|
| + static_cast<ServiceWorkerWriteToCacheJob*>(job.get());
|
|
|
| - // Navigations should trigger an update too.
|
| - handler.reset(NULL);
|
| - EXPECT_TRUE(version_->update_timer_.IsRunning());
|
| + // Verify the net request is initialized to bypass the browser cache.
|
| + EXPECT_TRUE(sw_job->net_request_->load_flags() & net::LOAD_BYPASS_CACHE);
|
| }
|
|
|
| +
|
| } // namespace content
|
|
|