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

Side by Side Diff: third_party/WebKit/Source/platform/WebProcessMemoryDumpImplTest.cpp

Issue 1660383002: Refactoring: Move some classes from content/child to platform (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move implementation from static functions to member functions as default impl Created 4 years, 10 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 "content/child/web_process_memory_dump_impl.h" 5 #include "platform/WebProcessMemoryDumpImpl.h"
6 6
7 #include "base/trace_event/memory_allocator_dump.h" 7 #include "base/trace_event/memory_allocator_dump.h"
8 #include "base/trace_event/process_memory_dump.h" 8 #include "base/trace_event/process_memory_dump.h"
9 #include "base/trace_event/trace_event_argument.h" 9 #include "base/trace_event/trace_event_argument.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "content/child/web_memory_allocator_dump_impl.h" 11 #include "platform/WebMemoryAllocatorDumpImpl.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "wtf/OwnPtr.h"
13 14
14 namespace content { 15 namespace blink {
15 16
16 // Tests that the Chromium<>Blink plumbing that exposes the MemoryInfra classes 17 // Tests that the Chromium<>Blink plumbing that exposes the MemoryInfra classes
17 // behaves correctly, performs the right transfers of memory ownerships and 18 // behaves correctly, performs the right transfers of memory ownerships and
18 // doesn't leak objects. 19 // doesn't leak objects.
19 TEST(WebProcessMemoryDumpImplTest, IntegrationTest) { 20 TEST(WebProcessMemoryDumpImplTest, IntegrationTest) {
20 scoped_refptr<base::trace_event::TracedValue> traced_value( 21 scoped_refptr<base::trace_event::TracedValue> traced_value(
21 new base::trace_event::TracedValue()); 22 new base::trace_event::TracedValue());
22 23
23 scoped_ptr<WebProcessMemoryDumpImpl> wpmd1(new WebProcessMemoryDumpImpl()); 24 OwnPtr<WebProcessMemoryDumpImpl> wpmd1(adoptPtr(new WebProcessMemoryDumpImpl() ));
24 auto wmad1 = wpmd1->createMemoryAllocatorDump("1/1"); 25 auto wmad1 = wpmd1->createMemoryAllocatorDump("1/1");
25 auto wmad2 = wpmd1->createMemoryAllocatorDump("1/2"); 26 auto wmad2 = wpmd1->createMemoryAllocatorDump("1/2");
26 ASSERT_EQ(wmad1, wpmd1->getMemoryAllocatorDump("1/1")); 27 ASSERT_EQ(wmad1, wpmd1->getMemoryAllocatorDump("1/1"));
27 ASSERT_EQ(wmad2, wpmd1->getMemoryAllocatorDump("1/2")); 28 ASSERT_EQ(wmad2, wpmd1->getMemoryAllocatorDump("1/2"));
28 29
29 scoped_ptr<WebProcessMemoryDumpImpl> wpmd2(new WebProcessMemoryDumpImpl()); 30 OwnPtr<WebProcessMemoryDumpImpl> wpmd2(adoptPtr(new WebProcessMemoryDumpImpl() ));
30 wpmd2->createMemoryAllocatorDump("2/1"); 31 wpmd2->createMemoryAllocatorDump("2/1");
31 wpmd2->createMemoryAllocatorDump("2/2"); 32 wpmd2->createMemoryAllocatorDump("2/2");
32 33
33 wpmd1->takeAllDumpsFrom(wpmd2.get()); 34 wpmd1->takeAllDumpsFrom(wpmd2.get());
34 35
35 // Make sure that wpmd2 still owns its own PMD, even if empty. 36 // Make sure that wpmd2 still owns its own PMD, even if empty.
36 ASSERT_NE(static_cast<base::trace_event::ProcessMemoryDump*>(nullptr), 37 ASSERT_NE(static_cast<base::trace_event::ProcessMemoryDump*>(nullptr),
37 wpmd2->process_memory_dump_); 38 wpmd2->process_memory_dump_);
38 ASSERT_EQ(wpmd2->owned_process_memory_dump_.get(), 39 ASSERT_EQ(wpmd2->owned_process_memory_dump_.get(),
39 wpmd2->process_memory_dump()); 40 wpmd2->process_memory_dump());
(...skipping 25 matching lines...) Expand all
65 ASSERT_EQ(base::trace_event::MemoryAllocatorDump::kTypeScalar, attr_value); 66 ASSERT_EQ(base::trace_event::MemoryAllocatorDump::kTypeScalar, attr_value);
66 ASSERT_TRUE(attr->GetString("units", &attr_value)); 67 ASSERT_TRUE(attr->GetString("units", &attr_value));
67 ASSERT_EQ("rate", attr_value); 68 ASSERT_EQ("rate", attr_value);
68 ASSERT_TRUE(attr->HasKey("value")); 69 ASSERT_TRUE(attr->HasKey("value"));
69 70
70 // Check that AsValueInto() doesn't cause a crash. 71 // Check that AsValueInto() doesn't cause a crash.
71 wpmd2->process_memory_dump()->AsValueInto(traced_value.get()); 72 wpmd2->process_memory_dump()->AsValueInto(traced_value.get());
72 73
73 // Free the |wpmd2| to check that the memory ownership of the two MAD(s) 74 // Free the |wpmd2| to check that the memory ownership of the two MAD(s)
74 // has been transferred to |wpmd1|. 75 // has been transferred to |wpmd1|.
75 wpmd2.reset(); 76 wpmd2.clear();
76 77
77 // Now check that |wpmd1| has been effectively merged. 78 // Now check that |wpmd1| has been effectively merged.
78 ASSERT_EQ(4u, wpmd1->process_memory_dump()->allocator_dumps().size()); 79 ASSERT_EQ(4u, wpmd1->process_memory_dump()->allocator_dumps().size());
79 ASSERT_EQ(1u, wpmd1->process_memory_dump()->allocator_dumps().count("1/1")); 80 ASSERT_EQ(1u, wpmd1->process_memory_dump()->allocator_dumps().count("1/1"));
80 ASSERT_EQ(1u, wpmd1->process_memory_dump()->allocator_dumps().count("1/2")); 81 ASSERT_EQ(1u, wpmd1->process_memory_dump()->allocator_dumps().count("1/2"));
81 ASSERT_EQ(1u, wpmd1->process_memory_dump()->allocator_dumps().count("2/1")); 82 ASSERT_EQ(1u, wpmd1->process_memory_dump()->allocator_dumps().count("2/1"));
82 ASSERT_EQ(1u, wpmd1->process_memory_dump()->allocator_dumps().count("1/2")); 83 ASSERT_EQ(1u, wpmd1->process_memory_dump()->allocator_dumps().count("1/2"));
83 84
84 // Check that also the WMAD wrappers got merged. 85 // Check that also the WMAD wrappers got merged.
85 blink::WebMemoryAllocatorDump* null_wmad = nullptr; 86 blink::WebMemoryAllocatorDump* null_wmad = nullptr;
(...skipping 25 matching lines...) Expand all
111 112
112 // Check that AddOwnershipEdge is propagated correctly. 113 // Check that AddOwnershipEdge is propagated correctly.
113 auto wmad4 = wpmd1->createMemoryAllocatorDump("1/4"); 114 auto wmad4 = wpmd1->createMemoryAllocatorDump("1/4");
114 wpmd1->addOwnershipEdge(wmad4->guid(), guid); 115 wpmd1->addOwnershipEdge(wmad4->guid(), guid);
115 auto allocator_dumps_edges = 116 auto allocator_dumps_edges =
116 wpmd1->process_memory_dump()->allocator_dumps_edges(); 117 wpmd1->process_memory_dump()->allocator_dumps_edges();
117 ASSERT_EQ(1u, allocator_dumps_edges.size()); 118 ASSERT_EQ(1u, allocator_dumps_edges.size());
118 ASSERT_EQ(wmad4->guid(), allocator_dumps_edges[0].source.ToUint64()); 119 ASSERT_EQ(wmad4->guid(), allocator_dumps_edges[0].source.ToUint64());
119 ASSERT_EQ(guid, allocator_dumps_edges[0].target.ToUint64()); 120 ASSERT_EQ(guid, allocator_dumps_edges[0].target.ToUint64());
120 121
121 wpmd1.reset(); 122 wpmd1.clear();
122 } 123 }
123 124
124 } // namespace content 125 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698