nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_TESTER_H_ |
| 6 | #define CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_TESTER_H_ |
| 7 | |
nick | 50b0649 | 2016-05-10 23:40:27 | [diff] [blame] | 8 | #include <stdint.h> |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 9 | |
| 10 | #include <memory> |
| 11 | |
| 12 | #include "base/callback_forward.h" |
| 13 | #include "base/strings/string16.h" |
nick | 50b0649 | 2016-05-10 23:40:27 | [diff] [blame] | 14 | #include "chrome/browser/task_management/task_manager_browsertest_util.h" |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 15 | |
| 16 | namespace task_management { |
| 17 | |
avi | b6ebc442 | 2016-08-03 18:40:50 | [diff] [blame] | 18 | class ScopedInterceptTableModelObserver; |
| 19 | class TaskManagerInterface; |
| 20 | class TaskManagerTableModel; |
| 21 | |
avi | 71aebed | 2016-08-02 21:57:59 | [diff] [blame] | 22 | // An adapter to simplify testing the task manager. |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 23 | class TaskManagerTester { |
| 24 | public: |
nick | 50b0649 | 2016-05-10 23:40:27 | [diff] [blame] | 25 | using ColumnSpecifier = browsertest_util::ColumnSpecifier; |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 26 | |
avi | b6ebc442 | 2016-08-03 18:40:50 | [diff] [blame] | 27 | ~TaskManagerTester(); |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 28 | |
avi | b6ebc442 | 2016-08-03 18:40:50 | [diff] [blame] | 29 | // Creates a TaskManagerTester backed by the current task manager. The task |
| 30 | // manager should already be visible when you call this function. |
| 31 | // |on_resource_change|, if not a null callback, will be invoked when the |
| 32 | // underlying model changes. |
| 33 | static std::unique_ptr<TaskManagerTester> Create( |
| 34 | const base::Closure& on_resource_change); |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 35 | |
| 36 | // Get the number of rows currently in the task manager. |
avi | b6ebc442 | 2016-08-03 18:40:50 | [diff] [blame] | 37 | int GetRowCount(); |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 38 | |
| 39 | // Get the title text of a particular |row|. |
avi | b6ebc442 | 2016-08-03 18:40:50 | [diff] [blame] | 40 | base::string16 GetRowTitle(int row); |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 41 | |
| 42 | // Hide or show a column. If a column is not visible its stats are not |
| 43 | // necessarily gathered. |
avi | b6ebc442 | 2016-08-03 18:40:50 | [diff] [blame] | 44 | void ToggleColumnVisibility(ColumnSpecifier column); |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 45 | |
| 46 | // Get the value of a column as an int64. Memory values are in bytes. |
avi | b6ebc442 | 2016-08-03 18:40:50 | [diff] [blame] | 47 | int64_t GetColumnValue(ColumnSpecifier column, int row); |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 48 | |
| 49 | // If |row| is associated with a WebContents, return its SessionID. Otherwise, |
| 50 | // return -1. |
avi | b6ebc442 | 2016-08-03 18:40:50 | [diff] [blame] | 51 | int32_t GetTabId(int row); |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 52 | |
| 53 | // Kill the process of |row|. |
avi | b6ebc442 | 2016-08-03 18:40:50 | [diff] [blame] | 54 | void Kill(int row); |
afakhry | 17406972 | 2016-05-24 19:16:16 | [diff] [blame] | 55 | |
avi | 1c6f3ff8 | 2016-08-01 22:33:35 | [diff] [blame] | 56 | // Gets the start index and length of the group to which the task at |
| 57 | // |row_index| belongs. |
avi | b6ebc442 | 2016-08-03 18:40:50 | [diff] [blame] | 58 | void GetRowsGroupRange(int row, int* out_start, int* out_length); |
| 59 | |
| 60 | private: |
| 61 | explicit TaskManagerTester(const base::Closure& on_resource_change); |
| 62 | |
| 63 | TaskManagerInterface* task_manager(); |
| 64 | |
| 65 | TaskManagerTableModel* model_; |
| 66 | std::unique_ptr<ScopedInterceptTableModelObserver> interceptor_; |
nick | 22bcc772 | 2016-05-10 18:43:41 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } // namespace task_management |
| 70 | |
| 71 | #endif // CHROME_BROWSER_TASK_MANAGEMENT_TASK_MANAGER_TESTER_H_ |