Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / base / trace_event / process_memory_totals_dump_provider_unittest.cc
blob015cb2d0afb626918774605f16a85ff60697cc12
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 "base/trace_event/process_memory_totals_dump_provider.h"
7 #include "base/trace_event/process_memory_dump.h"
8 #include "base/trace_event/process_memory_totals.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace base {
12 namespace trace_event {
14 TEST(ProcessMemoryTotalsDumpProviderTest, DumpRSS) {
15 const MemoryDumpArgs high_detail_args = {MemoryDumpArgs::LevelOfDetail::HIGH};
16 auto pmtdp = ProcessMemoryTotalsDumpProvider::GetInstance();
17 scoped_ptr<ProcessMemoryDump> pmd_before(new ProcessMemoryDump(nullptr));
18 scoped_ptr<ProcessMemoryDump> pmd_after(new ProcessMemoryDump(nullptr));
20 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 1024;
21 pmtdp->OnMemoryDump(high_detail_args, pmd_before.get());
23 // Pretend that the RSS of the process increased of +1M.
24 const size_t kAllocSize = 1048576;
25 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing += kAllocSize;
27 pmtdp->OnMemoryDump(high_detail_args, pmd_after.get());
29 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0;
31 ASSERT_TRUE(pmd_before->has_process_totals());
32 ASSERT_TRUE(pmd_after->has_process_totals());
34 const uint64 rss_before = pmd_before->process_totals()->resident_set_bytes();
35 const uint64 rss_after = pmd_after->process_totals()->resident_set_bytes();
37 EXPECT_NE(0U, rss_before);
38 EXPECT_NE(0U, rss_after);
40 EXPECT_EQ(rss_after - rss_before, kAllocSize);
43 } // namespace trace_event
44 } // namespace base