| Index: content/browser/memory/memory_monitor_mac_unittest.cc
|
| diff --git a/content/browser/memory/memory_monitor_mac_unittest.cc b/content/browser/memory/memory_monitor_mac_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f75d11a6aa0576803de8b03018aea4887cc92ce3
|
| --- /dev/null
|
| +++ b/content/browser/memory/memory_monitor_mac_unittest.cc
|
| @@ -0,0 +1,99 @@
|
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/memory/memory_monitor_mac.h"
|
| +
|
| +#include "content/browser/memory/test_memory_monitor.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +// A delegate that allows mocking the various inputs to MemoryMonitorMac.
|
| +class TestMemoryMonitorMacDelegate : public TestMemoryMonitorDelegate {
|
| + public:
|
| + TestMemoryMonitorMacDelegate() {}
|
| +
|
| + void SetFreeMemoryKB(int free_kb) { mem_info_.free = free_kb; }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(TestMemoryMonitorMacDelegate);
|
| +};
|
| +
|
| +class TestMemoryMonitorMac : public MemoryMonitorMac {};
|
| +
|
| +static const int kKBperMB = 1024;
|
| +
|
| +} // namespace
|
| +
|
| +class MemoryMonitorMacTest : public testing::Test {
|
| + public:
|
| + TestMemoryMonitorMacDelegate delegate_;
|
| + std::unique_ptr<MemoryMonitorMac> monitor_;
|
| +};
|
| +
|
| +TEST_F(MemoryMonitorMacTest, Create) {
|
| + delegate_.SetTotalMemoryKB(100000 * kKBperMB);
|
| + monitor_ = MemoryMonitorMac::Create(&delegate_);
|
| + EXPECT_EQ(0U, delegate_.calls());
|
| +}
|
| +
|
| +TEST_F(MemoryMonitorMacTest, GetFreeMemoryUntilCriticalMB) {
|
| + delegate_.SetTotalMemoryKB(1000 * kKBperMB);
|
| + delegate_.SetMemoryPressure(DISPATCH_MEMORYPRESSURE_NORMAL);
|
| +
|
| + monitor_.reset(new MemoryMonitorMac(&delegate_));
|
| + EXPECT_EQ(0u, delegate_.calls());
|
| +
|
| + delegate_.SetFreeMemoryKB(64 * kKBperMB);
|
| + EXPECT_EQ(64, monitor_->GetFreeMemoryUntilCriticalMB());
|
| + EXPECT_EQ(2U, delegate_.calls());
|
| + delegate_.ResetCalls();
|
| +
|
| + delegate_.SetFreeMemoryKB(64 * kKBperMB);
|
| + delegate_.SetMemoryPressure(DISPATCH_MEMORYPRESSURE_WARN);
|
| + EXPECT_EQ(32, monitor_->GetFreeMemoryUntilCriticalMB());
|
| + EXPECT_EQ(2U, delegate_.calls());
|
| + delegate_.ResetCalls();
|
| + EXPECT_EQ(31, monitor_->GetFreeMemoryUntilCriticalMB());
|
| + EXPECT_EQ(2U, delegate_.calls());
|
| + delegate_.ResetCalls();
|
| + EXPECT_EQ(30, monitor_->GetFreeMemoryUntilCriticalMB());
|
| + EXPECT_EQ(2U, delegate_.calls());
|
| + delegate_.ResetCalls();
|
| +
|
| + delegate_.SetMemoryPressure(DISPATCH_MEMORYPRESSURE_NORMAL);
|
| + EXPECT_EQ(31, monitor_->GetFreeMemoryUntilCriticalMB());
|
| + EXPECT_EQ(2U, delegate_.calls());
|
| + delegate_.ResetCalls();
|
| + EXPECT_EQ(32, monitor_->GetFreeMemoryUntilCriticalMB());
|
| + EXPECT_EQ(2U, delegate_.calls());
|
| + delegate_.ResetCalls();
|
| + EXPECT_EQ(33, monitor_->GetFreeMemoryUntilCriticalMB());
|
| + EXPECT_EQ(2U, delegate_.calls());
|
| + delegate_.ResetCalls();
|
| +
|
| + delegate_.SetFreeMemoryKB(64 * kKBperMB);
|
| + delegate_.SetMemoryPressure(DISPATCH_MEMORYPRESSURE_CRITICAL);
|
| + EXPECT_EQ(0, monitor_->GetFreeMemoryUntilCriticalMB());
|
| + EXPECT_EQ(2U, delegate_.calls());
|
| + delegate_.ResetCalls();
|
| + EXPECT_EQ(0, monitor_->GetFreeMemoryUntilCriticalMB());
|
| + EXPECT_EQ(2U, delegate_.calls());
|
| + delegate_.ResetCalls();
|
| +
|
| + delegate_.SetMemoryPressure(DISPATCH_MEMORYPRESSURE_NORMAL);
|
| + EXPECT_EQ(1, monitor_->GetFreeMemoryUntilCriticalMB());
|
| + EXPECT_EQ(2U, delegate_.calls());
|
| + delegate_.ResetCalls();
|
| + EXPECT_EQ(2, monitor_->GetFreeMemoryUntilCriticalMB());
|
| + EXPECT_EQ(2U, delegate_.calls());
|
| + delegate_.ResetCalls();
|
| + EXPECT_EQ(3, monitor_->GetFreeMemoryUntilCriticalMB());
|
| + EXPECT_EQ(2U, delegate_.calls());
|
| + delegate_.ResetCalls();
|
| +}
|
| +
|
| +} // namespace content
|
|
|