| 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 "chrome/browser/memory/tab_manager_delegate_chromeos.h" | 5 #include "chrome/browser/memory/tab_manager_delegate_chromeos.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 aura::client::ActivationClient* GetActivationClient() { | 61 aura::client::ActivationClient* GetActivationClient() { |
| 62 return aura::client::GetActivationClient( | 62 return aura::client::GetActivationClient( |
| 63 ash::Shell::GetPrimaryRootWindow()); | 63 ash::Shell::GetPrimaryRootWindow()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 aura::Window* arc_window_; | 66 aura::Window* arc_window_; |
| 67 std::string application_id_; | 67 std::string application_id_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 TEST_F(TabManagerDelegateTest, CandidatesSorted) { | 70 TEST_F(TabManagerDelegateTest, CandidatesSorted) { |
| 71 std::vector<arc::ArcProcess> arc_processes = { | 71 std::vector<arc::ArcProcess> arc_processes; |
| 72 {1, 10, "top", arc::mojom::ProcessState::TOP}, | 72 arc_processes.emplace_back(1, 10, "top", arc::mojom::ProcessState::TOP); |
| 73 {2, 20, "foreground", arc::mojom::ProcessState::FOREGROUND_SERVICE}, | 73 arc_processes.emplace_back(2, 20, "foreground", |
| 74 {3, 30, "service", arc::mojom::ProcessState::SERVICE}}; | 74 arc::mojom::ProcessState::FOREGROUND_SERVICE); |
| 75 arc_processes.emplace_back(3, 30, "service", |
| 76 arc::mojom::ProcessState::SERVICE); |
| 75 | 77 |
| 76 TabStats tab1, tab2, tab3, tab4, tab5; | 78 TabStats tab1, tab2, tab3, tab4, tab5; |
| 77 tab1.tab_contents_id = 100; | 79 tab1.tab_contents_id = 100; |
| 78 tab1.is_pinned = true; | 80 tab1.is_pinned = true; |
| 79 | 81 |
| 80 tab2.tab_contents_id = 200; | 82 tab2.tab_contents_id = 200; |
| 81 tab2.is_internal_page = true; | 83 tab2.is_internal_page = true; |
| 82 | 84 |
| 83 tab3.tab_contents_id = 300; | 85 tab3.tab_contents_id = 300; |
| 84 tab3.is_pinned = true; | 86 tab3.is_pinned = true; |
| 85 tab3.is_media = true; | 87 tab3.is_media = true; |
| 86 | 88 |
| 87 tab4.tab_contents_id = 400; | 89 tab4.tab_contents_id = 400; |
| 88 tab4.is_media = true; | 90 tab4.is_media = true; |
| 89 | 91 |
| 90 tab5.tab_contents_id = 500; | 92 tab5.tab_contents_id = 500; |
| 91 tab5.is_app = true; | 93 tab5.is_app = true; |
| 92 TabStatsList tab_list = { | 94 TabStatsList tab_list = { |
| 93 tab1, tab2, tab3, tab4, tab5 | 95 tab1, tab2, tab3, tab4, tab5 |
| 94 }; | 96 }; |
| 95 | 97 |
| 96 std::vector<TabManagerDelegate::Candidate> candidates; | 98 std::vector<TabManagerDelegate::Candidate> candidates; |
| 97 | 99 |
| 98 // Case 1: ARC window in the foreground. | 100 // Case 1: ARC window in the foreground. |
| 99 ActivateArcWindow(); | 101 ActivateArcWindow(); |
| 100 candidates = TabManagerDelegate::GetSortedCandidates( | 102 candidates = TabManagerDelegate::GetSortedCandidates( |
| 101 tab_list, arc_processes); | 103 tab_list, arc_processes); |
| 102 EXPECT_EQ(8U, candidates.size()); | 104 EXPECT_EQ(8U, candidates.size()); |
| 103 | 105 |
| 104 EXPECT_EQ("service", candidates[0].app->process_name); | 106 EXPECT_EQ("service", candidates[0].app->process_name()); |
| 105 EXPECT_EQ("foreground", candidates[1].app->process_name); | 107 EXPECT_EQ("foreground", candidates[1].app->process_name()); |
| 106 // internal page. | 108 // internal page. |
| 107 EXPECT_EQ(200, candidates[2].tab->tab_contents_id); | 109 EXPECT_EQ(200, candidates[2].tab->tab_contents_id); |
| 108 // chrome app. | 110 // chrome app. |
| 109 EXPECT_EQ(500, candidates[3].tab->tab_contents_id); | 111 EXPECT_EQ(500, candidates[3].tab->tab_contents_id); |
| 110 // pinned. | 112 // pinned. |
| 111 EXPECT_EQ(100, candidates[4].tab->tab_contents_id); | 113 EXPECT_EQ(100, candidates[4].tab->tab_contents_id); |
| 112 // media. | 114 // media. |
| 113 EXPECT_EQ(400, candidates[5].tab->tab_contents_id); | 115 EXPECT_EQ(400, candidates[5].tab->tab_contents_id); |
| 114 // pinned and media. | 116 // pinned and media. |
| 115 EXPECT_EQ(300, candidates[6].tab->tab_contents_id); | 117 EXPECT_EQ(300, candidates[6].tab->tab_contents_id); |
| 116 // ARC window is the active window, so top app has highest priority. | 118 // ARC window is the active window, so top app has highest priority. |
| 117 EXPECT_EQ("top", candidates[7].app->process_name); | 119 EXPECT_EQ("top", candidates[7].app->process_name()); |
| 118 | 120 |
| 119 // Case 2: ARC window in the background. | 121 // Case 2: ARC window in the background. |
| 120 DeactivateArcWindow(); | 122 DeactivateArcWindow(); |
| 121 candidates = TabManagerDelegate::GetSortedCandidates( | 123 candidates = TabManagerDelegate::GetSortedCandidates( |
| 122 tab_list, arc_processes); | 124 tab_list, arc_processes); |
| 123 EXPECT_EQ(8U, candidates.size()); | 125 EXPECT_EQ(8U, candidates.size()); |
| 124 | 126 |
| 125 EXPECT_EQ("service", candidates[0].app->process_name); | 127 EXPECT_EQ("service", candidates[0].app->process_name()); |
| 126 EXPECT_EQ("foreground", candidates[1].app->process_name); | 128 EXPECT_EQ("foreground", candidates[1].app->process_name()); |
| 127 // internal page. | 129 // internal page. |
| 128 EXPECT_EQ(200, candidates[2].tab->tab_contents_id); | 130 EXPECT_EQ(200, candidates[2].tab->tab_contents_id); |
| 129 | 131 |
| 130 // Chrome app and android app are tied, so both orders are correct. | 132 // Chrome app and android app are tied, so both orders are correct. |
| 131 if (candidates[3].is_arc_app) { | 133 if (candidates[3].is_arc_app) { |
| 132 EXPECT_EQ("top", candidates[3].app->process_name); | 134 EXPECT_EQ("top", candidates[3].app->process_name()); |
| 133 // chrome app. | 135 // chrome app. |
| 134 EXPECT_EQ(500, candidates[4].tab->tab_contents_id); | 136 EXPECT_EQ(500, candidates[4].tab->tab_contents_id); |
| 135 } else { | 137 } else { |
| 136 // chrome app. | 138 // chrome app. |
| 137 EXPECT_EQ(500, candidates[3].tab->tab_contents_id); | 139 EXPECT_EQ(500, candidates[3].tab->tab_contents_id); |
| 138 EXPECT_EQ("top", candidates[4].app->process_name); | 140 EXPECT_EQ("top", candidates[4].app->process_name()); |
| 139 } | 141 } |
| 140 | 142 |
| 141 // pinned. | 143 // pinned. |
| 142 EXPECT_EQ(100, candidates[5].tab->tab_contents_id); | 144 EXPECT_EQ(100, candidates[5].tab->tab_contents_id); |
| 143 // media. | 145 // media. |
| 144 EXPECT_EQ(400, candidates[6].tab->tab_contents_id); | 146 EXPECT_EQ(400, candidates[6].tab->tab_contents_id); |
| 145 // pinned and media. | 147 // pinned and media. |
| 146 EXPECT_EQ(300, candidates[7].tab->tab_contents_id); | 148 EXPECT_EQ(300, candidates[7].tab->tab_contents_id); |
| 147 } | 149 } |
| 148 | 150 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 private: | 220 private: |
| 219 int target_memory_to_free_kb_; | 221 int target_memory_to_free_kb_; |
| 220 std::map<base::ProcessHandle, int> process_pss_; | 222 std::map<base::ProcessHandle, int> process_pss_; |
| 221 }; | 223 }; |
| 222 | 224 |
| 223 TEST_F(TabManagerDelegateTest, SetOomScoreAdj) { | 225 TEST_F(TabManagerDelegateTest, SetOomScoreAdj) { |
| 224 arc::FakeArcBridgeService fake_arc_bridge_service; | 226 arc::FakeArcBridgeService fake_arc_bridge_service; |
| 225 MockTabManagerDelegate tab_manager_delegate; | 227 MockTabManagerDelegate tab_manager_delegate; |
| 226 | 228 |
| 227 ActivateArcWindow(); | 229 ActivateArcWindow(); |
| 228 std::vector<arc::ArcProcess> arc_processes = { | 230 std::vector<arc::ArcProcess> arc_processes; |
| 229 {1, 10, "top", arc::mojom::ProcessState::TOP}, | 231 arc_processes.emplace_back(1, 10, "top", arc::mojom::ProcessState::TOP); |
| 230 {2, 20, "foreground", arc::mojom::ProcessState::FOREGROUND_SERVICE}, | 232 arc_processes.emplace_back(2, 20, "foreground", |
| 231 {3, 30, "service", arc::mojom::ProcessState::SERVICE}}; | 233 arc::mojom::ProcessState::FOREGROUND_SERVICE); |
| 234 arc_processes.emplace_back(3, 30, "service", |
| 235 arc::mojom::ProcessState::SERVICE); |
| 232 | 236 |
| 233 TabStats tab1, tab2, tab3, tab4, tab5; | 237 TabStats tab1, tab2, tab3, tab4, tab5; |
| 234 tab1.is_pinned = true; | 238 tab1.is_pinned = true; |
| 235 tab1.renderer_handle = 11; | 239 tab1.renderer_handle = 11; |
| 236 | 240 |
| 237 tab2.is_internal_page = true; | 241 tab2.is_internal_page = true; |
| 238 tab2.renderer_handle = 11; | 242 tab2.renderer_handle = 11; |
| 239 | 243 |
| 240 tab3.is_pinned = true; | 244 tab3.is_pinned = true; |
| 241 tab3.is_media = true; | 245 tab3.is_media = true; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 arc::FakeArcBridgeService fake_arc_bridge_service; | 280 arc::FakeArcBridgeService fake_arc_bridge_service; |
| 277 | 281 |
| 278 // Not owned. | 282 // Not owned. |
| 279 MockMemoryStat* memory_stat = new MockMemoryStat(); | 283 MockMemoryStat* memory_stat = new MockMemoryStat(); |
| 280 | 284 |
| 281 // Instantiate the mock instance. | 285 // Instantiate the mock instance. |
| 282 MockTabManagerDelegate tab_manager_delegate(memory_stat); | 286 MockTabManagerDelegate tab_manager_delegate(memory_stat); |
| 283 | 287 |
| 284 ActivateArcWindow(); | 288 ActivateArcWindow(); |
| 285 | 289 |
| 286 std::vector<arc::ArcProcess> arc_processes = { | 290 std::vector<arc::ArcProcess> arc_processes; |
| 287 {10001, 100, "top", arc::mojom::ProcessState::TOP}, | 291 arc_processes.emplace_back(10001, 100, "top", arc::mojom::ProcessState::TOP); |
| 288 {10002, 200, "foreground", arc::mojom::ProcessState::FOREGROUND_SERVICE}, | 292 arc_processes.emplace_back(10002, 200, "foreground", |
| 289 {10003, 300, "service", arc::mojom::ProcessState::SERVICE}}; | 293 arc::mojom::ProcessState::FOREGROUND_SERVICE); |
| 294 arc_processes.emplace_back(10003, 300, "service", |
| 295 arc::mojom::ProcessState::SERVICE); |
| 290 | 296 |
| 291 TabStats tab1, tab2, tab3, tab4, tab5; | 297 TabStats tab1, tab2, tab3, tab4, tab5; |
| 292 tab1.is_pinned = true; | 298 tab1.is_pinned = true; |
| 293 tab1.renderer_handle = 11; | 299 tab1.renderer_handle = 11; |
| 294 tab1.tab_contents_id = 1; | 300 tab1.tab_contents_id = 1; |
| 295 | 301 |
| 296 tab2.is_internal_page = true; | 302 tab2.is_internal_page = true; |
| 297 tab2.renderer_handle = 11; | 303 tab2.renderer_handle = 11; |
| 298 tab2.tab_contents_id = 2; | 304 tab2.tab_contents_id = 2; |
| 299 | 305 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 EXPECT_EQ(1U, killed_tabs.size()); | 344 EXPECT_EQ(1U, killed_tabs.size()); |
| 339 | 345 |
| 340 // nspid. | 346 // nspid. |
| 341 EXPECT_EQ(10003, killed_arc_processes[0]); | 347 EXPECT_EQ(10003, killed_arc_processes[0]); |
| 342 EXPECT_EQ(10002, killed_arc_processes[1]); | 348 EXPECT_EQ(10002, killed_arc_processes[1]); |
| 343 // tab content id. | 349 // tab content id. |
| 344 EXPECT_EQ(2, killed_tabs[0]); | 350 EXPECT_EQ(2, killed_tabs[0]); |
| 345 } | 351 } |
| 346 | 352 |
| 347 } // namespace memory | 353 } // namespace memory |
| OLD | NEW |