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