Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: content/browser/service_worker/service_worker_browsertest.cc

Issue 153553008: Wire InstallFinished and add some InstallEvent.waitUntil tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/renderer/service_worker/embedded_worker_context_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "content/browser/service_worker/embedded_worker_instance.h" 9 #include "content/browser/service_worker/embedded_worker_instance.h"
10 #include "content/browser/service_worker/embedded_worker_registry.h" 10 #include "content/browser/service_worker/embedded_worker_registry.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 if (registration_) { 187 if (registration_) {
188 registration_->Shutdown(); 188 registration_->Shutdown();
189 registration_ = NULL; 189 registration_ = NULL;
190 } 190 }
191 if (version_) { 191 if (version_) {
192 version_->Shutdown(); 192 version_->Shutdown();
193 version_ = NULL; 193 version_ = NULL;
194 } 194 }
195 } 195 }
196 196
197 void InstallTestHelper(const std::string& worker_url) {
198 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this,
199 worker_url));
200
201 // Dispatch install on a worker.
202 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
203 base::RunLoop install_run_loop;
204 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
205 base::Bind(&self::InstallOnIOThread, this,
206 install_run_loop.QuitClosure(),
207 &status));
208 install_run_loop.Run();
209 ASSERT_EQ(SERVICE_WORKER_OK, status);
210
211 // Stop the worker.
212 status = SERVICE_WORKER_ERROR_FAILED;
213 base::RunLoop stop_run_loop;
214 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
215 base::Bind(&self::StopOnIOThread, this,
216 stop_run_loop.QuitClosure(),
217 &status));
218 stop_run_loop.Run();
219 ASSERT_EQ(SERVICE_WORKER_OK, status);
220 }
221
197 void SetUpRegistrationOnIOThread(const std::string& worker_url) { 222 void SetUpRegistrationOnIOThread(const std::string& worker_url) {
198 const int64 version_id = 1L; 223 const int64 version_id = 1L;
199 registration_ = new ServiceWorkerRegistration( 224 registration_ = new ServiceWorkerRegistration(
200 embedded_test_server()->GetURL("/*"), 225 embedded_test_server()->GetURL("/*"),
201 embedded_test_server()->GetURL(worker_url), 226 embedded_test_server()->GetURL(worker_url),
202 next_registration_id_++); 227 next_registration_id_++);
203 version_ = new ServiceWorkerVersion( 228 version_ = new ServiceWorkerVersion(
204 registration_, 229 registration_,
205 wrapper()->context()->embedded_worker_registry(), 230 wrapper()->context()->embedded_worker_registry(),
206 version_id); 231 version_id);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 base::RunLoop start_run_loop; 311 base::RunLoop start_run_loop;
287 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 312 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
288 base::Bind(&self::StartOnIOThread, this, 313 base::Bind(&self::StartOnIOThread, this,
289 start_run_loop.QuitClosure(), 314 start_run_loop.QuitClosure(),
290 &status)); 315 &status));
291 start_run_loop.Run(); 316 start_run_loop.Run();
292 ASSERT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); 317 ASSERT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status);
293 } 318 }
294 319
295 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) { 320 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) {
296 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, 321 InstallTestHelper("/service_worker/worker.js");
297 "/service_worker/worker.js")); 322 }
298 323
299 // Dispatch install on a worker. 324 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
300 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 325 InstallWithWaitUntil_Fulfilled) {
301 base::RunLoop install_run_loop; 326 InstallTestHelper("/service_worker/worker_install_fulfilled.js");
302 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 327 }
303 base::Bind(&self::InstallOnIOThread, this,
304 install_run_loop.QuitClosure(),
305 &status));
306 install_run_loop.Run();
307 ASSERT_EQ(SERVICE_WORKER_OK, status);
308 328
309 // Stop the worker. 329 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
310 status = SERVICE_WORKER_ERROR_FAILED; 330 InstallWithWaitUntil_Rejected) {
311 base::RunLoop stop_run_loop; 331 // TODO(kinuko): This should also report back an error, but we
312 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 332 // don't have plumbing for it yet.
313 base::Bind(&self::StopOnIOThread, this, 333 InstallTestHelper("/service_worker/worker_install_rejected.js");
314 stop_run_loop.QuitClosure(),
315 &status));
316 stop_run_loop.Run();
317 ASSERT_EQ(SERVICE_WORKER_OK, status);
318 } 334 }
319 335
320 } // namespace content 336 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/service_worker/embedded_worker_context_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698