job_coordinator()->Register(
GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"),
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration));
EXPECT_FALSE(called);
base::RunLoop().RunUntilIdle();
SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration2));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called);
- ASSERT_TRUE(registration1);
+ ASSERT_TRUE(registration1.get());
ASSERT_EQ(registration1, original_registration);
ASSERT_EQ(registration1, registration2);
}
job_coordinator()->Register(
GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"),
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration));
EXPECT_FALSE(called);
base::RunLoop().RunUntilIdle();
job_coordinator()->Register(
GURL("http://www.example.com/one/"),
GURL("http://www.example.com/service_worker.js"),
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1));
bool called2;
job_coordinator()->Register(
GURL("http://www.example.com/two/"),
GURL("http://www.example.com/service_worker.js"),
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2));
EXPECT_FALSE(called1);
job_coordinator()->Register(
GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"),
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called, ®istration));
ASSERT_FALSE(called);
job_coordinator()->Register(
pattern,
GURL("http://www.example.com/service_worker.js"),
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called, ®istration));
ASSERT_FALSE(called);
GURL pattern("http://www.example.com/");
bool called;
- job_coordinator()->Unregister(pattern,
- SaveUnregistration(SERVICE_WORKER_OK, &called));
+ job_coordinator()->Unregister(
+ pattern,
+ SaveUnregistration(SERVICE_WORKER_ERROR_NOT_FOUND, &called));
ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called);
}
-// Make sure that when a new registration replaces an existing
-// registration, that the old one is cleaned up.
+// Make sure registering a new script creates a new version and shares an
+// existing registration.
TEST_F(ServiceWorkerJobTest, RegisterNewScript) {
GURL pattern("http://www.example.com/");
job_coordinator()->Register(
pattern,
GURL("http://www.example.com/service_worker.js"),
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration));
ASSERT_FALSE(called);
job_coordinator()->Register(
pattern,
GURL("http://www.example.com/service_worker_new.js"),
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration));
ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called);
- ASSERT_TRUE(old_registration->HasOneRef());
-
- ASSERT_NE(old_registration, new_registration);
+ ASSERT_EQ(old_registration, new_registration);
scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern;
storage()->FindRegistrationForPattern(
job_coordinator()->Register(
pattern,
script_url,
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration));
ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called);
- ASSERT_TRUE(old_registration_by_pattern);
+ ASSERT_TRUE(old_registration_by_pattern.get());
scoped_refptr<ServiceWorkerRegistration> new_registration;
job_coordinator()->Register(
pattern,
script_url,
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration));
ASSERT_FALSE(called);
job_coordinator()->Register(
GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"),
- render_process_id_,
+ NULL,
SaveRegistration(
SERVICE_WORKER_ERROR_START_WORKER_FAILED, &called, ®istration));
job_coordinator()->Register(
pattern,
script_url,
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration));
bool unregistration_called = false;
job_coordinator()->Register(
pattern,
script_url1,
- render_process_id_,
+ NULL,
SaveRegistration(
SERVICE_WORKER_OK, ®istration1_called, ®istration1));
job_coordinator()->Register(
pattern,
script_url2,
- render_process_id_,
+ NULL,
SaveRegistration(
SERVICE_WORKER_OK, ®istration2_called, ®istration2));
job_coordinator()->Register(
pattern,
script_url,
- render_process_id_,
+ NULL,
SaveRegistration(
SERVICE_WORKER_OK, ®istration1_called, ®istration1));
job_coordinator()->Register(
pattern,
script_url,
- render_process_id_,
+ NULL,
SaveRegistration(
SERVICE_WORKER_OK, ®istration2_called, ®istration2));
bool unregistration1_called = false;
job_coordinator()->Unregister(
pattern,
- SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called));
+ SaveUnregistration(SERVICE_WORKER_ERROR_NOT_FOUND,
+ &unregistration1_called));
bool unregistration2_called = false;
job_coordinator()->Unregister(
- pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called));
+ pattern,
+ SaveUnregistration(SERVICE_WORKER_ERROR_NOT_FOUND,
+ &unregistration2_called));
ASSERT_FALSE(unregistration1_called);
ASSERT_FALSE(unregistration2_called);
job_coordinator()->Register(
pattern1,
script_url1,
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_ERROR_ABORT,
®istration_called1, ®istration1));
job_coordinator()->Register(
pattern2,
script_url2,
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_ERROR_ABORT,
®istration_called2, ®istration2));
job_coordinator()->Register(
pattern,
script_url,
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_ERROR_ABORT,
®istration_called, ®istration));
TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) {
scoped_refptr<ServiceWorkerRegistration> registration;
bool called = false;
+ GURL script_url("http://www.example.com/service_worker.js");
job_coordinator()->Register(
GURL("http://www.example.com/"),
- GURL("http://www.example.com/service_worker.js"),
- render_process_id_,
+ script_url,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called, ®istration));
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called);
- ASSERT_TRUE(registration);
+ ASSERT_TRUE(registration.get());
// Manually create the waiting worker since there is no way to become a
// waiting worker until Update is implemented.
scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
- registration, 1L, helper_->context()->AsWeakPtr());
+ registration.get(), script_url, 1L, helper_->context()->AsWeakPtr());
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
version->StartWorker(CreateReceiverOnCurrentThread(&status));
base::RunLoop().RunUntilIdle();
ASSERT_EQ(SERVICE_WORKER_OK, status);
version->SetStatus(ServiceWorkerVersion::INSTALLED);
- registration->SetWaitingVersion(version);
+ registration->SetWaitingVersion(version.get());
EXPECT_EQ(ServiceWorkerVersion::RUNNING,
version->running_status());
EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status());
job_coordinator()->Register(
GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"),
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called, ®istration));
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called);
- ASSERT_TRUE(registration);
+ ASSERT_TRUE(registration.get());
scoped_refptr<ServiceWorkerVersion> version = registration->active_version();
EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status());
job_coordinator()->Register(
GURL("http://www.example.com/"),
GURL("http://www.example.com/service_worker.js"),
- render_process_id_,
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called, ®istration));
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called);
- ASSERT_TRUE(registration);
+ ASSERT_TRUE(registration.get());
scoped_ptr<ServiceWorkerProviderHost> host(
new ServiceWorkerProviderHost(33 /* dummy render process id */,
new HttpResponseInfoIOBuffer(info.release());
int rv = -1234;
- writer->WriteInfo(info_buffer, base::Bind(&OnIOComplete, &rv));
+ writer->WriteInfo(info_buffer.get(), base::Bind(&OnIOComplete, &rv));
RunNestedUntilIdle();
EXPECT_LT(0, rv);
scoped_refptr<IOBuffer> body_buffer(new WrappedIOBuffer(body.data()));
const char kHttpHeaders[] = "HTTP/1.0 200 HONKYDORY\0\0";
std::string headers(kHttpHeaders, arraysize(kHttpHeaders));
- WriteResponse(storage, id, headers, body_buffer, body.length());
+ WriteResponse(storage, id, headers, body_buffer.get(), body.length());
}
class UpdateJobTestHelper
};
UpdateJobTestHelper(int mock_render_process_id)
- : EmbeddedWorkerTestHelper(mock_render_process_id) {}
+ : EmbeddedWorkerTestHelper(mock_render_process_id),
+ update_found_(false) {}
virtual ~UpdateJobTestHelper() {
- if (registration_)
+ if (registration_.get())
registration_->RemoveListener(this);
}
job_coordinator()->Register(
test_origin.Resolve(kScope),
test_origin.Resolve(kScript),
- mock_render_process_id(),
+ NULL,
SaveRegistration(SERVICE_WORKER_OK, &called, ®istration));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called);
- EXPECT_TRUE(registration);
+ EXPECT_TRUE(registration.get());
EXPECT_TRUE(registration->active_version());
EXPECT_FALSE(registration->installing_version());
EXPECT_FALSE(registration->waiting_version());
int64 resource_id = storage()->NewResourceId();
version->script_cache_map()->NotifyStartedCaching(script, resource_id);
WriteStringResponse(storage(), resource_id, kMockScriptBody);
- version->script_cache_map()->NotifyFinishedCaching(script, true);
+ version->script_cache_map()->NotifyFinishedCaching(
+ script, net::URLRequestStatus());
} else {
// Spoof caching the script for the new version.
int64 resource_id = storage()->NewResourceId();
WriteStringResponse(storage(), resource_id, kMockScriptBody);
else
WriteStringResponse(storage(), resource_id, "mock_different_script");
- version->script_cache_map()->NotifyFinishedCaching(script, true);
+ version->script_cache_map()->NotifyFinishedCaching(
+ script, net::URLRequestStatus());
}
EmbeddedWorkerTestHelper::OnStartWorker(
embedded_worker_id, version_id, scope, script, pause_after_download);
NOTREACHED();
}
+ virtual void OnRegistrationFinishedUninstalling(
+ ServiceWorkerRegistration* registration) OVERRIDE {
+ NOTREACHED();
+ }
+
+ virtual void OnUpdateFound(
+ ServiceWorkerRegistration* registration) OVERRIDE {
+ ASSERT_FALSE(update_found_);
+ update_found_ = true;
+ }
+
// ServiceWorkerVersion::Listener overrides
virtual void OnVersionStateChanged(ServiceWorkerVersion* version) OVERRIDE {
StateChangeLogEntry entry;
std::vector<AttributeChangeLogEntry> attribute_change_log_;
std::vector<StateChangeLogEntry> state_change_log_;
+ bool update_found_;
};
} // namespace
helper_.reset(update_helper);
scoped_refptr<ServiceWorkerRegistration> registration =
update_helper->SetupInitialRegistration(kNoChangeOrigin);
- ASSERT_TRUE(registration);
+ ASSERT_TRUE(registration.get());
ASSERT_EQ(4u, update_helper->state_change_log_.size());
EXPECT_EQ(ServiceWorkerVersion::INSTALLING,
update_helper->state_change_log_[0].status);
update_helper->state_change_log_[0].version_id);
EXPECT_EQ(ServiceWorkerVersion::REDUNDANT,
update_helper->state_change_log_[0].status);
+ EXPECT_FALSE(update_helper->update_found_);
}
TEST_F(ServiceWorkerJobTest, Update_NewVersion) {
helper_.reset(update_helper);
scoped_refptr<ServiceWorkerRegistration> registration =
update_helper->SetupInitialRegistration(kNewVersionOrigin);
- ASSERT_TRUE(registration);
+ ASSERT_TRUE(registration.get());
update_helper->state_change_log_.clear();
// Run the update job.
update_helper->state_change_log_[4].version_id);
EXPECT_EQ(ServiceWorkerVersion::ACTIVATED,
update_helper->state_change_log_[4].status);
+
+ EXPECT_TRUE(update_helper->update_found_);
+}
+
+TEST_F(ServiceWorkerJobTest, Update_NewestVersionChanged) {
+ bool called;
+ scoped_refptr<ServiceWorkerRegistration> registration;
+ job_coordinator()->Register(
+ GURL("http://www.example.com/one/"),
+ GURL("http://www.example.com/service_worker.js"),
+ NULL,
+ SaveRegistration(SERVICE_WORKER_OK, &called, ®istration));
+
+ EXPECT_FALSE(called);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(called);
+ ServiceWorkerVersion* active_version = registration->active_version();
+
+ // Queue an Update, it should abort when it starts and sees the new version.
+ job_coordinator()->Update(registration.get());
+
+ // Add a waiting version with new script.
+ scoped_refptr<ServiceWorkerVersion> version =
+ new ServiceWorkerVersion(registration.get(),
+ GURL("http://www.example.com/new_worker.js"),
+ 2L /* dummy version id */,
+ helper_->context()->AsWeakPtr());
+ registration->SetWaitingVersion(version.get());
+
+ base::RunLoop().RunUntilIdle();
+
+ // Verify the registration was not modified by the Update.
+ EXPECT_EQ(active_version, registration->active_version());
+ EXPECT_EQ(version.get(), registration->waiting_version());
+ EXPECT_EQ(NULL, registration->installing_version());
+}
+
+TEST_F(ServiceWorkerJobTest, Update_UninstallingRegistration) {
+ bool called;
+ scoped_refptr<ServiceWorkerRegistration> registration;
+ job_coordinator()->Register(
+ GURL("http://www.example.com/one/"),
+ GURL("http://www.example.com/service_worker.js"),
+ NULL,
+ SaveRegistration(SERVICE_WORKER_OK, &called, ®istration));
+
+ EXPECT_FALSE(called);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(called);
+
+ // Add a controllee and queue an unregister to force the uninstalling state.
+ scoped_ptr<ServiceWorkerProviderHost> host(
+ new ServiceWorkerProviderHost(33 /* dummy render_process id */,
+ 1 /* dummy provider_id */,
+ helper_->context()->AsWeakPtr(),
+ NULL));
+ ServiceWorkerVersion* active_version = registration->active_version();
+ active_version->AddControllee(host.get());
+ job_coordinator()->Unregister(GURL("http://www.example.com/one/"),
+ SaveUnregistration(SERVICE_WORKER_OK, &called));
+
+ // Update should abort after it starts and sees uninstalling.
+ job_coordinator()->Update(registration.get());
+
+ EXPECT_FALSE(called);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(called);
+
+ // Verify the registration was not modified by the Update.
+ EXPECT_TRUE(registration->is_uninstalling());
+ EXPECT_EQ(active_version, registration->active_version());
+ EXPECT_EQ(NULL, registration->waiting_version());
+ EXPECT_EQ(NULL, registration->installing_version());
}
} // namespace content