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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
21 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 25 #include "base/test/scoped_feature_list.h" |
25 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
26 #include "base/time/time.h" | 27 #include "base/time/time.h" |
27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
28 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 29 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
29 #include "content/browser/cache_storage/cache_storage_cache.h" | 30 #include "content/browser/cache_storage/cache_storage_cache.h" |
30 #include "content/browser/cache_storage/cache_storage_cache_handle.h" | 31 #include "content/browser/cache_storage/cache_storage_cache_handle.h" |
31 #include "content/browser/cache_storage/cache_storage_context_impl.h" | 32 #include "content/browser/cache_storage/cache_storage_context_impl.h" |
32 #include "content/browser/cache_storage/cache_storage_manager.h" | 33 #include "content/browser/cache_storage/cache_storage_manager.h" |
| 34 #include "content/browser/memory/memory_coordinator.h" |
33 #include "content/browser/service_worker/embedded_worker_instance.h" | 35 #include "content/browser/service_worker/embedded_worker_instance.h" |
34 #include "content/browser/service_worker/embedded_worker_registry.h" | 36 #include "content/browser/service_worker/embedded_worker_registry.h" |
35 #include "content/browser/service_worker/embedded_worker_status.h" | 37 #include "content/browser/service_worker/embedded_worker_status.h" |
36 #include "content/browser/service_worker/service_worker_context_core.h" | 38 #include "content/browser/service_worker/service_worker_context_core.h" |
37 #include "content/browser/service_worker/service_worker_context_observer.h" | 39 #include "content/browser/service_worker/service_worker_context_observer.h" |
38 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 40 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
39 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" | 41 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" |
40 #include "content/browser/service_worker/service_worker_registration.h" | 42 #include "content/browser/service_worker/service_worker_registration.h" |
41 #include "content/browser/service_worker/service_worker_test_utils.h" | 43 #include "content/browser/service_worker/service_worker_test_utils.h" |
42 #include "content/browser/service_worker/service_worker_version.h" | 44 #include "content/browser/service_worker/service_worker_version.h" |
(...skipping 2887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2930 | 2932 |
2931 IN_PROC_BROWSER_TEST_P(ServiceWorkerDisableWebSecurityTest, UpdateNoCrash) { | 2933 IN_PROC_BROWSER_TEST_P(ServiceWorkerDisableWebSecurityTest, UpdateNoCrash) { |
2932 StartServerAndNavigateToSetup(); | 2934 StartServerAndNavigateToSetup(); |
2933 const char kPageUrl[] = "/service_worker/disable_web_security_update.html"; | 2935 const char kPageUrl[] = "/service_worker/disable_web_security_update.html"; |
2934 const char kScopeUrl[] = "/service_worker/scope/"; | 2936 const char kScopeUrl[] = "/service_worker/scope/"; |
2935 const char kWorkerUrl[] = "/service_worker/fetch_event_blob.js"; | 2937 const char kWorkerUrl[] = "/service_worker/fetch_event_blob.js"; |
2936 RegisterServiceWorkerOnCrossOriginServer(kScopeUrl, kWorkerUrl); | 2938 RegisterServiceWorkerOnCrossOriginServer(kScopeUrl, kWorkerUrl); |
2937 RunTestWithCrossOriginURL(kPageUrl, kScopeUrl); | 2939 RunTestWithCrossOriginURL(kPageUrl, kScopeUrl); |
2938 } | 2940 } |
2939 | 2941 |
| 2942 class MemoryCoordinatorWithServiceWorkerTest |
| 2943 : public ServiceWorkerVersionBrowserTest { |
| 2944 public: |
| 2945 MemoryCoordinatorWithServiceWorkerTest() {} |
| 2946 |
| 2947 void SetUp() override { |
| 2948 scoped_feature_list_.InitAndEnableFeature(features::kMemoryCoordinator); |
| 2949 ServiceWorkerVersionBrowserTest::SetUp(); |
| 2950 } |
| 2951 |
| 2952 private: |
| 2953 base::test::ScopedFeatureList scoped_feature_list_; |
| 2954 |
| 2955 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorWithServiceWorkerTest); |
| 2956 }; |
| 2957 |
| 2958 class TestMemoryCoordinatorDelegate : public MemoryCoordinatorDelegate { |
| 2959 public: |
| 2960 TestMemoryCoordinatorDelegate() {} |
| 2961 ~TestMemoryCoordinatorDelegate() override {} |
| 2962 |
| 2963 bool CanSuspendBackgroundedRenderer(int render_process_id) override { |
| 2964 return true; |
| 2965 } |
| 2966 |
| 2967 private: |
| 2968 DISALLOW_COPY_AND_ASSIGN(TestMemoryCoordinatorDelegate); |
| 2969 }; |
| 2970 |
| 2971 #if !defined(OS_MACOSX) |
| 2972 IN_PROC_BROWSER_TEST_P(MemoryCoordinatorWithServiceWorkerTest, |
| 2973 CannotSuspendRendererWithServiceWorker) { |
| 2974 StartServerAndNavigateToSetup(); |
| 2975 ActivateTestHelper("/service_worker/fetch_event.js", SERVICE_WORKER_OK); |
| 2976 |
| 2977 auto* memory_coordinator = MemoryCoordinator::GetInstance(); |
| 2978 memory_coordinator->SetDelegateForTesting( |
| 2979 base::MakeUnique<TestMemoryCoordinatorDelegate>()); |
| 2980 |
| 2981 // Ensures only one process host exists. |
| 2982 ASSERT_EQ(1, CountRenderProcessHosts()); |
| 2983 ASSERT_EQ(1u, memory_coordinator->children().size()); |
| 2984 |
| 2985 // Checks the number of workers. |
| 2986 int render_process_id = memory_coordinator->children().begin()->first; |
| 2987 auto* rph = RenderProcessHost::FromID(render_process_id); |
| 2988 EXPECT_EQ(1u, rph->GetWorkerRefCount()); |
| 2989 |
| 2990 // A process should be backgrounded to ensure the worker reference count takes |
| 2991 // effect in CanSuspendRenderer(). |
| 2992 shell()->web_contents()->WasHidden(); |
| 2993 EXPECT_TRUE(rph->IsProcessBackgrounded()); |
| 2994 |
| 2995 // The process which has service worker thread shouldn't be suspended. |
| 2996 EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id)); |
| 2997 } |
| 2998 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, |
| 2999 MemoryCoordinatorWithServiceWorkerTest, |
| 3000 ::testing::Bool()); |
| 3001 #endif |
| 3002 |
2940 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, | 3003 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, |
2941 ServiceWorkerBrowserTest, | 3004 ServiceWorkerBrowserTest, |
2942 ::testing::Values(true, false)); | 3005 ::testing::Values(true, false)); |
2943 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, | 3006 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, |
2944 ServiceWorkerVersionBrowserV8CacheTest, | 3007 ServiceWorkerVersionBrowserV8CacheTest, |
2945 ::testing::Values(true, false)); | 3008 ::testing::Values(true, false)); |
2946 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, | 3009 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, |
2947 ServiceWorkerVersionBrowserTest, | 3010 ServiceWorkerVersionBrowserTest, |
2948 ::testing::Values(true, false)); | 3011 ::testing::Values(true, false)); |
2949 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, | 3012 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, |
(...skipping 12 matching lines...) Expand all Loading... |
2962 ServiceWorkerV8CacheStrategiesNormalTest, | 3025 ServiceWorkerV8CacheStrategiesNormalTest, |
2963 ::testing::Values(true, false)); | 3026 ::testing::Values(true, false)); |
2964 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, | 3027 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, |
2965 ServiceWorkerV8CacheStrategiesAggressiveTest, | 3028 ServiceWorkerV8CacheStrategiesAggressiveTest, |
2966 ::testing::Values(true, false)); | 3029 ::testing::Values(true, false)); |
2967 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, | 3030 INSTANTIATE_TEST_CASE_P(ServiceWorkerBrowserTest, |
2968 ServiceWorkerDisableWebSecurityTest, | 3031 ServiceWorkerDisableWebSecurityTest, |
2969 ::testing::Values(true, false)); | 3032 ::testing::Values(true, false)); |
2970 | 3033 |
2971 } // namespace content | 3034 } // namespace content |
OLD | NEW |