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_impl.h" | 5 #include "content/browser/memory/memory_coordinator_impl.h" |
6 | 6 |
7 #include "base/memory/memory_coordinator_proxy.h" | 7 #include "base/memory/memory_coordinator_proxy.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/test/scoped_feature_list.h" |
9 #include "content/browser/memory/memory_monitor.h" | 10 #include "content/browser/memory/memory_monitor.h" |
| 11 #include "content/public/common/content_features.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 | 13 |
12 namespace content { | 14 namespace content { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 class MockMemoryCoordinatorClient : public base::MemoryCoordinatorClient { | 18 class MockMemoryCoordinatorClient : public base::MemoryCoordinatorClient { |
17 public: | 19 public: |
18 void OnMemoryStateChange(base::MemoryState state) override { | 20 void OnMemoryStateChange(base::MemoryState state) override { |
19 is_called_ = true; | 21 is_called_ = true; |
(...skipping 24 matching lines...) Expand all Loading... |
44 | 46 |
45 private: | 47 private: |
46 int free_memory_ = 0; | 48 int free_memory_ = 0; |
47 | 49 |
48 DISALLOW_COPY_AND_ASSIGN(MockMemoryMonitor); | 50 DISALLOW_COPY_AND_ASSIGN(MockMemoryMonitor); |
49 }; | 51 }; |
50 | 52 |
51 class MemoryCoordinatorImplTest : public testing::Test { | 53 class MemoryCoordinatorImplTest : public testing::Test { |
52 public: | 54 public: |
53 void SetUp() override { | 55 void SetUp() override { |
54 MemoryCoordinator::EnableFeaturesForTesting(); | 56 scoped_feature_list_.InitAndEnableFeature(features::kMemoryCoordinator); |
55 | 57 |
56 coordinator_.reset(new MemoryCoordinatorImpl( | 58 coordinator_.reset(new MemoryCoordinatorImpl( |
57 message_loop_.task_runner(), base::WrapUnique(new MockMemoryMonitor))); | 59 message_loop_.task_runner(), base::WrapUnique(new MockMemoryMonitor))); |
58 | 60 |
59 base::MemoryCoordinatorProxy::GetInstance()-> | 61 base::MemoryCoordinatorProxy::GetInstance()-> |
60 SetGetCurrentMemoryStateCallback(base::Bind( | 62 SetGetCurrentMemoryStateCallback(base::Bind( |
61 &MemoryCoordinator::GetCurrentMemoryState, | 63 &MemoryCoordinator::GetCurrentMemoryState, |
62 base::Unretained(coordinator_.get()))); | 64 base::Unretained(coordinator_.get()))); |
63 base::MemoryCoordinatorProxy::GetInstance()-> | 65 base::MemoryCoordinatorProxy::GetInstance()-> |
64 SetSetCurrentMemoryStateForTestingCallback(base::Bind( | 66 SetSetCurrentMemoryStateForTestingCallback(base::Bind( |
65 &MemoryCoordinator::SetCurrentMemoryStateForTesting, | 67 &MemoryCoordinator::SetCurrentMemoryStateForTesting, |
66 base::Unretained(coordinator_.get()))); | 68 base::Unretained(coordinator_.get()))); |
67 } | 69 } |
68 | 70 |
69 MockMemoryMonitor* GetMockMemoryMonitor() { | 71 MockMemoryMonitor* GetMockMemoryMonitor() { |
70 return static_cast<MockMemoryMonitor*>(coordinator_->memory_monitor()); | 72 return static_cast<MockMemoryMonitor*>(coordinator_->memory_monitor()); |
71 } | 73 } |
72 | 74 |
73 protected: | 75 protected: |
74 std::unique_ptr<MemoryCoordinatorImpl> coordinator_; | 76 std::unique_ptr<MemoryCoordinatorImpl> coordinator_; |
75 base::MessageLoop message_loop_; | 77 base::MessageLoop message_loop_; |
| 78 base::test::ScopedFeatureList scoped_feature_list_; |
76 }; | 79 }; |
77 | 80 |
78 TEST_F(MemoryCoordinatorImplTest, CalculateNextState) { | 81 TEST_F(MemoryCoordinatorImplTest, CalculateNextState) { |
79 coordinator_->expected_renderer_size_ = 10; | 82 coordinator_->expected_renderer_size_ = 10; |
80 coordinator_->new_renderers_until_throttled_ = 4; | 83 coordinator_->new_renderers_until_throttled_ = 4; |
81 coordinator_->new_renderers_until_suspended_ = 2; | 84 coordinator_->new_renderers_until_suspended_ = 2; |
82 coordinator_->new_renderers_back_to_normal_ = 5; | 85 coordinator_->new_renderers_back_to_normal_ = 5; |
83 coordinator_->new_renderers_back_to_throttled_ = 3; | 86 coordinator_->new_renderers_back_to_throttled_ = 3; |
84 DCHECK(coordinator_->ValidateParameters()); | 87 DCHECK(coordinator_->ValidateParameters()); |
85 | 88 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 base::MemoryCoordinatorProxy::GetInstance()-> | 210 base::MemoryCoordinatorProxy::GetInstance()-> |
208 GetCurrentMemoryState()); | 211 GetCurrentMemoryState()); |
209 base::RunLoop loop; | 212 base::RunLoop loop; |
210 loop.RunUntilIdle(); | 213 loop.RunUntilIdle(); |
211 EXPECT_TRUE(client.is_called()); | 214 EXPECT_TRUE(client.is_called()); |
212 EXPECT_EQ(base::MemoryState::THROTTLED, client.state()); | 215 EXPECT_EQ(base::MemoryState::THROTTLED, client.state()); |
213 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); | 216 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); |
214 } | 217 } |
215 | 218 |
216 } // namespace content | 219 } // namespace content |
OLD | NEW |