Chromium Code Reviews| 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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 10 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 worker_.reset(); | 328 worker_.reset(); |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 void StartOnIOThread() { | 332 void StartOnIOThread() { |
| 333 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 333 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 334 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker(); | 334 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker(); |
| 335 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status()); | 335 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status()); |
| 336 worker_->AddListener(this); | 336 worker_->AddListener(this); |
| 337 | 337 |
| 338 | |
| 339 const int64 service_worker_version_id = 33L; | 338 const int64 service_worker_version_id = 33L; |
| 340 const GURL pattern = embedded_test_server()->GetURL("/"); | 339 const GURL pattern = embedded_test_server()->GetURL("/"); |
| 341 const GURL script_url = embedded_test_server()->GetURL( | 340 const GURL script_url = embedded_test_server()->GetURL( |
| 342 "/service_worker/worker.js"); | 341 "/service_worker/worker.js"); |
| 343 AssociateRendererProcessToPattern(pattern); | 342 AssociateRendererProcessToPattern(pattern); |
| 344 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); | 343 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); |
| 345 wrapper()->process_manager()->AddProcessReferenceToPattern( | 344 wrapper()->process_manager()->AddProcessReferenceToPattern( |
| 346 pattern, process_id); | 345 pattern, process_id); |
| 347 worker_->Start( | 346 worker_->Start( |
| 348 service_worker_version_id, | 347 service_worker_version_id, |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 wrapper()->context()->storage()->NewRegistrationId(), | 514 wrapper()->context()->storage()->NewRegistrationId(), |
| 516 wrapper()->context()->AsWeakPtr()); | 515 wrapper()->context()->AsWeakPtr()); |
| 517 version_ = new ServiceWorkerVersion( | 516 version_ = new ServiceWorkerVersion( |
| 518 registration_.get(), | 517 registration_.get(), |
| 519 embedded_test_server()->GetURL(worker_url), | 518 embedded_test_server()->GetURL(worker_url), |
| 520 wrapper()->context()->storage()->NewVersionId(), | 519 wrapper()->context()->storage()->NewVersionId(), |
| 521 wrapper()->context()->AsWeakPtr()); | 520 wrapper()->context()->AsWeakPtr()); |
| 522 AssociateRendererProcessToPattern(pattern); | 521 AssociateRendererProcessToPattern(pattern); |
| 523 } | 522 } |
| 524 | 523 |
| 524 void StartWorker(ServiceWorkerStatusCode expected_status) { | |
| 525 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 526 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | |
| 527 base::RunLoop start_run_loop; | |
| 528 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 529 base::Bind(&self::StartOnIOThread, this, | |
| 530 start_run_loop.QuitClosure(), | |
| 531 &status)); | |
| 532 start_run_loop.Run(); | |
| 533 ASSERT_EQ(expected_status, status); | |
| 534 } | |
| 535 | |
| 536 void StopWorker(ServiceWorkerStatusCode expected_status) { | |
| 537 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 538 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | |
| 539 base::RunLoop stop_run_loop; | |
| 540 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 541 base::Bind(&self::StopOnIOThread, this, | |
| 542 stop_run_loop.QuitClosure(), | |
| 543 &status)); | |
| 544 stop_run_loop.Run(); | |
| 545 ASSERT_EQ(expected_status, status); | |
| 546 } | |
| 547 | |
| 525 void StartOnIOThread(const base::Closure& done, | 548 void StartOnIOThread(const base::Closure& done, |
| 526 ServiceWorkerStatusCode* result) { | 549 ServiceWorkerStatusCode* result) { |
| 527 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 550 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 528 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); | 551 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); |
| 529 } | 552 } |
| 530 | 553 |
| 531 void InstallOnIOThread(const base::Closure& done, | 554 void InstallOnIOThread(const base::Closure& done, |
| 532 ServiceWorkerStatusCode* result) { | 555 ServiceWorkerStatusCode* result) { |
| 533 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 556 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 534 version_->SetStatus(ServiceWorkerVersion::INSTALLING); | 557 version_->SetStatus(ServiceWorkerVersion::INSTALLING); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 &status)); | 669 &status)); |
| 647 stop_run_loop.Run(); | 670 stop_run_loop.Run(); |
| 648 ASSERT_EQ(SERVICE_WORKER_OK, status); | 671 ASSERT_EQ(SERVICE_WORKER_OK, status); |
| 649 } | 672 } |
| 650 | 673 |
| 651 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartNotFound) { | 674 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartNotFound) { |
| 652 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, | 675 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, |
| 653 "/service_worker/nonexistent.js")); | 676 "/service_worker/nonexistent.js")); |
| 654 | 677 |
| 655 // Start a worker for nonexistent URL. | 678 // Start a worker for nonexistent URL. |
| 656 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 679 StartWorker(SERVICE_WORKER_ERROR_START_WORKER_FAILED); |
| 657 base::RunLoop start_run_loop; | |
| 658 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 659 base::Bind(&self::StartOnIOThread, this, | |
| 660 start_run_loop.QuitClosure(), | |
| 661 &status)); | |
| 662 start_run_loop.Run(); | |
| 663 ASSERT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); | |
| 664 } | 680 } |
| 665 | 681 |
| 666 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) { | 682 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) { |
| 667 InstallTestHelper("/service_worker/worker.js", SERVICE_WORKER_OK); | 683 InstallTestHelper("/service_worker/worker.js", SERVICE_WORKER_OK); |
| 668 } | 684 } |
| 669 | 685 |
| 670 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, | 686 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, |
| 671 InstallWithWaitUntil_Fulfilled) { | 687 InstallWithWaitUntil_Fulfilled) { |
| 672 InstallTestHelper("/service_worker/worker_install_fulfilled.js", | 688 InstallTestHelper("/service_worker/worker_install_fulfilled.js", |
| 673 SERVICE_WORKER_OK); | 689 SERVICE_WORKER_OK); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1039 "cross_site_xfer_confirm_via_serviceworker.html"; | 1055 "cross_site_xfer_confirm_via_serviceworker.html"; |
| 1040 const base::string16 kOKTitle2(base::ASCIIToUTF16("OK_2")); | 1056 const base::string16 kOKTitle2(base::ASCIIToUTF16("OK_2")); |
| 1041 const base::string16 kFailTitle2(base::ASCIIToUTF16("FAIL_2")); | 1057 const base::string16 kFailTitle2(base::ASCIIToUTF16("FAIL_2")); |
| 1042 content::TitleWatcher title_watcher2(shell()->web_contents(), kOKTitle2); | 1058 content::TitleWatcher title_watcher2(shell()->web_contents(), kOKTitle2); |
| 1043 title_watcher2.AlsoWaitForTitle(kFailTitle2); | 1059 title_watcher2.AlsoWaitForTitle(kFailTitle2); |
| 1044 | 1060 |
| 1045 NavigateToURL(shell(), embedded_test_server()->GetURL(kConfirmPageUrl)); | 1061 NavigateToURL(shell(), embedded_test_server()->GetURL(kConfirmPageUrl)); |
| 1046 EXPECT_EQ(kOKTitle2, title_watcher2.WaitAndGetTitle()); | 1062 EXPECT_EQ(kOKTitle2, title_watcher2.WaitAndGetTitle()); |
| 1047 } | 1063 } |
| 1048 | 1064 |
| 1065 class ServiceWorkerVersionBrowserV8CacheTest | |
| 1066 : public ServiceWorkerVersionBrowserTest, | |
| 1067 public ServiceWorkerVersion::Listener { | |
| 1068 public: | |
| 1069 typedef ServiceWorkerVersionBrowserV8CacheTest self; | |
|
kinuko
2015/02/24 05:21:39
nit: typedef -> using in new code?
horo
2015/02/24 06:15:52
Done.
| |
| 1070 ~ServiceWorkerVersionBrowserV8CacheTest() override { | |
| 1071 if (version_) | |
| 1072 version_->RemoveListener(this); | |
| 1073 } | |
| 1074 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 1075 ServiceWorkerBrowserTest::SetUpCommandLine(command_line); | |
| 1076 command_line->AppendSwitchASCII(switches::kV8CacheOptions, "code"); | |
| 1077 } | |
| 1078 void SetUpRegistrationAndListenerOnIOThread(const std::string& worker_url) { | |
| 1079 SetUpRegistrationOnIOThread(worker_url); | |
| 1080 version_->AddListener(this); | |
| 1081 } | |
| 1082 | |
| 1083 protected: | |
| 1084 // ServiceWorkerVersion::Listener overrides | |
| 1085 void OnCachedMetadataUpdated(ServiceWorkerVersion* version) override { | |
| 1086 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 1087 cache_updated_closure_); | |
| 1088 } | |
| 1089 | |
| 1090 base::Closure cache_updated_closure_; | |
| 1091 }; | |
| 1092 | |
| 1093 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserV8CacheTest, Restart) { | |
| 1094 RunOnIOThread(base::Bind(&self::SetUpRegistrationAndListenerOnIOThread, this, | |
| 1095 "/service_worker/worker.js")); | |
| 1096 | |
| 1097 base::RunLoop cached_metadata_run_loop; | |
| 1098 cache_updated_closure_ = cached_metadata_run_loop.QuitClosure(); | |
| 1099 | |
| 1100 // Start a worker. | |
| 1101 StartWorker(SERVICE_WORKER_OK); | |
| 1102 // Wait for the matadata is stored. | |
| 1103 cached_metadata_run_loop.Run(); | |
|
kinuko
2015/02/24 05:21:39
nit: please insert an empty line here, and add a c
horo
2015/02/24 06:15:53
Done.
| |
| 1104 // Activate the worker. | |
| 1105 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | |
| 1106 base::RunLoop acrivate_run_loop; | |
| 1107 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 1108 base::Bind(&self::ActivateOnIOThread, this, | |
| 1109 acrivate_run_loop.QuitClosure(), &status)); | |
| 1110 acrivate_run_loop.Run(); | |
| 1111 ASSERT_EQ(SERVICE_WORKER_OK, status); | |
| 1112 // Stop the worker. | |
| 1113 StopWorker(SERVICE_WORKER_OK); | |
| 1114 // Restart the worker. | |
| 1115 StartWorker(SERVICE_WORKER_OK); | |
| 1116 // Stop the worker. | |
| 1117 StopWorker(SERVICE_WORKER_OK); | |
| 1118 } | |
| 1119 | |
| 1049 } // namespace content | 1120 } // namespace content |
| OLD | NEW |