Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: content/browser/memory/memory_monitor_android_unittest.cc

Issue 2382623002: Add a test for MemoryMonitorAndroid::GetFreeMemoryUntilCriticalMB (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/memory/memory_monitor_android.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_android.h" 5 #include "content/browser/memory/memory_monitor_android.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 9
9 namespace content { 10 namespace content {
10 11
12 class MockMemoryMonitorAndroidDelegate : public MemoryMonitorAndroid::Delegate {
13 public:
14 MockMemoryMonitorAndroidDelegate() {}
15 ~MockMemoryMonitorAndroidDelegate() override {}
16
17 using MemoryInfo = MemoryMonitorAndroid::MemoryInfo;
18
19 void SetMemoryInfo(const MemoryInfo& info) {
20 memcpy(&memory_info_, &info, sizeof(memory_info_));
21 }
22
23 void GetMemoryInfo(MemoryInfo* out) override {
24 memcpy(out, &memory_info_, sizeof(memory_info_));
25 }
26
27 private:
28 MemoryInfo memory_info_;
29
30 DISALLOW_COPY_AND_ASSIGN(MockMemoryMonitorAndroidDelegate);
31 };
32
11 class MemoryMonitorAndroidTest : public testing::Test { 33 class MemoryMonitorAndroidTest : public testing::Test {
12 public: 34 public:
13 MemoryMonitorAndroidTest() : monitor_(MemoryMonitorAndroid::Create()) {} 35 MemoryMonitorAndroidTest() : monitor_(MemoryMonitorAndroid::Create()) {
36 auto mock_delegate = base::WrapUnique(new MockMemoryMonitorAndroidDelegate);
37 mocked_monitor_.reset(
38 new MemoryMonitorAndroid(std::move(mock_delegate)));
39 }
14 40
15 protected: 41 protected:
42 static const int kMBShift = 20;
43
44 MockMemoryMonitorAndroidDelegate* mock_delegate() {
45 return static_cast<MockMemoryMonitorAndroidDelegate*>(
46 mocked_monitor_->delegate());
47 }
48
16 std::unique_ptr<MemoryMonitorAndroid> monitor_; 49 std::unique_ptr<MemoryMonitorAndroid> monitor_;
50 std::unique_ptr<MemoryMonitorAndroid> mocked_monitor_;
17 }; 51 };
18 52
19 TEST_F(MemoryMonitorAndroidTest, GetMemoryInfo) { 53 TEST_F(MemoryMonitorAndroidTest, GetMemoryInfo) {
20 MemoryMonitorAndroid::MemoryInfo info; 54 MemoryMonitorAndroid::MemoryInfo info;
21 monitor_->GetMemoryInfo(&info); 55 monitor_->GetMemoryInfo(&info);
22 EXPECT_GT(info.avail_mem, 0); 56 EXPECT_GT(info.avail_mem, 0);
23 EXPECT_GT(info.threshold, 0); 57 EXPECT_GT(info.threshold, 0);
24 EXPECT_GT(info.total_mem, 0); 58 EXPECT_GT(info.total_mem, 0);
25 } 59 }
26 60
61 TEST_F(MemoryMonitorAndroidTest, GetFreeMemoryUntilCriticalMB) {
62 MemoryMonitorAndroid::MemoryInfo info = {
63 .avail_mem = 100 << kMBShift,
64 .low_memory = false,
65 .threshold = 80 << kMBShift,
66 .total_mem = 150 << kMBShift,
67 };
68 mock_delegate()->SetMemoryInfo(info);
69 EXPECT_EQ(20, mocked_monitor_->GetFreeMemoryUntilCriticalMB());
70 }
71
27 } // namespace content 72 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_monitor_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698