File: aura_test_helper.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (100 lines) | stat: -rw-r--r-- 3,195 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_AURA_TEST_AURA_TEST_HELPER_H_
#define UI_AURA_TEST_AURA_TEST_HELPER_H_

#include <memory>

#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/wm/core/wm_state.h"

namespace ui {
class ContextFactory;
class ScopedAnimationDurationScaleMode;
class TestContextFactories;
}

namespace aura {
class Env;
class TestScreen;
class Window;
class WindowTreeHost;

namespace client {
class CaptureClient;
class CursorShapeClient;
class DefaultCaptureClient;
class FocusClient;
class ScreenPositionClient;
}

namespace test {
class TestWindowParentingClient;

// A helper class owned by tests that does common initialization required for
// Aura use. This class creates a root window with clients and other objects
// that are necessary to run test on Aura.
class AuraTestHelper {
 public:
  // Instantiates/destroys an AuraTestHelper. This can happen in a
  // single-threaded phase without a backing task environment, and must not
  // create one lest the caller wish to do so.
  explicit AuraTestHelper(ui::ContextFactory* context_factory = nullptr);

  AuraTestHelper(const AuraTestHelper&) = delete;
  AuraTestHelper& operator=(const AuraTestHelper&) = delete;

  virtual ~AuraTestHelper();

  // Returns the current AuraTestHelper, or nullptr if it's not alive.
  static AuraTestHelper* GetInstance();

  // Creates and initializes (shows and sizes) the RootWindow for use in tests.
  // This implementation does not create a task environment, but subclasses may
  // choose to do so.
  virtual void SetUp();

  // Destroys the window, Env, and most other objects.  This will be called
  // automatically on destruction if it is not called manually earlier.
  virtual void TearDown();

  // Flushes message loop.
  void RunAllPendingInMessageLoop();

  virtual Window* GetContext();
  virtual WindowTreeHost* GetHost();
  virtual TestScreen* GetTestScreen();
  virtual client::FocusClient* GetFocusClient();
  virtual client::CaptureClient* GetCaptureClient();

  static constexpr gfx::Size kDefaultHostSize{800, 600};

  Env* GetEnv();

 protected:
  // May only be called between SetUp() and TearDown().
  ui::ContextFactory* GetContextFactory();

 private:
  std::unique_ptr<wm::WMState> wm_state_ = std::make_unique<wm::WMState>();
  std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
  std::unique_ptr<Env> env_;
  raw_ptr<ui::ContextFactory> context_factory_to_restore_ = nullptr;
  std::unique_ptr<ui::TestContextFactories> context_factories_;
  std::unique_ptr<TestScreen> test_screen_;
  std::unique_ptr<WindowTreeHost> host_;
  std::unique_ptr<client::FocusClient> focus_client_;
  std::unique_ptr<client::DefaultCaptureClient> capture_client_;
  std::unique_ptr<TestWindowParentingClient> parenting_client_;
  std::unique_ptr<client::ScreenPositionClient> screen_position_client_;
  std::unique_ptr<client::CursorShapeClient> cursor_shape_client_;
};

}  // namespace test
}  // namespace aura

#endif  // UI_AURA_TEST_AURA_TEST_HELPER_H_