[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 | f762e8da | 2014-12-02 20:57:10 | [diff] [blame] | 33 | // Constructs a BrowserActionTestUtil that uses the |browser|'s default |
34 | // browser action container. | ||||
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 35 | explicit BrowserActionTestUtil(Browser* browser); |
rdevlin.cronin | f762e8da | 2014-12-02 20:57:10 | [diff] [blame] | 36 | |
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 37 | // Constructs a BrowserActionTestUtil which, if |is_real_window| is false, |
38 | // will create its own browser actions container. This is useful in unit | ||||
39 | // tests, when the |browser|'s window doesn't create platform-specific views. | ||||
40 | BrowserActionTestUtil(Browser* browser, bool is_real_window); | ||||
41 | |||||
42 | ~BrowserActionTestUtil(); | ||||
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 43 | |
44 | // Returns the number of browser action buttons in the window toolbar. | ||||
45 | int NumberOfBrowserActions(); | ||||
46 | |||||
[email protected] | 7d9ad0b3 | 2010-02-12 21:44:45 | [diff] [blame] | 47 | // Returns the number of browser action currently visible. |
48 | int VisibleBrowserActions(); | ||||
49 | |||||
[email protected] | 93fb8d62 | 2014-05-10 18:42:58 | [diff] [blame] | 50 | // Inspects the extension popup for the action at the given index. |
51 | void InspectPopup(int index); | ||||
[email protected] | 53a7d2d | 2010-03-10 07:50:06 | [diff] [blame] | 52 | |
53 | // Returns whether the browser action at |index| has a non-null icon. Note | ||||
54 | // that the icon is loaded asynchronously, in which case you can wait for it | ||||
55 | // to load by calling WaitForBrowserActionUpdated. | ||||
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 56 | bool HasIcon(int index); |
57 | |||||
[email protected] | 866d940a | 2012-09-10 23:02:02 | [diff] [blame] | 58 | // Returns icon for the browser action at |index|. |
59 | gfx::Image GetIcon(int index); | ||||
60 | |||||
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 61 | // Simulates a user click on the browser action button at |index|. |
62 | void Press(int index); | ||||
63 | |||||
[email protected] | 7d9ad0b3 | 2010-02-12 21:44:45 | [diff] [blame] | 64 | // Returns the extension id of the extension at |index|. |
65 | std::string GetExtensionId(int index); | ||||
66 | |||||
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 67 | // Returns the current tooltip for the browser action button. |
68 | std::string GetTooltip(int index); | ||||
69 | |||||
[email protected] | 2e0a150 | 2014-05-14 02:59:43 | [diff] [blame] | 70 | gfx::NativeView GetPopupNativeView(); |
71 | |||||
tapted | 9e780e2 | 2017-06-01 06:13:19 | [diff] [blame] | 72 | // Spins a RunLoop until the NativeWindow hosting |GetPopupNativeView()| is |
73 | // reported as active by the OS. Returns true if successful. | ||||
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. |
77 | bool HasPopup(); | ||||
78 | |||||
andresantoso | 81b279ad | 2014-10-24 21:33:07 | [diff] [blame] | 79 | // Returns the size of the current browser action popup. |
80 | gfx::Size GetPopupSize(); | ||||
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 81 | |
82 | // Hides the given popup and returns whether the hide was successful. | ||||
83 | bool HidePopup(); | ||||
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. | ||||
87 | bool ActionButtonWantsToRun(size_t index); | ||||
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. | ||||
92 | void SetWidth(int width); | ||||
93 | |||||
rdevlin.cronin | b43d48e | 2015-01-29 17:51:41 | [diff] [blame] | 94 | // Returns the ToolbarActionsBar. |
95 | ToolbarActionsBar* GetToolbarActionsBar(); | ||||
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. | ||||
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 99 | std::unique_ptr<BrowserActionTestUtil> CreateOverflowBar(); |
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. |
102 | static gfx::Size GetMinPopupSize(); | ||||
103 | |||||
104 | // Returns the maximum allowed size of an extension popup. | ||||
105 | static gfx::Size GetMaxPopupSize(); | ||||
[email protected] | 73333786 | 2009-12-19 01:27:51 | [diff] [blame] | 106 | |
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 107 | private: |
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 108 | // A private constructor to create an overflow version. |
109 | BrowserActionTestUtil(Browser* browser, BrowserActionTestUtil* main_bar); | ||||
110 | |||||
Lei Zhang | 8bd9882c | 2017-11-28 21:24:08 | [diff] [blame] | 111 | Browser* const browser_; // weak |
rdevlin.cronin | f762e8da | 2014-12-02 20:57:10 | [diff] [blame] | 112 | |
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 113 | // Our test helper, which constructs and owns the views if we don't have a |
114 | // real browser window, or if this is an overflow version. | ||||
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 115 | std::unique_ptr<TestToolbarActionsBarHelper> test_helper_; |
rdevlin.cronin | 0c1c08b | 2015-04-27 21:35:18 | [diff] [blame] | 116 | |
117 | DISALLOW_COPY_AND_ASSIGN(BrowserActionTestUtil); | ||||
[email protected] | 51a9ec4 | 2009-12-14 21:42:57 | [diff] [blame] | 118 | }; |
119 | |||||
Christopher Lam | 851605b | 2018-02-09 05:24:04 | [diff] [blame^] | 120 | #endif // CHROME_BROWSER_UI_EXTENSIONS_BROWSER_ACTION_TEST_UTIL_H_ |