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