blob: 18ebc1787f6ab8c762120e7912b4521b54bb75d9 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2012 The Chromium Authors
[email protected]1dd1c1b2012-02-17 22:04:472// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UI_AURA_TEST_AURA_TEST_HELPER_H_
6#define UI_AURA_TEST_AURA_TEST_HELPER_H_
[email protected]1dd1c1b2012-02-17 22:04:477
sadrul578205fa2016-04-11 22:43:568#include <memory>
9
Keishi Hattori0e45c022021-11-27 09:25:5210#include "base/memory/raw_ptr.h"
Tomasz Moniuszkoa791670e2019-10-28 16:25:1111#include "build/build_config.h"
[email protected]fcc51c952014-02-21 21:31:2612#include "ui/aura/window_event_dispatcher.h"
Peter Kasting8ba25a72020-03-27 21:48:3613#include "ui/wm/core/wm_state.h"
[email protected]1dd1c1b2012-02-17 22:04:4714
[email protected]eff8b2f2012-05-30 02:19:1715namespace ui {
[email protected]fa69f2b62014-05-22 21:47:5816class ContextFactory;
[email protected]dd31fa82013-03-13 04:08:3617class ScopedAnimationDurationScaleMode;
Peter Kasting16204ab22020-03-12 03:38:4318class TestContextFactories;
[email protected]eff8b2f2012-05-30 02:19:1719}
20
[email protected]1dd1c1b2012-02-17 22:04:4721namespace aura {
skyf8fcebc2016-10-27 18:34:1322class Env;
[email protected]b9e08cf2012-10-13 02:20:2423class TestScreen;
sky25714fe2016-10-27 15:21:2524class Window;
Peter Kastingc4b24b82020-03-25 03:06:2425class WindowTreeHost;
sky25714fe2016-10-27 15:21:2526
[email protected]48dea152012-11-02 20:26:4627namespace client {
sky25714fe2016-10-27 15:21:2528class CaptureClient;
Henrique Ferreirofea50802022-10-04 22:22:1729class CursorShapeClient;
[email protected]48dea152012-11-02 20:26:4630class DefaultCaptureClient;
[email protected]8cfb6722012-11-28 03:28:4631class FocusClient;
Peter Kastingd3de61e2020-03-27 16:25:5532class ScreenPositionClient;
[email protected]60a978b72012-06-08 00:29:1833}
Peter Kasting017a1152020-03-30 17:31:2334
[email protected]1dd1c1b2012-02-17 22:04:4735namespace test {
sky28f20d62016-10-20 23:21:5936class TestWindowParentingClient;
[email protected]1dd1c1b2012-02-17 22:04:4737
38// A helper class owned by tests that does common initialization required for
[email protected]eff8b2f2012-05-30 02:19:1739// Aura use. This class creates a root window with clients and other objects
40// that are necessary to run test on Aura.
[email protected]1dd1c1b2012-02-17 22:04:4741class AuraTestHelper {
42 public:
Peter Kasting8ba25a72020-03-27 21:48:3643 // Instantiates/destroys an AuraTestHelper. This can happen in a
44 // single-threaded phase without a backing task environment, and must not
45 // create one lest the caller wish to do so.
James Cook0eda2542021-03-30 23:49:1946 explicit AuraTestHelper(ui::ContextFactory* context_factory = nullptr);
Peter Boströmc8c12352021-09-21 23:37:1547
48 AuraTestHelper(const AuraTestHelper&) = delete;
49 AuraTestHelper& operator=(const AuraTestHelper&) = delete;
50
Peter Kasting1618c312020-03-31 00:46:3651 virtual ~AuraTestHelper();
[email protected]1dd1c1b2012-02-17 22:04:4752
tapted3b39bb82017-01-31 11:01:3853 // Returns the current AuraTestHelper, or nullptr if it's not alive.
54 static AuraTestHelper* GetInstance();
55
[email protected]eff8b2f2012-05-30 02:19:1756 // Creates and initializes (shows and sizes) the RootWindow for use in tests.
Peter Kasting1618c312020-03-31 00:46:3657 // This implementation does not create a task environment, but subclasses may
58 // choose to do so.
59 virtual void SetUp();
[email protected]eff8b2f2012-05-30 02:19:1760
Peter Kasting8845dca2020-03-27 22:19:0561 // Destroys the window, Env, and most other objects. This will be called
62 // automatically on destruction if it is not called manually earlier.
Peter Kasting1618c312020-03-31 00:46:3663 virtual void TearDown();
[email protected]1dd1c1b2012-02-17 22:04:4764
65 // Flushes message loop.
[email protected]eff8b2f2012-05-30 02:19:1766 void RunAllPendingInMessageLoop();
[email protected]1dd1c1b2012-02-17 22:04:4767
Peter Kasting1618c312020-03-31 00:46:3668 virtual Window* GetContext();
69 virtual WindowTreeHost* GetHost();
70 virtual TestScreen* GetTestScreen();
71 virtual client::FocusClient* GetFocusClient();
72 virtual client::CaptureClient* GetCaptureClient();
sky25714fe2016-10-27 15:21:2573
John Phamab465aa2020-06-04 21:35:5974 static constexpr gfx::Size kDefaultHostSize{800, 600};
75
Xiyuan Xia82ceeef2018-09-14 20:50:5076 Env* GetEnv();
77
Peter Kasting8ba25a72020-03-27 21:48:3678 protected:
Peter Kasting16204ab22020-03-12 03:38:4379 // May only be called between SetUp() and TearDown().
80 ui::ContextFactory* GetContextFactory();
81
[email protected]1dd1c1b2012-02-17 22:04:4782 private:
Peter Kasting8ba25a72020-03-27 21:48:3683 std::unique_ptr<wm::WMState> wm_state_ = std::make_unique<wm::WMState>();
Peter Kasting8953da92020-03-27 16:50:0684 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
85 std::unique_ptr<Env> env_;
Keishi Hattori0e45c022021-11-27 09:25:5286 raw_ptr<ui::ContextFactory> context_factory_to_restore_ = nullptr;
Peter Kasting16204ab22020-03-12 03:38:4387 std::unique_ptr<ui::TestContextFactories> context_factories_;
Peter Kasting8953da92020-03-27 16:50:0688 std::unique_ptr<TestScreen> test_screen_;
danakj25c52c32016-04-12 21:51:0889 std::unique_ptr<WindowTreeHost> host_;
Peter Kasting8953da92020-03-27 16:50:0690 std::unique_ptr<client::FocusClient> focus_client_;
91 std::unique_ptr<client::DefaultCaptureClient> capture_client_;
sky28f20d62016-10-20 23:21:5992 std::unique_ptr<TestWindowParentingClient> parenting_client_;
Peter Kastingd3de61e2020-03-27 16:25:5593 std::unique_ptr<client::ScreenPositionClient> screen_position_client_;
Henrique Ferreirofea50802022-10-04 22:22:1794 std::unique_ptr<client::CursorShapeClient> cursor_shape_client_;
[email protected]1dd1c1b2012-02-17 22:04:4795};
96
97} // namespace test
98} // namespace aura
99
100#endif // UI_AURA_TEST_AURA_TEST_HELPER_H_