Commit a5333583 authored by kinuko@chromium.org's avatar kinuko@chromium.org

Wire InstallFinished and add some InstallEvent.waitUntil tests

BUG=285976
TEST=content_browsertests:ServiceWorkerVersionBrowserTest.Install*

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=250804

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250936 0039d316-1c4b-4281-b951-d872f2087c98
parent c81b2b78
...@@ -186,6 +186,31 @@ class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest { ...@@ -186,6 +186,31 @@ class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest {
} }
} }
void InstallTestHelper(const std::string& worker_url) {
RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this,
worker_url));
// Dispatch install on a worker.
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
base::RunLoop install_run_loop;
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&self::InstallOnIOThread, this,
install_run_loop.QuitClosure(),
&status));
install_run_loop.Run();
ASSERT_EQ(SERVICE_WORKER_OK, status);
// Stop the worker.
status = SERVICE_WORKER_ERROR_FAILED;
base::RunLoop stop_run_loop;
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&self::StopOnIOThread, this,
stop_run_loop.QuitClosure(),
&status));
stop_run_loop.Run();
ASSERT_EQ(SERVICE_WORKER_OK, status);
}
void SetUpRegistrationOnIOThread(const std::string& worker_url) { void SetUpRegistrationOnIOThread(const std::string& worker_url) {
const int64 version_id = 1L; const int64 version_id = 1L;
registration_ = new ServiceWorkerRegistration( registration_ = new ServiceWorkerRegistration(
...@@ -285,28 +310,19 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartNotFound) { ...@@ -285,28 +310,19 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartNotFound) {
} }
IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) { IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) {
RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, InstallTestHelper("/service_worker/worker.js");
"/service_worker/worker.js")); }
// Dispatch install on a worker. IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; InstallWithWaitUntil_Fulfilled) {
base::RunLoop install_run_loop; InstallTestHelper("/service_worker/worker_install_fulfilled.js");
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, }
base::Bind(&self::InstallOnIOThread, this,
install_run_loop.QuitClosure(),
&status));
install_run_loop.Run();
ASSERT_EQ(SERVICE_WORKER_OK, status);
// Stop the worker. IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
status = SERVICE_WORKER_ERROR_FAILED; InstallWithWaitUntil_Rejected) {
base::RunLoop stop_run_loop; // TODO(kinuko): This should also report back an error, but we
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, // don't have plumbing for it yet.
base::Bind(&self::StopOnIOThread, this, InstallTestHelper("/service_worker/worker_install_rejected.js");
stop_run_loop.QuitClosure(),
&status));
stop_run_loop.Run();
ASSERT_EQ(SERVICE_WORKER_OK, status);
} }
} // namespace content } // namespace content
...@@ -120,6 +120,11 @@ void EmbeddedWorkerContextClient::workerContextDestroyed() { ...@@ -120,6 +120,11 @@ void EmbeddedWorkerContextClient::workerContextDestroyed() {
embedded_worker_id_)); embedded_worker_id_));
} }
void EmbeddedWorkerContextClient::didHandleInstallEvent(int request_id) {
DCHECK(script_context_);
script_context_->DidHandleInstallEvent(request_id);
}
void EmbeddedWorkerContextClient::OnSendMessageToWorker( void EmbeddedWorkerContextClient::OnSendMessageToWorker(
int thread_id, int thread_id,
int embedded_worker_id, int embedded_worker_id,
......
...@@ -49,10 +49,12 @@ class EmbeddedWorkerContextClient ...@@ -49,10 +49,12 @@ class EmbeddedWorkerContextClient
void SendMessageToBrowser(int request_id, const IPC::Message& message); void SendMessageToBrowser(int request_id, const IPC::Message& message);
// WebServiceWorkerContextClient overrides. // WebServiceWorkerContextClient overrides, some of them are just dispatched
// on to script_context_.
virtual void workerContextFailedToStart(); virtual void workerContextFailedToStart();
virtual void workerContextStarted(blink::WebServiceWorkerContextProxy* proxy); virtual void workerContextStarted(blink::WebServiceWorkerContextProxy* proxy);
virtual void workerContextDestroyed(); virtual void workerContextDestroyed();
virtual void didHandleInstallEvent(int request_id);
// TODO: Implement DevTools related method overrides. // TODO: Implement DevTools related method overrides.
......
...@@ -48,12 +48,7 @@ void ServiceWorkerScriptContext::Send(int request_id, ...@@ -48,12 +48,7 @@ void ServiceWorkerScriptContext::Send(int request_id,
void ServiceWorkerScriptContext::OnInstallEvent( void ServiceWorkerScriptContext::OnInstallEvent(
int active_version_embedded_worker_id) { int active_version_embedded_worker_id) {
// TODO(kinuko): Uncomment this when blink side becomes ready. proxy_->dispatchInstallEvent(current_request_id_);
// proxy_->dispatchInstallEvent(current_request_id_);
// TODO(kinuko): this should be called asynchronously from blink side
// when blink-side plumbing is done.
DidHandleInstallEvent(current_request_id_);
} }
void ServiceWorkerScriptContext::OnFetchEvent( void ServiceWorkerScriptContext::OnFetchEvent(
......
...@@ -2,5 +2,4 @@ ...@@ -2,5 +2,4 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Has no content yet, this just needs to exist for script loading. this.oninstall = function(event) {};
this.oninstalled = function(event) {};
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
this.oninstall = function(event) {
event.waitUntil(new Promise(function(r) { setTimeout(r, 5); }));
event.waitUntil(1);
};
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
this.oninstall = function(event) {
event.waitUntil(new Promise(function(resolve, reject) {
setTimeout(reject, 5);
}));
};
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