OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/memory/memory_monitor_chromeos.h" |
| 6 |
| 7 #include "content/browser/memory/test_memory_monitor.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 12 namespace { |
| 13 |
| 14 // A delegate that allows mocking the various inputs to MemoryMonitorChromeOS. |
| 15 class TestMemoryMonitorChromeOSDelegate : public TestMemoryMonitorDelegate { |
| 16 public: |
| 17 TestMemoryMonitorChromeOSDelegate() {} |
| 18 |
| 19 void SetFreeMemoryKB(int free_kb, |
| 20 int swap_kb, |
| 21 int active_kb, |
| 22 int inactive_kb, |
| 23 int dirty_kb) { |
| 24 mem_info_.free = free_kb; |
| 25 mem_info_.swap_free = swap_kb; |
| 26 mem_info_.active_file = active_kb; |
| 27 mem_info_.inactive_file = inactive_kb; |
| 28 mem_info_.dirty = dirty_kb; |
| 29 } |
| 30 |
| 31 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(TestMemoryMonitorChromeOSDelegate); |
| 33 }; |
| 34 |
| 35 class TestMemoryMonitorChromeOS : public MemoryMonitorChromeOS {}; |
| 36 |
| 37 static const int kKBperMB = 1024; |
| 38 |
| 39 } // namespace |
| 40 |
| 41 class MemoryMonitorChromeOSTest : public testing::Test { |
| 42 public: |
| 43 TestMemoryMonitorChromeOSDelegate delegate_; |
| 44 std::unique_ptr<MemoryMonitorChromeOS> monitor_; |
| 45 }; |
| 46 |
| 47 TEST_F(MemoryMonitorChromeOSTest, Create) { |
| 48 delegate_.SetTotalMemoryKB(100000 * kKBperMB); |
| 49 monitor_ = MemoryMonitorChromeOS::Create(&delegate_); |
| 50 EXPECT_EQ(0U, delegate_.calls()); |
| 51 } |
| 52 |
| 53 TEST_F(MemoryMonitorChromeOSTest, GetFreeMemoryUntilCriticalMB) { |
| 54 delegate_.SetTotalMemoryKB(1000 * kKBperMB); |
| 55 |
| 56 monitor_.reset(new MemoryMonitorChromeOS(&delegate_)); |
| 57 EXPECT_EQ(0u, delegate_.calls()); |
| 58 |
| 59 delegate_.SetFreeMemoryKB(256 * kKBperMB, 128 * kKBperMB, 64 * kKBperMB, |
| 60 32 * kKBperMB, 16 * kKBperMB); |
| 61 EXPECT_EQ(318, monitor_->GetFreeMemoryUntilCriticalMB()); |
| 62 EXPECT_EQ(1U, delegate_.calls()); |
| 63 } |
| 64 |
| 65 } // namespace content |
OLD | NEW |