blob: 5bcff4553482ce027ac43cfba5b0029733d51a66 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2010 The Chromium Authors
[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
Devlin Cronin5ce7d582021-05-05 23:01:0313#include "extensions/common/extension_id.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;
[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
Alison Gale91301922024-04-15 19:35:2724// TODO(crbug.com/40177062): A lot of this class can be cleaned up for
Devlin Cronin5ce7d582021-05-05 23:01:0325// the new toolbar UI. Some of it may also be removable, since we now have
26// the platform-abstract ExtensionsContainer class.
Devlin Cronine458a222019-12-30 22:39:3727class ExtensionActionTestHelper {
[email protected]51a9ec42009-12-14 21:42:5728 public:
Devlin Cronine458a222019-12-30 22:39:3729 // Constructs a ExtensionActionTestHelper which, if |is_real_window| is false,
rdevlin.cronin0c1c08b2015-04-27 21:35:1830 // will create its own browser actions container. This is useful in unit
31 // tests, when the |browser|'s window doesn't create platform-specific views.
Devlin Cronine458a222019-12-30 22:39:3732 static std::unique_ptr<ExtensionActionTestHelper> Create(
Elly Fong-Jones914e0d52018-03-09 16:50:1433 Browser* browser,
34 bool is_real_window = true);
rdevlin.cronin0c1c08b2015-04-27 21:35:1835
Peter Boström53c6c5952021-09-17 09:41:2636 ExtensionActionTestHelper(const ExtensionActionTestHelper&) = delete;
37 ExtensionActionTestHelper& operator=(const ExtensionActionTestHelper&) =
38 delete;
39
Devlin Cronine458a222019-12-30 22:39:3740 virtual ~ExtensionActionTestHelper() {}
[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
Devlin Cronin5ce7d582021-05-05 23:01:0345 // Returns true if there is an action for the given `id`.
46 virtual bool HasAction(const extensions::ExtensionId& id) = 0;
[email protected]53a7d2d2010-03-10 07:50:0647
Devlin Cronin5ce7d582021-05-05 23:01:0348 // Inspects the extension popup for the action with the given `id`.
49 virtual void InspectPopup(const extensions::ExtensionId& id) = 0;
[email protected]51a9ec42009-12-14 21:42:5750
Devlin Cronin5ce7d582021-05-05 23:01:0351 // Returns icon for the action for the given `id`.
52 virtual gfx::Image GetIcon(const extensions::ExtensionId& id) = 0;
[email protected]51a9ec42009-12-14 21:42:5753
Devlin Cronin5ce7d582021-05-05 23:01:0354 // Simulates a user click on the action button for the given `id`.
55 virtual void Press(const extensions::ExtensionId& id) = 0;
[email protected]7d9ad0b32010-02-12 21:44:4556
Elly Fong-Jones914e0d52018-03-09 16:50:1457 virtual gfx::NativeView GetPopupNativeView() = 0;
[email protected]2e0a1502014-05-14 02:59:4358
tapted9e780e22017-06-01 06:13:1959 // Spins a RunLoop until the NativeWindow hosting |GetPopupNativeView()| is
Elly Fong-Jones914e0d52018-03-09 16:50:1460 // reported as active by the OS. Returns true if successful. This method is
61 // strange: it's not overridden by subclasses, and instead the implementation
62 // is selected at compile-time depending on the windowing system in use.
tapted9e780e22017-06-01 06:13:1963 bool WaitForPopup();
64
[email protected]733337862009-12-19 01:27:5165 // Returns whether a browser action popup is being shown currently.
Elly Fong-Jones914e0d52018-03-09 16:50:1466 virtual bool HasPopup() = 0;
[email protected]733337862009-12-19 01:27:5167
[email protected]733337862009-12-19 01:27:5168 // Hides the given popup and returns whether the hide was successful.
Elly Fong-Jones914e0d52018-03-09 16:50:1469 virtual bool HidePopup() = 0;
[email protected]733337862009-12-19 01:27:5170
Devlin Cronin256b4ae2019-12-09 18:34:2571 // Returns the associated ExtensionsContainer.
72 virtual ExtensionsContainer* GetExtensionsContainer() = 0;
73
Sanchit Abrol9f4190ad2020-11-05 17:19:2574 // Waits for the ExtensionContainer's layout to be done.
75 virtual void WaitForExtensionsContainerLayout() = 0;
76
[email protected]733337862009-12-19 01:27:5177 // Returns the minimum allowed size of an extension popup.
Elly Fong-Jones914e0d52018-03-09 16:50:1478 virtual gfx::Size GetMinPopupSize() = 0;
[email protected]733337862009-12-19 01:27:5179
Devlin Cronin256b4ae2019-12-09 18:34:2580 // Returns the size of the toolbar actions.
81 virtual gfx::Size GetToolbarActionSize() = 0;
82
[email protected]733337862009-12-19 01:27:5183 // Returns the maximum allowed size of an extension popup.
Elly Fong-Jones914e0d52018-03-09 16:50:1484 virtual gfx::Size GetMaxPopupSize() = 0;
85
Sanchit Abrol9f4190ad2020-11-05 17:19:2586 // Returns the maximum available size to place a bubble anchored to
Devlin Cronin5ce7d582021-05-05 23:01:0387 // the action with the given `id` on screen.
Sanchit Abrol9f4190ad2020-11-05 17:19:2588 virtual gfx::Size GetMaxAvailableSizeToFitBubbleOnScreen(
Devlin Cronin5ce7d582021-05-05 23:01:0389 const extensions::ExtensionId& id) = 0;
Sanchit Abrol9f4190ad2020-11-05 17:19:2590
Elly Fong-Jones914e0d52018-03-09 16:50:1491 protected:
Devlin Cronine458a222019-12-30 22:39:3792 ExtensionActionTestHelper() {}
[email protected]51a9ec42009-12-14 21:42:5793};
94
Devlin Cronine458a222019-12-30 22:39:3795#endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_TEST_HELPER_H_