Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(790)

Side by Side Diff: content/browser/service_worker/service_worker_browsertest.cc

Issue 2941123004: Remove MemoryCoordinator::CanSuspendRenderer() (Closed)
Patch Set: Fix tests Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
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/test/scoped_feature_list.h"
26 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
27 #include "base/time/time.h" 27 #include "base/time/time.h"
28 #include "build/build_config.h" 28 #include "build/build_config.h"
29 #include "content/browser/blob_storage/chrome_blob_storage_context.h" 29 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
30 #include "content/browser/cache_storage/cache_storage_cache.h" 30 #include "content/browser/cache_storage/cache_storage_cache.h"
31 #include "content/browser/cache_storage/cache_storage_cache_handle.h" 31 #include "content/browser/cache_storage/cache_storage_cache_handle.h"
32 #include "content/browser/cache_storage/cache_storage_context_impl.h" 32 #include "content/browser/cache_storage/cache_storage_context_impl.h"
33 #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_impl.h"
35 #include "content/browser/service_worker/embedded_worker_instance.h" 34 #include "content/browser/service_worker/embedded_worker_instance.h"
36 #include "content/browser/service_worker/embedded_worker_registry.h" 35 #include "content/browser/service_worker/embedded_worker_registry.h"
37 #include "content/browser/service_worker/embedded_worker_status.h" 36 #include "content/browser/service_worker/embedded_worker_status.h"
38 #include "content/browser/service_worker/service_worker_context_core.h" 37 #include "content/browser/service_worker/service_worker_context_core.h"
39 #include "content/browser/service_worker/service_worker_context_core_observer.h" 38 #include "content/browser/service_worker/service_worker_context_core_observer.h"
40 #include "content/browser/service_worker/service_worker_context_wrapper.h" 39 #include "content/browser/service_worker/service_worker_context_wrapper.h"
41 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" 40 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
42 #include "content/browser/service_worker/service_worker_registration.h" 41 #include "content/browser/service_worker/service_worker_registration.h"
43 #include "content/browser/service_worker/service_worker_test_utils.h" 42 #include "content/browser/service_worker/service_worker_test_utils.h"
44 #include "content/browser/service_worker/service_worker_version.h" 43 #include "content/browser/service_worker/service_worker_version.h"
(...skipping 2920 matching lines...) Expand 10 before | Expand all | Expand 10 after
2965 2964
2966 IN_PROC_BROWSER_TEST_F(ServiceWorkerDisableWebSecurityTest, UpdateNoCrash) { 2965 IN_PROC_BROWSER_TEST_F(ServiceWorkerDisableWebSecurityTest, UpdateNoCrash) {
2967 StartServerAndNavigateToSetup(); 2966 StartServerAndNavigateToSetup();
2968 const char kPageUrl[] = "/service_worker/disable_web_security_update.html"; 2967 const char kPageUrl[] = "/service_worker/disable_web_security_update.html";
2969 const char kScopeUrl[] = "/service_worker/scope/"; 2968 const char kScopeUrl[] = "/service_worker/scope/";
2970 const char kWorkerUrl[] = "/service_worker/fetch_event_blob.js"; 2969 const char kWorkerUrl[] = "/service_worker/fetch_event_blob.js";
2971 RegisterServiceWorkerOnCrossOriginServer(kScopeUrl, kWorkerUrl); 2970 RegisterServiceWorkerOnCrossOriginServer(kScopeUrl, kWorkerUrl);
2972 RunTestWithCrossOriginURL(kPageUrl, kScopeUrl); 2971 RunTestWithCrossOriginURL(kPageUrl, kScopeUrl);
2973 } 2972 }
2974 2973
2975 class MemoryCoordinatorWithServiceWorkerTest
2976 : public ServiceWorkerVersionBrowserTest {
2977 public:
2978 MemoryCoordinatorWithServiceWorkerTest() {}
2979
2980 void SetUp() override {
2981 scoped_feature_list_.InitAndEnableFeature(features::kMemoryCoordinator);
2982 ServiceWorkerVersionBrowserTest::SetUp();
2983 }
2984
2985 private:
2986 base::test::ScopedFeatureList scoped_feature_list_;
2987
2988 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorWithServiceWorkerTest);
2989 };
2990
2991 class TestMemoryCoordinatorDelegate : public MemoryCoordinatorDelegate {
2992 public:
2993 TestMemoryCoordinatorDelegate() {}
2994 ~TestMemoryCoordinatorDelegate() override {}
2995
2996 bool CanSuspendBackgroundedRenderer(int render_process_id) override {
2997 return true;
2998 }
2999
3000 private:
3001 DISALLOW_COPY_AND_ASSIGN(TestMemoryCoordinatorDelegate);
3002 };
3003
3004 // MemoryCoordinatorWithServiceWorkerTest checks if a process won't be
3005 // suspended when it has one or more shared workers or service workers.
3006 // TODO(shimazu): Enable these tests on macos when MemoryMonitorMac is
3007 // implemented.
3008 #if !defined(OS_MACOSX)
3009 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorWithServiceWorkerTest,
3010 CannotSuspendRendererWithServiceWorker) {
3011 StartServerAndNavigateToSetup();
3012 InstallTestHelper("/service_worker/fetch_event.js", SERVICE_WORKER_OK);
3013 ActivateTestHelper("/service_worker/fetch_event.js", SERVICE_WORKER_OK);
3014
3015 MemoryCoordinatorImpl* memory_coordinator =
3016 MemoryCoordinatorImpl::GetInstance();
3017 memory_coordinator->SetDelegateForTesting(
3018 base::MakeUnique<TestMemoryCoordinatorDelegate>());
3019
3020 // Ensure only one process host exists.
3021 ASSERT_EQ(1, CountRenderProcessHosts());
3022 ASSERT_EQ(1u, memory_coordinator->children().size());
3023
3024 // Check the number of workers.
3025 int render_process_id = memory_coordinator->children().begin()->first;
3026 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
3027 EXPECT_EQ(1u, rph->GetWorkerRefCount());
3028
3029 // A process should be backgrounded to ensure the worker reference count takes
3030 // effect in CanSuspendRenderer().
3031 shell()->web_contents()->WasHidden();
3032 EXPECT_TRUE(rph->IsProcessBackgrounded());
3033
3034 // The process which has service worker thread shouldn't be suspended.
3035 EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id));
3036 }
3037 #endif
3038
3039 } // namespace content 2974 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_coordinator_impl_unittest.cc ('k') | content/public/browser/memory_coordinator_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698