Commit 095ec973 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Do allowed origin check on StartWorker.

We were only doing this check at registration time previously, which is
sketchy since the browser or content settings could change in the
meantime after registration.

Actually the motivating example was if you register
an extension service worker once and then run Chrome with
--disable-extensions and then try to start the worker via
chrome://serviceworker-internals. It turns out the checks for
JavaScript and cookies in
ChromeContentBrowserClient::AllowServiceWorker were disallowing
start worker in that case, but it seems fragile to rely on those.

Change-Id: Iea3706ccf08ec72ed9e2306b01a6ddfd0fa3b9eb
Reviewed-on: https://chromium-review.googlesource.com/1027171Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553483}
parent 9c63d7a4
...@@ -200,8 +200,8 @@ class RecordableEmbeddedWorkerInstanceClient ...@@ -200,8 +200,8 @@ class RecordableEmbeddedWorkerInstanceClient
// Make sure basic registration is working. // Make sure basic registration is working.
TEST_F(ServiceWorkerContextTest, Register) { TEST_F(ServiceWorkerContextTest, Register) {
GURL pattern("http://www.example.com/"); GURL pattern("https://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = pattern; options.scope = pattern;
...@@ -245,8 +245,8 @@ TEST_F(ServiceWorkerContextTest, Register) { ...@@ -245,8 +245,8 @@ TEST_F(ServiceWorkerContextTest, Register) {
// registration callback should indicate success, but there should be no waiting // registration callback should indicate success, but there should be no waiting
// or active worker in the registration. // or active worker in the registration.
TEST_F(ServiceWorkerContextTest, Register_RejectInstall) { TEST_F(ServiceWorkerContextTest, Register_RejectInstall) {
GURL pattern("http://www.example.com/"); GURL pattern("https://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = pattern; options.scope = pattern;
...@@ -293,8 +293,8 @@ TEST_F(ServiceWorkerContextTest, Register_RejectInstall) { ...@@ -293,8 +293,8 @@ TEST_F(ServiceWorkerContextTest, Register_RejectInstall) {
// Test registration when the service worker rejects the activate event. The // Test registration when the service worker rejects the activate event. The
// worker should be activated anyway. // worker should be activated anyway.
TEST_F(ServiceWorkerContextTest, Register_RejectActivate) { TEST_F(ServiceWorkerContextTest, Register_RejectActivate) {
GURL pattern("http://www.example.com/"); GURL pattern("https://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = pattern; options.scope = pattern;
...@@ -340,14 +340,14 @@ TEST_F(ServiceWorkerContextTest, Register_RejectActivate) { ...@@ -340,14 +340,14 @@ TEST_F(ServiceWorkerContextTest, Register_RejectActivate) {
// Make sure registrations are cleaned up when they are unregistered. // Make sure registrations are cleaned up when they are unregistered.
TEST_F(ServiceWorkerContextTest, Unregister) { TEST_F(ServiceWorkerContextTest, Unregister) {
GURL pattern("http://www.example.com/"); GURL pattern("https://www.example.com/");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = pattern; options.scope = pattern;
bool called = false; bool called = false;
int64_t registration_id = blink::mojom::kInvalidServiceWorkerRegistrationId; int64_t registration_id = blink::mojom::kInvalidServiceWorkerRegistrationId;
context()->RegisterServiceWorker( context()->RegisterServiceWorker(
GURL("http://www.example.com/service_worker.js"), options, GURL("https://www.example.com/service_worker.js"), options,
MakeRegisteredCallback(&called, &registration_id)); MakeRegisteredCallback(&called, &registration_id));
ASSERT_FALSE(called); ASSERT_FALSE(called);
...@@ -380,10 +380,10 @@ TEST_F(ServiceWorkerContextTest, Unregister) { ...@@ -380,10 +380,10 @@ TEST_F(ServiceWorkerContextTest, Unregister) {
// Make sure registrations are cleaned up when they are unregistered in bulk. // Make sure registrations are cleaned up when they are unregistered in bulk.
TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { TEST_F(ServiceWorkerContextTest, UnregisterMultiple) {
GURL origin1_p1("http://www.example.com/test"); GURL origin1_p1("https://www.example.com/test");
GURL origin1_p2("http://www.example.com/hello"); GURL origin1_p2("https://www.example.com/hello");
GURL origin2_p1("http://www.example.com:8080/again"); GURL origin2_p1("https://www.example.com:8080/again");
GURL origin3_p1("http://www.other.com/"); GURL origin3_p1("https://www.other.com/");
int64_t registration_id1 = blink::mojom::kInvalidServiceWorkerRegistrationId; int64_t registration_id1 = blink::mojom::kInvalidServiceWorkerRegistrationId;
int64_t registration_id2 = blink::mojom::kInvalidServiceWorkerRegistrationId; int64_t registration_id2 = blink::mojom::kInvalidServiceWorkerRegistrationId;
int64_t registration_id3 = blink::mojom::kInvalidServiceWorkerRegistrationId; int64_t registration_id3 = blink::mojom::kInvalidServiceWorkerRegistrationId;
...@@ -394,7 +394,7 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { ...@@ -394,7 +394,7 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = origin1_p1; options.scope = origin1_p1;
context()->RegisterServiceWorker( context()->RegisterServiceWorker(
GURL("http://www.example.com/service_worker.js"), options, GURL("https://www.example.com/service_worker.js"), options,
MakeRegisteredCallback(&called, &registration_id1)); MakeRegisteredCallback(&called, &registration_id1));
ASSERT_FALSE(called); ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -406,7 +406,7 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { ...@@ -406,7 +406,7 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = origin1_p2; options.scope = origin1_p2;
context()->RegisterServiceWorker( context()->RegisterServiceWorker(
GURL("http://www.example.com/service_worker2.js"), options, GURL("https://www.example.com/service_worker2.js"), options,
MakeRegisteredCallback(&called, &registration_id2)); MakeRegisteredCallback(&called, &registration_id2));
ASSERT_FALSE(called); ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -418,7 +418,7 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { ...@@ -418,7 +418,7 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = origin2_p1; options.scope = origin2_p1;
context()->RegisterServiceWorker( context()->RegisterServiceWorker(
GURL("http://www.example.com:8080/service_worker3.js"), options, GURL("https://www.example.com:8080/service_worker3.js"), options,
MakeRegisteredCallback(&called, &registration_id3)); MakeRegisteredCallback(&called, &registration_id3));
ASSERT_FALSE(called); ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -430,7 +430,7 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { ...@@ -430,7 +430,7 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = origin3_p1; options.scope = origin3_p1;
context()->RegisterServiceWorker( context()->RegisterServiceWorker(
GURL("http://www.other.com/service_worker4.js"), options, GURL("https://www.other.com/service_worker4.js"), options,
MakeRegisteredCallback(&called, &registration_id4)); MakeRegisteredCallback(&called, &registration_id4));
ASSERT_FALSE(called); ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -497,7 +497,7 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { ...@@ -497,7 +497,7 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) {
// Make sure registering a new script shares an existing registration. // Make sure registering a new script shares an existing registration.
TEST_F(ServiceWorkerContextTest, RegisterNewScript) { TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
GURL pattern("http://www.example.com/"); GURL pattern("https://www.example.com/");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = pattern; options.scope = pattern;
...@@ -505,7 +505,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) { ...@@ -505,7 +505,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
int64_t old_registration_id = int64_t old_registration_id =
blink::mojom::kInvalidServiceWorkerRegistrationId; blink::mojom::kInvalidServiceWorkerRegistrationId;
context()->RegisterServiceWorker( context()->RegisterServiceWorker(
GURL("http://www.example.com/service_worker.js"), options, GURL("https://www.example.com/service_worker.js"), options,
MakeRegisteredCallback(&called, &old_registration_id)); MakeRegisteredCallback(&called, &old_registration_id));
ASSERT_FALSE(called); ASSERT_FALSE(called);
...@@ -518,7 +518,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) { ...@@ -518,7 +518,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
int64_t new_registration_id = int64_t new_registration_id =
blink::mojom::kInvalidServiceWorkerRegistrationId; blink::mojom::kInvalidServiceWorkerRegistrationId;
context()->RegisterServiceWorker( context()->RegisterServiceWorker(
GURL("http://www.example.com/service_worker_new.js"), options, GURL("https://www.example.com/service_worker_new.js"), options,
MakeRegisteredCallback(&called, &new_registration_id)); MakeRegisteredCallback(&called, &new_registration_id));
ASSERT_FALSE(called); ASSERT_FALSE(called);
...@@ -541,8 +541,8 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) { ...@@ -541,8 +541,8 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
// Make sure that when registering a duplicate pattern+script_url // Make sure that when registering a duplicate pattern+script_url
// combination, that the same registration is used. // combination, that the same registration is used.
TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) { TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
GURL pattern("http://www.example.com/"); GURL pattern("https://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = pattern; options.scope = pattern;
...@@ -583,8 +583,8 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) { ...@@ -583,8 +583,8 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
TEST_F(ServiceWorkerContextTest, ProviderHostIterator) { TEST_F(ServiceWorkerContextTest, ProviderHostIterator) {
const int kRenderProcessId1 = 1; const int kRenderProcessId1 = 1;
const int kRenderProcessId2 = 2; const int kRenderProcessId2 = 2;
const GURL kOrigin1 = GURL("http://www.example.com/"); const GURL kOrigin1 = GURL("https://www.example.com/");
const GURL kOrigin2 = GURL("https://www.example.com/"); const GURL kOrigin2 = GURL("https://another-origin.example.net/");
int provider_id = 1; int provider_id = 1;
std::vector<ServiceWorkerRemoteProviderEndpoint> remote_endpoints; std::vector<ServiceWorkerRemoteProviderEndpoint> remote_endpoints;
...@@ -617,14 +617,15 @@ TEST_F(ServiceWorkerContextTest, ProviderHostIterator) { ...@@ -617,14 +617,15 @@ TEST_F(ServiceWorkerContextTest, ProviderHostIterator) {
// CreateProviderHostForServiceWorkerContext, the provider_id is not a fixed // CreateProviderHostForServiceWorkerContext, the provider_id is not a fixed
// number. // number.
blink::mojom::ServiceWorkerRegistrationOptions registration_opt; blink::mojom::ServiceWorkerRegistrationOptions registration_opt;
registration_opt.scope = GURL("http://www.example.com/test/"); registration_opt.scope = GURL("https://another-origin.example.net/test/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
base::MakeRefCounted<ServiceWorkerRegistration>( base::MakeRefCounted<ServiceWorkerRegistration>(
registration_opt, 1L /* registration_id */, registration_opt, 1L /* registration_id */,
helper_->context()->AsWeakPtr()); helper_->context()->AsWeakPtr());
scoped_refptr<ServiceWorkerVersion> version = scoped_refptr<ServiceWorkerVersion> version =
base::MakeRefCounted<ServiceWorkerVersion>( base::MakeRefCounted<ServiceWorkerVersion>(
registration.get(), GURL("http://www.example.com/test/script_url"), registration.get(),
GURL("https://another-origin.example.net/test/script_url"),
1L /* version_id */, helper_->context()->AsWeakPtr()); 1L /* version_id */, helper_->context()->AsWeakPtr());
// CreateProviderHostForServiceWorkerContext calls // CreateProviderHostForServiceWorkerContext calls
// ServiceWorkerProviderHost::CompleteStartWorkerPreparation, which requires a // ServiceWorkerProviderHost::CompleteStartWorkerPreparation, which requires a
...@@ -685,8 +686,8 @@ class ServiceWorkerContextRecoveryTest ...@@ -685,8 +686,8 @@ class ServiceWorkerContextRecoveryTest
}; };
TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) { TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) {
GURL pattern("http://www.example.com/"); GURL pattern("https://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = pattern; options.scope = pattern;
......
...@@ -251,8 +251,8 @@ TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) { ...@@ -251,8 +251,8 @@ TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) {
} }
TEST_F(ServiceWorkerDispatcherHostTest, CleanupOnRendererCrash) { TEST_F(ServiceWorkerDispatcherHostTest, CleanupOnRendererCrash) {
GURL pattern = GURL("http://www.example.com/"); GURL pattern = GURL("https://www.example.com/");
GURL script_url = GURL("http://www.example.com/service_worker.js"); GURL script_url = GURL("https://www.example.com/service_worker.js");
int process_id = helper_->mock_render_process_id(); int process_id = helper_->mock_render_process_id();
SendProviderCreated(blink::mojom::ServiceWorkerProviderType::kForWindow, SendProviderCreated(blink::mojom::ServiceWorkerProviderType::kForWindow,
......
...@@ -201,17 +201,18 @@ ServiceWorkerJobTest::CreateControllee() { ...@@ -201,17 +201,18 @@ ServiceWorkerJobTest::CreateControllee() {
TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> original_registration = scoped_refptr<ServiceWorkerRegistration> original_registration =
RunRegisterJob(GURL("http://www.example.com/service_worker.js"), options); RunRegisterJob(GURL("https://www.example.com/service_worker.js"),
options);
bool called; bool called;
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
storage()->FindRegistrationForDocument( storage()->FindRegistrationForDocument(
GURL("http://www.example.com/"), GURL("https://www.example.com/"),
SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration1)); SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration1));
scoped_refptr<ServiceWorkerRegistration> registration2; scoped_refptr<ServiceWorkerRegistration> registration2;
storage()->FindRegistrationForDocument( storage()->FindRegistrationForDocument(
GURL("http://www.example.com/"), GURL("https://www.example.com/"),
SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration2)); SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration2));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called); EXPECT_TRUE(called);
...@@ -223,22 +224,23 @@ TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { ...@@ -223,22 +224,23 @@ TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) {
TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) {
bool called; bool called;
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> original_registration = scoped_refptr<ServiceWorkerRegistration> original_registration =
RunRegisterJob(GURL("http://www.example.com/service_worker.js"), options); RunRegisterJob(GURL("https://www.example.com/service_worker.js"),
options);
ASSERT_NE(static_cast<ServiceWorkerRegistration*>(nullptr), ASSERT_NE(static_cast<ServiceWorkerRegistration*>(nullptr),
original_registration.get()); original_registration.get());
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
storage()->FindRegistrationForDocument( storage()->FindRegistrationForDocument(
GURL("http://www.example.com/one"), GURL("https://www.example.com/one"),
SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration1)); SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration1));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called); EXPECT_TRUE(called);
scoped_refptr<ServiceWorkerRegistration> registration2; scoped_refptr<ServiceWorkerRegistration> registration2;
storage()->FindRegistrationForDocument( storage()->FindRegistrationForDocument(
GURL("http://www.example.com/two"), GURL("https://www.example.com/two"),
SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration2)); SaveFoundRegistration(SERVICE_WORKER_OK, &called, &registration2));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called); EXPECT_TRUE(called);
...@@ -249,18 +251,18 @@ TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { ...@@ -249,18 +251,18 @@ TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) {
TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) {
bool called1; bool called1;
blink::mojom::ServiceWorkerRegistrationOptions options1; blink::mojom::ServiceWorkerRegistrationOptions options1;
options1.scope = GURL("http://www.example.com/one/"); options1.scope = GURL("https://www.example.com/one/");
scoped_refptr<ServiceWorkerRegistration> original_registration1; scoped_refptr<ServiceWorkerRegistration> original_registration1;
job_coordinator()->Register( job_coordinator()->Register(
GURL("http://www.example.com/service_worker.js"), options1, GURL("https://www.example.com/service_worker.js"), options1,
SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1)); SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1));
bool called2; bool called2;
blink::mojom::ServiceWorkerRegistrationOptions options2; blink::mojom::ServiceWorkerRegistrationOptions options2;
options2.scope = GURL("http://www.example.com/two/"); options2.scope = GURL("https://www.example.com/two/");
scoped_refptr<ServiceWorkerRegistration> original_registration2; scoped_refptr<ServiceWorkerRegistration> original_registration2;
job_coordinator()->Register( job_coordinator()->Register(
GURL("http://www.example.com/service_worker.js"), options2, GURL("https://www.example.com/service_worker.js"), options2,
SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2)); SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2));
EXPECT_FALSE(called1); EXPECT_FALSE(called1);
...@@ -271,11 +273,11 @@ TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { ...@@ -271,11 +273,11 @@ TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) {
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
storage()->FindRegistrationForDocument( storage()->FindRegistrationForDocument(
GURL("http://www.example.com/one/"), GURL("https://www.example.com/one/"),
SaveFoundRegistration(SERVICE_WORKER_OK, &called1, &registration1)); SaveFoundRegistration(SERVICE_WORKER_OK, &called1, &registration1));
scoped_refptr<ServiceWorkerRegistration> registration2; scoped_refptr<ServiceWorkerRegistration> registration2;
storage()->FindRegistrationForDocument( storage()->FindRegistrationForDocument(
GURL("http://www.example.com/two/"), GURL("https://www.example.com/two/"),
SaveFoundRegistration(SERVICE_WORKER_OK, &called2, &registration2)); SaveFoundRegistration(SERVICE_WORKER_OK, &called2, &registration2));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -287,9 +289,9 @@ TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { ...@@ -287,9 +289,9 @@ TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) {
// Make sure basic registration is working. // Make sure basic registration is working.
TEST_F(ServiceWorkerJobTest, Register) { TEST_F(ServiceWorkerJobTest, Register) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob(
RunRegisterJob(GURL("http://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
EXPECT_TRUE(registration); EXPECT_TRUE(registration);
EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Install, EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Install,
...@@ -301,9 +303,9 @@ TEST_F(ServiceWorkerJobTest, Register) { ...@@ -301,9 +303,9 @@ TEST_F(ServiceWorkerJobTest, Register) {
// Make sure registrations are cleaned up when they are unregistered. // Make sure registrations are cleaned up when they are unregistered.
TEST_F(ServiceWorkerJobTest, Unregister) { TEST_F(ServiceWorkerJobTest, Unregister) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob(
RunRegisterJob(GURL("http://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); scoped_refptr<ServiceWorkerVersion> version = registration->active_version();
ServiceWorkerProviderHost* provider_host = ServiceWorkerProviderHost* provider_host =
...@@ -334,7 +336,7 @@ TEST_F(ServiceWorkerJobTest, Unregister) { ...@@ -334,7 +336,7 @@ TEST_F(ServiceWorkerJobTest, Unregister) {
} }
TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) {
GURL pattern("http://www.example.com/"); GURL pattern("https://www.example.com/");
RunUnregisterJob(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); RunUnregisterJob(pattern, SERVICE_WORKER_ERROR_NOT_FOUND);
} }
...@@ -343,10 +345,10 @@ TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { ...@@ -343,10 +345,10 @@ TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) {
// existing registration. // existing registration.
TEST_F(ServiceWorkerJobTest, RegisterNewScript) { TEST_F(ServiceWorkerJobTest, RegisterNewScript) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> old_registration = scoped_refptr<ServiceWorkerRegistration> old_registration = RunRegisterJob(
RunRegisterJob(GURL("http://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern = scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern =
FindRegistrationForPattern(options.scope); FindRegistrationForPattern(options.scope);
...@@ -355,7 +357,7 @@ TEST_F(ServiceWorkerJobTest, RegisterNewScript) { ...@@ -355,7 +357,7 @@ TEST_F(ServiceWorkerJobTest, RegisterNewScript) {
old_registration_by_pattern = nullptr; old_registration_by_pattern = nullptr;
scoped_refptr<ServiceWorkerRegistration> new_registration = RunRegisterJob( scoped_refptr<ServiceWorkerRegistration> new_registration = RunRegisterJob(
GURL("http://www.example.com/service_worker_new.js"), options); GURL("https://www.example.com/service_worker_new.js"), options);
ASSERT_EQ(old_registration, new_registration); ASSERT_EQ(old_registration, new_registration);
...@@ -368,9 +370,9 @@ TEST_F(ServiceWorkerJobTest, RegisterNewScript) { ...@@ -368,9 +370,9 @@ TEST_F(ServiceWorkerJobTest, RegisterNewScript) {
// Make sure that when registering a duplicate pattern+script_url // Make sure that when registering a duplicate pattern+script_url
// combination, that the same registration is used. // combination, that the same registration is used.
TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) {
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> old_registration = scoped_refptr<ServiceWorkerRegistration> old_registration =
RunRegisterJob(script_url, options); RunRegisterJob(script_url, options);
...@@ -487,9 +489,9 @@ TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { ...@@ -487,9 +489,9 @@ TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) {
helper_.reset(new FailToStartWorkerTestHelper); helper_.reset(new FailToStartWorkerTestHelper);
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(GURL("http://www.example.com/service_worker.js"), options, RunRegisterJob(GURL("https://www.example.com/service_worker.js"), options,
SERVICE_WORKER_ERROR_START_WORKER_FAILED); SERVICE_WORKER_ERROR_START_WORKER_FAILED);
ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(nullptr), registration); ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(nullptr), registration);
...@@ -498,9 +500,9 @@ TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { ...@@ -498,9 +500,9 @@ TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) {
// Register and then unregister the pattern, in parallel. Job coordinator should // Register and then unregister the pattern, in parallel. Job coordinator should
// process jobs until the last job. // process jobs until the last job.
TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) {
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
bool registration_called = false; bool registration_called = false;
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
...@@ -529,9 +531,9 @@ TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { ...@@ -529,9 +531,9 @@ TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) {
// registration should win, and the old registration should have been // registration should win, and the old registration should have been
// shutdown. // shutdown.
TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) {
GURL pattern("http://www.example.com/"); GURL pattern("https://www.example.com/");
GURL script_url1("http://www.example.com/service_worker1.js"); GURL script_url1("https://www.example.com/service_worker1.js");
bool registration1_called = false; bool registration1_called = false;
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
job_coordinator()->Register( job_coordinator()->Register(
...@@ -541,7 +543,7 @@ TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { ...@@ -541,7 +543,7 @@ TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) {
SaveRegistration(SERVICE_WORKER_OK, &registration1_called, SaveRegistration(SERVICE_WORKER_OK, &registration1_called,
&registration1)); &registration1));
GURL script_url2("http://www.example.com/service_worker2.js"); GURL script_url2("https://www.example.com/service_worker2.js");
bool registration2_called = false; bool registration2_called = false;
scoped_refptr<ServiceWorkerRegistration> registration2; scoped_refptr<ServiceWorkerRegistration> registration2;
job_coordinator()->Register( job_coordinator()->Register(
...@@ -568,9 +570,9 @@ TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { ...@@ -568,9 +570,9 @@ TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) {
// object. // object.
TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
GURL script_url("http://www.example.com/service_worker1.js"); GURL script_url("https://www.example.com/service_worker1.js");
bool registration1_called = false; bool registration1_called = false;
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
job_coordinator()->Register( job_coordinator()->Register(
...@@ -601,9 +603,9 @@ TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { ...@@ -601,9 +603,9 @@ TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) {
// Call simulataneous unregister calls. // Call simulataneous unregister calls.
TEST_F(ServiceWorkerJobTest, ParallelUnreg) { TEST_F(ServiceWorkerJobTest, ParallelUnreg) {
GURL pattern("http://www.example.com/"); GURL pattern("https://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("https://www.example.com/service_worker.js");
bool unregistration1_called = false; bool unregistration1_called = false;
job_coordinator()->Unregister( job_coordinator()->Unregister(
pattern, pattern,
...@@ -632,13 +634,13 @@ TEST_F(ServiceWorkerJobTest, ParallelUnreg) { ...@@ -632,13 +634,13 @@ TEST_F(ServiceWorkerJobTest, ParallelUnreg) {
} }
TEST_F(ServiceWorkerJobTest, AbortAll_Register) { TEST_F(ServiceWorkerJobTest, AbortAll_Register) {
GURL script_url1("http://www1.example.com/service_worker.js"); GURL script_url1("https://www1.example.com/service_worker.js");
GURL script_url2("http://www2.example.com/service_worker.js"); GURL script_url2("https://www2.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options1; blink::mojom::ServiceWorkerRegistrationOptions options1;
options1.scope = GURL("http://www1.example.com/"); options1.scope = GURL("https://www1.example.com/");
blink::mojom::ServiceWorkerRegistrationOptions options2; blink::mojom::ServiceWorkerRegistrationOptions options2;
options2.scope = GURL("http://www2.example.com/"); options2.scope = GURL("https://www2.example.com/");
bool registration_called1 = false; bool registration_called1 = false;
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
...@@ -680,8 +682,8 @@ TEST_F(ServiceWorkerJobTest, AbortAll_Register) { ...@@ -680,8 +682,8 @@ TEST_F(ServiceWorkerJobTest, AbortAll_Register) {
} }
TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) { TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) {
GURL pattern1("http://www1.example.com/"); GURL pattern1("https://www1.example.com/");
GURL pattern2("http://www2.example.com/"); GURL pattern2("https://www2.example.com/");
bool unregistration_called1 = false; bool unregistration_called1 = false;
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
...@@ -706,9 +708,9 @@ TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) { ...@@ -706,9 +708,9 @@ TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) {
} }
TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) { TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) {
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
bool registration_called = false; bool registration_called = false;
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
...@@ -739,9 +741,9 @@ TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) { ...@@ -739,9 +741,9 @@ TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) {
// Tests that the waiting worker enters the 'redundant' state upon // Tests that the waiting worker enters the 'redundant' state upon
// unregistration. // unregistration.
TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) {
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script_url, options); RunRegisterJob(script_url, options);
ASSERT_TRUE(registration.get()); ASSERT_TRUE(registration.get());
...@@ -763,7 +765,7 @@ TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { ...@@ -763,7 +765,7 @@ TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) {
EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status());
EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status());
RunUnregisterJob(GURL("http://www.example.com/")); RunUnregisterJob(GURL("https://www.example.com/"));
// The version should be stopped since there is no controllee after // The version should be stopped since there is no controllee after
// unregistration. // unregistration.
...@@ -775,16 +777,16 @@ TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { ...@@ -775,16 +777,16 @@ TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) {
// unregistration. // unregistration.
TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob(
RunRegisterJob(GURL("http://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
ASSERT_TRUE(registration.get()); ASSERT_TRUE(registration.get());
scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); scoped_refptr<ServiceWorkerVersion> version = registration->active_version();
EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status());
EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
RunUnregisterJob(GURL("http://www.example.com/")); RunUnregisterJob(GURL("https://www.example.com/"));
// The version should be stopped since there is no controllee after // The version should be stopped since there is no controllee after
// unregistration. // unregistration.
...@@ -797,9 +799,9 @@ TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { ...@@ -797,9 +799,9 @@ TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) {
TEST_F(ServiceWorkerJobTest, TEST_F(ServiceWorkerJobTest,
UnregisterActiveSetsRedundant_WaitForNoControllee) { UnregisterActiveSetsRedundant_WaitForNoControllee) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob(
RunRegisterJob(GURL("http://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
ASSERT_TRUE(registration.get()); ASSERT_TRUE(registration.get());
std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee(); std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee();
...@@ -809,7 +811,7 @@ TEST_F(ServiceWorkerJobTest, ...@@ -809,7 +811,7 @@ TEST_F(ServiceWorkerJobTest,
EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status());
EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
RunUnregisterJob(GURL("http://www.example.com/")); RunUnregisterJob(GURL("https://www.example.com/"));
// The version should be running since there is still a controllee. // The version should be running since there is still a controllee.
EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status()); EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version->running_status());
...@@ -825,8 +827,8 @@ TEST_F(ServiceWorkerJobTest, ...@@ -825,8 +827,8 @@ TEST_F(ServiceWorkerJobTest,
namespace { // Helpers for the update job tests. namespace { // Helpers for the update job tests.
const GURL kNoChangeOrigin("http://nochange/"); const GURL kNoChangeOrigin("https://nochange/");
const GURL kNewVersionOrigin("http://newversion/"); const GURL kNewVersionOrigin("https://newversion/");
const std::string kScope("scope/"); const std::string kScope("scope/");
const std::string kScript("script.js"); const std::string kScript("script.js");
...@@ -1287,15 +1289,15 @@ TEST_F(ServiceWorkerJobTest, Update_NewVersion) { ...@@ -1287,15 +1289,15 @@ TEST_F(ServiceWorkerJobTest, Update_NewVersion) {
TEST_F(ServiceWorkerJobTest, Update_ScriptUrlChanged) { TEST_F(ServiceWorkerJobTest, Update_ScriptUrlChanged) {
// Create a registration with an active version. // Create a registration with an active version.
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/one/"); options.scope = GURL("https://www.example.com/one/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob(
RunRegisterJob(GURL("http://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
// Queue an Update. When this runs, it will use the waiting version's script. // Queue an Update. When this runs, it will use the waiting version's script.
job_coordinator()->Update(registration.get(), false); job_coordinator()->Update(registration.get(), false);
// Add a waiting version with a new script. // Add a waiting version with a new script.
GURL new_script("http://www.example.com/new_worker.js"); GURL new_script("https://www.example.com/new_worker.js");
scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
registration.get(), new_script, 2L /* dummy version id */, registration.get(), new_script, 2L /* dummy version id */,
helper_->context()->AsWeakPtr()); helper_->context()->AsWeakPtr());
...@@ -1344,16 +1346,16 @@ TEST_F(ServiceWorkerJobTest, Update_EvictedIncumbent) { ...@@ -1344,16 +1346,16 @@ TEST_F(ServiceWorkerJobTest, Update_EvictedIncumbent) {
TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) { TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/one/"); options.scope = GURL("https://www.example.com/one/");
bool called; bool called;
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob(
RunRegisterJob(GURL("http://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
// Add a controllee and queue an unregister to force the uninstalling state. // Add a controllee and queue an unregister to force the uninstalling state.
std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee(); std::unique_ptr<ServiceWorkerProviderHost> host = CreateControllee();
ServiceWorkerVersion* active_version = registration->active_version(); ServiceWorkerVersion* active_version = registration->active_version();
active_version->AddControllee(host.get()); active_version->AddControllee(host.get());
job_coordinator()->Unregister(GURL("http://www.example.com/one/"), job_coordinator()->Unregister(GURL("https://www.example.com/one/"),
SaveUnregistration(SERVICE_WORKER_OK, &called)); SaveUnregistration(SERVICE_WORKER_OK, &called));
// Update should abort after it starts and sees uninstalling. // Update should abort after it starts and sees uninstalling.
...@@ -1371,10 +1373,10 @@ TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) { ...@@ -1371,10 +1373,10 @@ TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) {
} }
TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) { TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) {
GURL script1("http://www.example.com/service_worker.js"); GURL script1("https://www.example.com/service_worker.js");
GURL script2("http://www.example.com/service_worker.js?new"); GURL script2("https://www.example.com/service_worker.js?new");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/one/"); options.scope = GURL("https://www.example.com/one/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script1, options); RunRegisterJob(script1, options);
...@@ -1423,10 +1425,10 @@ TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) { ...@@ -1423,10 +1425,10 @@ TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) {
} }
TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) { TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) {
GURL script1("http://www.example.com/service_worker.js"); GURL script1("https://www.example.com/service_worker.js");
GURL script2("http://www.example.com/service_worker.js?new"); GURL script2("https://www.example.com/service_worker.js?new");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/one/"); options.scope = GURL("https://www.example.com/one/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script1, options); RunRegisterJob(script1, options);
...@@ -1472,10 +1474,10 @@ TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) { ...@@ -1472,10 +1474,10 @@ TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) {
} }
TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) { TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) {
GURL script1("http://www.example.com/service_worker.js"); GURL script1("https://www.example.com/service_worker.js");
GURL script2("http://www.example.com/service_worker.js?new"); GURL script2("https://www.example.com/service_worker.js?new");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/one/"); options.scope = GURL("https://www.example.com/one/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script1, options); RunRegisterJob(script1, options);
...@@ -1524,11 +1526,11 @@ TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) { ...@@ -1524,11 +1526,11 @@ TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) {
} }
TEST_F(ServiceWorkerJobTest, RegisterMultipleTimesWhileUninstalling) { TEST_F(ServiceWorkerJobTest, RegisterMultipleTimesWhileUninstalling) {
GURL script1("http://www.example.com/service_worker.js?first"); GURL script1("https://www.example.com/service_worker.js?first");
GURL script2("http://www.example.com/service_worker.js?second"); GURL script2("https://www.example.com/service_worker.js?second");
GURL script3("http://www.example.com/service_worker.js?third"); GURL script3("https://www.example.com/service_worker.js?third");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/one/"); options.scope = GURL("https://www.example.com/one/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script1, options); RunRegisterJob(script1, options);
...@@ -1629,10 +1631,10 @@ TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringInstall) { ...@@ -1629,10 +1631,10 @@ TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringInstall) {
EventCallbackHelper* helper = new EventCallbackHelper; EventCallbackHelper* helper = new EventCallbackHelper;
helper_.reset(helper); helper_.reset(helper);
GURL script1("http://www.example.com/service_worker.js"); GURL script1("https://www.example.com/service_worker.js");
GURL script2("http://www.example.com/service_worker.js?new"); GURL script2("https://www.example.com/service_worker.js?new");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/one/"); options.scope = GURL("https://www.example.com/one/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script1, options); RunRegisterJob(script1, options);
...@@ -1670,10 +1672,10 @@ TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringRejectedInstall) { ...@@ -1670,10 +1672,10 @@ TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringRejectedInstall) {
EventCallbackHelper* helper = new EventCallbackHelper; EventCallbackHelper* helper = new EventCallbackHelper;
helper_.reset(helper); helper_.reset(helper);
GURL script1("http://www.example.com/service_worker.js"); GURL script1("https://www.example.com/service_worker.js");
GURL script2("http://www.example.com/service_worker.js?new"); GURL script2("https://www.example.com/service_worker.js?new");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/one/"); options.scope = GURL("https://www.example.com/one/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script1, options); RunRegisterJob(script1, options);
...@@ -1708,10 +1710,10 @@ TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringInstall_RejectActivate) { ...@@ -1708,10 +1710,10 @@ TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringInstall_RejectActivate) {
EventCallbackHelper* helper = new EventCallbackHelper; EventCallbackHelper* helper = new EventCallbackHelper;
helper_.reset(helper); helper_.reset(helper);
GURL script1("http://www.example.com/service_worker.js"); GURL script1("https://www.example.com/service_worker.js");
GURL script2("http://www.example.com/service_worker.js?new"); GURL script2("https://www.example.com/service_worker.js?new");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/one/"); options.scope = GURL("https://www.example.com/one/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script1, options); RunRegisterJob(script1, options);
...@@ -1746,9 +1748,9 @@ TEST_F(ServiceWorkerJobTest, HasFetchHandler) { ...@@ -1746,9 +1748,9 @@ TEST_F(ServiceWorkerJobTest, HasFetchHandler) {
EventCallbackHelper* helper = new EventCallbackHelper; EventCallbackHelper* helper = new EventCallbackHelper;
helper_.reset(helper); helper_.reset(helper);
GURL script("http://www.example.com/service_worker.js"); GURL script("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
helper->set_has_fetch_handler(true); helper->set_has_fetch_handler(true);
...@@ -1823,9 +1825,9 @@ TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) { ...@@ -1823,9 +1825,9 @@ TEST_F(ServiceWorkerJobTest, Update_PauseAfterDownload) {
TEST_F(ServiceWorkerJobTest, ActivateCancelsOnShutdown) { TEST_F(ServiceWorkerJobTest, ActivateCancelsOnShutdown) {
UpdateJobTestHelper* update_helper = new UpdateJobTestHelper; UpdateJobTestHelper* update_helper = new UpdateJobTestHelper;
helper_.reset(update_helper); helper_.reset(update_helper);
GURL script("http://www.example.com/service_worker.js"); GURL script("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("http://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script, options); RunRegisterJob(script, options);
......
...@@ -504,15 +504,7 @@ void ServiceWorkerVersion::StartWorker(ServiceWorkerMetrics::EventType purpose, ...@@ -504,15 +504,7 @@ void ServiceWorkerVersion::StartWorker(ServiceWorkerMetrics::EventType purpose,
base::BindOnce(std::move(callback), SERVICE_WORKER_ERROR_REDUNDANT)); base::BindOnce(std::move(callback), SERVICE_WORKER_ERROR_REDUNDANT));
return; return;
} }
if (!IsStartWorkerAllowed()) {
// Check that the worker is allowed to start on the given scope. Since this
// worker might not be used for a specific tab, pass a null callback as
// WebContents getter.
// resource_context() can return null in unit tests.
if (context_->wrapper()->resource_context() &&
!GetContentClient()->browser()->AllowServiceWorker(
scope_, scope_, context_->wrapper()->resource_context(),
base::Callback<WebContents*(void)>())) {
RecordStartWorkerResult(purpose, status_, kInvalidTraceId, RecordStartWorkerResult(purpose, status_, kInvalidTraceId,
is_browser_startup_complete, is_browser_startup_complete,
SERVICE_WORKER_ERROR_DISALLOWED); SERVICE_WORKER_ERROR_DISALLOWED);
...@@ -1991,4 +1983,28 @@ void ServiceWorkerVersion::OnNoWorkInBrowser() { ...@@ -1991,4 +1983,28 @@ void ServiceWorkerVersion::OnNoWorkInBrowser() {
idle_timer_fired_in_renderer_ = false; idle_timer_fired_in_renderer_ = false;
} }
bool ServiceWorkerVersion::IsStartWorkerAllowed() const {
// Check that the worker is allowed on this origin. It's possible a
// worker was previously allowed and installed, but later the embedder's
// policy or binary changed to disallow this origin.
if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(
{script_url_})) {
return false;
}
// Check that the worker is allowed on the given scope. It's possible a worker
// was previously allowed and installed, but later content settings changed to
// disallow this scope. Since this worker might not be used for a specific
// tab, pass a null callback as WebContents getter.
// resource_context() can return null in unit tests.
if ((context_->wrapper()->resource_context() &&
!GetContentClient()->browser()->AllowServiceWorker(
scope_, scope_, context_->wrapper()->resource_context(),
base::Callback<WebContents*(void)>()))) {
return false;
}
return true;
}
} // namespace content } // namespace content
...@@ -722,6 +722,8 @@ class CONTENT_EXPORT ServiceWorkerVersion ...@@ -722,6 +722,8 @@ class CONTENT_EXPORT ServiceWorkerVersion
// has been fired or the worker has been stopped. // has been fired or the worker has been stopped.
void OnNoWorkInBrowser(); void OnNoWorkInBrowser();
bool IsStartWorkerAllowed() const;
const int64_t version_id_; const int64_t version_id_;
const int64_t registration_id_; const int64_t registration_id_;
const GURL script_url_; const GURL script_url_;
......
...@@ -177,7 +177,8 @@ class ServiceWorkerVersionTest : public testing::Test { ...@@ -177,7 +177,8 @@ class ServiceWorkerVersionTest : public testing::Test {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = pattern_; options.scope = pattern_;
registration_ = new ServiceWorkerRegistration( registration_ = new ServiceWorkerRegistration(
options, 1L, helper_->context()->AsWeakPtr()); options, helper_->context()->storage()->NewRegistrationId(),
helper_->context()->AsWeakPtr());
version_ = new ServiceWorkerVersion( version_ = new ServiceWorkerVersion(
registration_.get(), registration_.get(),
GURL("https://www.example.com/test/service_worker.js"), GURL("https://www.example.com/test/service_worker.js"),
...@@ -1266,6 +1267,26 @@ TEST_F(ServiceWorkerVersionTest, RendererCrashDuringEvent) { ...@@ -1266,6 +1267,26 @@ TEST_F(ServiceWorkerVersionTest, RendererCrashDuringEvent) {
base::Time::Now())); base::Time::Now()));
} }
// Test starting a service worker from a disallowed origin.
TEST_F(ServiceWorkerVersionTest, BadOrigin) {
const GURL scope("bad-origin://www.example.com/test/");
blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = scope;
auto registration = base::MakeRefCounted<ServiceWorkerRegistration>(
options, helper_->context()->storage()->NewRegistrationId(),
helper_->context()->AsWeakPtr());
auto version = base::MakeRefCounted<ServiceWorkerVersion>(
registration_.get(),
GURL("bad-origin://www.example.com/test/service_worker.js"),
helper_->context()->storage()->NewVersionId(),
helper_->context()->AsWeakPtr());
ServiceWorkerStatusCode status = SERVICE_WORKER_OK;
version->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
CreateReceiverOnCurrentThread(&status));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(SERVICE_WORKER_ERROR_DISALLOWED, status);
}
TEST_F(ServiceWorkerFailToStartTest, FailingWorkerUsesNewRendererProcess) { TEST_F(ServiceWorkerFailToStartTest, FailingWorkerUsesNewRendererProcess) {
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
ServiceWorkerContextCore* context = helper_->context(); ServiceWorkerContextCore* context = helper_->context();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment