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 "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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker(); | 157 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker(); |
158 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status()); | 158 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status()); |
159 worker_->AddListener(this); | 159 worker_->AddListener(this); |
160 | 160 |
161 AssociateRendererProcessToWorker(worker_.get()); | 161 AssociateRendererProcessToWorker(worker_.get()); |
162 | 162 |
163 const int64 service_worker_version_id = 33L; | 163 const int64 service_worker_version_id = 33L; |
164 const GURL scope = embedded_test_server()->GetURL("/*"); | 164 const GURL scope = embedded_test_server()->GetURL("/*"); |
165 const GURL script_url = embedded_test_server()->GetURL( | 165 const GURL script_url = embedded_test_server()->GetURL( |
166 "/service_worker/worker.js"); | 166 "/service_worker/worker.js"); |
167 ServiceWorkerStatusCode status = worker_->Start( | 167 std::vector<int> processes; |
168 service_worker_version_id, scope, script_url); | 168 processes.push_back( |
169 | 169 shell()->web_contents()->GetRenderProcessHost()->GetID()); |
170 worker_->Start( | |
171 service_worker_version_id, | |
172 scope, | |
173 script_url, | |
174 processes, | |
175 base::Bind(&EmbeddedWorkerBrowserTest::StartOnIOThread2, this)); | |
176 } | |
177 void StartOnIOThread2(ServiceWorkerStatusCode status) { | |
170 last_worker_status_ = worker_->status(); | 178 last_worker_status_ = worker_->status(); |
171 EXPECT_EQ(SERVICE_WORKER_OK, status); | 179 EXPECT_EQ(SERVICE_WORKER_OK, status); |
172 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, last_worker_status_); | 180 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, last_worker_status_); |
173 | 181 |
174 if (status != SERVICE_WORKER_OK && !done_closure_.is_null()) | 182 if (status != SERVICE_WORKER_OK && !done_closure_.is_null()) |
175 done_closure_.Run(); | 183 done_closure_.Run(); |
176 } | 184 } |
177 | 185 |
178 void StopOnIOThread() { | 186 void StopOnIOThread() { |
179 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 187 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 version_ = new ServiceWorkerVersion( | 321 version_ = new ServiceWorkerVersion( |
314 registration_, | 322 registration_, |
315 wrapper()->context()->storage()->NewVersionId(), | 323 wrapper()->context()->storage()->NewVersionId(), |
316 wrapper()->context()->AsWeakPtr()); | 324 wrapper()->context()->AsWeakPtr()); |
317 AssociateRendererProcessToWorker(version_->embedded_worker()); | 325 AssociateRendererProcessToWorker(version_->embedded_worker()); |
318 } | 326 } |
319 | 327 |
320 void StartOnIOThread(const base::Closure& done, | 328 void StartOnIOThread(const base::Closure& done, |
321 ServiceWorkerStatusCode* result) { | 329 ServiceWorkerStatusCode* result) { |
322 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 330 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
323 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); | 331 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result), |
332 std::vector<int>()); | |
324 } | 333 } |
325 | 334 |
326 void InstallOnIOThread(const base::Closure& done, | 335 void InstallOnIOThread(const base::Closure& done, |
327 ServiceWorkerStatusCode* result) { | 336 ServiceWorkerStatusCode* result) { |
328 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 337 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
329 version_->DispatchInstallEvent( | 338 version_->DispatchInstallEvent( |
330 -1, CreateReceiver(BrowserThread::UI, done, result)); | 339 -1, CreateReceiver(BrowserThread::UI, done, result)); |
331 } | 340 } |
332 | 341 |
333 void ActivateOnIOThread(const base::Closure& done, | 342 void ActivateOnIOThread(const base::Closure& done, |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 run_loop.QuitClosure())); | 598 run_loop.QuitClosure())); |
590 run_loop.Run(); | 599 run_loop.Run(); |
591 } | 600 } |
592 | 601 |
593 // Register returns when the promise would be resolved. | 602 // Register returns when the promise would be resolved. |
594 { | 603 { |
595 base::RunLoop run_loop; | 604 base::RunLoop run_loop; |
596 public_context()->RegisterServiceWorker( | 605 public_context()->RegisterServiceWorker( |
597 embedded_test_server()->GetURL("/*"), | 606 embedded_test_server()->GetURL("/*"), |
598 embedded_test_server()->GetURL(kWorkerUrl), | 607 embedded_test_server()->GetURL(kWorkerUrl), |
599 RenderProcessID(), | 608 shell()->web_contents()->GetBrowserContext(), |
Jeffrey Yasskin
2014/04/25 04:40:33
Since the new ServiceWorker has no ProviderHosts,
| |
600 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun, | 609 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun, |
601 true, | 610 true, |
602 run_loop.QuitClosure())); | 611 run_loop.QuitClosure())); |
603 run_loop.Run(); | 612 run_loop.Run(); |
604 } | 613 } |
605 | 614 |
606 // Registering again should succeed, although the algo still | 615 // Registering again should succeed, although the algo still |
607 // might not be complete. | 616 // might not be complete. |
608 { | 617 { |
609 base::RunLoop run_loop; | 618 base::RunLoop run_loop; |
610 public_context()->RegisterServiceWorker( | 619 public_context()->RegisterServiceWorker( |
611 embedded_test_server()->GetURL("/*"), | 620 embedded_test_server()->GetURL("/*"), |
612 embedded_test_server()->GetURL(kWorkerUrl), | 621 embedded_test_server()->GetURL(kWorkerUrl), |
613 RenderProcessID(), | 622 shell()->web_contents()->GetBrowserContext(), |
614 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun, | 623 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun, |
615 true, | 624 true, |
616 run_loop.QuitClosure())); | 625 run_loop.QuitClosure())); |
617 run_loop.Run(); | 626 run_loop.Run(); |
618 } | 627 } |
619 | 628 |
620 // The registration algo might not be far enough along to have | 629 // The registration algo might not be far enough along to have |
621 // stored the registration data, so it may not be findable | 630 // stored the registration data, so it may not be findable |
622 // at this point. | 631 // at this point. |
623 | 632 |
(...skipping 17 matching lines...) Expand all Loading... | |
641 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, | 650 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, |
642 this, | 651 this, |
643 embedded_test_server()->GetURL("/service_worker/empty.html"), | 652 embedded_test_server()->GetURL("/service_worker/empty.html"), |
644 &status, | 653 &status, |
645 &script_url)); | 654 &script_url)); |
646 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); | 655 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); |
647 } | 656 } |
648 } | 657 } |
649 | 658 |
650 } // namespace content | 659 } // namespace content |
OLD | NEW |