OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 TEST_F(OomPriorityManagerTest, Comparator) { | 36 TEST_F(OomPriorityManagerTest, Comparator) { |
37 chromeos::OomPriorityManager::TabStatsList test_list; | 37 chromeos::OomPriorityManager::TabStatsList test_list; |
38 const base::TimeTicks now = base::TimeTicks::Now(); | 38 const base::TimeTicks now = base::TimeTicks::Now(); |
39 | 39 |
40 // Add kSelected last to verify we are sorting the array. | 40 // Add kSelected last to verify we are sorting the array. |
41 | 41 |
42 { | 42 { |
43 OomPriorityManager::TabStats stats; | 43 OomPriorityManager::TabStats stats; |
44 stats.is_pinned = true; | 44 stats.is_pinned = true; |
45 stats.renderer_handle = kPinned; | 45 stats.renderer_handle = kPinned; |
| 46 stats.child_process_host_id = kPinned; |
46 test_list.push_back(stats); | 47 test_list.push_back(stats); |
47 } | 48 } |
48 | 49 |
49 { | 50 { |
50 OomPriorityManager::TabStats stats; | 51 OomPriorityManager::TabStats stats; |
51 stats.is_app = true; | 52 stats.is_app = true; |
52 stats.renderer_handle = kApp; | 53 stats.renderer_handle = kApp; |
| 54 stats.child_process_host_id = kApp; |
53 test_list.push_back(stats); | 55 test_list.push_back(stats); |
54 } | 56 } |
55 | 57 |
56 { | 58 { |
57 OomPriorityManager::TabStats stats; | 59 OomPriorityManager::TabStats stats; |
58 stats.is_playing_audio = true; | 60 stats.is_playing_audio = true; |
59 stats.renderer_handle = kPlayingAudio; | 61 stats.renderer_handle = kPlayingAudio; |
| 62 stats.child_process_host_id = kPlayingAudio; |
60 test_list.push_back(stats); | 63 test_list.push_back(stats); |
61 } | 64 } |
62 | 65 |
63 { | 66 { |
64 OomPriorityManager::TabStats stats; | 67 OomPriorityManager::TabStats stats; |
65 stats.last_active = now - base::TimeDelta::FromSeconds(10); | 68 stats.last_active = now - base::TimeDelta::FromSeconds(10); |
66 stats.renderer_handle = kRecent; | 69 stats.renderer_handle = kRecent; |
| 70 stats.child_process_host_id = kRecent; |
67 test_list.push_back(stats); | 71 test_list.push_back(stats); |
68 } | 72 } |
69 | 73 |
70 { | 74 { |
71 OomPriorityManager::TabStats stats; | 75 OomPriorityManager::TabStats stats; |
72 stats.last_active = now - base::TimeDelta::FromMinutes(15); | 76 stats.last_active = now - base::TimeDelta::FromMinutes(15); |
73 stats.renderer_handle = kOld; | 77 stats.renderer_handle = kOld; |
| 78 stats.child_process_host_id = kOld; |
74 test_list.push_back(stats); | 79 test_list.push_back(stats); |
75 } | 80 } |
76 | 81 |
77 { | 82 { |
78 OomPriorityManager::TabStats stats; | 83 OomPriorityManager::TabStats stats; |
79 stats.last_active = now - base::TimeDelta::FromDays(365); | 84 stats.last_active = now - base::TimeDelta::FromDays(365); |
80 stats.renderer_handle = kReallyOld; | 85 stats.renderer_handle = kReallyOld; |
| 86 stats.child_process_host_id = kReallyOld; |
81 test_list.push_back(stats); | 87 test_list.push_back(stats); |
82 } | 88 } |
83 | 89 |
84 { | 90 { |
85 OomPriorityManager::TabStats stats; | 91 OomPriorityManager::TabStats stats; |
86 stats.is_pinned = true; | 92 stats.is_pinned = true; |
87 stats.last_active = now - base::TimeDelta::FromDays(365); | 93 stats.last_active = now - base::TimeDelta::FromDays(365); |
88 stats.renderer_handle = kOldButPinned; | 94 stats.renderer_handle = kOldButPinned; |
| 95 stats.child_process_host_id = kOldButPinned; |
89 test_list.push_back(stats); | 96 test_list.push_back(stats); |
90 } | 97 } |
91 | 98 |
92 { | 99 { |
93 OomPriorityManager::TabStats stats; | 100 OomPriorityManager::TabStats stats; |
94 stats.is_reloadable_ui = true; | 101 stats.is_reloadable_ui = true; |
95 stats.renderer_handle = kReloadableUI; | 102 stats.renderer_handle = kReloadableUI; |
| 103 stats.child_process_host_id = kReloadableUI; |
96 test_list.push_back(stats); | 104 test_list.push_back(stats); |
97 } | 105 } |
98 | 106 |
99 // This entry sorts to the front, so by adding it last we verify that | 107 // This entry sorts to the front, so by adding it last we verify that |
100 // we are actually sorting the array. | 108 // we are actually sorting the array. |
101 { | 109 { |
102 OomPriorityManager::TabStats stats; | 110 OomPriorityManager::TabStats stats; |
103 stats.is_selected = true; | 111 stats.is_selected = true; |
104 stats.renderer_handle = kSelected; | 112 stats.renderer_handle = kSelected; |
| 113 stats.child_process_host_id = kSelected; |
105 test_list.push_back(stats); | 114 test_list.push_back(stats); |
106 } | 115 } |
107 | 116 |
108 std::sort(test_list.begin(), | 117 std::sort(test_list.begin(), |
109 test_list.end(), | 118 test_list.end(), |
110 OomPriorityManager::CompareTabStats); | 119 OomPriorityManager::CompareTabStats); |
111 | 120 |
112 int index = 0; | 121 int index = 0; |
113 EXPECT_EQ(kSelected, test_list[index++].renderer_handle); | 122 EXPECT_EQ(kSelected, test_list[index++].renderer_handle); |
114 EXPECT_EQ(kPinned, test_list[index++].renderer_handle); | 123 EXPECT_EQ(kPinned, test_list[index++].renderer_handle); |
115 EXPECT_EQ(kOldButPinned, test_list[index++].renderer_handle); | 124 EXPECT_EQ(kOldButPinned, test_list[index++].renderer_handle); |
116 EXPECT_EQ(kApp, test_list[index++].renderer_handle); | 125 EXPECT_EQ(kApp, test_list[index++].renderer_handle); |
117 EXPECT_EQ(kPlayingAudio, test_list[index++].renderer_handle); | 126 EXPECT_EQ(kPlayingAudio, test_list[index++].renderer_handle); |
118 EXPECT_EQ(kRecent, test_list[index++].renderer_handle); | 127 EXPECT_EQ(kRecent, test_list[index++].renderer_handle); |
119 EXPECT_EQ(kOld, test_list[index++].renderer_handle); | 128 EXPECT_EQ(kOld, test_list[index++].renderer_handle); |
120 EXPECT_EQ(kReallyOld, test_list[index++].renderer_handle); | 129 EXPECT_EQ(kReallyOld, test_list[index++].renderer_handle); |
121 EXPECT_EQ(kReloadableUI, test_list[index++].renderer_handle); | 130 EXPECT_EQ(kReloadableUI, test_list[index++].renderer_handle); |
| 131 |
| 132 index = 0; |
| 133 EXPECT_EQ(kSelected, test_list[index++].child_process_host_id); |
| 134 EXPECT_EQ(kPinned, test_list[index++].child_process_host_id); |
| 135 EXPECT_EQ(kOldButPinned, test_list[index++].child_process_host_id); |
| 136 EXPECT_EQ(kApp, test_list[index++].child_process_host_id); |
| 137 EXPECT_EQ(kPlayingAudio, test_list[index++].child_process_host_id); |
| 138 EXPECT_EQ(kRecent, test_list[index++].child_process_host_id); |
| 139 EXPECT_EQ(kOld, test_list[index++].child_process_host_id); |
| 140 EXPECT_EQ(kReallyOld, test_list[index++].child_process_host_id); |
| 141 EXPECT_EQ(kReloadableUI, test_list[index++].child_process_host_id); |
122 } | 142 } |
123 | 143 |
124 TEST_F(OomPriorityManagerTest, IsReloadableUI) { | 144 TEST_F(OomPriorityManagerTest, IsReloadableUI) { |
125 EXPECT_TRUE(OomPriorityManager::IsReloadableUI( | 145 EXPECT_TRUE(OomPriorityManager::IsReloadableUI( |
126 GURL(chrome::kChromeUIDownloadsURL))); | 146 GURL(chrome::kChromeUIDownloadsURL))); |
127 EXPECT_TRUE(OomPriorityManager::IsReloadableUI( | 147 EXPECT_TRUE(OomPriorityManager::IsReloadableUI( |
128 GURL(chrome::kChromeUIHistoryURL))); | 148 GURL(chrome::kChromeUIHistoryURL))); |
129 EXPECT_TRUE(OomPriorityManager::IsReloadableUI( | 149 EXPECT_TRUE(OomPriorityManager::IsReloadableUI( |
130 GURL(chrome::kChromeUINewTabURL))); | 150 GURL(chrome::kChromeUINewTabURL))); |
131 EXPECT_TRUE(OomPriorityManager::IsReloadableUI( | 151 EXPECT_TRUE(OomPriorityManager::IsReloadableUI( |
132 GURL(chrome::kChromeUISettingsURL))); | 152 GURL(chrome::kChromeUISettingsURL))); |
133 | 153 |
134 // Debugging URLs are not included. | 154 // Debugging URLs are not included. |
135 EXPECT_FALSE(OomPriorityManager::IsReloadableUI( | 155 EXPECT_FALSE(OomPriorityManager::IsReloadableUI( |
136 GURL(chrome::kChromeUIDiscardsURL))); | 156 GURL(chrome::kChromeUIDiscardsURL))); |
137 EXPECT_FALSE(OomPriorityManager::IsReloadableUI( | 157 EXPECT_FALSE(OomPriorityManager::IsReloadableUI( |
138 GURL(chrome::kChromeUINetInternalsURL))); | 158 GURL(chrome::kChromeUINetInternalsURL))); |
139 | 159 |
140 // Prefix matches are included. | 160 // Prefix matches are included. |
141 EXPECT_TRUE(OomPriorityManager::IsReloadableUI( | 161 EXPECT_TRUE(OomPriorityManager::IsReloadableUI( |
142 GURL("chrome://settings/fakeSetting"))); | 162 GURL("chrome://settings/fakeSetting"))); |
143 } | 163 } |
144 | 164 |
145 TEST_F(OomPriorityManagerTest, GetProcessHandles) { | 165 TEST_F(OomPriorityManagerTest, GetProcessHandles) { |
146 OomPriorityManager::TabStats stats; | 166 OomPriorityManager::TabStats stats; |
147 std::vector<base::ProcessHandle> handles; | 167 std::vector<int> child_process_host_ids; |
148 | 168 |
149 // Empty stats list gives empty handles list. | 169 // Empty stats list gives empty |child_process_host_ids| list. |
150 OomPriorityManager::TabStatsList empty_list; | 170 OomPriorityManager::TabStatsList empty_list; |
151 handles = OomPriorityManager::GetProcessHandles(empty_list); | 171 child_process_host_ids = |
152 EXPECT_EQ(0u, handles.size()); | 172 OomPriorityManager::GetChildProcessHostIds(empty_list); |
| 173 EXPECT_EQ(0u, child_process_host_ids.size()); |
153 | 174 |
154 // Two tabs in two different processes generates two handles out. | 175 // Two tabs in two different processes generates two |
| 176 // |child_process_host_id| out. |
155 OomPriorityManager::TabStatsList two_list; | 177 OomPriorityManager::TabStatsList two_list; |
156 stats.renderer_handle = 100; | 178 stats.renderer_handle = 100; |
| 179 stats.child_process_host_id = 100; |
157 two_list.push_back(stats); | 180 two_list.push_back(stats); |
158 stats.renderer_handle = 101; | 181 stats.renderer_handle = 101; |
| 182 stats.child_process_host_id = 101; |
159 two_list.push_back(stats); | 183 two_list.push_back(stats); |
160 handles = OomPriorityManager::GetProcessHandles(two_list); | 184 child_process_host_ids = OomPriorityManager::GetChildProcessHostIds(two_list); |
161 EXPECT_EQ(2u, handles.size()); | 185 EXPECT_EQ(2u, child_process_host_ids.size()); |
162 EXPECT_EQ(100, handles[0]); | 186 EXPECT_EQ(100, child_process_host_ids[0]); |
163 EXPECT_EQ(101, handles[1]); | 187 EXPECT_EQ(101, child_process_host_ids[1]); |
164 | 188 |
165 // Zero handles are removed. | 189 // Zero handles are removed. |
166 OomPriorityManager::TabStatsList zero_handle_list; | 190 OomPriorityManager::TabStatsList zero_handle_list; |
167 stats.renderer_handle = 0; | 191 stats.renderer_handle = 0; |
| 192 stats.child_process_host_id = 100; |
168 zero_handle_list.push_back(stats); | 193 zero_handle_list.push_back(stats); |
169 handles = OomPriorityManager::GetProcessHandles(zero_handle_list); | 194 child_process_host_ids = |
170 EXPECT_EQ(0u, handles.size()); | 195 OomPriorityManager::GetChildProcessHostIds(zero_handle_list); |
| 196 EXPECT_EQ(0u, child_process_host_ids.size()); |
171 | 197 |
172 // Two tabs in the same process generates one handle out. When a duplicate | 198 // Two tabs in the same process generates one handle out. When a duplicate |
173 // occurs the later instance is dropped. | 199 // occurs the later instance is dropped. |
174 OomPriorityManager::TabStatsList same_process_list; | 200 OomPriorityManager::TabStatsList same_process_list; |
175 stats.renderer_handle = 100; | 201 stats.renderer_handle = 100; |
| 202 stats.child_process_host_id = 100; |
176 same_process_list.push_back(stats); | 203 same_process_list.push_back(stats); |
177 stats.renderer_handle = 101; | 204 stats.renderer_handle = 101; |
| 205 stats.child_process_host_id = 101; |
178 same_process_list.push_back(stats); | 206 same_process_list.push_back(stats); |
179 stats.renderer_handle = 100; // Duplicate. | 207 stats.renderer_handle = 100; // Duplicate. |
| 208 stats.child_process_host_id = 103; |
180 same_process_list.push_back(stats); | 209 same_process_list.push_back(stats); |
181 handles = OomPriorityManager::GetProcessHandles(same_process_list); | 210 child_process_host_ids = |
182 EXPECT_EQ(2u, handles.size()); | 211 OomPriorityManager::GetChildProcessHostIds(same_process_list); |
183 EXPECT_EQ(100, handles[0]); | 212 EXPECT_EQ(2u, child_process_host_ids.size()); |
184 EXPECT_EQ(101, handles[1]); | 213 EXPECT_EQ(100, child_process_host_ids[0]); |
| 214 EXPECT_EQ(101, child_process_host_ids[1]); |
185 } | 215 } |
186 | 216 |
187 } // namespace chromeos | 217 } // namespace chromeos |
OLD | NEW |