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

Side by Side Diff: content/browser/memory/memory_coordinator_impl_browsertest.cc

Issue 2579233002: Merge MemoryCoordinator and MemoryCoordinatorImpl into one class (Closed)
Patch Set: addressed comments Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/memory/memory_coordinator.h" 5 #include "content/browser/memory/memory_coordinator_impl.h"
6 6
7 #include "base/test/scoped_feature_list.h" 7 #include "base/test/scoped_feature_list.h"
8 #include "content/browser/browser_main_loop.h" 8 #include "content/browser/browser_main_loop.h"
9 #include "content/public/common/content_features.h" 9 #include "content/public/common/content_features.h"
10 #include "content/public/test/content_browser_test.h" 10 #include "content/public/test/content_browser_test.h"
11 #include "content/public/test/content_browser_test_utils.h" 11 #include "content/public/test/content_browser_test_utils.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 class TestMemoryCoordinatorDelegate : public MemoryCoordinatorDelegate { 15 class TestMemoryCoordinatorDelegate : public MemoryCoordinatorDelegate {
16 public: 16 public:
17 TestMemoryCoordinatorDelegate() {} 17 TestMemoryCoordinatorDelegate() {}
18 ~TestMemoryCoordinatorDelegate() override {} 18 ~TestMemoryCoordinatorDelegate() override {}
19 19
20 bool CanSuspendBackgroundedRenderer(int render_process_id) override { 20 bool CanSuspendBackgroundedRenderer(int render_process_id) override {
21 return true; 21 return true;
22 } 22 }
23 23
24 private: 24 private:
25 DISALLOW_COPY_AND_ASSIGN(TestMemoryCoordinatorDelegate); 25 DISALLOW_COPY_AND_ASSIGN(TestMemoryCoordinatorDelegate);
26 }; 26 };
27 27
28 class MemoryCoordinatorTest : public ContentBrowserTest { 28 class MemoryCoordinatorImplBrowserTest : public ContentBrowserTest {
29 public: 29 public:
30 MemoryCoordinatorTest() {} 30 MemoryCoordinatorImplBrowserTest() {}
31 31
32 void SetUp() override { 32 void SetUp() override {
33 scoped_feature_list_.InitAndEnableFeature(features::kMemoryCoordinator); 33 scoped_feature_list_.InitAndEnableFeature(features::kMemoryCoordinator);
34 ContentBrowserTest::SetUp(); 34 ContentBrowserTest::SetUp();
35 } 35 }
36 36
37 private: 37 private:
38 base::test::ScopedFeatureList scoped_feature_list_; 38 base::test::ScopedFeatureList scoped_feature_list_;
39 39
40 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorTest); 40 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorImplBrowserTest);
41 }; 41 };
42 42
43 // TODO(bashi): Enable these tests on macos when MemoryMonitorMac is 43 // TODO(bashi): Enable these tests on macos when MemoryMonitorMac is
44 // implemented. 44 // implemented.
45 #if !defined(OS_MACOSX) 45 #if !defined(OS_MACOSX)
46 46
47 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorTest, HandleAdded) { 47 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorImplBrowserTest, HandleAdded) {
48 GURL url = GetTestUrl("", "simple_page.html"); 48 GURL url = GetTestUrl("", "simple_page.html");
49 NavigateToURL(shell(), url); 49 NavigateToURL(shell(), url);
50 EXPECT_EQ(1u, MemoryCoordinator::GetInstance()->children().size()); 50 size_t num_children = MemoryCoordinatorImpl::GetInstance()->children().size();
51 EXPECT_EQ(1u, num_children);
51 } 52 }
52 53
53 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorTest, CanSuspendRenderer) { 54 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorImplBrowserTest, CanSuspendRenderer) {
54 GURL url = GetTestUrl("", "simple_page.html"); 55 GURL url = GetTestUrl("", "simple_page.html");
55 NavigateToURL(shell(), url); 56 NavigateToURL(shell(), url);
56 auto* memory_coordinator = MemoryCoordinator::GetInstance(); 57 auto* memory_coordinator = MemoryCoordinatorImpl::GetInstance();
57 memory_coordinator->SetDelegateForTesting( 58 memory_coordinator->SetDelegateForTesting(
58 base::MakeUnique<TestMemoryCoordinatorDelegate>()); 59 base::MakeUnique<TestMemoryCoordinatorDelegate>());
59 EXPECT_EQ(1u, memory_coordinator->children().size()); 60 EXPECT_EQ(1u, memory_coordinator->children().size());
60 int render_process_id = memory_coordinator->children().begin()->first; 61 int render_process_id = memory_coordinator->children().begin()->first;
61 // Foreground tab cannot be suspended. 62 // Foreground tab cannot be suspended.
62 EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id)); 63 EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id));
63 } 64 }
64 65
65 #endif // !defined(OS_MACOSX) 66 #endif // !defined(OS_MACOSX)
66 67
67 } // namespace content 68 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_coordinator_impl.cc ('k') | content/browser/memory/memory_coordinator_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698