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

Unified Diff: ios/chrome/browser/memory/memory_wedge_unittest.cc

Issue 1107963002: Add MemoryWedge to ios/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback. Created 5 years, 8 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 | « ios/chrome/browser/memory/memory_wedge.cc ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/memory/memory_wedge_unittest.cc
diff --git a/ios/chrome/browser/memory/memory_wedge_unittest.cc b/ios/chrome/browser/memory/memory_wedge_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8ef4433fb66ccc734b757173ca71215175376b9a
--- /dev/null
+++ b/ios/chrome/browser/memory/memory_wedge_unittest.cc
@@ -0,0 +1,73 @@
+// Copyright 2015 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 "ios/chrome/browser/memory/memory_wedge.h"
+
+#include "base/macros.h"
+#include "ios/chrome/browser/memory/memory_metrics.h"
+#include "testing/gtest/include/gtest/gtest-param-test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace memory_wedge {
+
+namespace {
+
+// The number of bytes in a megabyte.
+const uint64 kNumBytesInMB = 1024 * 1024;
+
+// Note: in the following tests, only memory_util::GetInternalVMBytes,
+// and memory_util::GetRealMemoryUsedInBytes are used to check the state of the
+// memory before and after an action.
+// memory_util::GetFreePhysicalBytes and memory_util::GetDirtyVMBytes are not
+// used because external events can change these values, making them not
+// reliable.
+
+// Performs a snapshot of the memory when constructed. Deviation from the
+// initial values can be verified with VerifyDeviation. The comparison is
+// on the integer part of the values in MB.
+class MemoryChecker {
+ public:
+ MemoryChecker() {
+ internal_vm_ = memory_util::GetInternalVMBytes() / kNumBytesInMB;
+ real_memory_used_ = memory_util::GetRealMemoryUsedInBytes() / kNumBytesInMB;
+ }
+
+ // Verifies that the memory metrics deviated only by |deviation| in MB.
+ void VerifyDeviation(uint64 deviation) const {
+ EXPECT_NEAR(memory_util::GetInternalVMBytes() / kNumBytesInMB,
+ deviation + internal_vm_, 1);
+ EXPECT_NEAR(memory_util::GetRealMemoryUsedInBytes() / kNumBytesInMB,
+ deviation + real_memory_used_, 1);
+ }
+
+ private:
+ uint64 internal_vm_;
+ uint64 real_memory_used_;
+
+ DISALLOW_COPY_AND_ASSIGN(MemoryChecker);
+};
+
+class MemoryWedgeTest : public testing::TestWithParam<size_t> {};
+
+} // namespace
+
+// Checks that the wedge size passed to AddWedge is indeed added to the global
+// footprint of the app.
+TEST_P(MemoryWedgeTest, WedgeSize) {
+ const MemoryChecker memory_checker;
+ size_t wedge_size = GetParam();
+
+ AddWedge(wedge_size);
+
+ memory_checker.VerifyDeviation(wedge_size);
+ if (wedge_size > 0)
+ RemoveWedgeForTesting();
+}
+
+INSTANTIATE_TEST_CASE_P(
+ /* No InstantiationName */,
+ MemoryWedgeTest,
+ testing::Values(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100));
+
+} // namespace memory_wedge
« no previous file with comments | « ios/chrome/browser/memory/memory_wedge.cc ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698