1 // Copyright 2017 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. 4 5 #ifndef COMPONENTS_PERFORMANCE_MANAGER_TEST_SUPPORT_MOCK_GRAPHS_H_ 6 #define COMPONENTS_PERFORMANCE_MANAGER_TEST_SUPPORT_MOCK_GRAPHS_H_ 7 8 #include "components/performance_manager/graph/process_node_impl.h" 9 #include "components/performance_manager/test_support/graph_test_harness.h" 10 11 namespace performance_manager { 12 13 class FrameNodeImpl; 14 class PageNodeImpl; 15 class SystemNodeImpl; 16 17 // A for-testing subclass of the process node that allows mocking the 18 // process' PID. 19 class TestProcessNodeImpl : public ProcessNodeImpl { 20 public: 21 TestProcessNodeImpl(); 22 23 void SetProcessWithPid(base::ProcessId pid, 24 base::Process process, 25 base::Time launch_time); 26 }; 27 28 // The following graph topology is created to emulate a scenario when a single 29 // page executes in a single process: 30 // 31 // Pr Pg 32 // \ / 33 // F 34 // 35 // Where: 36 // F: frame(frame_tree_id:0) 37 // Pr: process(pid:1) 38 // Pg: page 39 struct MockSinglePageInSingleProcessGraph { 40 explicit MockSinglePageInSingleProcessGraph(TestGraphImpl* graph); 41 ~MockSinglePageInSingleProcessGraph(); 42 TestNodeWrapper<SystemNodeImpl> system; 43 TestNodeWrapper<TestProcessNodeImpl> process; 44 TestNodeWrapper<PageNodeImpl> page; 45 TestNodeWrapper<FrameNodeImpl> frame; 46 }; 47 48 // The following graph topology is created to emulate a scenario where multiple 49 // pages are executing in a single process: 50 // 51 // Pg Pr OPg 52 // \ / \ / 53 // F OF 54 // 55 // Where: 56 // F: frame(frame_tree_id:0) 57 // OF: other_frame(frame_tree_id:1) 58 // Pg: page 59 // OPg: other_page 60 // Pr: process(pid:1) 61 struct MockMultiplePagesInSingleProcessGraph 62 : public MockSinglePageInSingleProcessGraph { 63 explicit MockMultiplePagesInSingleProcessGraph(TestGraphImpl* graph); 64 ~MockMultiplePagesInSingleProcessGraph(); 65 TestNodeWrapper<PageNodeImpl> other_page; 66 TestNodeWrapper<FrameNodeImpl> other_frame; 67 }; 68 69 // The following graph topology is created to emulate a scenario where a single 70 // page that has frames is executing in different processes (e.g. out-of-process 71 // iFrames): 72 // 73 // Pg Pr 74 // |\ / 75 // | F OPr 76 // | \ / 77 // |__CF 78 // 79 // Where: 80 // F: frame(frame_tree_id:0) 81 // CF: child_frame(frame_tree_id:2) 82 // Pg: page 83 // Pr: process(pid:1) 84 // OPr: other_process(pid:2) 85 struct MockSinglePageWithMultipleProcessesGraph 86 : public MockSinglePageInSingleProcessGraph { 87 explicit MockSinglePageWithMultipleProcessesGraph(TestGraphImpl* graph); 88 ~MockSinglePageWithMultipleProcessesGraph(); 89 TestNodeWrapper<TestProcessNodeImpl> other_process; 90 TestNodeWrapper<FrameNodeImpl> child_frame; 91 }; 92 93 // The following graph topology is created to emulate a scenario where multiple 94 // pages are utilizing multiple processes (e.g. out-of-process iFrames and 95 // multiple pages in a process): 96 // 97 // Pg Pr OPg___ 98 // \ / \ / | 99 // F OF OPr | 100 // \ / | 101 // CF___| 102 // 103 // Where: 104 // F: frame(frame_tree_id:0) 105 // OF: other_frame(frame_tree_id:1) 106 // CF: child_frame(frame_tree_id:3) 107 // Pg: page 108 // OPg: other_page 109 // Pr: process(pid:1) 110 // OPr: other_process(pid:2) 111 struct MockMultiplePagesWithMultipleProcessesGraph 112 : public MockMultiplePagesInSingleProcessGraph { 113 explicit MockMultiplePagesWithMultipleProcessesGraph(TestGraphImpl* graph); 114 ~MockMultiplePagesWithMultipleProcessesGraph(); 115 TestNodeWrapper<TestProcessNodeImpl> other_process; 116 TestNodeWrapper<FrameNodeImpl> child_frame; 117 }; 118 119 } // namespace performance_manager 120 121 #endif // COMPONENTS_PERFORMANCE_MANAGER_TEST_SUPPORT_MOCK_GRAPHS_H_ 122