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

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

Issue 2552603002: Add tests for MemoryCoordinator::Can{Throttle,Suspend}Renderer() (Closed)
Patch Set: Fix unittests 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.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 {
16 public:
17 TestMemoryCoordinatorDelegate() {}
18 ~TestMemoryCoordinatorDelegate() override {}
19
20 bool CanSuspendBackgroundedRenderer(int render_process_id) override {
21 return true;
22 }
23
24 private:
25 DISALLOW_COPY_AND_ASSIGN(TestMemoryCoordinatorDelegate);
26 };
27
15 class MemoryCoordinatorTest : public ContentBrowserTest { 28 class MemoryCoordinatorTest : public ContentBrowserTest {
16 public: 29 public:
17 MemoryCoordinatorTest() {} 30 MemoryCoordinatorTest() {}
18 31
19 void SetUp() override { 32 void SetUp() override {
20 scoped_feature_list_.InitAndEnableFeature(features::kMemoryCoordinator); 33 scoped_feature_list_.InitAndEnableFeature(features::kMemoryCoordinator);
21 ContentBrowserTest::SetUp(); 34 ContentBrowserTest::SetUp();
22 } 35 }
23 36
24 private: 37 private:
25 base::test::ScopedFeatureList scoped_feature_list_; 38 base::test::ScopedFeatureList scoped_feature_list_;
26 39
27 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorTest); 40 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorTest);
28 }; 41 };
29 42
30 // TODO(bashi): Enable this test on macos when MemoryMonitorMac is implemented. 43 // TODO(bashi): Enable these tests on macos when MemoryMonitorMac is
31 #if defined(OS_MACOSX) 44 // implemented.
32 #define MAYBE_HandleAdded DISABLED_HandleAdded 45 #if !defined(OS_MACOSX)
33 #else 46
34 #define MAYBE_HandleAdded HandleAdded 47 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorTest, HandleAdded) {
35 #endif
36 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorTest, MAYBE_HandleAdded) {
37 GURL url = GetTestUrl("", "simple_page.html"); 48 GURL url = GetTestUrl("", "simple_page.html");
38 NavigateToURL(shell(), url); 49 NavigateToURL(shell(), url);
39 EXPECT_EQ(1u, MemoryCoordinator::GetInstance()->NumChildrenForTesting()); 50 EXPECT_EQ(1u, MemoryCoordinator::GetInstance()->children().size());
40 } 51 }
41 52
53 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorTest, CanSuspendRenderer) {
54 GURL url = GetTestUrl("", "simple_page.html");
55 NavigateToURL(shell(), url);
56 auto* memory_coordinator = MemoryCoordinator::GetInstance();
57 memory_coordinator->SetDelegateForTesting(
58 base::MakeUnique<TestMemoryCoordinatorDelegate>());
59 EXPECT_EQ(1u, memory_coordinator->children().size());
60 int render_process_id = memory_coordinator->children().begin()->first;
61 // Foreground tab cannot be suspended.
62 EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id));
63 }
64
65 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorTest, CanThrottleRenderer) {
66 GURL url = GetTestUrl("", "simple_page.html");
67 NavigateToURL(shell(), url);
68 auto* memory_coordinator = MemoryCoordinator::GetInstance();
69 memory_coordinator->SetDelegateForTesting(
70 base::MakeUnique<TestMemoryCoordinatorDelegate>());
71 EXPECT_EQ(1u, memory_coordinator->children().size());
72 int render_process_id = memory_coordinator->children().begin()->first;
73 // Foreground tab cannot be throttled.
74 EXPECT_FALSE(memory_coordinator->CanThrottleRenderer(render_process_id));
75 }
76
77 #endif // !defined(OS_MACOSX)
78
42 } // namespace content 79 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_coordinator.cc ('k') | content/browser/memory/memory_coordinator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698