blob: 85439911890b6a2f342eda270b7a1cb46565b6d9 [file] [log] [blame]
[email protected]7d9ad0b32010-02-12 21:44:451// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]51a9ec42009-12-14 21:42:572// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Christopher Lam851605b2018-02-09 05:24:045#ifndef CHROME_BROWSER_UI_EXTENSIONS_BROWSER_ACTION_TEST_UTIL_H_
6#define CHROME_BROWSER_UI_EXTENSIONS_BROWSER_ACTION_TEST_UTIL_H_
[email protected]51a9ec42009-12-14 21:42:577
avia2f4804a2015-12-24 23:11:138#include <stddef.h>
9
dchengc963c7142016-04-08 03:55:2210#include <memory>
[email protected]51a9ec42009-12-14 21:42:5711#include <string>
12
avia2f4804a2015-12-24 23:11:1313#include "base/macros.h"
[email protected]2e0a1502014-05-14 02:59:4314#include "ui/gfx/native_widget_types.h"
[email protected]a39f1a92010-03-10 18:36:5815
[email protected]51a9ec42009-12-14 21:42:5716class Browser;
rdevlin.croninb43d48e2015-01-29 17:51:4117class ToolbarActionsBar;
[email protected]51a9ec42009-12-14 21:42:5718
[email protected]733337862009-12-19 01:27:5119namespace gfx {
[email protected]866d940a2012-09-10 23:02:0220class Image;
[email protected]733337862009-12-19 01:27:5121class Size;
22} // namespace gfx
23
rdevlin.cronin0c1c08b2015-04-27 21:35:1824// A class that creates and owns the platform-specific views for the browser
25// actions container. Specific implementations are in the .cc/.mm files.
26class TestToolbarActionsBarHelper {
27 public:
28 virtual ~TestToolbarActionsBarHelper() {}
29};
30
[email protected]51a9ec42009-12-14 21:42:5731class BrowserActionTestUtil {
32 public:
rdevlin.croninf762e8da2014-12-02 20:57:1033 // Constructs a BrowserActionTestUtil that uses the |browser|'s default
34 // browser action container.
rdevlin.cronin0c1c08b2015-04-27 21:35:1835 explicit BrowserActionTestUtil(Browser* browser);
rdevlin.croninf762e8da2014-12-02 20:57:1036
rdevlin.cronin0c1c08b2015-04-27 21:35:1837 // 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]51a9ec42009-12-14 21:42:5743
44 // Returns the number of browser action buttons in the window toolbar.
45 int NumberOfBrowserActions();
46
[email protected]7d9ad0b32010-02-12 21:44:4547 // Returns the number of browser action currently visible.
48 int VisibleBrowserActions();
49
[email protected]93fb8d622014-05-10 18:42:5850 // Inspects the extension popup for the action at the given index.
51 void InspectPopup(int index);
[email protected]53a7d2d2010-03-10 07:50:0652
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]51a9ec42009-12-14 21:42:5756 bool HasIcon(int index);
57
[email protected]866d940a2012-09-10 23:02:0258 // Returns icon for the browser action at |index|.
59 gfx::Image GetIcon(int index);
60
[email protected]51a9ec42009-12-14 21:42:5761 // Simulates a user click on the browser action button at |index|.
62 void Press(int index);
63
[email protected]7d9ad0b32010-02-12 21:44:4564 // Returns the extension id of the extension at |index|.
65 std::string GetExtensionId(int index);
66
[email protected]51a9ec42009-12-14 21:42:5767 // Returns the current tooltip for the browser action button.
68 std::string GetTooltip(int index);
69
[email protected]2e0a1502014-05-14 02:59:4370 gfx::NativeView GetPopupNativeView();
71
tapted9e780e22017-06-01 06:13:1972 // 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]733337862009-12-19 01:27:5176 // Returns whether a browser action popup is being shown currently.
77 bool HasPopup();
78
andresantoso81b279ad2014-10-24 21:33:0779 // Returns the size of the current browser action popup.
80 gfx::Size GetPopupSize();
[email protected]733337862009-12-19 01:27:5181
82 // Hides the given popup and returns whether the hide was successful.
83 bool HidePopup();
84
rdevlin.cronin5face972015-01-05 23:18:1485 // Tests that the button at the given |index| is displaying that it wants
86 // to run.
87 bool ActionButtonWantsToRun(size_t index);
88
rdevlin.croninede728b2015-09-17 21:47:3289 // 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.croninb43d48e2015-01-29 17:51:4194 // Returns the ToolbarActionsBar.
95 ToolbarActionsBar* GetToolbarActionsBar();
96
rdevlin.cronin0c1c08b2015-04-27 21:35:1897 // Creates and returns a BrowserActionTestUtil with an "overflow" container,
98 // with this object's container as the main bar.
dchengc963c7142016-04-08 03:55:2299 std::unique_ptr<BrowserActionTestUtil> CreateOverflowBar();
rdevlin.cronin0c1c08b2015-04-27 21:35:18100
[email protected]733337862009-12-19 01:27:51101 // 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]733337862009-12-19 01:27:51106
[email protected]51a9ec42009-12-14 21:42:57107 private:
rdevlin.cronin0c1c08b2015-04-27 21:35:18108 // A private constructor to create an overflow version.
109 BrowserActionTestUtil(Browser* browser, BrowserActionTestUtil* main_bar);
110
Lei Zhang8bd9882c2017-11-28 21:24:08111 Browser* const browser_; // weak
rdevlin.croninf762e8da2014-12-02 20:57:10112
rdevlin.cronin0c1c08b2015-04-27 21:35:18113 // 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.
dchengc963c7142016-04-08 03:55:22115 std::unique_ptr<TestToolbarActionsBarHelper> test_helper_;
rdevlin.cronin0c1c08b2015-04-27 21:35:18116
117 DISALLOW_COPY_AND_ASSIGN(BrowserActionTestUtil);
[email protected]51a9ec42009-12-14 21:42:57118};
119
Christopher Lam851605b2018-02-09 05:24:04120#endif // CHROME_BROWSER_UI_EXTENSIONS_BROWSER_ACTION_TEST_UTIL_H_