| 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 "content/browser/memory/memory_monitor.h" | 9 #include "content/browser/memory/memory_monitor.h" |
| 10 #include "content/public/test/memory_coordinator_test_utils.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 class MockMemoryCoordinatorClient : public base::MemoryCoordinatorClient { | 17 class MockMemoryCoordinatorClient : public base::MemoryCoordinatorClient { |
| 17 public: | 18 public: |
| 18 void OnMemoryStateChange(base::MemoryState state) override { | 19 void OnMemoryStateChange(base::MemoryState state) override { |
| 19 is_called_ = true; | 20 is_called_ = true; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 44 | 45 |
| 45 private: | 46 private: |
| 46 int free_memory_ = 0; | 47 int free_memory_ = 0; |
| 47 | 48 |
| 48 DISALLOW_COPY_AND_ASSIGN(MockMemoryMonitor); | 49 DISALLOW_COPY_AND_ASSIGN(MockMemoryMonitor); |
| 49 }; | 50 }; |
| 50 | 51 |
| 51 class MemoryCoordinatorImplTest : public testing::Test { | 52 class MemoryCoordinatorImplTest : public testing::Test { |
| 52 public: | 53 public: |
| 53 void SetUp() override { | 54 void SetUp() override { |
| 54 MemoryCoordinator::EnableFeaturesForTesting(); | 55 content::EnableMemoryCoordinatorFeaturesForTesting(); |
| 55 | 56 |
| 56 coordinator_.reset(new MemoryCoordinatorImpl( | 57 coordinator_.reset(new MemoryCoordinatorImpl( |
| 57 message_loop_.task_runner(), base::WrapUnique(new MockMemoryMonitor))); | 58 message_loop_.task_runner(), base::WrapUnique(new MockMemoryMonitor))); |
| 58 | 59 |
| 59 base::MemoryCoordinatorProxy::GetInstance()-> | 60 base::MemoryCoordinatorProxy::GetInstance()-> |
| 60 SetGetCurrentMemoryStateCallback(base::Bind( | 61 SetGetCurrentMemoryStateCallback(base::Bind( |
| 61 &MemoryCoordinator::GetCurrentMemoryState, | 62 &MemoryCoordinator::GetCurrentMemoryState, |
| 62 base::Unretained(coordinator_.get()))); | 63 base::Unretained(coordinator_.get()))); |
| 63 base::MemoryCoordinatorProxy::GetInstance()-> | 64 base::MemoryCoordinatorProxy::GetInstance()-> |
| 64 SetSetCurrentMemoryStateForTestingCallback(base::Bind( | 65 SetSetCurrentMemoryStateForTestingCallback(base::Bind( |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 base::MemoryCoordinatorProxy::GetInstance()-> | 208 base::MemoryCoordinatorProxy::GetInstance()-> |
| 208 GetCurrentMemoryState()); | 209 GetCurrentMemoryState()); |
| 209 base::RunLoop loop; | 210 base::RunLoop loop; |
| 210 loop.RunUntilIdle(); | 211 loop.RunUntilIdle(); |
| 211 EXPECT_TRUE(client.is_called()); | 212 EXPECT_TRUE(client.is_called()); |
| 212 EXPECT_EQ(base::MemoryState::THROTTLED, client.state()); | 213 EXPECT_EQ(base::MemoryState::THROTTLED, client.state()); |
| 213 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); | 214 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(&client); |
| 214 } | 215 } |
| 215 | 216 |
| 216 } // namespace content | 217 } // namespace content |
| OLD | NEW |