| 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> |
| 11 | 11 |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/message_loop/message_loop.h" | |
| 17 #include "base/process/process_handle.h" | 16 #include "base/process/process_handle.h" |
| 18 #include "chrome/browser/chromeos/arc/process/arc_process.h" | 17 #include "chrome/browser/chromeos/arc/process/arc_process.h" |
| 19 #include "chrome/browser/memory/tab_manager.h" | 18 #include "chrome/browser/memory/tab_manager.h" |
| 20 #include "chrome/browser/memory/tab_stats.h" | 19 #include "chrome/browser/memory/tab_stats.h" |
| 21 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 22 #include "chromeos/dbus/fake_debug_daemon_client.h" | 21 #include "chromeos/dbus/fake_debug_daemon_client.h" |
| 23 #include "components/arc/common/process.mojom.h" | 22 #include "components/arc/common/process.mojom.h" |
| 24 #include "components/exo/shell_surface.h" | 23 #include "components/exo/shell_surface.h" |
| 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 27 #include "ui/wm/public/activation_client.h" | 27 #include "ui/wm/public/activation_client.h" |
| 28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 29 | 29 |
| 30 namespace memory { | 30 namespace memory { |
| 31 | 31 |
| 32 using TabManagerDelegateTest = testing::Test; | 32 class TabManagerDelegateTest : public testing::Test { |
| 33 public: |
| 34 TabManagerDelegateTest() {} |
| 35 ~TabManagerDelegateTest() override {} |
| 36 |
| 37 private: |
| 38 content::TestBrowserThreadBundle thread_bundle_; |
| 39 }; |
| 33 | 40 |
| 34 namespace { | 41 namespace { |
| 35 constexpr bool kIsFocused = true; | 42 constexpr bool kIsFocused = true; |
| 36 constexpr bool kNotFocused = false; | 43 constexpr bool kNotFocused = false; |
| 37 } // namespace | 44 } // namespace |
| 38 | 45 |
| 39 TEST_F(TabManagerDelegateTest, CandidatesSorted) { | 46 TEST_F(TabManagerDelegateTest, CandidatesSorted) { |
| 40 std::vector<arc::ArcProcess> arc_processes; | 47 std::vector<arc::ArcProcess> arc_processes; |
| 41 arc_processes.emplace_back(1, 10, "focused", arc::mojom::ProcessState::TOP, | 48 arc_processes.emplace_back(1, 10, "focused", arc::mojom::ProcessState::TOP, |
| 42 kIsFocused, 100); | 49 kIsFocused, 100); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 void SetProcessPss(base::ProcessHandle pid, int pss) { | 168 void SetProcessPss(base::ProcessHandle pid, int pss) { |
| 162 process_pss_[pid] = pss; | 169 process_pss_[pid] = pss; |
| 163 } | 170 } |
| 164 | 171 |
| 165 private: | 172 private: |
| 166 int target_memory_to_free_kb_; | 173 int target_memory_to_free_kb_; |
| 167 std::map<base::ProcessHandle, int> process_pss_; | 174 std::map<base::ProcessHandle, int> process_pss_; |
| 168 }; | 175 }; |
| 169 | 176 |
| 170 TEST_F(TabManagerDelegateTest, SetOomScoreAdj) { | 177 TEST_F(TabManagerDelegateTest, SetOomScoreAdj) { |
| 171 base::MessageLoop message_loop; | |
| 172 MockTabManagerDelegate tab_manager_delegate; | 178 MockTabManagerDelegate tab_manager_delegate; |
| 173 | 179 |
| 174 std::vector<arc::ArcProcess> arc_processes; | 180 std::vector<arc::ArcProcess> arc_processes; |
| 175 arc_processes.emplace_back(1, 10, "focused", arc::mojom::ProcessState::TOP, | 181 arc_processes.emplace_back(1, 10, "focused", arc::mojom::ProcessState::TOP, |
| 176 kIsFocused, 100); | 182 kIsFocused, 100); |
| 177 arc_processes.emplace_back(2, 20, "visible1", arc::mojom::ProcessState::TOP, | 183 arc_processes.emplace_back(2, 20, "visible1", arc::mojom::ProcessState::TOP, |
| 178 kNotFocused, 200); | 184 kNotFocused, 200); |
| 179 arc_processes.emplace_back( | 185 arc_processes.emplace_back( |
| 180 3, 30, "service", arc::mojom::ProcessState::SERVICE, kNotFocused, 500); | 186 3, 30, "service", arc::mojom::ProcessState::SERVICE, kNotFocused, 500); |
| 181 arc_processes.emplace_back(4, 40, "visible2", arc::mojom::ProcessState::TOP, | 187 arc_processes.emplace_back(4, 40, "visible2", arc::mojom::ProcessState::TOP, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 // Killed tabs and their content id. | 302 // Killed tabs and their content id. |
| 297 // Note that process with pid 11 is counted twice. But so far I don't have a | 303 // Note that process with pid 11 is counted twice. But so far I don't have a |
| 298 // good way to estimate the memory freed if multiple tabs share one process. | 304 // good way to estimate the memory freed if multiple tabs share one process. |
| 299 EXPECT_EQ(3U, killed_tabs.size()); | 305 EXPECT_EQ(3U, killed_tabs.size()); |
| 300 EXPECT_EQ(2, killed_tabs[0]); | 306 EXPECT_EQ(2, killed_tabs[0]); |
| 301 EXPECT_EQ(5, killed_tabs[1]); | 307 EXPECT_EQ(5, killed_tabs[1]); |
| 302 EXPECT_EQ(1, killed_tabs[2]); | 308 EXPECT_EQ(1, killed_tabs[2]); |
| 303 } | 309 } |
| 304 | 310 |
| 305 } // namespace memory | 311 } // namespace memory |
| OLD | NEW |