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

Unified Diff: content/browser/memory/memory_monitor_android_unittest.cc

Issue 2382623002: Add a test for MemoryMonitorAndroid::GetFreeMemoryUntilCriticalMB (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/memory/memory_monitor_android.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/memory/memory_monitor_android_unittest.cc
diff --git a/content/browser/memory/memory_monitor_android_unittest.cc b/content/browser/memory/memory_monitor_android_unittest.cc
index bb6e85c2da73469e6c8f4719864959e5f92923b0..7c62d5f16879e08010d0032bd30f2aefca3c9ece 100644
--- a/content/browser/memory/memory_monitor_android_unittest.cc
+++ b/content/browser/memory/memory_monitor_android_unittest.cc
@@ -4,16 +4,50 @@
#include "content/browser/memory/memory_monitor_android.h"
+#include "base/memory/ptr_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
+class MockMemoryMonitorAndroidDelegate : public MemoryMonitorAndroid::Delegate {
+ public:
+ MockMemoryMonitorAndroidDelegate() {}
+ ~MockMemoryMonitorAndroidDelegate() override {}
+
+ using MemoryInfo = MemoryMonitorAndroid::MemoryInfo;
+
+ void SetMemoryInfo(const MemoryInfo& info) {
+ memcpy(&memory_info_, &info, sizeof(memory_info_));
+ }
+
+ void GetMemoryInfo(MemoryInfo* out) override {
+ memcpy(out, &memory_info_, sizeof(memory_info_));
+ }
+
+ private:
+ MemoryInfo memory_info_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockMemoryMonitorAndroidDelegate);
+};
+
class MemoryMonitorAndroidTest : public testing::Test {
public:
- MemoryMonitorAndroidTest() : monitor_(MemoryMonitorAndroid::Create()) {}
+ MemoryMonitorAndroidTest() : monitor_(MemoryMonitorAndroid::Create()) {
+ auto mock_delegate = base::WrapUnique(new MockMemoryMonitorAndroidDelegate);
+ mocked_monitor_.reset(
+ new MemoryMonitorAndroid(std::move(mock_delegate)));
+ }
protected:
+ static const int kMBShift = 20;
+
+ MockMemoryMonitorAndroidDelegate* mock_delegate() {
+ return static_cast<MockMemoryMonitorAndroidDelegate*>(
+ mocked_monitor_->delegate());
+ }
+
std::unique_ptr<MemoryMonitorAndroid> monitor_;
+ std::unique_ptr<MemoryMonitorAndroid> mocked_monitor_;
};
TEST_F(MemoryMonitorAndroidTest, GetMemoryInfo) {
@@ -24,4 +58,15 @@ TEST_F(MemoryMonitorAndroidTest, GetMemoryInfo) {
EXPECT_GT(info.total_mem, 0);
}
+TEST_F(MemoryMonitorAndroidTest, GetFreeMemoryUntilCriticalMB) {
+ MemoryMonitorAndroid::MemoryInfo info = {
+ .avail_mem = 100 << kMBShift,
+ .low_memory = false,
+ .threshold = 80 << kMBShift,
+ .total_mem = 150 << kMBShift,
+ };
+ mock_delegate()->SetMemoryInfo(info);
+ EXPECT_EQ(20, mocked_monitor_->GetFreeMemoryUntilCriticalMB());
+}
+
} // namespace content
« 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