[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 | |||||
Christopher Lam | 851605b | 2018-02-09 05:24:04 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_UI_EXTENSIONS_BROWSER_ACTION_TEST_UTIL_H_ |
6 | #define CHROME_BROWSER_UI_EXTENSIONS_BROWSER_ACTION_TEST_UTIL_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" |
[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; |
rdevlin.cronin | b43d48e | 2015-01-29 17:51:41 | [diff] [blame] | 17 | class ToolbarActionsBar; |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 18 | |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 19 | namespace gfx { |
[email protected] | 866d940a | 2012-09-10 23:02:02 | [diff] [blame] | 20 | class Image; |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 21 | class Size; |
22 | } // namespace gfx | ||||
23 | |||||
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 24 | // A class that creates and owns the platform-specific views for the browser |
25 | // actions container. Specific implementations are in the .cc/.mm files. | ||||
26 | class TestToolbarActionsBarHelper { | ||||
27 | public: | ||||
28 | virtual ~TestToolbarActionsBarHelper() {} | ||||
29 | }; | ||||
30 | |||||
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 31 | class BrowserActionTestUtil { |
32 | public: | ||||
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 33 | // Constructs a BrowserActionTestUtil which, if |is_real_window| is false, |
34 | // will create its own browser actions container. This is useful in unit | ||||
35 | // tests, when the |browser|'s window doesn't create platform-specific views. | ||||
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 36 | static std::unique_ptr<BrowserActionTestUtil> Create( |
37 | Browser* browser, | ||||
38 | bool is_real_window = true); | ||||
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 39 | |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 40 | virtual ~BrowserActionTestUtil() {} |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 41 | |
42 | // Returns the number of browser action buttons in the window toolbar. | ||||
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 43 | virtual int NumberOfBrowserActions() = 0; |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 44 | |
[email protected] | 7d9ad0b3 | 2010-02-12 21:44:45 | [diff] [blame] | 45 | // Returns the number of browser action currently visible. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 46 | virtual int VisibleBrowserActions() = 0; |
[email protected] | 7d9ad0b3 | 2010-02-12 21:44:45 | [diff] [blame] | 47 | |
[email protected] | 93fb8d62 | 2014-05-10 18:42:58 | [diff] [blame] | 48 | // Inspects the extension popup for the action at the given index. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 49 | virtual void InspectPopup(int index) = 0; |
[email protected] | 53a7d2d | 2010-03-10 07:50:06 | [diff] [blame] | 50 | |
51 | // Returns whether the browser action at |index| has a non-null icon. Note | ||||
52 | // that the icon is loaded asynchronously, in which case you can wait for it | ||||
53 | // to load by calling WaitForBrowserActionUpdated. | ||||
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 54 | virtual bool HasIcon(int index) = 0; |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 55 | |
[email protected] | 866d940a | 2012-09-10 23:02:02 | [diff] [blame] | 56 | // Returns icon for the browser action at |index|. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 57 | virtual gfx::Image GetIcon(int index) = 0; |
[email protected] | 866d940a | 2012-09-10 23:02:02 | [diff] [blame] | 58 | |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 59 | // Simulates a user click on the browser action button at |index|. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 60 | virtual void Press(int index) = 0; |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 61 | |
[email protected] | 7d9ad0b3 | 2010-02-12 21:44:45 | [diff] [blame] | 62 | // Returns the extension id of the extension at |index|. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 63 | virtual std::string GetExtensionId(int index) = 0; |
[email protected] | 7d9ad0b3 | 2010-02-12 21:44:45 | [diff] [blame] | 64 | |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 65 | // Returns the current tooltip for the browser action button. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 66 | virtual std::string GetTooltip(int index) = 0; |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 67 | |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 68 | virtual gfx::NativeView GetPopupNativeView() = 0; |
[email protected] | 2e0a150 | 2014-05-14 02:59:43 | [diff] [blame] | 69 | |
tapted | 9e780e2 | 2017-06-01 06:13:19 | [diff] [blame] | 70 | // Spins a RunLoop until the NativeWindow hosting |GetPopupNativeView()| is |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 71 | // reported as active by the OS. Returns true if successful. This method is |
72 | // strange: it's not overridden by subclasses, and instead the implementation | ||||
73 | // is selected at compile-time depending on the windowing system in use. | ||||
tapted | 9e780e2 | 2017-06-01 06:13:19 | [diff] [blame] | 74 | bool WaitForPopup(); |
75 | |||||
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 76 | // Returns whether a browser action popup is being shown currently. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 77 | virtual bool HasPopup() = 0; |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 78 | |
andresantoso | 81b279ad | 2014-10-24 21:33:07 | [diff] [blame] | 79 | // Returns the size of the current browser action popup. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 80 | virtual gfx::Size GetPopupSize() = 0; |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 81 | |
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 | 5face97 | 2015-01-05 23:18:14 | [diff] [blame] | 85 | // Tests that the button at the given |index| is displaying that it wants |
86 | // to run. | ||||
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 87 | virtual bool ActionButtonWantsToRun(size_t index) = 0; |
rdevlin.cronin | 5face97 | 2015-01-05 23:18:14 | [diff] [blame] | 88 | |
rdevlin.cronin | ede728b | 2015-09-17 21:47:32 | [diff] [blame] | 89 | // Sets the current width of the browser actions container without resizing |
90 | // the underlying controller. This is to simulate e.g. when the browser window | ||||
91 | // is too small for the preferred width. | ||||
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 92 | virtual void SetWidth(int width) = 0; |
rdevlin.cronin | ede728b | 2015-09-17 21:47:32 | [diff] [blame] | 93 | |
rdevlin.cronin | b43d48e | 2015-01-29 17:51:41 | [diff] [blame] | 94 | // Returns the ToolbarActionsBar. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 95 | virtual ToolbarActionsBar* GetToolbarActionsBar() = 0; |
rdevlin.cronin | b43d48e | 2015-01-29 17:51:41 | [diff] [blame] | 96 | |
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 97 | // Creates and returns a BrowserActionTestUtil with an "overflow" container, |
98 | // with this object's container as the main bar. | ||||
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 99 | virtual std::unique_ptr<BrowserActionTestUtil> CreateOverflowBar() = 0; |
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 100 | |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 101 | // Returns the minimum allowed size of an extension popup. |
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 102 | virtual gfx::Size GetMinPopupSize() = 0; |
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 103 | |
104 | // Returns the maximum allowed size of an extension popup. | ||||
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 105 | virtual gfx::Size GetMaxPopupSize() = 0; |
106 | |||||
Elly Fong-Jones | ac78297 | 2018-03-15 16:32:35 | [diff] [blame^] | 107 | // Returns whether the browser action container can currently be resized. |
108 | virtual bool CanBeResized() = 0; | ||||
109 | |||||
Elly Fong-Jones | 914e0d5 | 2018-03-09 16:50:14 | [diff] [blame] | 110 | protected: |
111 | BrowserActionTestUtil() {} | ||||
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 112 | |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 113 | private: |
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 114 | DISALLOW_COPY_AND_ASSIGN(BrowserActionTestUtil); |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 115 | }; |
116 | |||||
Christopher Lam | 851605b | 2018-02-09 05:24:04 | [diff] [blame] | 117 | #endif // CHROME_BROWSER_UI_EXTENSIONS_BROWSER_ACTION_TEST_UTIL_H_ |