Chromium Code Reviews| Index: content/browser/service_worker/service_worker_browsertest.cc |
| diff --git a/content/browser/service_worker/service_worker_browsertest.cc b/content/browser/service_worker/service_worker_browsertest.cc |
| index bf62e063391cbf2b957c0636fe12fa46b4155883..21d72527a641169e305ef0b63f6bc3edb381a21e 100644 |
| --- a/content/browser/service_worker/service_worker_browsertest.cc |
| +++ b/content/browser/service_worker/service_worker_browsertest.cc |
| @@ -22,6 +22,7 @@ |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/test/scoped_feature_list.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "base/time/time.h" |
| #include "build/build_config.h" |
| @@ -30,6 +31,7 @@ |
| #include "content/browser/cache_storage/cache_storage_cache_handle.h" |
| #include "content/browser/cache_storage/cache_storage_context_impl.h" |
| #include "content/browser/cache_storage/cache_storage_manager.h" |
| +#include "content/browser/memory/memory_coordinator.h" |
| #include "content/browser/service_worker/embedded_worker_instance.h" |
| #include "content/browser/service_worker/embedded_worker_registry.h" |
| #include "content/browser/service_worker/embedded_worker_status.h" |
| @@ -2937,6 +2939,62 @@ IN_PROC_BROWSER_TEST_P(ServiceWorkerDisableWebSecurityTest, UpdateNoCrash) { |
| RunTestWithCrossOriginURL(kPageUrl, kScopeUrl); |
| } |
| +class MemoryCoordinatorWithServiceWorkerTest |
| + : public ServiceWorkerVersionBrowserTest { |
| + public: |
| + MemoryCoordinatorWithServiceWorkerTest() {} |
| + |
| + void SetUp() override { |
| + scoped_feature_list_.InitAndEnableFeature(features::kMemoryCoordinator); |
| + ServiceWorkerVersionBrowserTest::SetUp(); |
| + } |
| + |
| + private: |
| + base::test::ScopedFeatureList scoped_feature_list_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorWithServiceWorkerTest); |
| +}; |
| + |
| +class TestMemoryCoordinatorDelegate : public MemoryCoordinatorDelegate { |
| + public: |
| + TestMemoryCoordinatorDelegate() {} |
| + ~TestMemoryCoordinatorDelegate() override {} |
| + |
| + bool CanSuspendBackgroundedRenderer(int render_process_id) override { |
| + return true; |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TestMemoryCoordinatorDelegate); |
| +}; |
| + |
| +#if !defined(OS_MACOSX) |
| +IN_PROC_BROWSER_TEST_P(MemoryCoordinatorWithServiceWorkerTest, |
| + CannotSuspendRendererWithServiceWorker) { |
| + StartServerAndNavigateToSetup(); |
| + ActivateTestHelper("/service_worker/fetch_event.js", SERVICE_WORKER_OK); |
| + |
| + auto* memory_coordinator = MemoryCoordinator::GetInstance(); |
| + memory_coordinator->SetDelegateForTesting( |
| + base::MakeUnique<TestMemoryCoordinatorDelegate>()); |
| + |
| + // Ensures only one process host exists. |
| + ASSERT_EQ(1, CountRenderProcessHosts()); |
| + ASSERT_EQ(1u, memory_coordinator->children().size()); |
| + |
| + // Checks the number of workers. |
| + int render_process_id = memory_coordinator->children().begin()->first; |
| + auto* rph = RenderProcessHost::FromID(render_process_id); |
| + EXPECT_EQ(1u, rph->GetWorkerRefCount()); |
|
nhiroki
2016/12/13 10:24:29
Can you check rph->IsProcessBackgrounded() before
shimazu
2016/12/14 06:18:35
Thanks, I forgot to set rph to background. Added.
|
| + |
| + // The process which has service worker thread shouldn't be suspended. |
| + EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id)); |
| +} |
| +INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, |
| + MemoryCoordinatorWithServiceWorkerTest, |
| + ::testing::Bool()); |
| +#endif |
| + |
| INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, |
| ServiceWorkerBrowserTest, |
| ::testing::Values(true, false)); |