Chromium Code Reviews| 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/task_manager/task_manager_browsertest_util.h" | 5 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | |
| 7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 8 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/ptr_util.h" | |
| 9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 10 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 11 #include "base/strings/pattern.h" | 13 #include "base/strings/pattern.h" |
| 12 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/test/test_timeouts.h" | 17 #include "base/test/test_timeouts.h" |
| 16 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
| 18 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/sessions/session_tab_helper.h" | |
| 23 #include "chrome/browser/task_management/task_manager_interface.h" | |
| 20 #include "chrome/browser/task_manager/resource_provider.h" | 24 #include "chrome/browser/task_manager/resource_provider.h" |
| 21 #include "chrome/browser/task_manager/task_manager.h" | 25 #include "chrome/browser/task_manager/task_manager.h" |
| 26 #include "chrome/browser/ui/task_manager/task_manager_table_model.h" | |
| 22 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
| 24 #include "extensions/strings/grit/extensions_strings.h" | 29 #include "extensions/strings/grit/extensions_strings.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/models/table_model_observer.h" | |
| 33 | |
| 34 // TODO(nick): Move everything here (except for LegacyTaskManagerTesterImpl) | |
| 35 // into the task_management namespace. | |
| 36 namespace task_management { | |
| 37 | |
| 38 // Temporarily intercepts the calls between a TableModel and its Observer, | |
| 39 // running |callback| whenever anything happens. | |
| 40 class ScopedInterceptTableModelObserver : public ui::TableModelObserver { | |
| 41 public: | |
| 42 ScopedInterceptTableModelObserver( | |
| 43 ui::TableModel* model_to_intercept, | |
| 44 ui::TableModelObserver* real_table_model_observer, | |
| 45 const base::Closure& callback) | |
| 46 : model_to_intercept_(model_to_intercept), | |
| 47 real_table_model_observer_(real_table_model_observer), | |
| 48 callback_(callback) { | |
| 49 model_to_intercept_->SetObserver(this); | |
| 50 } | |
| 51 | |
| 52 ~ScopedInterceptTableModelObserver() override { | |
| 53 model_to_intercept_->SetObserver(real_table_model_observer_); | |
| 54 } | |
| 55 | |
| 56 // ui::TableModelObserver: | |
| 57 void OnModelChanged() override { | |
| 58 real_table_model_observer_->OnModelChanged(); | |
| 59 callback_.Run(); | |
| 60 } | |
| 61 void OnItemsChanged(int start, int length) override { | |
| 62 real_table_model_observer_->OnItemsChanged(start, length); | |
| 63 callback_.Run(); | |
| 64 } | |
| 65 void OnItemsAdded(int start, int length) override { | |
| 66 real_table_model_observer_->OnItemsAdded(start, length); | |
| 67 callback_.Run(); | |
| 68 } | |
| 69 void OnItemsRemoved(int start, int length) override { | |
| 70 real_table_model_observer_->OnItemsRemoved(start, length); | |
| 71 callback_.Run(); | |
| 72 } | |
| 73 | |
| 74 private: | |
| 75 ui::TableModel* model_to_intercept_; | |
| 76 ui::TableModelObserver* real_table_model_observer_; | |
| 77 base::Closure callback_; | |
| 78 }; | |
| 79 | |
| 80 class TaskManagerTesterImpl | |
| 81 : public task_manager::browsertest_util::TaskManagerTester { | |
| 82 public: | |
| 83 explicit TaskManagerTesterImpl(const base::Closure& on_resource_change) | |
| 84 : model_(GetRealModel()) { | |
| 85 // Eavesdrop the model->view conversation, since the model only supports | |
| 86 // single observation. | |
| 87 if (!on_resource_change.is_null()) { | |
| 88 interceptor_.reset(new ScopedInterceptTableModelObserver( | |
| 89 model_, model_->table_model_observer_, on_resource_change)); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 ~TaskManagerTesterImpl() override { | |
| 94 CHECK_EQ(GetRealModel(), model_) << "Task Manager should not be hidden " | |
| 95 "while TaskManagerTester is alive. " | |
| 96 "This indicates a test bug."; | |
| 97 } | |
| 98 | |
| 99 // TaskManagerTester: | |
| 100 int GetRowCount() override { return model_->RowCount(); } | |
| 101 | |
| 102 base::string16 GetRowTitle(int row) override { | |
| 103 return model_->GetText(row, IDS_TASK_MANAGER_TASK_COLUMN); | |
| 104 } | |
| 105 | |
| 106 void ToggleColumnVisibility( | |
| 107 task_manager::browsertest_util::ColumnSpecifier column) override { | |
| 108 int column_id = 0; | |
| 109 switch (column) { | |
| 110 case task_manager::browsertest_util::COLUMN_NONE: | |
| 111 return; | |
| 112 case task_manager::browsertest_util::SQLITE_MEMORY_USED: | |
| 113 column_id = IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN; | |
| 114 break; | |
| 115 case task_manager::browsertest_util::V8_MEMORY_USED: | |
| 116 case task_manager::browsertest_util::V8_MEMORY: | |
| 117 column_id = IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN; | |
| 118 break; | |
| 119 } | |
| 120 model_->ToggleColumnVisibility(column_id); | |
| 121 } | |
| 122 | |
| 123 int64_t GetColumnValue(task_manager::browsertest_util::ColumnSpecifier column, | |
| 124 int row) override { | |
| 125 TaskId task_id = model_->tasks_[row]; | |
| 126 int64_t value = 0; | |
| 127 int64_t ignored = 0; | |
| 128 bool success = false; | |
| 129 | |
| 130 switch (column) { | |
| 131 case task_manager::browsertest_util::COLUMN_NONE: | |
| 132 break; | |
| 133 case task_manager::browsertest_util::V8_MEMORY: | |
| 134 success = task_manager()->GetV8Memory(task_id, &value, &ignored); | |
| 135 break; | |
| 136 case task_manager::browsertest_util::V8_MEMORY_USED: | |
| 137 success = task_manager()->GetV8Memory(task_id, &ignored, &value); | |
| 138 break; | |
| 139 case task_manager::browsertest_util::SQLITE_MEMORY_USED: | |
| 140 value = task_manager()->GetSqliteMemoryUsed(task_id); | |
| 141 success = true; | |
| 142 break; | |
| 143 } | |
| 144 if (!success) | |
| 145 return 0; | |
| 146 return value; | |
| 147 } | |
| 148 | |
| 149 int32_t GetTabId(int row) override { | |
| 150 TaskId task_id = model_->tasks_[row]; | |
| 151 return task_manager()->GetTabId(task_id); | |
| 152 } | |
| 153 | |
| 154 void Kill(int row) override { model_->KillTask(row); } | |
| 155 | |
| 156 private: | |
| 157 TaskManagerInterface* task_manager() { | |
| 158 return model_->observed_task_manager(); | |
| 159 } | |
| 160 | |
| 161 // Returns the TaskManagerTableModel for the the visible NewTaskManagerView. | |
| 162 static TaskManagerTableModel* GetRealModel() { | |
| 163 // TODO(nick): Solve the following ui/views layering/deps problem: | |
| 164 // TaskManagerTableModel::GetInstanceForTesting() and its global variable | |
| 165 // only exist so that we can call it here. That's kind of lame. If we were | |
| 166 // allowed to #include ui/views here, we could befriend and call | |
| 167 // NewTaskManagerView::GetInstanceForTesting() and get the model from that. | |
| 168 TaskManagerTableModel* result = | |
| 169 TaskManagerTableModel::GetInstanceForTesting(); | |
|
sky
2016/05/03 13:28:19
If you need access to members of the created view
ncarter (slow)
2016/05/04 21:53:41
Done. This was a great idea that I hadn't consider
| |
| 170 CHECK(result) << "Task Manager must be visible to get the model."; | |
| 171 return result; | |
| 172 } | |
| 173 | |
| 174 TaskManagerTableModel* model_; | |
| 175 std::unique_ptr<ScopedInterceptTableModelObserver> interceptor_; | |
| 176 }; | |
| 177 | |
| 178 } // namespace task_management | |
| 27 | 179 |
| 28 namespace task_manager { | 180 namespace task_manager { |
| 29 namespace browsertest_util { | 181 namespace browsertest_util { |
| 30 | 182 |
| 31 namespace { | 183 namespace { |
| 32 | 184 |
| 33 class ResourceChangeObserver : public TaskManagerModelObserver { | 185 class LegacyTaskManagerTesterImpl : public TaskManagerTester, |
| 34 public: | 186 public TaskManagerModelObserver { |
| 35 ResourceChangeObserver(const TaskManagerModel* model, | 187 public: |
| 36 int required_count, | 188 explicit LegacyTaskManagerTesterImpl(const base::Closure& on_resource_change) |
| 189 : on_resource_change_(on_resource_change), | |
| 190 model_(TaskManager::GetInstance()->model()) { | |
| 191 if (!on_resource_change_.is_null()) | |
| 192 model_->AddObserver(this); | |
| 193 } | |
| 194 ~LegacyTaskManagerTesterImpl() override { | |
| 195 if (!on_resource_change_.is_null()) | |
| 196 model_->RemoveObserver(this); | |
| 197 } | |
| 198 | |
| 199 // TaskManagerTester: | |
| 200 int GetRowCount() override { return model_->ResourceCount(); } | |
| 201 | |
| 202 base::string16 GetRowTitle(int row) override { | |
| 203 return model_->GetResourceTitle(row); | |
| 204 } | |
| 205 | |
| 206 int64_t GetColumnValue(ColumnSpecifier column, int row) override { | |
| 207 size_t value = 0; | |
| 208 bool success = false; | |
| 209 switch (column) { | |
| 210 case COLUMN_NONE: | |
| 211 break; | |
| 212 case V8_MEMORY: | |
| 213 success = model_->GetV8Memory(row, &value); | |
| 214 break; | |
| 215 case V8_MEMORY_USED: | |
| 216 success = model_->GetV8MemoryUsed(row, &value); | |
| 217 break; | |
| 218 case SQLITE_MEMORY_USED: | |
| 219 success = model_->GetSqliteMemoryUsedBytes(row, &value); | |
| 220 break; | |
| 221 } | |
| 222 if (!success) | |
| 223 return 0; | |
| 224 return static_cast<int64_t>(value); | |
| 225 } | |
| 226 | |
| 227 void ToggleColumnVisibility(ColumnSpecifier column) override { | |
| 228 // Doing nothing is okay here; the legacy TaskManager always collects all | |
| 229 // stats. | |
| 230 } | |
| 231 | |
| 232 int32_t GetTabId(int row) override { | |
| 233 if (model_->GetResourceWebContents(row)) { | |
| 234 return SessionTabHelper::IdForTab(model_->GetResourceWebContents(row)); | |
| 235 } | |
| 236 return -1; | |
| 237 } | |
| 238 | |
| 239 void Kill(int row) override { TaskManager::GetInstance()->KillProcess(row); } | |
| 240 | |
| 241 // TaskManagerModelObserver: | |
| 242 void OnModelChanged() override { OnResourceChange(); } | |
| 243 void OnItemsChanged(int start, int length) override { OnResourceChange(); } | |
| 244 void OnItemsAdded(int start, int length) override { OnResourceChange(); } | |
| 245 void OnItemsRemoved(int start, int length) override { OnResourceChange(); } | |
| 246 | |
| 247 private: | |
| 248 void OnResourceChange() { | |
| 249 if (!on_resource_change_.is_null()) | |
| 250 on_resource_change_.Run(); | |
| 251 } | |
| 252 base::Closure on_resource_change_; | |
| 253 TaskManagerModel* model_; | |
| 254 }; | |
| 255 | |
| 256 // Helper class to run a message loop until a TaskManagerTester is in an | |
| 257 // expected state. If timeout occurs, an ASCII version of the task manager's | |
| 258 // contents, along with a summary of the expected state, are dumped to test | |
| 259 // output, to assist debugging. | |
| 260 class ResourceChangeObserver { | |
| 261 public: | |
| 262 ResourceChangeObserver(int required_count, | |
| 37 const base::string16& title_pattern, | 263 const base::string16& title_pattern, |
| 38 ColumnSpecifier column_specifier, | 264 ColumnSpecifier column_specifier, |
| 39 size_t min_column_value) | 265 size_t min_column_value) |
| 40 : model_(model), | 266 : required_count_(required_count), |
| 41 required_count_(required_count), | |
| 42 title_pattern_(title_pattern), | 267 title_pattern_(title_pattern), |
| 43 column_specifier_(column_specifier), | 268 column_specifier_(column_specifier), |
| 44 min_column_value_(min_column_value) {} | 269 min_column_value_(min_column_value) { |
| 45 | 270 base::Closure on_resource_change = base::Bind( |
| 46 void OnModelChanged() override { OnResourceChange(); } | 271 &ResourceChangeObserver::OnResourceChange, base::Unretained(this)); |
| 47 | 272 |
| 48 void OnItemsChanged(int start, int length) override { OnResourceChange(); } | 273 if (switches::NewTaskManagerEnabled()) { |
| 49 | 274 task_manager_tester_.reset( |
| 50 void OnItemsAdded(int start, int length) override { OnResourceChange(); } | 275 new task_management::TaskManagerTesterImpl(on_resource_change)); |
| 51 | 276 } else { |
| 52 void OnItemsRemoved(int start, int length) override { OnResourceChange(); } | 277 task_manager_tester_.reset( |
| 278 new LegacyTaskManagerTesterImpl(on_resource_change)); | |
| 279 } | |
| 280 } | |
| 53 | 281 |
| 54 void RunUntilSatisfied() { | 282 void RunUntilSatisfied() { |
| 55 // See if the condition is satisfied without having to run the loop. This | 283 // See if the condition is satisfied without having to run the loop. This |
| 56 // check has to be placed after the installation of the | 284 // check has to be placed after the installation of the |
| 57 // TaskManagerModelObserver, because resources may change before that. | 285 // TaskManagerModelObserver, because resources may change before that. |
| 58 if (IsSatisfied()) | 286 if (IsSatisfied()) |
| 59 return; | 287 return; |
| 60 | 288 |
| 61 timer_.Start(FROM_HERE, | 289 timer_.Start(FROM_HERE, TestTimeouts::action_timeout(), this, |
| 62 TestTimeouts::action_timeout(), | |
| 63 this, | |
| 64 &ResourceChangeObserver::OnTimeout); | 290 &ResourceChangeObserver::OnTimeout); |
| 65 | 291 |
| 66 run_loop_.Run(); | 292 run_loop_.Run(); |
| 67 | 293 |
| 68 // If we succeeded normally (no timeout), check our post condition again | 294 // If we succeeded normally (no timeout), check our post condition again |
| 69 // before returning control to the test. If it is no longer satisfied, the | 295 // before returning control to the test. If it is no longer satisfied, the |
| 70 // test is likely flaky: we were waiting for a state that was only achieved | 296 // test is likely flaky: we were waiting for a state that was only achieved |
| 71 // emphemerally), so treat this as a failure. | 297 // emphemerally), so treat this as a failure. |
| 72 if (!IsSatisfied() && timer_.IsRunning()) { | 298 if (!IsSatisfied() && timer_.IsRunning()) { |
| 73 FAIL() << "Wait condition satisfied only emphemerally. Likely test " | 299 FAIL() << "Wait condition satisfied only emphemerally. Likely test " |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 84 return; | 310 return; |
| 85 | 311 |
| 86 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 312 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 87 run_loop_.QuitClosure()); | 313 run_loop_.QuitClosure()); |
| 88 } | 314 } |
| 89 | 315 |
| 90 bool IsSatisfied() { return CountMatches() == required_count_; } | 316 bool IsSatisfied() { return CountMatches() == required_count_; } |
| 91 | 317 |
| 92 int CountMatches() { | 318 int CountMatches() { |
| 93 int match_count = 0; | 319 int match_count = 0; |
| 94 for (int i = 0; i < model_->ResourceCount(); i++) { | 320 for (int i = 0; i < task_manager_tester_->GetRowCount(); i++) { |
| 95 if (!base::MatchPattern(model_->GetResourceTitle(i), title_pattern_)) | 321 if (!base::MatchPattern(task_manager_tester_->GetRowTitle(i), |
| 322 title_pattern_)) | |
| 96 continue; | 323 continue; |
| 97 | 324 |
| 98 if (GetColumnValue(i) < min_column_value_) | 325 if (GetColumnValue(i) < min_column_value_) |
| 99 continue; | 326 continue; |
| 100 | 327 |
| 101 match_count++; | 328 match_count++; |
| 102 } | 329 } |
| 103 return match_count; | 330 return match_count; |
| 104 } | 331 } |
| 105 | 332 |
| 106 size_t GetColumnValue(int index) { | 333 int64_t GetColumnValue(int index) { |
| 107 size_t value = 0; | 334 return task_manager_tester_->GetColumnValue(column_specifier_, index); |
| 108 bool success = false; | |
| 109 switch (column_specifier_) { | |
| 110 case COLUMN_NONE: | |
| 111 break; | |
| 112 case V8_MEMORY: | |
| 113 success = model_->GetV8Memory(index, &value); | |
| 114 break; | |
| 115 case V8_MEMORY_USED: | |
| 116 success = model_->GetV8MemoryUsed(index, &value); | |
| 117 break; | |
| 118 case SQLITE_MEMORY_USED: | |
| 119 success = model_->GetSqliteMemoryUsedBytes(index, &value); | |
| 120 break; | |
| 121 } | |
| 122 if (!success) | |
| 123 return 0; | |
| 124 return value; | |
| 125 } | 335 } |
| 126 | 336 |
| 127 const char* GetColumnName() { | 337 const char* GetColumnName() { |
| 128 switch (column_specifier_) { | 338 switch (column_specifier_) { |
| 129 case COLUMN_NONE: | 339 case COLUMN_NONE: |
| 130 return "N/A"; | 340 return "N/A"; |
| 131 case V8_MEMORY: | 341 case V8_MEMORY: |
| 132 return "V8 Memory"; | 342 return "V8 Memory"; |
| 133 case V8_MEMORY_USED: | 343 case V8_MEMORY_USED: |
| 134 return "V8 Memory Used"; | 344 return "V8 Memory Used"; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 149 task_manager_state_dump << "Waiting for exactly " << required_count_ | 359 task_manager_state_dump << "Waiting for exactly " << required_count_ |
| 150 << " matches of wildcard pattern \"" | 360 << " matches of wildcard pattern \"" |
| 151 << base::UTF16ToASCII(title_pattern_) << "\""; | 361 << base::UTF16ToASCII(title_pattern_) << "\""; |
| 152 if (min_column_value_ > 0) { | 362 if (min_column_value_ > 0) { |
| 153 task_manager_state_dump << " && [" << GetColumnName() | 363 task_manager_state_dump << " && [" << GetColumnName() |
| 154 << " >= " << min_column_value_ << "]"; | 364 << " >= " << min_column_value_ << "]"; |
| 155 } | 365 } |
| 156 task_manager_state_dump << "\nCurrently there are " << CountMatches() | 366 task_manager_state_dump << "\nCurrently there are " << CountMatches() |
| 157 << " matches."; | 367 << " matches."; |
| 158 task_manager_state_dump << "\nCurrent Task Manager Model is:"; | 368 task_manager_state_dump << "\nCurrent Task Manager Model is:"; |
| 159 for (int i = 0; i < model_->ResourceCount(); i++) { | 369 for (int i = 0; i < task_manager_tester_->GetRowCount(); i++) { |
| 160 task_manager_state_dump | 370 task_manager_state_dump |
| 161 << "\n > " << std::setw(40) << std::left | 371 << "\n > " << std::setw(40) << std::left |
| 162 << base::UTF16ToASCII(model_->GetResourceTitle(i)); | 372 << base::UTF16ToASCII(task_manager_tester_->GetRowTitle(i)); |
| 163 if (min_column_value_ > 0) { | 373 if (min_column_value_ > 0) { |
| 164 task_manager_state_dump << " [" << GetColumnName() | 374 task_manager_state_dump << " [" << GetColumnName() |
| 165 << " == " << GetColumnValue(i) << "]"; | 375 << " == " << GetColumnValue(i) << "]"; |
| 166 } | 376 } |
| 167 } | 377 } |
| 168 return task_manager_state_dump; | 378 return task_manager_state_dump; |
| 169 } | 379 } |
| 170 | 380 |
| 171 const TaskManagerModel* model_; | 381 std::unique_ptr<TaskManagerTester> task_manager_tester_; |
| 172 const int required_count_; | 382 const int required_count_; |
| 173 const base::string16 title_pattern_; | 383 const base::string16 title_pattern_; |
| 174 const ColumnSpecifier column_specifier_; | 384 const ColumnSpecifier column_specifier_; |
| 175 const size_t min_column_value_; | 385 const int64_t min_column_value_; |
| 176 base::RunLoop run_loop_; | 386 base::RunLoop run_loop_; |
| 177 base::OneShotTimer timer_; | 387 base::OneShotTimer timer_; |
| 178 }; | 388 }; |
| 179 | 389 |
| 180 } // namespace | 390 } // namespace |
| 181 | 391 |
| 182 void EnableOldTaskManager() { | 392 std::unique_ptr<TaskManagerTester> GetTaskManagerTester() { |
| 183 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 393 if (switches::NewTaskManagerEnabled()) { |
| 184 switches::kDisableNewTaskManager); | 394 return base::WrapUnique( |
| 395 new task_management::TaskManagerTesterImpl(base::Closure())); | |
| 396 } else { | |
| 397 return base::WrapUnique(new LegacyTaskManagerTesterImpl(base::Closure())); | |
| 398 } | |
| 185 } | 399 } |
| 186 | 400 |
| 187 void WaitForTaskManagerRows(int required_count, | 401 void WaitForTaskManagerRows(int required_count, |
| 188 const base::string16& title_pattern) { | 402 const base::string16& title_pattern) { |
| 189 TaskManagerModel* model = TaskManager::GetInstance()->model(); | |
| 190 | |
| 191 const int column_value_dont_care = 0; | 403 const int column_value_dont_care = 0; |
| 192 ResourceChangeObserver observer(model, required_count, title_pattern, | 404 ResourceChangeObserver observer(required_count, title_pattern, COLUMN_NONE, |
| 193 COLUMN_NONE, column_value_dont_care); | 405 column_value_dont_care); |
| 194 model->AddObserver(&observer); | |
| 195 observer.RunUntilSatisfied(); | 406 observer.RunUntilSatisfied(); |
| 196 model->RemoveObserver(&observer); | |
| 197 } | 407 } |
| 198 | 408 |
| 199 void WaitForTaskManagerStatToExceed(const base::string16& title_pattern, | 409 void WaitForTaskManagerStatToExceed(const base::string16& title_pattern, |
| 200 ColumnSpecifier column_getter, | 410 ColumnSpecifier column_getter, |
| 201 size_t min_column_value) { | 411 size_t min_column_value) { |
| 202 TaskManagerModel* model = TaskManager::GetInstance()->model(); | |
| 203 | |
| 204 const int wait_for_one_match = 1; | 412 const int wait_for_one_match = 1; |
| 205 ResourceChangeObserver observer(model, wait_for_one_match, title_pattern, | 413 ResourceChangeObserver observer(wait_for_one_match, title_pattern, |
| 206 column_getter, min_column_value); | 414 column_getter, min_column_value); |
| 207 model->AddObserver(&observer); | |
| 208 observer.RunUntilSatisfied(); | 415 observer.RunUntilSatisfied(); |
| 209 model->RemoveObserver(&observer); | |
| 210 } | 416 } |
| 211 | 417 |
| 212 base::string16 MatchTab(const char* title) { | 418 base::string16 MatchTab(const char* title) { |
| 213 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_TAB_PREFIX, | 419 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_TAB_PREFIX, |
| 214 base::ASCIIToUTF16(title)); | 420 base::ASCIIToUTF16(title)); |
| 215 } | 421 } |
| 216 | 422 |
| 217 base::string16 MatchAnyTab() { return MatchTab("*"); } | 423 base::string16 MatchAnyTab() { |
| 424 return MatchTab("*"); | |
| 425 } | |
| 218 | 426 |
| 219 base::string16 MatchAboutBlankTab() { return MatchTab("about:blank"); } | 427 base::string16 MatchAboutBlankTab() { |
| 428 return MatchTab("about:blank"); | |
| 429 } | |
| 220 | 430 |
| 221 base::string16 MatchExtension(const char* title) { | 431 base::string16 MatchExtension(const char* title) { |
| 222 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_EXTENSION_PREFIX, | 432 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_EXTENSION_PREFIX, |
| 223 base::ASCIIToUTF16(title)); | 433 base::ASCIIToUTF16(title)); |
| 224 } | 434 } |
| 225 | 435 |
| 226 base::string16 MatchAnyExtension() { return MatchExtension("*"); } | 436 base::string16 MatchAnyExtension() { |
| 437 return MatchExtension("*"); | |
| 438 } | |
| 227 | 439 |
| 228 base::string16 MatchApp(const char* title) { | 440 base::string16 MatchApp(const char* title) { |
| 229 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_APP_PREFIX, | 441 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_APP_PREFIX, |
| 230 base::ASCIIToUTF16(title)); | 442 base::ASCIIToUTF16(title)); |
| 231 } | 443 } |
| 232 | 444 |
| 233 base::string16 MatchAnyApp() { return MatchApp("*"); } | 445 base::string16 MatchAnyApp() { |
| 446 return MatchApp("*"); | |
| 447 } | |
| 234 | 448 |
| 235 base::string16 MatchWebView(const char* title) { | 449 base::string16 MatchWebView(const char* title) { |
| 236 return l10n_util::GetStringFUTF16( | 450 return l10n_util::GetStringFUTF16( |
| 237 IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX, | 451 IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX, base::ASCIIToUTF16(title)); |
| 238 base::ASCIIToUTF16(title)); | |
| 239 } | 452 } |
| 240 | 453 |
| 241 base::string16 MatchAnyWebView() { return MatchWebView("*"); } | 454 base::string16 MatchAnyWebView() { |
| 455 return MatchWebView("*"); | |
| 456 } | |
| 242 | 457 |
| 243 base::string16 MatchBackground(const char* title) { | 458 base::string16 MatchBackground(const char* title) { |
| 244 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_BACKGROUND_PREFIX, | 459 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_BACKGROUND_PREFIX, |
| 245 base::ASCIIToUTF16(title)); | 460 base::ASCIIToUTF16(title)); |
| 246 } | 461 } |
| 247 | 462 |
| 248 base::string16 MatchAnyBackground() { return MatchBackground("*"); } | 463 base::string16 MatchAnyBackground() { |
| 464 return MatchBackground("*"); | |
| 465 } | |
| 249 | 466 |
| 250 base::string16 MatchPrint(const char* title) { | 467 base::string16 MatchPrint(const char* title) { |
| 251 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRINT_PREFIX, | 468 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRINT_PREFIX, |
| 252 base::ASCIIToUTF16(title)); | 469 base::ASCIIToUTF16(title)); |
| 253 } | 470 } |
| 254 | 471 |
| 255 base::string16 MatchAnyPrint() { return MatchPrint("*"); } | 472 base::string16 MatchAnyPrint() { |
| 473 return MatchPrint("*"); | |
| 474 } | |
| 256 | 475 |
| 257 base::string16 MatchSubframe(const char* title) { | 476 base::string16 MatchSubframe(const char* title) { |
| 258 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_SUBFRAME_PREFIX, | 477 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_SUBFRAME_PREFIX, |
| 259 base::ASCIIToUTF16(title)); | 478 base::ASCIIToUTF16(title)); |
| 260 } | 479 } |
| 261 | 480 |
| 262 base::string16 MatchAnySubframe() { | 481 base::string16 MatchAnySubframe() { |
| 263 return MatchSubframe("*"); | 482 return MatchSubframe("*"); |
| 264 } | 483 } |
| 265 | 484 |
| 266 base::string16 MatchUtility(const base::string16& title) { | 485 base::string16 MatchUtility(const base::string16& title) { |
| 267 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_UTILITY_PREFIX, title); | 486 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_UTILITY_PREFIX, title); |
| 268 } | 487 } |
| 269 | 488 |
| 270 base::string16 MatchAnyUtility() { | 489 base::string16 MatchAnyUtility() { |
| 271 return MatchUtility(base::ASCIIToUTF16("*")); | 490 return MatchUtility(base::ASCIIToUTF16("*")); |
| 272 } | 491 } |
| 273 | 492 |
| 274 } // namespace browsertest_util | 493 } // namespace browsertest_util |
| 275 } // namespace task_manager | 494 } // namespace task_manager |
| OLD | NEW |