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 {
}
}
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) {
const int64 version_id = 1L;
registration_ = new ServiceWorkerRegistration(
......@@ -285,28 +310,19 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartNotFound) {
}
IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) {
RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this,
"/service_worker/worker.js"));
InstallTestHelper("/service_worker/worker.js");
}
// 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);
IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
InstallWithWaitUntil_Fulfilled) {
InstallTestHelper("/service_worker/worker_install_fulfilled.js");
}
// 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);
IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
InstallWithWaitUntil_Rejected) {
// TODO(kinuko): This should also report back an error, but we
// don't have plumbing for it yet.
InstallTestHelper("/service_worker/worker_install_rejected.js");
}
} // namespace content
......@@ -120,6 +120,11 @@ void EmbeddedWorkerContextClient::workerContextDestroyed() {
embedded_worker_id_));
}
void EmbeddedWorkerContextClient::didHandleInstallEvent(int request_id) {
DCHECK(script_context_);
script_context_->DidHandleInstallEvent(request_id);
}
void EmbeddedWorkerContextClient::OnSendMessageToWorker(
int thread_id,
int embedded_worker_id,
......
......@@ -49,10 +49,12 @@ class EmbeddedWorkerContextClient
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 workerContextStarted(blink::WebServiceWorkerContextProxy* proxy);
virtual void workerContextDestroyed();
virtual void didHandleInstallEvent(int request_id);
// TODO: Implement DevTools related method overrides.
......
......@@ -48,12 +48,7 @@ void ServiceWorkerScriptContext::Send(int request_id,
void ServiceWorkerScriptContext::OnInstallEvent(
int active_version_embedded_worker_id) {
// TODO(kinuko): Uncomment this when blink side becomes ready.
// 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_);
proxy_->dispatchInstallEvent(current_request_id_);
}
void ServiceWorkerScriptContext::OnFetchEvent(
......
......@@ -2,5 +2,4 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Has no content yet, this just needs to exist for script loading.
this.oninstalled = function(event) {};
this.oninstall = 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