Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Unified Diff: content/browser/service_worker/service_worker_controllee_request_handler_unittest.cc

Issue 637243003: Service Worker: Obey content settings when deciding to control a page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@content
Patch Set: explicit, and better log Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_controllee_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_controllee_request_handler_unittest.cc
index 34eb2a3a6d40249c5c96598b0f49ad60e7969d1f..d030972453e449887eedc0f216886d2dd947a9f4 100644
--- a/content/browser/service_worker/service_worker_controllee_request_handler_unittest.cc
+++ b/content/browser/service_worker/service_worker_controllee_request_handler_unittest.cc
@@ -16,10 +16,13 @@
#include "content/browser/service_worker/service_worker_url_request_job.h"
#include "content/browser/service_worker/service_worker_utils.h"
#include "content/common/resource_request_body.h"
+#include "content/public/browser/resource_context.h"
#include "content/public/common/request_context_frame_type.h"
#include "content/public/common/request_context_type.h"
#include "content/public/common/resource_type.h"
+#include "content/public/test/mock_resource_context.h"
#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/test/test_content_browser_client.h"
#include "net/url_request/url_request_context.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -77,10 +80,68 @@ class ServiceWorkerControlleeRequestHandlerTest : public testing::Test {
base::WeakPtr<ServiceWorkerProviderHost> provider_host_;
net::URLRequestContext url_request_context_;
MockURLRequestDelegate url_request_delegate_;
+ MockResourceContext mock_resource_context_;
GURL scope_;
GURL script_url_;
};
+class ServiceWorkerTestContentBrowserClient : public TestContentBrowserClient {
+ public:
+ ServiceWorkerTestContentBrowserClient() {}
+ virtual bool AllowServiceWorker(const GURL& scope,
+ const GURL& first_party,
+ content::ResourceContext* context) OVERRIDE {
+ return false;
+ }
+};
+
+TEST_F(ServiceWorkerControlleeRequestHandlerTest, DisallowServiceWorker) {
+ ServiceWorkerTestContentBrowserClient test_browser_client;
+ ContentBrowserClient* old_browser_client =
+ SetBrowserClientForTesting(&test_browser_client);
+
+ // Store an activated worker.
+ version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
+ registration_->SetActiveVersion(version_.get());
+ context()->storage()->StoreRegistration(
+ registration_.get(),
+ version_.get(),
+ base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
+ base::RunLoop().RunUntilIdle();
+
+ // Conduct a main resource load.
+ const GURL kDocUrl("http://host/scope/doc");
+ scoped_ptr<net::URLRequest> request = url_request_context_.CreateRequest(
+ kDocUrl, net::DEFAULT_PRIORITY, &url_request_delegate_, NULL);
+ scoped_ptr<ServiceWorkerControlleeRequestHandler> handler(
+ new ServiceWorkerControlleeRequestHandler(
+ context()->AsWeakPtr(),
+ provider_host_,
+ base::WeakPtr<storage::BlobStorageContext>(),
+ FETCH_REQUEST_MODE_NO_CORS,
+ FETCH_CREDENTIALS_MODE_OMIT,
+ RESOURCE_TYPE_MAIN_FRAME,
+ REQUEST_CONTEXT_TYPE_HYPERLINK,
+ REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL,
+ scoped_refptr<ResourceRequestBody>()));
+ scoped_refptr<net::URLRequestJob> job =
+ handler->MaybeCreateJob(request.get(), NULL, &mock_resource_context_);
+ ServiceWorkerURLRequestJob* sw_job =
+ static_cast<ServiceWorkerURLRequestJob*>(job.get());
+
+ EXPECT_FALSE(sw_job->ShouldFallbackToNetwork());
+ EXPECT_FALSE(sw_job->ShouldForwardToServiceWorker());
+ EXPECT_FALSE(version_->HasControllee());
+ base::RunLoop().RunUntilIdle();
+
+ // Verify we did not use the worker.
+ EXPECT_TRUE(sw_job->ShouldFallbackToNetwork());
+ EXPECT_FALSE(sw_job->ShouldForwardToServiceWorker());
+ EXPECT_FALSE(version_->HasControllee());
+
+ SetBrowserClientForTesting(old_browser_client);
+}
+
TEST_F(ServiceWorkerControlleeRequestHandlerTest, ActivateWaitingVersion) {
// Store a registration that is installed but not activated yet.
version_->SetStatus(ServiceWorkerVersion::INSTALLED);
@@ -110,7 +171,7 @@ TEST_F(ServiceWorkerControlleeRequestHandlerTest, ActivateWaitingVersion) {
REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL,
scoped_refptr<ResourceRequestBody>()));
scoped_refptr<net::URLRequestJob> job =
- handler->MaybeCreateJob(request.get(), NULL);
+ handler->MaybeCreateJob(request.get(), NULL, &mock_resource_context_);
ServiceWorkerURLRequestJob* sw_job =
static_cast<ServiceWorkerURLRequestJob*>(job.get());
@@ -164,7 +225,7 @@ TEST_F(ServiceWorkerControlleeRequestHandlerTest, DeletedProviderHost) {
REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL,
scoped_refptr<ResourceRequestBody>()));
scoped_refptr<net::URLRequestJob> job =
- handler->MaybeCreateJob(request.get(), NULL);
+ handler->MaybeCreateJob(request.get(), NULL, &mock_resource_context_);
ServiceWorkerURLRequestJob* sw_job =
static_cast<ServiceWorkerURLRequestJob*>(job.get());

Powered by Google App Engine
This is Rietveld 408576698