Commit 20d7c2f9 authored by nhiroki@chromium.org's avatar nhiroki@chromium.org

ServiceWorker: Remove wildcard from scope matching (Chromium)

Wildcard '*' was removed from scope matching algorithm in the spec.
After this patch, a scope always does a prefix match.

Issue: https://github.com/slightlyoff/ServiceWorker/issues/287


BUG=398892
TEST=content_unittests --gtest_filter=ServiceWorker*

Review URL: https://codereview.chromium.org/435873002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287501 0039d316-1c4b-4281-b951-d872f2087c98
parent 8201bbf6
...@@ -62,7 +62,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StartAndStop) { ...@@ -62,7 +62,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StartAndStop) {
const int embedded_worker_id = worker->embedded_worker_id(); const int embedded_worker_id = worker->embedded_worker_id();
const int64 service_worker_version_id = 55L; const int64 service_worker_version_id = 55L;
const GURL scope("http://example.com/*"); const GURL scope("http://example.com/");
const GURL url("http://example.com/worker.js"); const GURL url("http://example.com/worker.js");
// Simulate adding one process to the worker. // Simulate adding one process to the worker.
...@@ -108,7 +108,7 @@ TEST_F(EmbeddedWorkerInstanceTest, InstanceDestroyedBeforeStartFinishes) { ...@@ -108,7 +108,7 @@ TEST_F(EmbeddedWorkerInstanceTest, InstanceDestroyedBeforeStartFinishes) {
EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status()); EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
const int64 service_worker_version_id = 55L; const int64 service_worker_version_id = 55L;
const GURL scope("http://example.com/*"); const GURL scope("http://example.com/");
const GURL url("http://example.com/worker.js"); const GURL url("http://example.com/worker.js");
ServiceWorkerStatusCode status; ServiceWorkerStatusCode status;
......
...@@ -244,7 +244,7 @@ class EmbeddedWorkerBrowserTest : public ServiceWorkerBrowserTest, ...@@ -244,7 +244,7 @@ class EmbeddedWorkerBrowserTest : public ServiceWorkerBrowserTest,
AssociateRendererProcessToWorker(worker_.get()); AssociateRendererProcessToWorker(worker_.get());
const int64 service_worker_version_id = 33L; const int64 service_worker_version_id = 33L;
const GURL scope = embedded_test_server()->GetURL("/*"); const GURL scope = embedded_test_server()->GetURL("/");
const GURL script_url = embedded_test_server()->GetURL( const GURL script_url = embedded_test_server()->GetURL(
"/service_worker/worker.js"); "/service_worker/worker.js");
std::vector<int> processes; std::vector<int> processes;
...@@ -417,7 +417,7 @@ class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest { ...@@ -417,7 +417,7 @@ class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest {
void SetUpRegistrationOnIOThread(const std::string& worker_url) { void SetUpRegistrationOnIOThread(const std::string& worker_url) {
registration_ = new ServiceWorkerRegistration( registration_ = new ServiceWorkerRegistration(
embedded_test_server()->GetURL("/*"), embedded_test_server()->GetURL("/"),
embedded_test_server()->GetURL(worker_url), embedded_test_server()->GetURL(worker_url),
wrapper()->context()->storage()->NewRegistrationId(), wrapper()->context()->storage()->NewRegistrationId(),
wrapper()->context()->AsWeakPtr()); wrapper()->context()->AsWeakPtr());
...@@ -759,7 +759,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, MAYBE_Registration) { ...@@ -759,7 +759,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, MAYBE_Registration) {
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
public_context()->UnregisterServiceWorker( public_context()->UnregisterServiceWorker(
embedded_test_server()->GetURL("/*"), embedded_test_server()->GetURL("/"),
base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure()));
run_loop.Run(); run_loop.Run();
} }
...@@ -768,7 +768,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, MAYBE_Registration) { ...@@ -768,7 +768,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, MAYBE_Registration) {
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
public_context()->RegisterServiceWorker( public_context()->RegisterServiceWorker(
embedded_test_server()->GetURL("/*"), embedded_test_server()->GetURL("/"),
embedded_test_server()->GetURL("/does/not/exist"), embedded_test_server()->GetURL("/does/not/exist"),
base::Bind(&ExpectResultAndRun, false, run_loop.QuitClosure())); base::Bind(&ExpectResultAndRun, false, run_loop.QuitClosure()));
run_loop.Run(); run_loop.Run();
...@@ -779,7 +779,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, MAYBE_Registration) { ...@@ -779,7 +779,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, MAYBE_Registration) {
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
public_context()->RegisterServiceWorker( public_context()->RegisterServiceWorker(
embedded_test_server()->GetURL("/*"), embedded_test_server()->GetURL("/"),
embedded_test_server()->GetURL(kWorkerUrl), embedded_test_server()->GetURL(kWorkerUrl),
base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure()));
run_loop.Run(); run_loop.Run();
...@@ -791,7 +791,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, MAYBE_Registration) { ...@@ -791,7 +791,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, MAYBE_Registration) {
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
public_context()->RegisterServiceWorker( public_context()->RegisterServiceWorker(
embedded_test_server()->GetURL("/*"), embedded_test_server()->GetURL("/"),
embedded_test_server()->GetURL(kWorkerUrl), embedded_test_server()->GetURL(kWorkerUrl),
base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure()));
run_loop.Run(); run_loop.Run();
...@@ -805,7 +805,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, MAYBE_Registration) { ...@@ -805,7 +805,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, MAYBE_Registration) {
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
public_context()->UnregisterServiceWorker( public_context()->UnregisterServiceWorker(
embedded_test_server()->GetURL("/*"), embedded_test_server()->GetURL("/"),
base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure()));
run_loop.Run(); run_loop.Run();
} }
......
...@@ -142,7 +142,7 @@ TEST_F(ServiceWorkerContextTest, Register) { ...@@ -142,7 +142,7 @@ TEST_F(ServiceWorkerContextTest, Register) {
int64 version_id = kInvalidServiceWorkerVersionId; int64 version_id = kInvalidServiceWorkerVersionId;
bool called = false; bool called = false;
context()->RegisterServiceWorker( context()->RegisterServiceWorker(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
NULL, NULL,
...@@ -185,7 +185,7 @@ TEST_F(ServiceWorkerContextTest, Register_RejectInstall) { ...@@ -185,7 +185,7 @@ TEST_F(ServiceWorkerContextTest, Register_RejectInstall) {
int64 version_id = kInvalidServiceWorkerVersionId; int64 version_id = kInvalidServiceWorkerVersionId;
bool called = false; bool called = false;
context()->RegisterServiceWorker( context()->RegisterServiceWorker(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
NULL, NULL,
...@@ -228,7 +228,7 @@ TEST_F(ServiceWorkerContextTest, Register_RejectActivate) { ...@@ -228,7 +228,7 @@ TEST_F(ServiceWorkerContextTest, Register_RejectActivate) {
int64 version_id = kInvalidServiceWorkerVersionId; int64 version_id = kInvalidServiceWorkerVersionId;
bool called = false; bool called = false;
context()->RegisterServiceWorker( context()->RegisterServiceWorker(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
NULL, NULL,
...@@ -263,7 +263,7 @@ TEST_F(ServiceWorkerContextTest, Register_RejectActivate) { ...@@ -263,7 +263,7 @@ 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("http://www.example.com/");
bool called = false; bool called = false;
int64 registration_id = kInvalidServiceWorkerRegistrationId; int64 registration_id = kInvalidServiceWorkerRegistrationId;
...@@ -303,7 +303,7 @@ TEST_F(ServiceWorkerContextTest, Unregister) { ...@@ -303,7 +303,7 @@ TEST_F(ServiceWorkerContextTest, Unregister) {
// Make sure that when a new registration replaces an existing // Make sure that when a new registration replaces an existing
// registration, that the old one is cleaned up. // registration, that the old one is cleaned up.
TEST_F(ServiceWorkerContextTest, RegisterNewScript) { TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
GURL pattern("http://www.example.com/*"); GURL pattern("http://www.example.com/");
bool called = false; bool called = false;
int64 old_registration_id = kInvalidServiceWorkerRegistrationId; int64 old_registration_id = kInvalidServiceWorkerRegistrationId;
...@@ -346,7 +346,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) { ...@@ -346,7 +346,7 @@ 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("http://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("http://www.example.com/service_worker.js");
bool called = false; bool called = false;
...@@ -388,7 +388,7 @@ TEST_F(ServiceWorkerContextTest, DeleteAndStartOver) { ...@@ -388,7 +388,7 @@ TEST_F(ServiceWorkerContextTest, DeleteAndStartOver) {
int64 version_id = kInvalidServiceWorkerVersionId; int64 version_id = kInvalidServiceWorkerVersionId;
bool called = false; bool called = false;
context()->RegisterServiceWorker( context()->RegisterServiceWorker(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
NULL, NULL,
...@@ -436,7 +436,7 @@ TEST_F(ServiceWorkerContextTest, DeleteAndStartOver) { ...@@ -436,7 +436,7 @@ TEST_F(ServiceWorkerContextTest, DeleteAndStartOver) {
called = false; called = false;
context()->RegisterServiceWorker( context()->RegisterServiceWorker(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
NULL, NULL,
......
...@@ -38,7 +38,7 @@ class ServiceWorkerControlleeRequestHandlerTest : public testing::Test { ...@@ -38,7 +38,7 @@ class ServiceWorkerControlleeRequestHandlerTest : public testing::Test {
helper_.reset(new EmbeddedWorkerTestHelper(kMockRenderProcessId)); helper_.reset(new EmbeddedWorkerTestHelper(kMockRenderProcessId));
// A new unstored registration/version. // A new unstored registration/version.
scope_ = GURL("http://host/scope/*"); scope_ = GURL("http://host/scope/");
script_url_ = GURL("http://host/script.js"); script_url_ = GURL("http://host/script.js");
registration_ = new ServiceWorkerRegistration( registration_ = new ServiceWorkerRegistration(
scope_, script_url_, 1L, context()->AsWeakPtr()); scope_, script_url_, 1L, context()->AsWeakPtr());
......
...@@ -117,7 +117,7 @@ TEST_F(ServiceWorkerDispatcherHostTest, Register_SameOrigin) { ...@@ -117,7 +117,7 @@ TEST_F(ServiceWorkerDispatcherHostTest, Register_SameOrigin) {
context()->AddProviderHost(host.Pass()); context()->AddProviderHost(host.Pass());
Register(kProviderId, Register(kProviderId,
GURL("https://www.example.com/*"), GURL("https://www.example.com/"),
GURL("https://www.example.com/bar"), GURL("https://www.example.com/bar"),
ServiceWorkerMsg_ServiceWorkerRegistered::ID); ServiceWorkerMsg_ServiceWorkerRegistered::ID);
} }
...@@ -132,31 +132,31 @@ TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOrigin) { ...@@ -132,31 +132,31 @@ TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOrigin) {
// Script has a different host // Script has a different host
SendRegister(kProviderId, SendRegister(kProviderId,
GURL("https://www.example.com/*"), GURL("https://www.example.com/"),
GURL("https://foo.example.com/bar")); GURL("https://foo.example.com/bar"));
EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
// Scope has a different host // Scope has a different host
SendRegister(kProviderId, SendRegister(kProviderId,
GURL("https://foo.example.com/*"), GURL("https://foo.example.com/"),
GURL("https://www.example.com/bar")); GURL("https://www.example.com/bar"));
EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_);
// Script has a different port // Script has a different port
SendRegister(kProviderId, SendRegister(kProviderId,
GURL("https://www.example.com/*"), GURL("https://www.example.com/"),
GURL("https://www.example.com:8080/bar")); GURL("https://www.example.com:8080/bar"));
EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_);
// Scope has a different transport // Scope has a different transport
SendRegister(kProviderId, SendRegister(kProviderId,
GURL("wss://www.example.com/*"), GURL("wss://www.example.com/"),
GURL("https://www.example.com/bar")); GURL("https://www.example.com/bar"));
EXPECT_EQ(4, dispatcher_host_->bad_messages_received_count_); EXPECT_EQ(4, dispatcher_host_->bad_messages_received_count_);
// Script and scope have different hosts // Script and scope have different hosts
SendRegister(kProviderId, SendRegister(kProviderId,
GURL("https://foo.example.com/*"), GURL("https://foo.example.com/"),
GURL("https://foo.example.com/bar")); GURL("https://foo.example.com/bar"));
EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_); EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_);
...@@ -176,7 +176,7 @@ TEST_F(ServiceWorkerDispatcherHostTest, Unregister_SameOrigin) { ...@@ -176,7 +176,7 @@ TEST_F(ServiceWorkerDispatcherHostTest, Unregister_SameOrigin) {
context()->AddProviderHost(host.Pass()); context()->AddProviderHost(host.Pass());
Unregister(kProviderId, Unregister(kProviderId,
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
ServiceWorkerMsg_ServiceWorkerUnregistered::ID); ServiceWorkerMsg_ServiceWorkerUnregistered::ID);
} }
...@@ -188,7 +188,7 @@ TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOrigin) { ...@@ -188,7 +188,7 @@ TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOrigin) {
base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
context()->AddProviderHost(host.Pass()); context()->AddProviderHost(host.Pass());
SendUnregister(kProviderId, GURL("http://foo.example.com/*")); SendUnregister(kProviderId, GURL("http://foo.example.com/"));
EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
} }
......
...@@ -47,7 +47,7 @@ class ServiceWorkerHandleTest : public testing::Test { ...@@ -47,7 +47,7 @@ class ServiceWorkerHandleTest : public testing::Test {
helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId)); helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId));
registration_ = new ServiceWorkerRegistration( registration_ = new ServiceWorkerRegistration(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
1L, 1L,
helper_->context()->AsWeakPtr()); helper_->context()->AsWeakPtr());
......
...@@ -130,7 +130,7 @@ TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { ...@@ -130,7 +130,7 @@ TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) {
scoped_refptr<ServiceWorkerRegistration> original_registration; scoped_refptr<ServiceWorkerRegistration> original_registration;
bool called; bool called;
job_coordinator()->Register( job_coordinator()->Register(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration));
...@@ -157,7 +157,7 @@ TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { ...@@ -157,7 +157,7 @@ TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) {
bool called; bool called;
scoped_refptr<ServiceWorkerRegistration> original_registration; scoped_refptr<ServiceWorkerRegistration> original_registration;
job_coordinator()->Register( job_coordinator()->Register(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration));
...@@ -188,7 +188,7 @@ TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { ...@@ -188,7 +188,7 @@ TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) {
bool called1; bool called1;
scoped_refptr<ServiceWorkerRegistration> original_registration1; scoped_refptr<ServiceWorkerRegistration> original_registration1;
job_coordinator()->Register( job_coordinator()->Register(
GURL("http://www.example.com/one/*"), GURL("http://www.example.com/one/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1)); SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1));
...@@ -196,7 +196,7 @@ TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { ...@@ -196,7 +196,7 @@ TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) {
bool called2; bool called2;
scoped_refptr<ServiceWorkerRegistration> original_registration2; scoped_refptr<ServiceWorkerRegistration> original_registration2;
job_coordinator()->Register( job_coordinator()->Register(
GURL("http://www.example.com/two/*"), GURL("http://www.example.com/two/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2)); SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2));
...@@ -227,7 +227,7 @@ TEST_F(ServiceWorkerJobTest, Register) { ...@@ -227,7 +227,7 @@ TEST_F(ServiceWorkerJobTest, Register) {
bool called = false; bool called = false;
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
job_coordinator()->Register( job_coordinator()->Register(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
SaveRegistration(SERVICE_WORKER_OK, &called, &registration)); SaveRegistration(SERVICE_WORKER_OK, &called, &registration));
...@@ -241,7 +241,7 @@ TEST_F(ServiceWorkerJobTest, Register) { ...@@ -241,7 +241,7 @@ 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) {
GURL pattern("http://www.example.com/*"); GURL pattern("http://www.example.com/");
bool called; bool called;
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
...@@ -277,7 +277,7 @@ TEST_F(ServiceWorkerJobTest, Unregister) { ...@@ -277,7 +277,7 @@ TEST_F(ServiceWorkerJobTest, Unregister) {
} }
TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) {
GURL pattern("http://www.example.com/*"); GURL pattern("http://www.example.com/");
bool called; bool called;
job_coordinator()->Unregister(pattern, job_coordinator()->Unregister(pattern,
...@@ -291,7 +291,7 @@ TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { ...@@ -291,7 +291,7 @@ TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) {
// Make sure that when a new registration replaces an existing // Make sure that when a new registration replaces an existing
// registration, that the old one is cleaned up. // registration, that the old one is cleaned up.
TEST_F(ServiceWorkerJobTest, RegisterNewScript) { TEST_F(ServiceWorkerJobTest, RegisterNewScript) {
GURL pattern("http://www.example.com/*"); GURL pattern("http://www.example.com/");
bool called; bool called;
scoped_refptr<ServiceWorkerRegistration> old_registration; scoped_refptr<ServiceWorkerRegistration> old_registration;
...@@ -349,7 +349,7 @@ TEST_F(ServiceWorkerJobTest, RegisterNewScript) { ...@@ -349,7 +349,7 @@ 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 pattern("http://www.example.com/*"); GURL pattern("http://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("http://www.example.com/service_worker.js");
bool called; bool called;
...@@ -424,7 +424,7 @@ TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { ...@@ -424,7 +424,7 @@ TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) {
bool called = false; bool called = false;
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
job_coordinator()->Register( job_coordinator()->Register(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
SaveRegistration( SaveRegistration(
...@@ -440,7 +440,7 @@ TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { ...@@ -440,7 +440,7 @@ 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 pattern("http://www.example.com/*"); GURL pattern("http://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("http://www.example.com/service_worker.js");
bool registration_called = false; bool registration_called = false;
...@@ -477,7 +477,7 @@ TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { ...@@ -477,7 +477,7 @@ 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("http://www.example.com/");
GURL script_url1("http://www.example.com/service_worker1.js"); GURL script_url1("http://www.example.com/service_worker1.js");
bool registration1_called = false; bool registration1_called = false;
...@@ -521,7 +521,7 @@ TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { ...@@ -521,7 +521,7 @@ TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) {
// coalesced such that both callers get the exact same registration // coalesced such that both callers get the exact same registration
// object. // object.
TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) {
GURL pattern("http://www.example.com/*"); GURL pattern("http://www.example.com/");
GURL script_url("http://www.example.com/service_worker1.js"); GURL script_url("http://www.example.com/service_worker1.js");
bool registration1_called = false; bool registration1_called = false;
...@@ -563,7 +563,7 @@ TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { ...@@ -563,7 +563,7 @@ 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("http://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("http://www.example.com/service_worker.js");
bool unregistration1_called = false; bool unregistration1_called = false;
...@@ -596,8 +596,8 @@ TEST_F(ServiceWorkerJobTest, ParallelUnreg) { ...@@ -596,8 +596,8 @@ TEST_F(ServiceWorkerJobTest, ParallelUnreg) {
} }
TEST_F(ServiceWorkerJobTest, AbortAll_Register) { TEST_F(ServiceWorkerJobTest, AbortAll_Register) {
GURL pattern1("http://www1.example.com/*"); GURL pattern1("http://www1.example.com/");
GURL pattern2("http://www2.example.com/*"); GURL pattern2("http://www2.example.com/");
GURL script_url1("http://www1.example.com/service_worker.js"); GURL script_url1("http://www1.example.com/service_worker.js");
GURL script_url2("http://www2.example.com/service_worker.js"); GURL script_url2("http://www2.example.com/service_worker.js");
...@@ -647,8 +647,8 @@ TEST_F(ServiceWorkerJobTest, AbortAll_Register) { ...@@ -647,8 +647,8 @@ TEST_F(ServiceWorkerJobTest, AbortAll_Register) {
} }
TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) { TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) {
GURL pattern1("http://www1.example.com/*"); GURL pattern1("http://www1.example.com/");
GURL pattern2("http://www2.example.com/*"); GURL pattern2("http://www2.example.com/");
bool unregistration_called1 = false; bool unregistration_called1 = false;
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
...@@ -673,7 +673,7 @@ TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) { ...@@ -673,7 +673,7 @@ TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) {
} }
TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) { TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) {
GURL pattern("http://www.example.com/*"); GURL pattern("http://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js"); GURL script_url("http://www.example.com/service_worker.js");
bool registration_called = false; bool registration_called = false;
...@@ -716,7 +716,7 @@ TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { ...@@ -716,7 +716,7 @@ TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) {
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
bool called = false; bool called = false;
job_coordinator()->Register( job_coordinator()->Register(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
SaveRegistration(SERVICE_WORKER_OK, &called, &registration)); SaveRegistration(SERVICE_WORKER_OK, &called, &registration));
...@@ -740,7 +740,7 @@ TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { ...@@ -740,7 +740,7 @@ TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) {
EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status());
called = false; called = false;
job_coordinator()->Unregister(GURL("http://www.example.com/*"), job_coordinator()->Unregister(GURL("http://www.example.com/"),
SaveUnregistration(SERVICE_WORKER_OK, &called)); SaveUnregistration(SERVICE_WORKER_OK, &called));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called); ASSERT_TRUE(called);
...@@ -757,7 +757,7 @@ TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { ...@@ -757,7 +757,7 @@ TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) {
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
bool called = false; bool called = false;
job_coordinator()->Register( job_coordinator()->Register(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
SaveRegistration(SERVICE_WORKER_OK, &called, &registration)); SaveRegistration(SERVICE_WORKER_OK, &called, &registration));
...@@ -770,7 +770,7 @@ TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { ...@@ -770,7 +770,7 @@ TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) {
EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
called = false; called = false;
job_coordinator()->Unregister(GURL("http://www.example.com/*"), job_coordinator()->Unregister(GURL("http://www.example.com/"),
SaveUnregistration(SERVICE_WORKER_OK, &called)); SaveUnregistration(SERVICE_WORKER_OK, &called));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called); ASSERT_TRUE(called);
...@@ -788,7 +788,7 @@ TEST_F(ServiceWorkerJobTest, ...@@ -788,7 +788,7 @@ TEST_F(ServiceWorkerJobTest,
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
bool called = false; bool called = false;
job_coordinator()->Register( job_coordinator()->Register(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
render_process_id_, render_process_id_,
SaveRegistration(SERVICE_WORKER_OK, &called, &registration)); SaveRegistration(SERVICE_WORKER_OK, &called, &registration));
...@@ -808,7 +808,7 @@ TEST_F(ServiceWorkerJobTest, ...@@ -808,7 +808,7 @@ TEST_F(ServiceWorkerJobTest,
EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
called = false; called = false;
job_coordinator()->Unregister(GURL("http://www.example.com/*"), job_coordinator()->Unregister(GURL("http://www.example.com/"),
SaveUnregistration(SERVICE_WORKER_OK, &called)); SaveUnregistration(SERVICE_WORKER_OK, &called));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called); ASSERT_TRUE(called);
...@@ -829,7 +829,7 @@ namespace { // Helpers for the update job tests. ...@@ -829,7 +829,7 @@ namespace { // Helpers for the update job tests.
const GURL kNoChangeOrigin("http://nochange/"); const GURL kNoChangeOrigin("http://nochange/");
const GURL kNewVersionOrigin("http://newversion/"); const GURL kNewVersionOrigin("http://newversion/");
const std::string kScope("scope/*"); const std::string kScope("scope/");
const std::string kScript("script.js"); const std::string kScript("script.js");
void RunNestedUntilIdle() { void RunNestedUntilIdle() {
......
...@@ -32,7 +32,7 @@ class ServiceWorkerProviderHostTest : public testing::Test { ...@@ -32,7 +32,7 @@ class ServiceWorkerProviderHostTest : public testing::Test {
NULL, NULL,
NULL)); NULL));
scope_ = GURL("http://www.example.com/*"); scope_ = GURL("http://www.example.com/");
script_url_ = GURL("http://www.example.com/service_worker.js"); script_url_ = GURL("http://www.example.com/service_worker.js");
registration_ = new ServiceWorkerRegistration( registration_ = new ServiceWorkerRegistration(
scope_, script_url_, 1L, context_->AsWeakPtr()); scope_, script_url_, 1L, context_->AsWeakPtr());
...@@ -203,7 +203,7 @@ class ServiceWorkerProviderHostWaitingVersionTest : public testing::Test { ...@@ -203,7 +203,7 @@ class ServiceWorkerProviderHostWaitingVersionTest : public testing::Test {
TEST_F(ServiceWorkerProviderHostWaitingVersionTest, TEST_F(ServiceWorkerProviderHostWaitingVersionTest,
AssociateInstallingVersionToDocuments) { AssociateInstallingVersionToDocuments) {
const GURL scope1("http://www.example.com/*"); const GURL scope1("http://www.example.com/");
const GURL script_url1("http://www.example.com/service_worker1.js"); const GURL script_url1("http://www.example.com/service_worker1.js");
scoped_refptr<ServiceWorkerRegistration> registration1( scoped_refptr<ServiceWorkerRegistration> registration1(
new ServiceWorkerRegistration( new ServiceWorkerRegistration(
...@@ -247,7 +247,7 @@ TEST_F(ServiceWorkerProviderHostWaitingVersionTest, ...@@ -247,7 +247,7 @@ TEST_F(ServiceWorkerProviderHostWaitingVersionTest,
TEST_F(ServiceWorkerProviderHostWaitingVersionTest, TEST_F(ServiceWorkerProviderHostWaitingVersionTest,
DisassociateVersionFromDocuments) { DisassociateVersionFromDocuments) {
const GURL scope1("http://www.example.com/*"); const GURL scope1("http://www.example.com/");
const GURL script_url1("http://www.example.com/service_worker.js"); const GURL script_url1("http://www.example.com/service_worker.js");
scoped_refptr<ServiceWorkerRegistration> registration1( scoped_refptr<ServiceWorkerRegistration> registration1(
new ServiceWorkerRegistration( new ServiceWorkerRegistration(
...@@ -255,7 +255,7 @@ TEST_F(ServiceWorkerProviderHostWaitingVersionTest, ...@@ -255,7 +255,7 @@ TEST_F(ServiceWorkerProviderHostWaitingVersionTest,
scoped_refptr<ServiceWorkerVersion> version1( scoped_refptr<ServiceWorkerVersion> version1(
new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr())); new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr()));
const GURL scope2("http://www.example.ca/*"); const GURL scope2("http://www.example.ca/");
const GURL script_url2("http://www.example.ca/service_worker.js"); const GURL script_url2("http://www.example.ca/service_worker.js");
scoped_refptr<ServiceWorkerRegistration> registration2( scoped_refptr<ServiceWorkerRegistration> registration2(
new ServiceWorkerRegistration( new ServiceWorkerRegistration(
......
...@@ -70,7 +70,7 @@ class ServiceWorkerRegistrationTest : public testing::Test { ...@@ -70,7 +70,7 @@ class ServiceWorkerRegistrationTest : public testing::Test {
}; };
TEST_F(ServiceWorkerRegistrationTest, SetAndUnsetVersions) { TEST_F(ServiceWorkerRegistrationTest, SetAndUnsetVersions) {
const GURL kScope("http://www.example.not/*"); const GURL kScope("http://www.example.not/");
const GURL kScript("http://www.example.not/service_worker.js"); const GURL kScript("http://www.example.not/service_worker.js");
int64 kRegistrationId = 1L; int64 kRegistrationId = 1L;
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
......
...@@ -318,7 +318,7 @@ class ServiceWorkerStorageTest : public testing::Test { ...@@ -318,7 +318,7 @@ class ServiceWorkerStorageTest : public testing::Test {
}; };
TEST_F(ServiceWorkerStorageTest, StoreFindUpdateDeleteRegistration) { TEST_F(ServiceWorkerStorageTest, StoreFindUpdateDeleteRegistration) {
const GURL kScope("http://www.test.not/scope/*"); const GURL kScope("http://www.test.not/scope/");
const GURL kScript("http://www.test.not/script.js"); const GURL kScript("http://www.test.not/script.js");
const GURL kDocumentUrl("http://www.test.not/scope/document.html"); const GURL kDocumentUrl("http://www.test.not/scope/document.html");
const int64 kRegistrationId = 0; const int64 kRegistrationId = 0;
...@@ -445,7 +445,7 @@ TEST_F(ServiceWorkerStorageTest, StoreFindUpdateDeleteRegistration) { ...@@ -445,7 +445,7 @@ TEST_F(ServiceWorkerStorageTest, StoreFindUpdateDeleteRegistration) {
} }
TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) { TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) {
const GURL kScope("http://www.test.not/scope/*"); const GURL kScope("http://www.test.not/scope/");
const GURL kScript("http://www.test.not/script.js"); const GURL kScript("http://www.test.not/script.js");
const GURL kDocumentUrl("http://www.test.not/scope/document.html"); const GURL kDocumentUrl("http://www.test.not/scope/document.html");
const int64 kRegistrationId = 0; const int64 kRegistrationId = 0;
...@@ -534,7 +534,7 @@ class ServiceWorkerResourceStorageTest : public ServiceWorkerStorageTest { ...@@ -534,7 +534,7 @@ class ServiceWorkerResourceStorageTest : public ServiceWorkerStorageTest {
storage()->LazyInitialize(base::Bind(&base::DoNothing)); storage()->LazyInitialize(base::Bind(&base::DoNothing));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
scope_ = GURL("http://www.test.not/scope/*"); scope_ = GURL("http://www.test.not/scope/");
script_ = GURL("http://www.test.not/script.js"); script_ = GURL("http://www.test.not/script.js");
import_ = GURL("http://www.test.not/import.js"); import_ = GURL("http://www.test.not/import.js");
document_url_ = GURL("http://www.test.not/scope/document.html"); document_url_ = GURL("http://www.test.not/scope/document.html");
...@@ -891,8 +891,8 @@ TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) { ...@@ -891,8 +891,8 @@ TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) {
const GURL kDocumentUrl("http://www.example.com/scope/foo"); const GURL kDocumentUrl("http://www.example.com/scope/foo");
scoped_refptr<ServiceWorkerRegistration> found_registration; scoped_refptr<ServiceWorkerRegistration> found_registration;
// Registration for "/scope/*". // Registration for "/scope/".
const GURL kScope1("http://www.example.com/scope/*"); const GURL kScope1("http://www.example.com/scope/");
const GURL kScript1("http://www.example.com/script1.js"); const GURL kScript1("http://www.example.com/script1.js");
const int64 kRegistrationId1 = 1; const int64 kRegistrationId1 = 1;
const int64 kVersionId1 = 1; const int64 kVersionId1 = 1;
...@@ -905,8 +905,8 @@ TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) { ...@@ -905,8 +905,8 @@ TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) {
live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); live_version1->SetStatus(ServiceWorkerVersion::INSTALLED);
live_registration1->SetWaitingVersion(live_version1); live_registration1->SetWaitingVersion(live_version1);
// Registration for "/scope/foo*". // Registration for "/scope/foo".
const GURL kScope2("http://www.example.com/scope/foo*"); const GURL kScope2("http://www.example.com/scope/foo");
const GURL kScript2("http://www.example.com/script2.js"); const GURL kScript2("http://www.example.com/script2.js");
const int64 kRegistrationId2 = 2; const int64 kRegistrationId2 = 2;
const int64 kVersionId2 = 2; const int64 kVersionId2 = 2;
...@@ -919,8 +919,8 @@ TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) { ...@@ -919,8 +919,8 @@ TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) {
live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); live_version2->SetStatus(ServiceWorkerVersion::INSTALLED);
live_registration2->SetWaitingVersion(live_version2); live_registration2->SetWaitingVersion(live_version2);
// Registration for "/scope/foo". // Registration for "/scope/foobar".
const GURL kScope3("http://www.example.com/scope/foo"); const GURL kScope3("http://www.example.com/scope/foobar");
const GURL kScript3("http://www.example.com/script3.js"); const GURL kScript3("http://www.example.com/script3.js");
const int64 kRegistrationId3 = 3; const int64 kRegistrationId3 = 3;
const int64 kVersionId3 = 3; const int64 kVersionId3 = 3;
......
...@@ -95,7 +95,7 @@ class ServiceWorkerURLRequestJobTest : public testing::Test { ...@@ -95,7 +95,7 @@ class ServiceWorkerURLRequestJobTest : public testing::Test {
helper_.reset(helper); helper_.reset(helper);
registration_ = new ServiceWorkerRegistration( registration_ = new ServiceWorkerRegistration(
GURL("http://example.com/*"), GURL("http://example.com/"),
GURL("http://example.com/service_worker.js"), GURL("http://example.com/service_worker.js"),
1L, 1L,
helper_->context()->AsWeakPtr()); helper_->context()->AsWeakPtr());
......
...@@ -6,10 +6,8 @@ ...@@ -6,10 +6,8 @@
#include <string> #include <string>
#include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "content/public/common/content_switches.h" #include "base/strings/string_util.h"
#include "url/gurl.h"
namespace content { namespace content {
...@@ -17,41 +15,16 @@ namespace content { ...@@ -17,41 +15,16 @@ namespace content {
bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) { bool ServiceWorkerUtils::ScopeMatches(const GURL& scope, const GURL& url) {
DCHECK(!scope.has_ref()); DCHECK(!scope.has_ref());
DCHECK(!url.has_ref()); DCHECK(!url.has_ref());
const std::string& scope_spec = scope.spec(); return StartsWithASCII(url.spec(), scope.spec(), true);
const std::string& url_spec = url.spec();
size_t len = scope_spec.size();
if (len > 0 && scope_spec[len - 1] == '*')
return scope_spec.compare(0, len - 1, url_spec, 0, len - 1) == 0;
return scope_spec == url_spec;
} }
bool LongestScopeMatcher::MatchLongest(const GURL& scope) { bool LongestScopeMatcher::MatchLongest(const GURL& scope) {
if (!ServiceWorkerUtils::ScopeMatches(scope, url_)) if (!ServiceWorkerUtils::ScopeMatches(scope, url_))
return false; return false;
if (match_.is_empty()) { if (match_.is_empty() || match_.spec().size() < scope.spec().size()) {
match_ = scope;
return true;
}
const std::string match_spec = match_.spec();
const std::string scope_spec = scope.spec();
if (match_spec.size() < scope_spec.size()) {
match_ = scope; match_ = scope;
return true; return true;
} }
// If |scope| has the same length with |match_|, they are compared as strings.
// For example:
// 1) for a document "/foo", "/foo" is prioritized over "/fo*".
// 2) for a document "/f(1)", "/f(1*" is prioritized over "/f(1)".
// TODO(nhiroki): This isn't in the spec.
// (https://github.com/slightlyoff/ServiceWorker/issues/287)
if (match_spec.size() == scope_spec.size() && match_spec < scope_spec) {
match_ = scope;
return true;
}
return false; return false;
} }
......
...@@ -9,26 +9,42 @@ namespace content { ...@@ -9,26 +9,42 @@ namespace content {
TEST(ServiceWorkerUtilsTest, ScopeMatches) { TEST(ServiceWorkerUtilsTest, ScopeMatches) {
ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"))); GURL("http://www.example.com/"), GURL("http://www.example.com/")));
ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/page.html"))); GURL("http://www.example.com/page.html")));
ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*"), GURL("https://www.example.com/"))); GURL("http://www.example.com/"), GURL("https://www.example.com/")));
ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("https://www.example.com/page.html"))); GURL("https://www.example.com/page.html")));
ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*"), GURL("http://www.foo.com/"))); GURL("http://www.example.com/"), GURL("http://www.foo.com/")));
ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*"), GURL("https://www.foo.com/page.html"))); GURL("http://www.example.com/"), GURL("https://www.foo.com/page.html")));
// '*' is not a wildcard.
ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*"), GURL("http://www.example.com/x")));
ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*"), GURL("http://www.example.com/")));
ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*"), GURL("http://www.example.com/xx")));
ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/"), GURL("http://www.example.com/"))); GURL("http://www.example.com/*"), GURL("http://www.example.com/*")));
ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*/x"), GURL("http://www.example.com/*/x")));
ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/"), GURL("http://www.example.com/x"))); GURL("http://www.example.com/*/x"), GURL("http://www.example.com/a/x")));
ASSERT_FALSE(
ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"),
GURL("http://www.example.com/a/x/b")));
ASSERT_FALSE(
ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"),
GURL("http://www.example.com/*/x/b")));
// '?' is not a wildcard. // '?' is not a wildcard.
ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
...@@ -45,59 +61,28 @@ TEST(ServiceWorkerUtilsTest, ScopeMatches) { ...@@ -45,59 +61,28 @@ TEST(ServiceWorkerUtilsTest, ScopeMatches) {
ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/?a=b"), ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/?a=b"),
GURL("http://www.example.com/?a=b"))); GURL("http://www.example.com/?a=b")));
ASSERT_TRUE( ASSERT_TRUE(
ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/?a=*"), ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/?a="),
GURL("http://www.example.com/?a=b"))); GURL("http://www.example.com/?a=b")));
ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*"), GURL("http://www.example.com/?a=b")));
ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/"), GURL("http://www.example.com/?a=b"))); GURL("http://www.example.com/"), GURL("http://www.example.com/?a=b")));
// '*' only has special meaning in terminal position. // URLs canonicalize \ to / so this is equivalent to "...//x"
ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*/x"), GURL("http://www.example.com/*/x"))); GURL("http://www.example.com/\\x"), GURL("http://www.example.com//x")));
ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/*/x"), GURL("http://www.example.com/a/x")));
ASSERT_FALSE(
ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"),
GURL("http://www.example.com/a/x/b")));
ASSERT_TRUE(
ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"),
GURL("http://www.example.com/*/x/b")));
// URLs canonicalize \ to / so this is equivalent to "...//*" and "...//x"
ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x")));
} }
TEST(ServiceWorkerUtilsTest, FindLongestScopeMatch_Basic) { TEST(ServiceWorkerUtilsTest, FindLongestScopeMatch) {
LongestScopeMatcher matcher(GURL("http://www.example.com/xxx")); LongestScopeMatcher matcher(GURL("http://www.example.com/xxx"));
// "/xx*" should be matched longest. // "/xx" should be matched longest.
ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/x*"))); ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/x")));
ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/*"))); ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/")));
ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xx*"))); ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xx")));
// "xxx*" should be matched longer than "/xx*".
ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xxx*")));
ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/xxxx*")));
}
TEST(ServiceWorkerUtilsTest, FindLongestScopeMatch_SameLength) {
LongestScopeMatcher matcher1(GURL("http://www.example.com/xxx"));
// "/xxx" has the same length with "/xx*", so they are compared as strings
// and "/xxx" should win.
// TODO(nhiroki): This isn't in the spec (see: service_worker_utils.cc)
ASSERT_TRUE(matcher1.MatchLongest(GURL("http://www.example.com/xxx")));
ASSERT_FALSE(matcher1.MatchLongest(GURL("http://www.example.com/xx*")));
LongestScopeMatcher matcher2(GURL("http://www.example.com/x(1)")); // "/xxx" should be matched longer than "/xx".
ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xxx")));
// "/xx*" should be prioritized over "/x(1)". ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/xxxx")));
// TODO(nhiroki): This isn't in the spec (see: service_worker_utils.cc)
ASSERT_TRUE(matcher2.MatchLongest(GURL("http://www.example.com/x(1)")));
ASSERT_TRUE(matcher2.MatchLongest(GURL("http://www.example.com/x(1*")));
} }
} // namespace content } // namespace content
...@@ -120,7 +120,7 @@ class ServiceWorkerVersionTest : public testing::Test { ...@@ -120,7 +120,7 @@ class ServiceWorkerVersionTest : public testing::Test {
helper_.reset(new MessageReceiver()); helper_.reset(new MessageReceiver());
registration_ = new ServiceWorkerRegistration( registration_ = new ServiceWorkerRegistration(
GURL("http://www.example.com/*"), GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"), GURL("http://www.example.com/service_worker.js"),
1L, 1L,
helper_->context()->AsWeakPtr()); helper_->context()->AsWeakPtr());
......
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