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

Side by Side Diff: components/memory_pressure/direct_memory_pressure_calculator_win_unittest.cc

Issue 2558043007: Fix free memory calculation. (Closed)
Patch Set: Fix integer overflow in unittest. Created 3 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/memory_pressure/direct_memory_pressure_calculator_win.h" 5 #include "components/memory_pressure/direct_memory_pressure_calculator_win.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/process/process_metrics.h" 8 #include "base/process/process_metrics.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 if (large_memory) 52 if (large_memory)
53 return total_mb * 2; 53 return total_mb * 2;
54 return total_mb / 2; 54 return total_mb / 2;
55 } 55 }
56 56
57 // Sets up the memory status to reflect the provided absolute memory left. 57 // Sets up the memory status to reflect the provided absolute memory left.
58 void SetMemoryFree(int phys_left_mb) { 58 void SetMemoryFree(int phys_left_mb) {
59 // |total| is set in the constructor and not modified. 59 // |total| is set in the constructor and not modified.
60 60
61 // Set the amount of free memory. 61 // Set the amount of free memory.
62 mem_info_.free = phys_left_mb * kKBperMB; 62 mem_info_.avail_phys = phys_left_mb * kKBperMB;
63 DCHECK_LT(mem_info_.free, mem_info_.total); 63 DCHECK_LT(mem_info_.avail_phys, mem_info_.total);
64 } 64 }
65 65
66 void SetNone() { SetMemoryFree(moderate_threshold_mb() + 1); } 66 void SetNone() { SetMemoryFree(moderate_threshold_mb() + 1); }
67 67
68 void SetModerate() { SetMemoryFree(moderate_threshold_mb() - 1); } 68 void SetModerate() { SetMemoryFree(moderate_threshold_mb() - 1); }
69 69
70 void SetCritical() { SetMemoryFree(critical_threshold_mb() - 1); } 70 void SetCritical() { SetMemoryFree(critical_threshold_mb() - 1); }
71 71
72 private: 72 private:
73 bool GetSystemMemoryInfo(base::SystemMemoryInfoKB* mem_info) const override { 73 bool GetSystemMemoryInfo(base::SystemMemoryInfoKB* mem_info) const override {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 EXPECT_EQ(kModerateMb, calc.moderate_threshold_mb()); 173 EXPECT_EQ(kModerateMb, calc.moderate_threshold_mb());
174 EXPECT_EQ(kCriticalMb, calc.critical_threshold_mb()); 174 EXPECT_EQ(kCriticalMb, calc.critical_threshold_mb());
175 175
176 ASSERT_NO_FATAL_FAILURE(CalculateCurrentPressureLevelTest(&calc)); 176 ASSERT_NO_FATAL_FAILURE(CalculateCurrentPressureLevelTest(&calc));
177 } 177 }
178 178
179 #endif // defined(MEMORY_PRESSURE_IS_POLLING) 179 #endif // defined(MEMORY_PRESSURE_IS_POLLING)
180 180
181 } // namespace memory_pressure 181 } // namespace memory_pressure
OLDNEW
« no previous file with comments | « components/memory_pressure/direct_memory_pressure_calculator_win.cc ('k') | content/browser/memory/memory_monitor_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698