Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/browser/memory/tab_manager_delegate_chromeos_unittest.cc

Issue 2247433002: TabManager: Set OOM scores via a new debugd interface on ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unittest Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
16 #include "base/process/process_handle.h" 17 #include "base/process/process_handle.h"
17 #include "chrome/browser/chromeos/arc/arc_process.h" 18 #include "chrome/browser/chromeos/arc/arc_process.h"
18 #include "chrome/browser/memory/tab_manager.h" 19 #include "chrome/browser/memory/tab_manager.h"
19 #include "chrome/browser/memory/tab_stats.h" 20 #include "chrome/browser/memory/tab_stats.h"
20 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
22 #include "chromeos/dbus/fake_debug_daemon_client.h"
21 #include "components/arc/common/process.mojom.h" 23 #include "components/arc/common/process.mojom.h"
22 #include "components/arc/test/fake_arc_bridge_service.h" 24 #include "components/arc/test/fake_arc_bridge_service.h"
23 #include "components/exo/shell_surface.h" 25 #include "components/exo/shell_surface.h"
24 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/aura/window.h" 27 #include "ui/aura/window.h"
26 #include "ui/wm/public/activation_client.h" 28 #include "ui/wm/public/activation_client.h"
27 #include "url/gurl.h" 29 #include "url/gurl.h"
28 30
29 namespace memory { 31 namespace memory {
30 32
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 return killed_tabs_; 113 return killed_tabs_;
112 } 114 }
113 115
114 // unit test. 116 // unit test.
115 void Clear() { 117 void Clear() {
116 killed_arc_processes_.clear(); 118 killed_arc_processes_.clear();
117 killed_tabs_.clear(); 119 killed_tabs_.clear();
118 } 120 }
119 121
120 protected: 122 protected:
121 // Nullify the operation for unit test.
122 void SetOomScoreAdjForTabs(
123 const std::vector<std::pair<base::ProcessHandle, int>>& entries)
124 override {}
125
126 bool KillArcProcess(const int nspid) override { 123 bool KillArcProcess(const int nspid) override {
127 killed_arc_processes_.push_back(nspid); 124 killed_arc_processes_.push_back(nspid);
128 return true; 125 return true;
129 } 126 }
130 127
131 bool KillTab(int64_t tab_id) override { 128 bool KillTab(int64_t tab_id) override {
132 killed_tabs_.push_back(tab_id); 129 killed_tabs_.push_back(tab_id);
133 return true; 130 return true;
134 } 131 }
135 132
133 chromeos::DebugDaemonClient* GetDebugDaemonClient() override {
134 return &debugd_client_;
135 }
136
136 private: 137 private:
138 chromeos::FakeDebugDaemonClient debugd_client_;
137 std::vector<int> killed_arc_processes_; 139 std::vector<int> killed_arc_processes_;
138 std::vector<int64_t> killed_tabs_; 140 std::vector<int64_t> killed_tabs_;
139 }; 141 };
140 142
141 class MockMemoryStat : public TabManagerDelegate::MemoryStat { 143 class MockMemoryStat : public TabManagerDelegate::MemoryStat {
142 public: 144 public:
143 MockMemoryStat() {} 145 MockMemoryStat() {}
144 ~MockMemoryStat() override {} 146 ~MockMemoryStat() override {}
145 147
146 int TargetMemoryToFreeKB() override { 148 int TargetMemoryToFreeKB() override {
(...skipping 13 matching lines...) Expand all
160 void SetProcessPss(base::ProcessHandle pid, int pss) { 162 void SetProcessPss(base::ProcessHandle pid, int pss) {
161 process_pss_[pid] = pss; 163 process_pss_[pid] = pss;
162 } 164 }
163 165
164 private: 166 private:
165 int target_memory_to_free_kb_; 167 int target_memory_to_free_kb_;
166 std::map<base::ProcessHandle, int> process_pss_; 168 std::map<base::ProcessHandle, int> process_pss_;
167 }; 169 };
168 170
169 TEST_F(TabManagerDelegateTest, SetOomScoreAdj) { 171 TEST_F(TabManagerDelegateTest, SetOomScoreAdj) {
172 base::MessageLoop message_loop;
170 arc::FakeArcBridgeService fake_arc_bridge_service; 173 arc::FakeArcBridgeService fake_arc_bridge_service;
171 MockTabManagerDelegate tab_manager_delegate; 174 MockTabManagerDelegate tab_manager_delegate;
172 175
173 std::vector<arc::ArcProcess> arc_processes; 176 std::vector<arc::ArcProcess> arc_processes;
174 arc_processes.emplace_back(1, 10, "focused", arc::mojom::ProcessState::TOP, 177 arc_processes.emplace_back(1, 10, "focused", arc::mojom::ProcessState::TOP,
175 kIsFocused, 100); 178 kIsFocused, 100);
176 arc_processes.emplace_back(2, 20, "visible1", arc::mojom::ProcessState::TOP, 179 arc_processes.emplace_back(2, 20, "visible1", arc::mojom::ProcessState::TOP,
177 kNotFocused, 200); 180 kNotFocused, 200);
178 arc_processes.emplace_back( 181 arc_processes.emplace_back(
179 3, 30, "service", arc::mojom::ProcessState::SERVICE, kNotFocused, 500); 182 3, 30, "service", arc::mojom::ProcessState::SERVICE, kNotFocused, 500);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // Killed tabs and their content id. 300 // Killed tabs and their content id.
298 // Note that process with pid 11 is counted twice. But so far I don't have a 301 // Note that process with pid 11 is counted twice. But so far I don't have a
299 // good way to estimate the memory freed if multiple tabs share one process. 302 // good way to estimate the memory freed if multiple tabs share one process.
300 EXPECT_EQ(3U, killed_tabs.size()); 303 EXPECT_EQ(3U, killed_tabs.size());
301 EXPECT_EQ(2, killed_tabs[0]); 304 EXPECT_EQ(2, killed_tabs[0]);
302 EXPECT_EQ(5, killed_tabs[1]); 305 EXPECT_EQ(5, killed_tabs[1]);
303 EXPECT_EQ(1, killed_tabs[2]); 306 EXPECT_EQ(1, killed_tabs[2]);
304 } 307 }
305 308
306 } // namespace memory 309 } // namespace memory
OLDNEW
« no previous file with comments | « chrome/browser/memory/tab_manager_delegate_chromeos.cc ('k') | chromeos/dbus/debug_daemon_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698