[email protected] | 7d9ad0b3 | 2010-02-12 21:44:45 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[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 | |||||
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 13 | #include "base/macros.h" |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 14 | #include "extensions/common/extension_id.h" |
[email protected] | 2e0a150 | 2014-05-14 02:59:43 | [diff] [blame] | 15 | #include "ui/gfx/native_widget_types.h" |
[email protected] | a39f1a9 | 2010-03-10 18:36:58 | [diff] [blame] | 16 | |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 17 | class Browser; |
Devlin Cronin | 256b4ae | 2019-12-09 18:34:25 | [diff] [blame] | 18 | class ExtensionsContainer; |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 19 | |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 20 | namespace gfx { |
[email protected] | 866d940a | 2012-09-10 23:02:02 | [diff] [blame] | 21 | class Image; |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 22 | class Size; |
23 | } // namespace gfx | ||||
24 | |||||
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 25 | // TODO(https://crbug.com/1197766): A lot of this class can be cleaned up for |
26 | // the new toolbar UI. Some of it may also be removable, since we now have | ||||
27 | // the platform-abstract ExtensionsContainer class. | ||||
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 28 | class ExtensionActionTestHelper { |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 29 | public: |
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 30 | // Constructs a ExtensionActionTestHelper which, if |is_real_window| is false, |
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 31 | // will create its own browser actions container. This is useful in unit |
32 | // tests, when the |browser|'s window doesn't create platform-specific views. | ||||
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 33 | static std::unique_ptr<ExtensionActionTestHelper> Create( |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 34 | Browser* browser, |
35 | bool is_real_window = true); | ||||
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 36 | |
Peter Boström | 53c6c595 | 2021-09-17 09:41:26 | [diff] [blame^] | 37 | ExtensionActionTestHelper(const ExtensionActionTestHelper&) = delete; |
38 | ExtensionActionTestHelper& operator=(const ExtensionActionTestHelper&) = | ||||
39 | delete; | ||||
40 | |||||
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 41 | virtual ~ExtensionActionTestHelper() {} |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 42 | |
43 | // Returns the number of browser action buttons in the window toolbar. | ||||
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 44 | virtual int NumberOfBrowserActions() = 0; |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 45 | |
Collin Baker | 58fb6e0f | 2020-04-28 01:59:17 | [diff] [blame] | 46 | // Returns the number of browser action currently visible. Note that a correct |
47 | // result may require a UI layout. Ensure the UI layout is up-to-date (e.g. by | ||||
48 | // calling InProcessBrowserTest::RunScheduledLayouts()) for a browser test. | ||||
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 49 | virtual int VisibleBrowserActions() = 0; |
[email protected] | 7d9ad0b3 | 2010-02-12 21:44:45 | [diff] [blame] | 50 | |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 51 | // Returns true if there is an action for the given `id`. |
52 | virtual bool HasAction(const extensions::ExtensionId& id) = 0; | ||||
[email protected] | 53a7d2d | 2010-03-10 07:50:06 | [diff] [blame] | 53 | |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 54 | // Inspects the extension popup for the action with the given `id`. |
55 | virtual void InspectPopup(const extensions::ExtensionId& id) = 0; | ||||
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 56 | |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 57 | // Returns whether the extension action for the given `id` has a non-null |
58 | // icon. Note that the icon is loaded asynchronously, in which case you can | ||||
59 | // wait for it to load by calling WaitForBrowserActionUpdated. | ||||
60 | virtual bool HasIcon(const extensions::ExtensionId& id) = 0; | ||||
[email protected] | 866d940a | 2012-09-10 23:02:02 | [diff] [blame] | 61 | |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 62 | // Returns icon for the action for the given `id`. |
63 | virtual gfx::Image GetIcon(const extensions::ExtensionId& id) = 0; | ||||
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 64 | |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 65 | // Simulates a user click on the action button for the given `id`. |
66 | virtual void Press(const extensions::ExtensionId& id) = 0; | ||||
[email protected] | 7d9ad0b3 | 2010-02-12 21:44:45 | [diff] [blame] | 67 | |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 68 | // Returns the current tooltip of the action for the given `id`. |
69 | virtual std::string GetTooltip(const extensions::ExtensionId& id) = 0; | ||||
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 70 | |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 71 | virtual gfx::NativeView GetPopupNativeView() = 0; |
[email protected] | 2e0a150 | 2014-05-14 02:59:43 | [diff] [blame] | 72 | |
tapted | 9e780e2 | 2017-06-01 06:13:19 | [diff] [blame] | 73 | // Spins a RunLoop until the NativeWindow hosting |GetPopupNativeView()| is |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 74 | // reported as active by the OS. Returns true if successful. This method is |
75 | // strange: it's not overridden by subclasses, and instead the implementation | ||||
76 | // is selected at compile-time depending on the windowing system in use. | ||||
tapted | 9e780e2 | 2017-06-01 06:13:19 | [diff] [blame] | 77 | bool WaitForPopup(); |
78 | |||||
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 79 | // Returns whether a browser action popup is being shown currently. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 80 | virtual bool HasPopup() = 0; |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 81 | |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 82 | // Hides the given popup and returns whether the hide was successful. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 83 | virtual bool HidePopup() = 0; |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 84 | |
rdevlin.cronin | ede728b | 2015-09-17 21:47:32 | [diff] [blame] | 85 | // Sets the current width of the browser actions container without resizing |
86 | // the underlying controller. This is to simulate e.g. when the browser window | ||||
87 | // is too small for the preferred width. | ||||
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 88 | virtual void SetWidth(int width) = 0; |
rdevlin.cronin | ede728b | 2015-09-17 21:47:32 | [diff] [blame] | 89 | |
Devlin Cronin | 256b4ae | 2019-12-09 18:34:25 | [diff] [blame] | 90 | // Returns the associated ExtensionsContainer. |
91 | virtual ExtensionsContainer* GetExtensionsContainer() = 0; | ||||
92 | |||||
Sanchit Abrol | 9f4190ad | 2020-11-05 17:19:25 | [diff] [blame] | 93 | // Waits for the ExtensionContainer's layout to be done. |
94 | virtual void WaitForExtensionsContainerLayout() = 0; | ||||
95 | |||||
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 96 | // Creates and returns a ExtensionActionTestHelper with an "overflow" |
97 | // container, with this object's container as the main bar. | ||||
98 | virtual std::unique_ptr<ExtensionActionTestHelper> CreateOverflowBar( | ||||
Devlin Cronin | 794c0a7 | 2019-10-25 01:45:46 | [diff] [blame] | 99 | Browser* browser) = 0; |
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 100 | |
Collin Baker | 58fb6e0f | 2020-04-28 01:59:17 | [diff] [blame] | 101 | // Forces a layout of an overflow bar. Must only be called on the helper |
102 | // returned by CreateOverflowBar(). | ||||
103 | virtual void LayoutForOverflowBar() = 0; | ||||
104 | |||||
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 105 | // Returns the minimum allowed size of an extension popup. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 106 | virtual gfx::Size GetMinPopupSize() = 0; |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 107 | |
Devlin Cronin | 256b4ae | 2019-12-09 18:34:25 | [diff] [blame] | 108 | // Returns the size of the toolbar actions. |
109 | virtual gfx::Size GetToolbarActionSize() = 0; | ||||
110 | |||||
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 111 | // Returns the maximum allowed size of an extension popup. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 112 | virtual gfx::Size GetMaxPopupSize() = 0; |
113 | |||||
Sanchit Abrol | 9f4190ad | 2020-11-05 17:19:25 | [diff] [blame] | 114 | // Returns the maximum available size to place a bubble anchored to |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 115 | // the action with the given `id` on screen. |
Sanchit Abrol | 9f4190ad | 2020-11-05 17:19:25 | [diff] [blame] | 116 | virtual gfx::Size GetMaxAvailableSizeToFitBubbleOnScreen( |
Devlin Cronin | 5ce7d58 | 2021-05-05 23:01:03 | [diff] [blame] | 117 | const extensions::ExtensionId& id) = 0; |
Sanchit Abrol | 9f4190ad | 2020-11-05 17:19:25 | [diff] [blame] | 118 | |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 119 | protected: |
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 120 | ExtensionActionTestHelper() {} |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 121 | }; |
122 | |||||
Devlin Cronin | e458a22 | 2019-12-30 22:39:37 | [diff] [blame] | 123 | #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_TEST_HELPER_H_ |