blob: a0b460908f00c005d07b7bb8a7e69dd222d4d057 [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
Devlin Cronine458a222019-12-30 22:39:375#ifndef CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_TEST_HELPER_H_
6#define CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_TEST_HELPER_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;
Devlin Cronin256b4ae2019-12-09 18:34:2517class ExtensionsContainer;
rdevlin.croninb43d48e2015-01-29 17:51:4118class ToolbarActionsBar;
[email protected]51a9ec42009-12-14 21:42:5719
[email protected]733337862009-12-19 01:27:5120namespace gfx {
[email protected]866d940a2012-09-10 23:02:0221class Image;
[email protected]733337862009-12-19 01:27:5122class Size;
23} // namespace gfx
24
Devlin Cronine458a222019-12-30 22:39:3725class ExtensionActionTestHelper {
[email protected]51a9ec42009-12-14 21:42:5726 public:
Devlin Cronine458a222019-12-30 22:39:3727 // Constructs a ExtensionActionTestHelper which, if |is_real_window| is false,
rdevlin.cronin0c1c08b2015-04-27 21:35:1828 // will create its own browser actions container. This is useful in unit
29 // tests, when the |browser|'s window doesn't create platform-specific views.
Devlin Cronine458a222019-12-30 22:39:3730 static std::unique_ptr<ExtensionActionTestHelper> Create(
Elly Fong-Jones914e0d52018-03-09 16:50:1431 Browser* browser,
32 bool is_real_window = true);
rdevlin.cronin0c1c08b2015-04-27 21:35:1833
Devlin Cronine458a222019-12-30 22:39:3734 virtual ~ExtensionActionTestHelper() {}
[email protected]51a9ec42009-12-14 21:42:5735
36 // Returns the number of browser action buttons in the window toolbar.
Elly Fong-Jones914e0d52018-03-09 16:50:1437 virtual int NumberOfBrowserActions() = 0;
[email protected]51a9ec42009-12-14 21:42:5738
[email protected]7d9ad0b32010-02-12 21:44:4539 // Returns the number of browser action currently visible.
Elly Fong-Jones914e0d52018-03-09 16:50:1440 virtual int VisibleBrowserActions() = 0;
[email protected]7d9ad0b32010-02-12 21:44:4541
[email protected]93fb8d622014-05-10 18:42:5842 // Inspects the extension popup for the action at the given index.
Elly Fong-Jones914e0d52018-03-09 16:50:1443 virtual void InspectPopup(int index) = 0;
[email protected]53a7d2d2010-03-10 07:50:0644
45 // Returns whether the browser action at |index| has a non-null icon. Note
46 // that the icon is loaded asynchronously, in which case you can wait for it
47 // to load by calling WaitForBrowserActionUpdated.
Elly Fong-Jones914e0d52018-03-09 16:50:1448 virtual bool HasIcon(int index) = 0;
[email protected]51a9ec42009-12-14 21:42:5749
[email protected]866d940a2012-09-10 23:02:0250 // Returns icon for the browser action at |index|.
Elly Fong-Jones914e0d52018-03-09 16:50:1451 virtual gfx::Image GetIcon(int index) = 0;
[email protected]866d940a2012-09-10 23:02:0252
[email protected]51a9ec42009-12-14 21:42:5753 // Simulates a user click on the browser action button at |index|.
Elly Fong-Jones914e0d52018-03-09 16:50:1454 virtual void Press(int index) = 0;
[email protected]51a9ec42009-12-14 21:42:5755
[email protected]7d9ad0b32010-02-12 21:44:4556 // Returns the extension id of the extension at |index|.
Elly Fong-Jones914e0d52018-03-09 16:50:1457 virtual std::string GetExtensionId(int index) = 0;
[email protected]7d9ad0b32010-02-12 21:44:4558
[email protected]51a9ec42009-12-14 21:42:5759 // Returns the current tooltip for the browser action button.
Elly Fong-Jones914e0d52018-03-09 16:50:1460 virtual std::string GetTooltip(int index) = 0;
[email protected]51a9ec42009-12-14 21:42:5761
Elly Fong-Jones914e0d52018-03-09 16:50:1462 virtual gfx::NativeView GetPopupNativeView() = 0;
[email protected]2e0a1502014-05-14 02:59:4363
tapted9e780e22017-06-01 06:13:1964 // Spins a RunLoop until the NativeWindow hosting |GetPopupNativeView()| is
Elly Fong-Jones914e0d52018-03-09 16:50:1465 // reported as active by the OS. Returns true if successful. This method is
66 // strange: it's not overridden by subclasses, and instead the implementation
67 // is selected at compile-time depending on the windowing system in use.
tapted9e780e22017-06-01 06:13:1968 bool WaitForPopup();
69
[email protected]733337862009-12-19 01:27:5170 // Returns whether a browser action popup is being shown currently.
Elly Fong-Jones914e0d52018-03-09 16:50:1471 virtual bool HasPopup() = 0;
[email protected]733337862009-12-19 01:27:5172
andresantoso81b279ad2014-10-24 21:33:0773 // Returns the size of the current browser action popup.
Elly Fong-Jones914e0d52018-03-09 16:50:1474 virtual gfx::Size GetPopupSize() = 0;
[email protected]733337862009-12-19 01:27:5175
76 // Hides the given popup and returns whether the hide was successful.
Elly Fong-Jones914e0d52018-03-09 16:50:1477 virtual bool HidePopup() = 0;
[email protected]733337862009-12-19 01:27:5178
rdevlin.cronin5face972015-01-05 23:18:1479 // Tests that the button at the given |index| is displaying that it wants
80 // to run.
Elly Fong-Jones914e0d52018-03-09 16:50:1481 virtual bool ActionButtonWantsToRun(size_t index) = 0;
rdevlin.cronin5face972015-01-05 23:18:1482
rdevlin.croninede728b2015-09-17 21:47:3283 // Sets the current width of the browser actions container without resizing
84 // the underlying controller. This is to simulate e.g. when the browser window
85 // is too small for the preferred width.
Elly Fong-Jones914e0d52018-03-09 16:50:1486 virtual void SetWidth(int width) = 0;
rdevlin.croninede728b2015-09-17 21:47:3287
rdevlin.croninb43d48e2015-01-29 17:51:4188 // Returns the ToolbarActionsBar.
Elly Fong-Jones914e0d52018-03-09 16:50:1489 virtual ToolbarActionsBar* GetToolbarActionsBar() = 0;
rdevlin.croninb43d48e2015-01-29 17:51:4190
Devlin Cronin256b4ae2019-12-09 18:34:2591 // Returns the associated ExtensionsContainer.
92 virtual ExtensionsContainer* GetExtensionsContainer() = 0;
93
Devlin Cronine458a222019-12-30 22:39:3794 // Creates and returns a ExtensionActionTestHelper with an "overflow"
95 // container, with this object's container as the main bar.
96 virtual std::unique_ptr<ExtensionActionTestHelper> CreateOverflowBar(
Devlin Cronin794c0a72019-10-25 01:45:4697 Browser* browser) = 0;
rdevlin.cronin0c1c08b2015-04-27 21:35:1898
[email protected]733337862009-12-19 01:27:5199 // Returns the minimum allowed size of an extension popup.
Elly Fong-Jones914e0d52018-03-09 16:50:14100 virtual gfx::Size GetMinPopupSize() = 0;
[email protected]733337862009-12-19 01:27:51101
Devlin Cronin256b4ae2019-12-09 18:34:25102 // Returns the size of the toolbar actions.
103 virtual gfx::Size GetToolbarActionSize() = 0;
104
[email protected]733337862009-12-19 01:27:51105 // Returns the maximum allowed size of an extension popup.
Elly Fong-Jones914e0d52018-03-09 16:50:14106 virtual gfx::Size GetMaxPopupSize() = 0;
107
Elly Fong-Jonesac782972018-03-15 16:32:35108 // Returns whether the browser action container can currently be resized.
109 virtual bool CanBeResized() = 0;
110
Elly Fong-Jones914e0d52018-03-09 16:50:14111 protected:
Devlin Cronine458a222019-12-30 22:39:37112 ExtensionActionTestHelper() {}
[email protected]733337862009-12-19 01:27:51113
[email protected]51a9ec42009-12-14 21:42:57114 private:
Devlin Cronine458a222019-12-30 22:39:37115 DISALLOW_COPY_AND_ASSIGN(ExtensionActionTestHelper);
[email protected]51a9ec42009-12-14 21:42:57116};
117
Devlin Cronine458a222019-12-30 22:39:37118#endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_TEST_HELPER_H_