blob: f392ed897e5f83e464a92262f8feb388700d03c9 [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.cronin0c1c08b2015-04-27 21:35:1833 // 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-Jones914e0d52018-03-09 16:50:1436 static std::unique_ptr<BrowserActionTestUtil> Create(
37 Browser* browser,
38 bool is_real_window = true);
rdevlin.cronin0c1c08b2015-04-27 21:35:1839
Elly Fong-Jones914e0d52018-03-09 16:50:1440 virtual ~BrowserActionTestUtil() {}
[email protected]51a9ec42009-12-14 21:42:5741
42 // Returns the number of browser action buttons in the window toolbar.
Elly Fong-Jones914e0d52018-03-09 16:50:1443 virtual int NumberOfBrowserActions() = 0;
[email protected]51a9ec42009-12-14 21:42:5744
[email protected]7d9ad0b32010-02-12 21:44:4545 // Returns the number of browser action currently visible.
Elly Fong-Jones914e0d52018-03-09 16:50:1446 virtual int VisibleBrowserActions() = 0;
[email protected]7d9ad0b32010-02-12 21:44:4547
[email protected]93fb8d622014-05-10 18:42:5848 // Inspects the extension popup for the action at the given index.
Elly Fong-Jones914e0d52018-03-09 16:50:1449 virtual void InspectPopup(int index) = 0;
[email protected]53a7d2d2010-03-10 07:50:0650
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-Jones914e0d52018-03-09 16:50:1454 virtual bool HasIcon(int index) = 0;
[email protected]51a9ec42009-12-14 21:42:5755
[email protected]866d940a2012-09-10 23:02:0256 // Returns icon for the browser action at |index|.
Elly Fong-Jones914e0d52018-03-09 16:50:1457 virtual gfx::Image GetIcon(int index) = 0;
[email protected]866d940a2012-09-10 23:02:0258
[email protected]51a9ec42009-12-14 21:42:5759 // Simulates a user click on the browser action button at |index|.
Elly Fong-Jones914e0d52018-03-09 16:50:1460 virtual void Press(int index) = 0;
[email protected]51a9ec42009-12-14 21:42:5761
[email protected]7d9ad0b32010-02-12 21:44:4562 // Returns the extension id of the extension at |index|.
Elly Fong-Jones914e0d52018-03-09 16:50:1463 virtual std::string GetExtensionId(int index) = 0;
[email protected]7d9ad0b32010-02-12 21:44:4564
[email protected]51a9ec42009-12-14 21:42:5765 // Returns the current tooltip for the browser action button.
Elly Fong-Jones914e0d52018-03-09 16:50:1466 virtual std::string GetTooltip(int index) = 0;
[email protected]51a9ec42009-12-14 21:42:5767
Elly Fong-Jones914e0d52018-03-09 16:50:1468 virtual gfx::NativeView GetPopupNativeView() = 0;
[email protected]2e0a1502014-05-14 02:59:4369
tapted9e780e22017-06-01 06:13:1970 // Spins a RunLoop until the NativeWindow hosting |GetPopupNativeView()| is
Elly Fong-Jones914e0d52018-03-09 16:50:1471 // 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.
tapted9e780e22017-06-01 06:13:1974 bool WaitForPopup();
75
[email protected]733337862009-12-19 01:27:5176 // Returns whether a browser action popup is being shown currently.
Elly Fong-Jones914e0d52018-03-09 16:50:1477 virtual bool HasPopup() = 0;
[email protected]733337862009-12-19 01:27:5178
andresantoso81b279ad2014-10-24 21:33:0779 // Returns the size of the current browser action popup.
Elly Fong-Jones914e0d52018-03-09 16:50:1480 virtual gfx::Size GetPopupSize() = 0;
[email protected]733337862009-12-19 01:27:5181
82 // Hides the given popup and returns whether the hide was successful.
Elly Fong-Jones914e0d52018-03-09 16:50:1483 virtual bool HidePopup() = 0;
[email protected]733337862009-12-19 01:27:5184
rdevlin.cronin5face972015-01-05 23:18:1485 // Tests that the button at the given |index| is displaying that it wants
86 // to run.
Elly Fong-Jones914e0d52018-03-09 16:50:1487 virtual bool ActionButtonWantsToRun(size_t index) = 0;
rdevlin.cronin5face972015-01-05 23:18:1488
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.
Elly Fong-Jones914e0d52018-03-09 16:50:1492 virtual void SetWidth(int width) = 0;
rdevlin.croninede728b2015-09-17 21:47:3293
rdevlin.croninb43d48e2015-01-29 17:51:4194 // Returns the ToolbarActionsBar.
Elly Fong-Jones914e0d52018-03-09 16:50:1495 virtual ToolbarActionsBar* GetToolbarActionsBar() = 0;
rdevlin.croninb43d48e2015-01-29 17:51:4196
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.
Elly Fong-Jones914e0d52018-03-09 16:50:1499 virtual std::unique_ptr<BrowserActionTestUtil> CreateOverflowBar() = 0;
rdevlin.cronin0c1c08b2015-04-27 21:35:18100
[email protected]733337862009-12-19 01:27:51101 // Returns the minimum allowed size of an extension popup.
Elly Fong-Jones914e0d52018-03-09 16:50:14102 virtual gfx::Size GetMinPopupSize() = 0;
[email protected]733337862009-12-19 01:27:51103
104 // Returns the maximum allowed size of an extension popup.
Elly Fong-Jones914e0d52018-03-09 16:50:14105 virtual gfx::Size GetMaxPopupSize() = 0;
106
Elly Fong-Jonesac782972018-03-15 16:32:35107 // Returns whether the browser action container can currently be resized.
108 virtual bool CanBeResized() = 0;
109
Elly Fong-Jones914e0d52018-03-09 16:50:14110 protected:
111 BrowserActionTestUtil() {}
[email protected]733337862009-12-19 01:27:51112
[email protected]51a9ec42009-12-14 21:42:57113 private:
rdevlin.cronin0c1c08b2015-04-27 21:35:18114 DISALLOW_COPY_AND_ASSIGN(BrowserActionTestUtil);
[email protected]51a9ec42009-12-14 21:42:57115};
116
Christopher Lam851605b2018-02-09 05:24:04117#endif // CHROME_BROWSER_UI_EXTENSIONS_BROWSER_ACTION_TEST_UTIL_H_