Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 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_monitor_chromeos.h" | 5 #include "content/browser/memory/memory_monitor_chromeos.h" |
| 6 | 6 |
| 7 #include "content/browser/memory/test_memory_monitor.h" | 7 #include "content/browser/memory/test_memory_monitor.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // A delegate that allows mocking the various inputs to MemoryMonitorChromeOS. | 14 // A delegate that allows mocking the various inputs to MemoryMonitorChromeOS. |
| 15 class TestMemoryMonitorChromeOSDelegate : public TestMemoryMonitorDelegate { | 15 class TestMemoryMonitorChromeOSDelegate : public TestMemoryMonitorDelegate { |
| 16 public: | 16 public: |
| 17 TestMemoryMonitorChromeOSDelegate() {} | 17 TestMemoryMonitorChromeOSDelegate() {} |
| 18 | 18 |
| 19 void SetFreeMemoryKB(int free_kb, | 19 void SetFreeMemoryKB(int free_kb, |
| 20 int swap_kb, | 20 int swap_kb, |
| 21 int active_kb, | 21 int active_kb, |
| 22 int inactive_kb, | 22 int inactive_kb, |
| 23 int dirty_kb) { | 23 int dirty_kb, |
| 24 int available_kb) { | |
| 24 mem_info_.free = free_kb; | 25 mem_info_.free = free_kb; |
| 25 mem_info_.swap_free = swap_kb; | 26 mem_info_.swap_free = swap_kb; |
| 26 mem_info_.active_file = active_kb; | 27 mem_info_.active_file = active_kb; |
| 27 mem_info_.inactive_file = inactive_kb; | 28 mem_info_.inactive_file = inactive_kb; |
| 28 mem_info_.dirty = dirty_kb; | 29 mem_info_.dirty = dirty_kb; |
| 30 mem_info_.available = available_kb; | |
| 29 } | 31 } |
| 30 | 32 |
| 31 private: | 33 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(TestMemoryMonitorChromeOSDelegate); | 34 DISALLOW_COPY_AND_ASSIGN(TestMemoryMonitorChromeOSDelegate); |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 class TestMemoryMonitorChromeOS : public MemoryMonitorChromeOS {}; | 37 class TestMemoryMonitorChromeOS : public MemoryMonitorChromeOS {}; |
| 36 | 38 |
| 37 static const int kKBperMB = 1024; | 39 static const int kKBperMB = 1024; |
| 38 | 40 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 49 monitor_ = MemoryMonitorChromeOS::Create(&delegate_); | 51 monitor_ = MemoryMonitorChromeOS::Create(&delegate_); |
| 50 EXPECT_EQ(0U, delegate_.calls()); | 52 EXPECT_EQ(0U, delegate_.calls()); |
| 51 } | 53 } |
| 52 | 54 |
| 53 TEST_F(MemoryMonitorChromeOSTest, GetFreeMemoryUntilCriticalMB) { | 55 TEST_F(MemoryMonitorChromeOSTest, GetFreeMemoryUntilCriticalMB) { |
| 54 delegate_.SetTotalMemoryKB(1000 * kKBperMB); | 56 delegate_.SetTotalMemoryKB(1000 * kKBperMB); |
| 55 | 57 |
| 56 monitor_.reset(new MemoryMonitorChromeOS(&delegate_)); | 58 monitor_.reset(new MemoryMonitorChromeOS(&delegate_)); |
| 57 EXPECT_EQ(0u, delegate_.calls()); | 59 EXPECT_EQ(0u, delegate_.calls()); |
| 58 | 60 |
| 61 // |available| is supported. | |
| 59 delegate_.SetFreeMemoryKB(256 * kKBperMB, 128 * kKBperMB, 64 * kKBperMB, | 62 delegate_.SetFreeMemoryKB(256 * kKBperMB, 128 * kKBperMB, 64 * kKBperMB, |
| 60 32 * kKBperMB, 16 * kKBperMB); | 63 32 * kKBperMB, 16 * kKBperMB, 512 * kKBperMB); |
|
Wez
2017/03/08 01:59:06
Consider passing in more obviously-wrong values fo
bashi
2017/03/10 01:59:10
Done.
| |
| 61 EXPECT_EQ(318, monitor_->GetFreeMemoryUntilCriticalMB()); | 64 EXPECT_EQ(512, monitor_->GetFreeMemoryUntilCriticalMB()); |
| 62 EXPECT_EQ(1U, delegate_.calls()); | 65 EXPECT_EQ(1U, delegate_.calls()); |
| 66 | |
| 67 // |available| is not supported. | |
|
Wez
2017/03/08 01:59:05
It seems it would be useful to verify here that th
bashi
2017/03/10 01:59:10
Done.
| |
| 68 delegate_.SetFreeMemoryKB(256 * kKBperMB, 128 * kKBperMB, 64 * kKBperMB, | |
| 69 32 * kKBperMB, 16 * kKBperMB, 0 * kKBperMB); | |
| 70 EXPECT_EQ(286, monitor_->GetFreeMemoryUntilCriticalMB()); | |
| 71 EXPECT_EQ(2U, delegate_.calls()); | |
| 63 } | 72 } |
| 64 | 73 |
| 65 } // namespace content | 74 } // namespace content |
| OLD | NEW |