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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 scoped_ptr<storage::BlobDataHandle> blob_data_handle; | 55 scoped_ptr<storage::BlobDataHandle> blob_data_handle; |
56 }; | 56 }; |
57 | 57 |
58 void RunAndQuit(const base::Closure& closure, | 58 void RunAndQuit(const base::Closure& closure, |
59 const base::Closure& quit, | 59 const base::Closure& quit, |
60 base::MessageLoopProxy* original_message_loop) { | 60 base::MessageLoopProxy* original_message_loop) { |
61 closure.Run(); | 61 closure.Run(); |
62 original_message_loop->PostTask(FROM_HERE, quit); | 62 original_message_loop->PostTask(FROM_HERE, quit); |
63 } | 63 } |
64 | 64 |
65 void RunOnIOThreadWithDelay(const base::Closure& closure, | |
66 base::TimeDelta delay) { | |
67 base::RunLoop run_loop; | |
68 BrowserThread::PostDelayedTask( | |
69 BrowserThread::IO, FROM_HERE, | |
70 base::Bind(&RunAndQuit, closure, run_loop.QuitClosure(), | |
71 base::MessageLoopProxy::current()), | |
72 delay); | |
73 run_loop.Run(); | |
74 } | |
75 | |
65 void RunOnIOThread(const base::Closure& closure) { | 76 void RunOnIOThread(const base::Closure& closure) { |
66 base::RunLoop run_loop; | 77 base::RunLoop run_loop; |
67 BrowserThread::PostTask( | 78 BrowserThread::PostTask( |
68 BrowserThread::IO, FROM_HERE, | 79 BrowserThread::IO, FROM_HERE, |
69 base::Bind(&RunAndQuit, closure, run_loop.QuitClosure(), | 80 base::Bind(&RunAndQuit, closure, run_loop.QuitClosure(), |
70 base::MessageLoopProxy::current())); | 81 base::MessageLoopProxy::current())); |
kinuko
2015/02/18 13:06:24
nit: this could just call RunOnIOThreadWithDelay w
falken
2015/02/23 05:00:06
Done.
| |
71 run_loop.Run(); | 82 run_loop.Run(); |
72 } | 83 } |
73 | 84 |
74 void RunOnIOThread( | 85 void RunOnIOThread( |
75 const base::Callback<void(const base::Closure& continuation)>& closure) { | 86 const base::Callback<void(const base::Closure& continuation)>& closure) { |
76 base::RunLoop run_loop; | 87 base::RunLoop run_loop; |
77 base::Closure quit_on_original_thread = | 88 base::Closure quit_on_original_thread = |
78 base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask), | 89 base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask), |
79 base::MessageLoopProxy::current().get(), | 90 base::MessageLoopProxy::current().get(), |
80 FROM_HERE, | 91 FROM_HERE, |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 wrapper()->context()->storage()->NewRegistrationId(), | 526 wrapper()->context()->storage()->NewRegistrationId(), |
516 wrapper()->context()->AsWeakPtr()); | 527 wrapper()->context()->AsWeakPtr()); |
517 version_ = new ServiceWorkerVersion( | 528 version_ = new ServiceWorkerVersion( |
518 registration_.get(), | 529 registration_.get(), |
519 embedded_test_server()->GetURL(worker_url), | 530 embedded_test_server()->GetURL(worker_url), |
520 wrapper()->context()->storage()->NewVersionId(), | 531 wrapper()->context()->storage()->NewVersionId(), |
521 wrapper()->context()->AsWeakPtr()); | 532 wrapper()->context()->AsWeakPtr()); |
522 AssociateRendererProcessToPattern(pattern); | 533 AssociateRendererProcessToPattern(pattern); |
523 } | 534 } |
524 | 535 |
536 void TimeoutWorkerOnIOThread() { | |
537 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
538 version_->PingWorker(); | |
539 version_->OnPingTimeout(); | |
540 } | |
541 | |
525 void StartOnIOThread(const base::Closure& done, | 542 void StartOnIOThread(const base::Closure& done, |
526 ServiceWorkerStatusCode* result) { | 543 ServiceWorkerStatusCode* result) { |
527 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 544 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
528 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); | 545 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); |
529 } | 546 } |
530 | 547 |
531 void InstallOnIOThread(const base::Closure& done, | 548 void InstallOnIOThread(const base::Closure& done, |
532 ServiceWorkerStatusCode* result) { | 549 ServiceWorkerStatusCode* result) { |
533 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 550 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
534 version_->SetStatus(ServiceWorkerVersion::INSTALLING); | 551 version_->SetStatus(ServiceWorkerVersion::INSTALLING); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 ActivateTestHelper("/service_worker/worker_activate_rejected.js", | 709 ActivateTestHelper("/service_worker/worker_activate_rejected.js", |
693 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); | 710 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); |
694 } | 711 } |
695 | 712 |
696 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, | 713 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, |
697 InstallWithWaitUntil_Rejected) { | 714 InstallWithWaitUntil_Rejected) { |
698 InstallTestHelper("/service_worker/worker_install_rejected.js", | 715 InstallTestHelper("/service_worker/worker_install_rejected.js", |
699 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); | 716 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); |
700 } | 717 } |
701 | 718 |
719 class WaitForLoaded : public EmbeddedWorkerInstance::Listener { | |
720 public: | |
721 WaitForLoaded(const base::Closure& quit) : quit_(quit) {} | |
722 | |
723 void OnScriptLoaded() override { | |
724 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_); | |
725 } | |
726 bool OnMessageReceived(const IPC::Message& message) override { return false; } | |
727 | |
728 private: | |
729 base::Closure quit_; | |
730 }; | |
731 | |
732 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, TimeoutStartingWorker) { | |
733 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, | |
734 "/service_worker/while_true_worker.js")); | |
735 | |
736 // Start a worker, waiting until the script is loaded. | |
737 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | |
738 base::RunLoop start_run_loop; | |
739 base::RunLoop load_run_loop; | |
740 WaitForLoaded wait_for_load(load_run_loop.QuitClosure()); | |
741 version_->embedded_worker()->AddListener(&wait_for_load); | |
742 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
743 base::Bind(&self::StartOnIOThread, this, | |
744 start_run_loop.QuitClosure(), &status)); | |
745 load_run_loop.Run(); | |
746 version_->embedded_worker()->RemoveListener(&wait_for_load); | |
747 | |
748 // The script has loaded but start has not completed yet. | |
749 ASSERT_EQ(SERVICE_WORKER_ERROR_FAILED, status); | |
750 EXPECT_EQ(ServiceWorkerVersion::STARTING, version_->running_status()); | |
751 | |
752 // Simulate execution timeout. Use a delay to prevent killing the worker | |
753 // before it's started execution. | |
754 EXPECT_TRUE(version_->ping_worker_timer_.IsRunning()); | |
755 RunOnIOThreadWithDelay(base::Bind(&self::TimeoutWorkerOnIOThread, this), | |
756 base::TimeDelta::FromMilliseconds(100)); | |
757 start_run_loop.Run(); | |
758 | |
759 EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); | |
760 } | |
761 | |
762 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, TimeoutWorkerInEvent) { | |
763 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, | |
764 "/service_worker/while_true_in_install_worker.js")); | |
765 | |
766 // Start a worker. | |
767 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | |
768 base::RunLoop start_run_loop; | |
769 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
770 base::Bind(&self::StartOnIOThread, this, | |
771 start_run_loop.QuitClosure(), &status)); | |
772 start_run_loop.Run(); | |
773 ASSERT_EQ(SERVICE_WORKER_OK, status); | |
774 | |
775 // Dispatch an event. | |
776 base::RunLoop install_run_loop; | |
777 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
778 base::Bind(&self::InstallOnIOThread, this, | |
779 install_run_loop.QuitClosure(), &status)); | |
780 | |
781 // Simulate execution timeout. Use a delay to prevent killing the worker | |
782 // before it's started execution. | |
783 EXPECT_TRUE(version_->ping_worker_timer_.IsRunning()); | |
784 RunOnIOThreadWithDelay(base::Bind(&self::TimeoutWorkerOnIOThread, this), | |
785 base::TimeDelta::FromMilliseconds(100)); | |
786 install_run_loop.Run(); | |
787 | |
788 EXPECT_EQ(SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED, status); | |
789 } | |
790 | |
702 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Response) { | 791 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Response) { |
703 ServiceWorkerFetchEventResult result; | 792 ServiceWorkerFetchEventResult result; |
704 ServiceWorkerResponse response; | 793 ServiceWorkerResponse response; |
705 scoped_ptr<storage::BlobDataHandle> blob_data_handle; | 794 scoped_ptr<storage::BlobDataHandle> blob_data_handle; |
706 FetchTestHelper("/service_worker/fetch_event.js", | 795 FetchTestHelper("/service_worker/fetch_event.js", |
707 &result, &response, &blob_data_handle); | 796 &result, &response, &blob_data_handle); |
708 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); | 797 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); |
709 EXPECT_EQ(301, response.status_code); | 798 EXPECT_EQ(301, response.status_code); |
710 EXPECT_EQ("Moved Permanently", response.status_text); | 799 EXPECT_EQ("Moved Permanently", response.status_text); |
711 ServiceWorkerHeaderMap expected_headers; | 800 ServiceWorkerHeaderMap expected_headers; |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1040 const base::string16 kOKTitle2(base::ASCIIToUTF16("OK_2")); | 1129 const base::string16 kOKTitle2(base::ASCIIToUTF16("OK_2")); |
1041 const base::string16 kFailTitle2(base::ASCIIToUTF16("FAIL_2")); | 1130 const base::string16 kFailTitle2(base::ASCIIToUTF16("FAIL_2")); |
1042 content::TitleWatcher title_watcher2(shell()->web_contents(), kOKTitle2); | 1131 content::TitleWatcher title_watcher2(shell()->web_contents(), kOKTitle2); |
1043 title_watcher2.AlsoWaitForTitle(kFailTitle2); | 1132 title_watcher2.AlsoWaitForTitle(kFailTitle2); |
1044 | 1133 |
1045 NavigateToURL(shell(), embedded_test_server()->GetURL(kConfirmPageUrl)); | 1134 NavigateToURL(shell(), embedded_test_server()->GetURL(kConfirmPageUrl)); |
1046 EXPECT_EQ(kOKTitle2, title_watcher2.WaitAndGetTitle()); | 1135 EXPECT_EQ(kOKTitle2, title_watcher2.WaitAndGetTitle()); |
1047 } | 1136 } |
1048 | 1137 |
1049 } // namespace content | 1138 } // namespace content |
OLD | NEW |