Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 2 | // 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] | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 7 | |
sadrul | 578205fa | 2016-04-11 22:43:56 | [diff] [blame] | 8 | #include <memory> |
9 | |||||
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 10 | #include "base/memory/raw_ptr.h" |
Tomasz Moniuszko | a791670e | 2019-10-28 16:25:11 | [diff] [blame] | 11 | #include "build/build_config.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 12 | #include "ui/aura/window_event_dispatcher.h" |
Peter Kasting | 8ba25a7 | 2020-03-27 21:48:36 | [diff] [blame] | 13 | #include "ui/wm/core/wm_state.h" |
[email protected] | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 14 | |
[email protected] | eff8b2f | 2012-05-30 02:19:17 | [diff] [blame] | 15 | namespace ui { |
[email protected] | fa69f2b6 | 2014-05-22 21:47:58 | [diff] [blame] | 16 | class ContextFactory; |
[email protected] | dd31fa8 | 2013-03-13 04:08:36 | [diff] [blame] | 17 | class ScopedAnimationDurationScaleMode; |
Peter Kasting | 16204ab2 | 2020-03-12 03:38:43 | [diff] [blame] | 18 | class TestContextFactories; |
[email protected] | eff8b2f | 2012-05-30 02:19:17 | [diff] [blame] | 19 | } |
20 | |||||
[email protected] | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 21 | namespace aura { |
sky | f8fcebc | 2016-10-27 18:34:13 | [diff] [blame] | 22 | class Env; |
[email protected] | b9e08cf | 2012-10-13 02:20:24 | [diff] [blame] | 23 | class TestScreen; |
sky | 25714fe | 2016-10-27 15:21:25 | [diff] [blame] | 24 | class Window; |
Peter Kasting | c4b24b8 | 2020-03-25 03:06:24 | [diff] [blame] | 25 | class WindowTreeHost; |
sky | 25714fe | 2016-10-27 15:21:25 | [diff] [blame] | 26 | |
[email protected] | 48dea15 | 2012-11-02 20:26:46 | [diff] [blame] | 27 | namespace client { |
sky | 25714fe | 2016-10-27 15:21:25 | [diff] [blame] | 28 | class CaptureClient; |
Henrique Ferreiro | fea5080 | 2022-10-04 22:22:17 | [diff] [blame] | 29 | class CursorShapeClient; |
[email protected] | 48dea15 | 2012-11-02 20:26:46 | [diff] [blame] | 30 | class DefaultCaptureClient; |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 31 | class FocusClient; |
Peter Kasting | d3de61e | 2020-03-27 16:25:55 | [diff] [blame] | 32 | class ScreenPositionClient; |
[email protected] | 60a978b7 | 2012-06-08 00:29:18 | [diff] [blame] | 33 | } |
Peter Kasting | 017a115 | 2020-03-30 17:31:23 | [diff] [blame] | 34 | |
[email protected] | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 35 | namespace test { |
sky | 28f20d6 | 2016-10-20 23:21:59 | [diff] [blame] | 36 | class TestWindowParentingClient; |
[email protected] | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 37 | |
38 | // A helper class owned by tests that does common initialization required for | ||||
[email protected] | eff8b2f | 2012-05-30 02:19:17 | [diff] [blame] | 39 | // Aura use. This class creates a root window with clients and other objects |
40 | // that are necessary to run test on Aura. | ||||
[email protected] | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 41 | class AuraTestHelper { |
42 | public: | ||||
Peter Kasting | 8ba25a7 | 2020-03-27 21:48:36 | [diff] [blame] | 43 | // 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 Cook | 0eda254 | 2021-03-30 23:49:19 | [diff] [blame] | 46 | explicit AuraTestHelper(ui::ContextFactory* context_factory = nullptr); |
Peter Boström | c8c1235 | 2021-09-21 23:37:15 | [diff] [blame] | 47 | |
48 | AuraTestHelper(const AuraTestHelper&) = delete; | ||||
49 | AuraTestHelper& operator=(const AuraTestHelper&) = delete; | ||||
50 | |||||
Peter Kasting | 1618c31 | 2020-03-31 00:46:36 | [diff] [blame] | 51 | virtual ~AuraTestHelper(); |
[email protected] | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 52 | |
tapted | 3b39bb8 | 2017-01-31 11:01:38 | [diff] [blame] | 53 | // Returns the current AuraTestHelper, or nullptr if it's not alive. |
54 | static AuraTestHelper* GetInstance(); | ||||
55 | |||||
[email protected] | eff8b2f | 2012-05-30 02:19:17 | [diff] [blame] | 56 | // Creates and initializes (shows and sizes) the RootWindow for use in tests. |
Peter Kasting | 1618c31 | 2020-03-31 00:46:36 | [diff] [blame] | 57 | // This implementation does not create a task environment, but subclasses may |
58 | // choose to do so. | ||||
59 | virtual void SetUp(); | ||||
[email protected] | eff8b2f | 2012-05-30 02:19:17 | [diff] [blame] | 60 | |
Peter Kasting | 8845dca | 2020-03-27 22:19:05 | [diff] [blame] | 61 | // Destroys the window, Env, and most other objects. This will be called |
62 | // automatically on destruction if it is not called manually earlier. | ||||
Peter Kasting | 1618c31 | 2020-03-31 00:46:36 | [diff] [blame] | 63 | virtual void TearDown(); |
[email protected] | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 64 | |
65 | // Flushes message loop. | ||||
[email protected] | eff8b2f | 2012-05-30 02:19:17 | [diff] [blame] | 66 | void RunAllPendingInMessageLoop(); |
[email protected] | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 67 | |
Peter Kasting | 1618c31 | 2020-03-31 00:46:36 | [diff] [blame] | 68 | virtual Window* GetContext(); |
69 | virtual WindowTreeHost* GetHost(); | ||||
70 | virtual TestScreen* GetTestScreen(); | ||||
71 | virtual client::FocusClient* GetFocusClient(); | ||||
72 | virtual client::CaptureClient* GetCaptureClient(); | ||||
sky | 25714fe | 2016-10-27 15:21:25 | [diff] [blame] | 73 | |
John Pham | ab465aa | 2020-06-04 21:35:59 | [diff] [blame] | 74 | static constexpr gfx::Size kDefaultHostSize{800, 600}; |
75 | |||||
Xiyuan Xia | 82ceeef | 2018-09-14 20:50:50 | [diff] [blame] | 76 | Env* GetEnv(); |
77 | |||||
Peter Kasting | 8ba25a7 | 2020-03-27 21:48:36 | [diff] [blame] | 78 | protected: |
Peter Kasting | 16204ab2 | 2020-03-12 03:38:43 | [diff] [blame] | 79 | // May only be called between SetUp() and TearDown(). |
80 | ui::ContextFactory* GetContextFactory(); | ||||
81 | |||||
[email protected] | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 82 | private: |
Peter Kasting | 8ba25a7 | 2020-03-27 21:48:36 | [diff] [blame] | 83 | std::unique_ptr<wm::WMState> wm_state_ = std::make_unique<wm::WMState>(); |
Peter Kasting | 8953da9 | 2020-03-27 16:50:06 | [diff] [blame] | 84 | std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; |
85 | std::unique_ptr<Env> env_; | ||||
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 86 | raw_ptr<ui::ContextFactory> context_factory_to_restore_ = nullptr; |
Peter Kasting | 16204ab2 | 2020-03-12 03:38:43 | [diff] [blame] | 87 | std::unique_ptr<ui::TestContextFactories> context_factories_; |
Peter Kasting | 8953da9 | 2020-03-27 16:50:06 | [diff] [blame] | 88 | std::unique_ptr<TestScreen> test_screen_; |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 89 | std::unique_ptr<WindowTreeHost> host_; |
Peter Kasting | 8953da9 | 2020-03-27 16:50:06 | [diff] [blame] | 90 | std::unique_ptr<client::FocusClient> focus_client_; |
91 | std::unique_ptr<client::DefaultCaptureClient> capture_client_; | ||||
sky | 28f20d6 | 2016-10-20 23:21:59 | [diff] [blame] | 92 | std::unique_ptr<TestWindowParentingClient> parenting_client_; |
Peter Kasting | d3de61e | 2020-03-27 16:25:55 | [diff] [blame] | 93 | std::unique_ptr<client::ScreenPositionClient> screen_position_client_; |
Henrique Ferreiro | fea5080 | 2022-10-04 22:22:17 | [diff] [blame] | 94 | std::unique_ptr<client::CursorShapeClient> cursor_shape_client_; |
[email protected] | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 95 | }; |
96 | |||||
97 | } // namespace test | ||||
98 | } // namespace aura | ||||
99 | |||||
100 | #endif // UI_AURA_TEST_AURA_TEST_HELPER_H_ |