blob: bcdcfa3737e0bc95dc1ec13915a5c97de0fc5415 [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"
Devlin Cronin5ce7d582021-05-05 23:01:0314#include "extensions/common/extension_id.h"
[email protected]2e0a1502014-05-14 02:59:4315#include "ui/gfx/native_widget_types.h"
[email protected]a39f1a92010-03-10 18:36:5816
[email protected]51a9ec42009-12-14 21:42:5717class Browser;
Devlin Cronin256b4ae2019-12-09 18:34:2518class ExtensionsContainer;
[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 Cronin5ce7d582021-05-05 23:01:0325// TODO(https://crbug.com/1197766): A lot of this class can be cleaned up for
26// the new toolbar UI. Some of it may also be removable, since we now have
27// the platform-abstract ExtensionsContainer class.
Devlin Cronine458a222019-12-30 22:39:3728class ExtensionActionTestHelper {
[email protected]51a9ec42009-12-14 21:42:5729 public:
Devlin Cronine458a222019-12-30 22:39:3730 // Constructs a ExtensionActionTestHelper which, if |is_real_window| is false,
rdevlin.cronin0c1c08b2015-04-27 21:35:1831 // will create its own browser actions container. This is useful in unit
32 // tests, when the |browser|'s window doesn't create platform-specific views.
Devlin Cronine458a222019-12-30 22:39:3733 static std::unique_ptr<ExtensionActionTestHelper> Create(
Elly Fong-Jones914e0d52018-03-09 16:50:1434 Browser* browser,
35 bool is_real_window = true);
rdevlin.cronin0c1c08b2015-04-27 21:35:1836
Devlin Cronine458a222019-12-30 22:39:3737 virtual ~ExtensionActionTestHelper() {}
[email protected]51a9ec42009-12-14 21:42:5738
39 // Returns the number of browser action buttons in the window toolbar.
Elly Fong-Jones914e0d52018-03-09 16:50:1440 virtual int NumberOfBrowserActions() = 0;
[email protected]51a9ec42009-12-14 21:42:5741
Collin Baker58fb6e0f2020-04-28 01:59:1742 // Returns the number of browser action currently visible. Note that a correct
43 // result may require a UI layout. Ensure the UI layout is up-to-date (e.g. by
44 // calling InProcessBrowserTest::RunScheduledLayouts()) for a browser test.
Elly Fong-Jones914e0d52018-03-09 16:50:1445 virtual int VisibleBrowserActions() = 0;
[email protected]7d9ad0b32010-02-12 21:44:4546
Devlin Cronin5ce7d582021-05-05 23:01:0347 // Returns true if there is an action for the given `id`.
48 virtual bool HasAction(const extensions::ExtensionId& id) = 0;
[email protected]53a7d2d2010-03-10 07:50:0649
Devlin Cronin5ce7d582021-05-05 23:01:0350 // Inspects the extension popup for the action with the given `id`.
51 virtual void InspectPopup(const extensions::ExtensionId& id) = 0;
[email protected]51a9ec42009-12-14 21:42:5752
Devlin Cronin5ce7d582021-05-05 23:01:0353 // Returns whether the extension action for the given `id` has a non-null
54 // icon. Note that the icon is loaded asynchronously, in which case you can
55 // wait for it to load by calling WaitForBrowserActionUpdated.
56 virtual bool HasIcon(const extensions::ExtensionId& id) = 0;
[email protected]866d940a2012-09-10 23:02:0257
Devlin Cronin5ce7d582021-05-05 23:01:0358 // Returns icon for the action for the given `id`.
59 virtual gfx::Image GetIcon(const extensions::ExtensionId& id) = 0;
[email protected]51a9ec42009-12-14 21:42:5760
Devlin Cronin5ce7d582021-05-05 23:01:0361 // Simulates a user click on the action button for the given `id`.
62 virtual void Press(const extensions::ExtensionId& id) = 0;
[email protected]7d9ad0b32010-02-12 21:44:4563
Devlin Cronin5ce7d582021-05-05 23:01:0364 // Returns the current tooltip of the action for the given `id`.
65 virtual std::string GetTooltip(const extensions::ExtensionId& id) = 0;
[email protected]51a9ec42009-12-14 21:42:5766
Elly Fong-Jones914e0d52018-03-09 16:50:1467 virtual gfx::NativeView GetPopupNativeView() = 0;
[email protected]2e0a1502014-05-14 02:59:4368
tapted9e780e22017-06-01 06:13:1969 // Spins a RunLoop until the NativeWindow hosting |GetPopupNativeView()| is
Elly Fong-Jones914e0d52018-03-09 16:50:1470 // reported as active by the OS. Returns true if successful. This method is
71 // strange: it's not overridden by subclasses, and instead the implementation
72 // is selected at compile-time depending on the windowing system in use.
tapted9e780e22017-06-01 06:13:1973 bool WaitForPopup();
74
[email protected]733337862009-12-19 01:27:5175 // Returns whether a browser action popup is being shown currently.
Elly Fong-Jones914e0d52018-03-09 16:50:1476 virtual bool HasPopup() = 0;
[email protected]733337862009-12-19 01:27:5177
[email protected]733337862009-12-19 01:27:5178 // Hides the given popup and returns whether the hide was successful.
Elly Fong-Jones914e0d52018-03-09 16:50:1479 virtual bool HidePopup() = 0;
[email protected]733337862009-12-19 01:27:5180
rdevlin.croninede728b2015-09-17 21:47:3281 // Sets the current width of the browser actions container without resizing
82 // the underlying controller. This is to simulate e.g. when the browser window
83 // is too small for the preferred width.
Elly Fong-Jones914e0d52018-03-09 16:50:1484 virtual void SetWidth(int width) = 0;
rdevlin.croninede728b2015-09-17 21:47:3285
Devlin Cronin256b4ae2019-12-09 18:34:2586 // Returns the associated ExtensionsContainer.
87 virtual ExtensionsContainer* GetExtensionsContainer() = 0;
88
Sanchit Abrol9f4190ad2020-11-05 17:19:2589 // Waits for the ExtensionContainer's layout to be done.
90 virtual void WaitForExtensionsContainerLayout() = 0;
91
Devlin Cronine458a222019-12-30 22:39:3792 // Creates and returns a ExtensionActionTestHelper with an "overflow"
93 // container, with this object's container as the main bar.
94 virtual std::unique_ptr<ExtensionActionTestHelper> CreateOverflowBar(
Devlin Cronin794c0a72019-10-25 01:45:4695 Browser* browser) = 0;
rdevlin.cronin0c1c08b2015-04-27 21:35:1896
Collin Baker58fb6e0f2020-04-28 01:59:1797 // Forces a layout of an overflow bar. Must only be called on the helper
98 // returned by CreateOverflowBar().
99 virtual void LayoutForOverflowBar() = 0;
100
[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
Devlin Cronin256b4ae2019-12-09 18:34:25104 // Returns the size of the toolbar actions.
105 virtual gfx::Size GetToolbarActionSize() = 0;
106
[email protected]733337862009-12-19 01:27:51107 // Returns the maximum allowed size of an extension popup.
Elly Fong-Jones914e0d52018-03-09 16:50:14108 virtual gfx::Size GetMaxPopupSize() = 0;
109
Sanchit Abrol9f4190ad2020-11-05 17:19:25110 // Returns the maximum available size to place a bubble anchored to
Devlin Cronin5ce7d582021-05-05 23:01:03111 // the action with the given `id` on screen.
Sanchit Abrol9f4190ad2020-11-05 17:19:25112 virtual gfx::Size GetMaxAvailableSizeToFitBubbleOnScreen(
Devlin Cronin5ce7d582021-05-05 23:01:03113 const extensions::ExtensionId& id) = 0;
Sanchit Abrol9f4190ad2020-11-05 17:19:25114
Elly Fong-Jones914e0d52018-03-09 16:50:14115 protected:
Devlin Cronine458a222019-12-30 22:39:37116 ExtensionActionTestHelper() {}
[email protected]733337862009-12-19 01:27:51117
[email protected]51a9ec42009-12-14 21:42:57118 private:
Devlin Cronine458a222019-12-30 22:39:37119 DISALLOW_COPY_AND_ASSIGN(ExtensionActionTestHelper);
[email protected]51a9ec42009-12-14 21:42:57120};
121
Devlin Cronine458a222019-12-30 22:39:37122#endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_TEST_HELPER_H_