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

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: 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_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..8897ae3825d0d658ad3605ed828632ec811a6dce 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,34 @@ 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_);
+}
+
falken 2014/10/27 03:54:17 Can you add checks for invalid GURLs too, like the
TEST_F(ServiceWorkerDispatcherHostTest, Register_NonSecureOriginShouldFail) {
const int64 kProviderId = 99; // Dummy value
scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(

Powered by Google App Engine
This is Rietveld 408576698