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

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

Issue 677003002: [ServiceWorker] Introduce the directory restriction of ServiceWorker scope in chromium side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated falken's comment 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
« no previous file with comments | « content/browser/service_worker/service_worker_dispatcher_host.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
diff --git a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
index 6f7f25d0e8081b7da901b0d23e139e2aef5fcac4..393f1594d41296f006ee42b6c89de20f4ea5f0a3 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
@@ -186,6 +186,57 @@ TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureTransportLocalhost) {
ServiceWorkerMsg_ServiceWorkerRegistered::ID);
}
+TEST_F(ServiceWorkerDispatcherHostTest,
+ Register_DifferentDirectoryThanScriptShouldFail) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
+ kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
+ host->SetDocumentUrl(GURL("https://www.example.com/foo"));
+ context()->AddProviderHost(host.Pass());
+
+ SendRegister(kProviderId,
+ GURL("https://www.example.com/hoge/piyo"),
+ GURL("https://www.example.com/bar/hoge.js"));
+ EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
+}
+
+TEST_F(ServiceWorkerDispatcherHostTest,
+ Register_SameDirectoryAsScriptButNoSlashShouldFail) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
+ kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
+ host->SetDocumentUrl(GURL("https://www.example.com/foo"));
+ context()->AddProviderHost(host.Pass());
+
+ SendRegister(kProviderId,
+ GURL("https://www.example.com/bar"),
+ GURL("https://www.example.com/bar/hoge.js"));
+ EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
+}
+
+TEST_F(ServiceWorkerDispatcherHostTest, Register_InvalidScopeShouldFail) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
+ kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
+ host->SetDocumentUrl(GURL("https://www.example.com/foo"));
+ context()->AddProviderHost(host.Pass());
+
+ SendRegister(
+ kProviderId, GURL(""), GURL("https://www.example.com/bar/hoge.js"));
+ EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
+}
+
+TEST_F(ServiceWorkerDispatcherHostTest, Register_InvalidScriptShouldFail) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
+ kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
+ host->SetDocumentUrl(GURL("https://www.example.com/foo"));
+ context()->AddProviderHost(host.Pass());
+
+ SendRegister(kProviderId, GURL("https://www.example.com/bar/"), GURL(""));
+ EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
+}
+
TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureOriginShouldFail) {
const int64 kProviderId = 99; // Dummy value
scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
@@ -279,6 +330,17 @@ TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOriginShouldFail) {
EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
}
+TEST_F(ServiceWorkerDispatcherHostTest, Unregister_InvalidScopeShouldFail) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
+ kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
+ host->SetDocumentUrl(GURL("https://www.example.com/foo"));
+ context()->AddProviderHost(host.Pass());
+
+ SendUnregister(kProviderId, GURL(""));
+ EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
+}
+
TEST_F(ServiceWorkerDispatcherHostTest, Unregister_NonSecureOriginShouldFail) {
const int64 kProviderId = 99; // Dummy value
scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
@@ -357,6 +419,18 @@ TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_CrossOriginShouldFail) {
}
TEST_F(ServiceWorkerDispatcherHostTest,
+ GetRegistration_InvalidScopeShouldFail) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
+ kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL));
+ host->SetDocumentUrl(GURL("https://www.example.com/foo"));
+ context()->AddProviderHost(host.Pass());
+
+ SendGetRegistration(kProviderId, GURL(""));
+ EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
+}
+
+TEST_F(ServiceWorkerDispatcherHostTest,
GetRegistration_NotSecureOriginShouldFail) {
const int64 kProviderId = 99; // Dummy value
scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
« no previous file with comments | « content/browser/service_worker/service_worker_dispatcher_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698