Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2010 The Chromium Authors |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_TEST_HELPER_H_ |
6 | #define CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_TEST_HELPER_H_ | ||||
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 7 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 8 | #include <stddef.h> |
9 | |||||
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 11 | #include <string> |
12 | |||||
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 13 | #include "extensions/common/extension_id.h" |
[email protected] | 2e0a150 | 2014-05-14 02:59:43 | [diff] [blame] | 14 | #include "ui/gfx/native_widget_types.h" |
[email protected] | a39f1a9 | 2010-03-10 18:36:58 | [diff] [blame] | 15 | |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 16 | class Browser; |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 17 | |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 18 | namespace gfx { |
[email protected] | 866d940a | 2012-09-10 23:02:02 | [diff] [blame] | 19 | class Image; |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 20 | class Size; |
21 | } // namespace gfx | ||||
22 | |||||
Alison Gale | 9130192d | 2024-04-15 19:35:27 | [diff] [blame] | 23 | // TODO(crbug.com/40177062): A lot of this class can be cleaned up for |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 24 | // the new toolbar UI. Some of it may also be removable, since we now have |
25 | // the platform-abstract ExtensionsContainer class. | ||||
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 26 | class ExtensionActionTestHelper { |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 27 | public: |
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 28 | // Constructs a ExtensionActionTestHelper which, if |is_real_window| is false, |
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 29 | // will create its own browser actions container. This is useful in unit |
30 | // tests, when the |browser|'s window doesn't create platform-specific views. | ||||
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 31 | static std::unique_ptr<ExtensionActionTestHelper> Create( |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 32 | Browser* browser, |
33 | bool is_real_window = true); | ||||
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 34 | |
Peter Boström | 53c6c595 | 2021-09-17 09:41:26 | [diff] [blame] | 35 | ExtensionActionTestHelper(const ExtensionActionTestHelper&) = delete; |
36 | ExtensionActionTestHelper& operator=(const ExtensionActionTestHelper&) = | ||||
37 | delete; | ||||
38 | |||||
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 39 | virtual ~ExtensionActionTestHelper() {} |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 40 | |
41 | // Returns the number of browser action buttons in the window toolbar. | ||||
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 42 | virtual int NumberOfBrowserActions() = 0; |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 43 | |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 44 | // Returns true if there is an action for the given `id`. |
45 | virtual bool HasAction(const extensions::ExtensionId& id) = 0; | ||||
[email protected] | 53a7d2d | 2010-03-10 07:50:06 | [diff] [blame] | 46 | |
Keren Zhu | 321371e | 2024-05-15 19:49:52 | [diff] [blame] | 47 | // Simulates a user click on the action button for the given `id`. |
48 | virtual void Press(const extensions::ExtensionId& id) = 0; | ||||
49 | |||||
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 50 | // Inspects the extension popup for the action with the given `id`. |
51 | virtual void InspectPopup(const extensions::ExtensionId& id) = 0; | ||||
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 52 | |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 53 | // Returns icon for the action for the given `id`. |
54 | virtual gfx::Image GetIcon(const extensions::ExtensionId& id) = 0; | ||||
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 55 | |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 56 | virtual gfx::NativeView GetPopupNativeView() = 0; |
[email protected] | 2e0a150 | 2014-05-14 02:59:43 | [diff] [blame] | 57 | |
tapted | 9e780e2 | 2017-06-01 06:13:19 | [diff] [blame] | 58 | // Spins a RunLoop until the NativeWindow hosting |GetPopupNativeView()| is |
Devlin Cronin | ca573201 | 2024-07-11 23:09:01 | [diff] [blame] | 59 | // reported as active by the OS. This method is strange: it's not overridden |
60 | // by subclasses, and instead the implementation is selected at compile-time | ||||
61 | // depending on the windowing system in use. | ||||
62 | void WaitForPopup(); | ||||
tapted | 9e780e2 | 2017-06-01 06:13:19 | [diff] [blame] | 63 | |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 64 | // Returns whether a browser action popup is being shown currently. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 65 | virtual bool HasPopup() = 0; |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 66 | |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 67 | // Hides the given popup and returns whether the hide was successful. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 68 | virtual bool HidePopup() = 0; |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 69 | |
Sanchit Abrol | 9f4190ad | 2020-11-05 17:19:25 | [diff] [blame] | 70 | // Waits for the ExtensionContainer's layout to be done. |
71 | virtual void WaitForExtensionsContainerLayout() = 0; | ||||
72 | |||||
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 73 | // Returns the minimum allowed size of an extension popup. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 74 | virtual gfx::Size GetMinPopupSize() = 0; |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 75 | |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 76 | // Returns the maximum allowed size of an extension popup. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 77 | virtual gfx::Size GetMaxPopupSize() = 0; |
78 | |||||
Sanchit Abrol | 9f4190ad | 2020-11-05 17:19:25 | [diff] [blame] | 79 | // Returns the maximum available size to place a bubble anchored to |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 80 | // the action with the given `id` on screen. |
Sanchit Abrol | 9f4190ad | 2020-11-05 17:19:25 | [diff] [blame] | 81 | virtual gfx::Size GetMaxAvailableSizeToFitBubbleOnScreen( |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 82 | const extensions::ExtensionId& id) = 0; |
Sanchit Abrol | 9f4190ad | 2020-11-05 17:19:25 | [diff] [blame] | 83 | |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 84 | protected: |
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 85 | ExtensionActionTestHelper() {} |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 86 | }; |
87 | |||||
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 88 | #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_TEST_HELPER_H_ |