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 17 matching lines...) Expand all Loading... |
28 kReallyOld, | 28 kReallyOld, |
29 kOldButPinned, | 29 kOldButPinned, |
30 kReloadableUI, | 30 kReloadableUI, |
31 }; | 31 }; |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 // Tests the sorting comparator so that we know it's producing the | 34 // Tests the sorting comparator so that we know it's producing the |
35 // desired order. | 35 // desired order. |
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::Time now = base::Time::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.last_active = now; |
44 stats.is_pinned = true; | 45 stats.is_pinned = true; |
45 stats.renderer_handle = kPinned; | 46 stats.renderer_handle = kPinned; |
46 stats.child_process_host_id = kPinned; | 47 stats.child_process_host_id = kPinned; |
47 test_list.push_back(stats); | 48 test_list.push_back(stats); |
48 } | 49 } |
49 | 50 |
50 { | 51 { |
51 OomPriorityManager::TabStats stats; | 52 OomPriorityManager::TabStats stats; |
| 53 stats.last_active = now; |
52 stats.is_app = true; | 54 stats.is_app = true; |
53 stats.renderer_handle = kApp; | 55 stats.renderer_handle = kApp; |
54 stats.child_process_host_id = kApp; | 56 stats.child_process_host_id = kApp; |
55 test_list.push_back(stats); | 57 test_list.push_back(stats); |
56 } | 58 } |
57 | 59 |
58 { | 60 { |
59 OomPriorityManager::TabStats stats; | 61 OomPriorityManager::TabStats stats; |
| 62 stats.last_active = now; |
60 stats.is_playing_audio = true; | 63 stats.is_playing_audio = true; |
61 stats.renderer_handle = kPlayingAudio; | 64 stats.renderer_handle = kPlayingAudio; |
62 stats.child_process_host_id = kPlayingAudio; | 65 stats.child_process_host_id = kPlayingAudio; |
63 test_list.push_back(stats); | 66 test_list.push_back(stats); |
64 } | 67 } |
65 | 68 |
66 { | 69 { |
67 OomPriorityManager::TabStats stats; | 70 OomPriorityManager::TabStats stats; |
68 stats.last_active = now - base::TimeDelta::FromSeconds(10); | 71 stats.last_active = now - base::TimeDelta::FromSeconds(10); |
69 stats.renderer_handle = kRecent; | 72 stats.renderer_handle = kRecent; |
(...skipping 21 matching lines...) Expand all Loading... |
91 OomPriorityManager::TabStats stats; | 94 OomPriorityManager::TabStats stats; |
92 stats.is_pinned = true; | 95 stats.is_pinned = true; |
93 stats.last_active = now - base::TimeDelta::FromDays(365); | 96 stats.last_active = now - base::TimeDelta::FromDays(365); |
94 stats.renderer_handle = kOldButPinned; | 97 stats.renderer_handle = kOldButPinned; |
95 stats.child_process_host_id = kOldButPinned; | 98 stats.child_process_host_id = kOldButPinned; |
96 test_list.push_back(stats); | 99 test_list.push_back(stats); |
97 } | 100 } |
98 | 101 |
99 { | 102 { |
100 OomPriorityManager::TabStats stats; | 103 OomPriorityManager::TabStats stats; |
| 104 stats.last_active = now; |
101 stats.is_reloadable_ui = true; | 105 stats.is_reloadable_ui = true; |
102 stats.renderer_handle = kReloadableUI; | 106 stats.renderer_handle = kReloadableUI; |
103 stats.child_process_host_id = kReloadableUI; | 107 stats.child_process_host_id = kReloadableUI; |
104 test_list.push_back(stats); | 108 test_list.push_back(stats); |
105 } | 109 } |
106 | 110 |
107 // This entry sorts to the front, so by adding it last we verify that | 111 // This entry sorts to the front, so by adding it last we verify that |
108 // we are actually sorting the array. | 112 // we are actually sorting the array. |
109 { | 113 { |
110 OomPriorityManager::TabStats stats; | 114 OomPriorityManager::TabStats stats; |
| 115 stats.last_active = now; |
111 stats.is_selected = true; | 116 stats.is_selected = true; |
112 stats.renderer_handle = kSelected; | 117 stats.renderer_handle = kSelected; |
113 stats.child_process_host_id = kSelected; | 118 stats.child_process_host_id = kSelected; |
114 test_list.push_back(stats); | 119 test_list.push_back(stats); |
115 } | 120 } |
116 | 121 |
117 std::sort(test_list.begin(), | 122 std::sort(test_list.begin(), |
118 test_list.end(), | 123 test_list.end(), |
119 OomPriorityManager::CompareTabStats); | 124 OomPriorityManager::CompareTabStats); |
120 | 125 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 process_id_pairs = | 217 process_id_pairs = |
213 OomPriorityManager::GetChildProcessInfos(same_process_list); | 218 OomPriorityManager::GetChildProcessInfos(same_process_list); |
214 EXPECT_EQ(2u, process_id_pairs.size()); | 219 EXPECT_EQ(2u, process_id_pairs.size()); |
215 EXPECT_EQ(100, process_id_pairs[0].first); | 220 EXPECT_EQ(100, process_id_pairs[0].first); |
216 EXPECT_EQ(101, process_id_pairs[0].second); | 221 EXPECT_EQ(101, process_id_pairs[0].second); |
217 EXPECT_EQ(200, process_id_pairs[1].first); | 222 EXPECT_EQ(200, process_id_pairs[1].first); |
218 EXPECT_EQ(201, process_id_pairs[1].second); | 223 EXPECT_EQ(201, process_id_pairs[1].second); |
219 } | 224 } |
220 | 225 |
221 } // namespace chromeos | 226 } // namespace chromeos |
OLD | NEW |