Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / ios / chrome / browser / memory / memory_wedge_unittest.cc
blob8ef4433fb66ccc734b757173ca71215175376b9a
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
3 // found in the LICENSE file.
5 #include "ios/chrome/browser/memory/memory_wedge.h"
7 #include "base/macros.h"
8 #include "ios/chrome/browser/memory/memory_metrics.h"
9 #include "testing/gtest/include/gtest/gtest-param-test.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace memory_wedge {
14 namespace {
16 // The number of bytes in a megabyte.
17 const uint64 kNumBytesInMB = 1024 * 1024;
19 // Note: in the following tests, only memory_util::GetInternalVMBytes,
20 // and memory_util::GetRealMemoryUsedInBytes are used to check the state of the
21 // memory before and after an action.
22 // memory_util::GetFreePhysicalBytes and memory_util::GetDirtyVMBytes are not
23 // used because external events can change these values, making them not
24 // reliable.
26 // Performs a snapshot of the memory when constructed. Deviation from the
27 // initial values can be verified with VerifyDeviation. The comparison is
28 // on the integer part of the values in MB.
29 class MemoryChecker {
30 public:
31 MemoryChecker() {
32 internal_vm_ = memory_util::GetInternalVMBytes() / kNumBytesInMB;
33 real_memory_used_ = memory_util::GetRealMemoryUsedInBytes() / kNumBytesInMB;
36 // Verifies that the memory metrics deviated only by |deviation| in MB.
37 void VerifyDeviation(uint64 deviation) const {
38 EXPECT_NEAR(memory_util::GetInternalVMBytes() / kNumBytesInMB,
39 deviation + internal_vm_, 1);
40 EXPECT_NEAR(memory_util::GetRealMemoryUsedInBytes() / kNumBytesInMB,
41 deviation + real_memory_used_, 1);
44 private:
45 uint64 internal_vm_;
46 uint64 real_memory_used_;
48 DISALLOW_COPY_AND_ASSIGN(MemoryChecker);
51 class MemoryWedgeTest : public testing::TestWithParam<size_t> {};
53 } // namespace
55 // Checks that the wedge size passed to AddWedge is indeed added to the global
56 // footprint of the app.
57 TEST_P(MemoryWedgeTest, WedgeSize) {
58 const MemoryChecker memory_checker;
59 size_t wedge_size = GetParam();
61 AddWedge(wedge_size);
63 memory_checker.VerifyDeviation(wedge_size);
64 if (wedge_size > 0)
65 RemoveWedgeForTesting();
68 INSTANTIATE_TEST_CASE_P(
69 /* No InstantiationName */,
70 MemoryWedgeTest,
71 testing::Values(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100));
73 } // namespace memory_wedge