Chromium Code Reviews| OLD | NEW |
|---|---|
| 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)); | |
|
bashi
2016/12/05 00:04:19
Not directly related to this CL but we might want
| |
| 75 } | |
| 76 | |
| 77 #endif // !defined(OS_MACOSX) | |
| 78 | |
| 42 } // namespace content | 79 } // namespace content |
| OLD | NEW |