| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 | 566 |
| 567 class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest { | 567 class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest { |
| 568 public: | 568 public: |
| 569 using self = ServiceWorkerVersionBrowserTest; | 569 using self = ServiceWorkerVersionBrowserTest; |
| 570 | 570 |
| 571 ~ServiceWorkerVersionBrowserTest() override {} | 571 ~ServiceWorkerVersionBrowserTest() override {} |
| 572 | 572 |
| 573 void TearDownOnIOThread() override { | 573 void TearDownOnIOThread() override { |
| 574 registration_ = NULL; | 574 registration_ = NULL; |
| 575 version_ = NULL; | 575 version_ = NULL; |
| 576 remote_endpoints_.clear(); |
| 576 } | 577 } |
| 577 | 578 |
| 578 void InstallTestHelper(const std::string& worker_url, | 579 void InstallTestHelper(const std::string& worker_url, |
| 579 ServiceWorkerStatusCode expected_status) { | 580 ServiceWorkerStatusCode expected_status) { |
| 580 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, | 581 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, |
| 581 base::Unretained(this), worker_url)); | 582 base::Unretained(this), worker_url)); |
| 582 | 583 |
| 583 // Dispatch install on a worker. | 584 // Dispatch install on a worker. |
| 584 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 585 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
| 585 base::RunLoop install_run_loop; | 586 base::RunLoop install_run_loop; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 AssociateRendererProcessToPattern(pattern); | 662 AssociateRendererProcessToPattern(pattern); |
| 662 } | 663 } |
| 663 | 664 |
| 664 void TimeoutWorkerOnIOThread() { | 665 void TimeoutWorkerOnIOThread() { |
| 665 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 666 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 666 version_->SimulatePingTimeoutForTesting(); | 667 version_->SimulatePingTimeoutForTesting(); |
| 667 } | 668 } |
| 668 | 669 |
| 669 void AddControlleeOnIOThread() { | 670 void AddControlleeOnIOThread() { |
| 670 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 671 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 672 remote_endpoints_.emplace_back(); |
| 671 std::unique_ptr<ServiceWorkerProviderHost> host = | 673 std::unique_ptr<ServiceWorkerProviderHost> host = |
| 672 CreateProviderHostForWindow(33 /* dummy render process id */, | 674 CreateProviderHostForWindow( |
| 673 1 /* dummy provider_id */, | 675 33 /* dummy render process id */, 1 /* dummy provider_id */, |
| 674 true /* is_parent_frame_secure */, | 676 true /* is_parent_frame_secure */, |
| 675 wrapper()->context()->AsWeakPtr()); | 677 wrapper()->context()->AsWeakPtr(), &remote_endpoints_.back()); |
| 676 host->SetDocumentUrl( | 678 host->SetDocumentUrl( |
| 677 embedded_test_server()->GetURL("/service_worker/host")); | 679 embedded_test_server()->GetURL("/service_worker/host")); |
| 678 host->AssociateRegistration(registration_.get(), | 680 host->AssociateRegistration(registration_.get(), |
| 679 false /* notify_controllerchange */); | 681 false /* notify_controllerchange */); |
| 680 wrapper()->context()->AddProviderHost(std::move(host)); | 682 wrapper()->context()->AddProviderHost(std::move(host)); |
| 681 } | 683 } |
| 682 | 684 |
| 683 void AddWaitingWorkerOnIOThread(const std::string& worker_url) { | 685 void AddWaitingWorkerOnIOThread(const std::string& worker_url) { |
| 684 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 686 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 685 scoped_refptr<ServiceWorkerVersion> waiting_version( | 687 scoped_refptr<ServiceWorkerVersion> waiting_version( |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 ServiceWorkerStatusCode* result) { | 914 ServiceWorkerStatusCode* result) { |
| 913 ASSERT_TRUE(version_.get()); | 915 ASSERT_TRUE(version_.get()); |
| 914 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); | 916 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); |
| 915 } | 917 } |
| 916 | 918 |
| 917 protected: | 919 protected: |
| 918 scoped_refptr<ServiceWorkerRegistration> registration_; | 920 scoped_refptr<ServiceWorkerRegistration> registration_; |
| 919 scoped_refptr<ServiceWorkerVersion> version_; | 921 scoped_refptr<ServiceWorkerVersion> version_; |
| 920 scoped_refptr<ChromeBlobStorageContext> blob_context_; | 922 scoped_refptr<ChromeBlobStorageContext> blob_context_; |
| 921 std::unique_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_; | 923 std::unique_ptr<ServiceWorkerFetchDispatcher> fetch_dispatcher_; |
| 924 std::vector<ServiceWorkerRemoteProviderEndpoint> remote_endpoints_; |
| 922 }; | 925 }; |
| 923 | 926 |
| 924 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartAndStop) { | 927 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartAndStop) { |
| 925 StartServerAndNavigateToSetup(); | 928 StartServerAndNavigateToSetup(); |
| 926 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, | 929 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, |
| 927 base::Unretained(this), | 930 base::Unretained(this), |
| 928 "/service_worker/worker.js")); | 931 "/service_worker/worker.js")); |
| 929 | 932 |
| 930 // Start a worker. | 933 // Start a worker. |
| 931 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 934 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
| (...skipping 2096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3028 // effect in CanSuspendRenderer(). | 3031 // effect in CanSuspendRenderer(). |
| 3029 shell()->web_contents()->WasHidden(); | 3032 shell()->web_contents()->WasHidden(); |
| 3030 EXPECT_TRUE(rph->IsProcessBackgrounded()); | 3033 EXPECT_TRUE(rph->IsProcessBackgrounded()); |
| 3031 | 3034 |
| 3032 // The process which has service worker thread shouldn't be suspended. | 3035 // The process which has service worker thread shouldn't be suspended. |
| 3033 EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id)); | 3036 EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id)); |
| 3034 } | 3037 } |
| 3035 #endif | 3038 #endif |
| 3036 | 3039 |
| 3037 } // namespace content | 3040 } // namespace content |
| OLD | NEW |