| OLD | NEW |
| 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 "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 if (worker_) { | 355 if (worker_) { |
| 356 worker_->RemoveListener(this); | 356 worker_->RemoveListener(this); |
| 357 if (worker_->status() == EmbeddedWorkerInstance::STARTING || | 357 if (worker_->status() == EmbeddedWorkerInstance::STARTING || |
| 358 worker_->status() == EmbeddedWorkerInstance::RUNNING) { | 358 worker_->status() == EmbeddedWorkerInstance::RUNNING) { |
| 359 worker_->Stop(); | 359 worker_->Stop(); |
| 360 } | 360 } |
| 361 worker_.reset(); | 361 worker_.reset(); |
| 362 } | 362 } |
| 363 } | 363 } |
| 364 | 364 |
| 365 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 366 ServiceWorkerBrowserTest::SetUpCommandLine(command_line); |
| 367 |
| 368 // Code caching requires a bit more infrastructure that we don't care |
| 369 // about in this test. |
| 370 command_line->AppendSwitchASCII(switches::kV8CacheOptions, "none"); |
| 371 } |
| 372 |
| 365 void StartOnIOThread() { | 373 void StartOnIOThread() { |
| 366 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 374 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 367 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker(); | 375 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker(); |
| 368 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status()); | 376 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status()); |
| 369 worker_->AddListener(this); | 377 worker_->AddListener(this); |
| 370 | 378 |
| 371 const int64 service_worker_version_id = 33L; | 379 const int64 service_worker_version_id = 33L; |
| 372 const GURL pattern = embedded_test_server()->GetURL("/"); | 380 const GURL pattern = embedded_test_server()->GetURL("/"); |
| 373 const GURL script_url = embedded_test_server()->GetURL( | 381 const GURL script_url = embedded_test_server()->GetURL( |
| 374 "/service_worker/worker.js"); | 382 "/service_worker/worker.js"); |
| 375 AssociateRendererProcessToPattern(pattern); | 383 AssociateRendererProcessToPattern(pattern); |
| 376 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); | 384 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); |
| 377 wrapper()->process_manager()->AddProcessReferenceToPattern( | 385 wrapper()->process_manager()->AddProcessReferenceToPattern( |
| 378 pattern, process_id); | 386 pattern, process_id); |
| 379 worker_->Start( | 387 worker_->Start( |
| 380 service_worker_version_id, | 388 service_worker_version_id, |
| 381 pattern, | 389 pattern, |
| 382 script_url, | 390 script_url, |
| 383 pause_mode_ != DONT_PAUSE, | 391 pause_mode_ != DONT_PAUSE, |
| 384 base::Bind(&EmbeddedWorkerBrowserTest::StartOnIOThread2, this)); | 392 base::Bind(&EmbeddedWorkerBrowserTest::StartOnIOThread2, this)); |
| 385 } | 393 } |
| 394 |
| 386 void StartOnIOThread2(ServiceWorkerStatusCode status) { | 395 void StartOnIOThread2(ServiceWorkerStatusCode status) { |
| 387 last_worker_status_ = worker_->status(); | 396 last_worker_status_ = worker_->status(); |
| 388 EXPECT_EQ(SERVICE_WORKER_OK, status); | 397 EXPECT_EQ(SERVICE_WORKER_OK, status); |
| 389 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, last_worker_status_); | 398 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, last_worker_status_); |
| 390 | 399 |
| 391 if (status != SERVICE_WORKER_OK && !done_closure_.is_null()) | 400 if (status != SERVICE_WORKER_OK && !done_closure_.is_null()) |
| 392 done_closure_.Run(); | 401 done_closure_.Run(); |
| 393 } | 402 } |
| 394 | 403 |
| 395 void StopOnIOThread() { | 404 void StopOnIOThread() { |
| (...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 ASSERT_EQ(SERVICE_WORKER_OK, status); | 1578 ASSERT_EQ(SERVICE_WORKER_OK, status); |
| 1570 // Stop the worker. | 1579 // Stop the worker. |
| 1571 StopWorker(SERVICE_WORKER_OK); | 1580 StopWorker(SERVICE_WORKER_OK); |
| 1572 // Restart the worker. | 1581 // Restart the worker. |
| 1573 StartWorker(SERVICE_WORKER_OK); | 1582 StartWorker(SERVICE_WORKER_OK); |
| 1574 // Stop the worker. | 1583 // Stop the worker. |
| 1575 StopWorker(SERVICE_WORKER_OK); | 1584 StopWorker(SERVICE_WORKER_OK); |
| 1576 } | 1585 } |
| 1577 | 1586 |
| 1578 } // namespace content | 1587 } // namespace content |
| OLD | NEW |