OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_BROWSERTEST_UTIL_H_ | 5 #ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_BROWSERTEST_UTIL_H_ |
6 #define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_BROWSERTEST_UTIL_H_ | 6 #define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_BROWSERTEST_UTIL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
| 10 #include <memory> |
| 11 |
10 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
11 | 13 |
| 14 namespace content { |
| 15 class WebContents; |
| 16 } |
| 17 |
| 18 // TODO(nick): Move everything here (except for LegacyTaskManagerTesterImpl) |
| 19 // into the task_management namespace. |
12 namespace task_manager { | 20 namespace task_manager { |
13 namespace browsertest_util { | 21 namespace browsertest_util { |
14 | 22 |
15 // For the old task manager browser tests, we must call this to disable the | 23 // Specifies some integer-valued column of numeric data reported by the task |
16 // use of the new implementation and revert back to the old one. | 24 // manager model. Please add more here as needed by tests. |
17 void EnableOldTaskManager(); | 25 enum ColumnSpecifier { |
| 26 V8_MEMORY, |
| 27 V8_MEMORY_USED, |
| 28 SQLITE_MEMORY_USED, |
| 29 |
| 30 COLUMN_NONE, // Default value. |
| 31 }; |
| 32 |
| 33 // An adapter that abstracts away the difference of old vs. new task manager. |
| 34 class TaskManagerTester { |
| 35 public: |
| 36 virtual ~TaskManagerTester() {} |
| 37 |
| 38 // Get the number of rows currently in the task manager. |
| 39 virtual int GetRowCount() = 0; |
| 40 |
| 41 // Get the title text of a particular |row|. |
| 42 virtual base::string16 GetRowTitle(int row) = 0; |
| 43 |
| 44 // Hide or show a column. If a column is not visible its stats are not |
| 45 // necessarily gathered. |
| 46 virtual void ToggleColumnVisibility(ColumnSpecifier column) = 0; |
| 47 |
| 48 // Get the value of a column as an int64. Memory values are in bytes. |
| 49 virtual int64_t GetColumnValue(ColumnSpecifier column, int row) = 0; |
| 50 |
| 51 // If |row| is associated with a WebContents, return its SessionID. Otherwise, |
| 52 // return -1. |
| 53 virtual int32_t GetTabId(int row) = 0; |
| 54 |
| 55 // Kill the process of |row|. |
| 56 virtual void Kill(int row) = 0; |
| 57 }; |
| 58 |
| 59 // Creates a TaskManagerTester backed by the current task manager. The task |
| 60 // manager should already be visible when you call this function. |
| 61 std::unique_ptr<TaskManagerTester> GetTaskManagerTester(); |
18 | 62 |
19 // Runs the message loop, observing the task manager, until there are exactly | 63 // Runs the message loop, observing the task manager, until there are exactly |
20 // |resource_count| many resources whose titles match the pattern | 64 // |resource_count| many resources whose titles match the pattern |
21 // |title_pattern|. The match is done via string_util's base::MatchPattern, so | 65 // |title_pattern|. The match is done via string_util's base::MatchPattern, so |
22 // |title_pattern| may contain wildcards like "*". | 66 // |title_pattern| may contain wildcards like "*". |
23 // | 67 // |
24 // If the wait times out, this test will trigger a gtest failure. To get | 68 // If the wait times out, this test will trigger a gtest failure. To get |
25 // meaningful errors, tests should wrap invocations of this function with | 69 // meaningful errors, tests should wrap invocations of this function with |
26 // ASSERT_NO_FATAL_FAILURE(). | 70 // ASSERT_NO_FATAL_FAILURE(). |
27 void WaitForTaskManagerRows(int resource_count, | 71 void WaitForTaskManagerRows(int resource_count, |
28 const base::string16& title_pattern); | 72 const base::string16& title_pattern); |
29 | 73 |
30 // Specifies some integer-valued column of numeric data reported by the task | 74 // Make the indicated TaskManager column be visible. |
31 // manager model. Please add more here as needed by tests. | 75 void ShowColumn(ColumnSpecifier column_specifier); |
32 enum ColumnSpecifier { | |
33 V8_MEMORY, | |
34 V8_MEMORY_USED, | |
35 SQLITE_MEMORY_USED, | |
36 | |
37 COLUMN_NONE, // Default value. | |
38 }; | |
39 | 76 |
40 // Waits for the row identified by |title_pattern| to be showing a numeric data | 77 // Waits for the row identified by |title_pattern| to be showing a numeric data |
41 // value of at least |min_column_value| in the task manager column identified by | 78 // value of at least |min_column_value| in the task manager column identified by |
42 // |column_specifier|. As with WaitForTaskManagerRows(), |title_pattern| is | 79 // |column_specifier|. As with WaitForTaskManagerRows(), |title_pattern| is |
43 // meant to be a string returned by MatchTab() or similar. | 80 // meant to be a string returned by MatchTab() or similar. |
44 // | 81 // |
45 // To get meaningful errors, tests should wrap invocations of this function with | 82 // To get meaningful errors, tests should wrap invocations of this function with |
46 // ASSERT_NO_FATAL_FAILURE(). | 83 // ASSERT_NO_FATAL_FAILURE(). |
47 void WaitForTaskManagerStatToExceed(const base::string16& title_pattern, | 84 void WaitForTaskManagerStatToExceed(const base::string16& title_pattern, |
48 ColumnSpecifier column_specifier, | 85 ColumnSpecifier column_specifier, |
(...skipping 16 matching lines...) Expand all Loading... |
65 base::string16 MatchSubframe(const char* title); // "Subframe: " + title | 102 base::string16 MatchSubframe(const char* title); // "Subframe: " + title |
66 base::string16 MatchAnySubframe(); // "Subframe: *" | 103 base::string16 MatchAnySubframe(); // "Subframe: *" |
67 // "Utility: " + title | 104 // "Utility: " + title |
68 base::string16 MatchUtility(const base::string16& title); | 105 base::string16 MatchUtility(const base::string16& title); |
69 base::string16 MatchAnyUtility(); // "Utility: *" | 106 base::string16 MatchAnyUtility(); // "Utility: *" |
70 | 107 |
71 } // namespace browsertest_util | 108 } // namespace browsertest_util |
72 } // namespace task_manager | 109 } // namespace task_manager |
73 | 110 |
74 #endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_BROWSERTEST_UTIL_H_ | 111 #endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_BROWSERTEST_UTIL_H_ |
OLD | NEW |