File: interactive_views_test_internal.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (148 lines) | stat: -rw-r--r-- 5,011 bytes parent folder | download | duplicates (5)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright 2022 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_VIEWS_INTERACTION_INTERACTIVE_VIEWS_TEST_INTERNAL_H_
#define UI_VIEWS_INTERACTION_INTERACTIVE_VIEWS_TEST_INTERNAL_H_

#include <compare>
#include <concepts>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <type_traits>
#include <utility>
#include <variant>

#include "base/memory/raw_ptr.h"
#include "base/types/to_address.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/interaction/interaction_sequence.h"
#include "ui/base/interaction/interaction_test_util.h"
#include "ui/base/interaction/interactive_test_internal.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/interaction/interaction_test_util_mouse.h"
#include "ui/views/interaction/widget_focus_observer.h"

namespace views {
class NativeWindowTracker;
class View;
}  // namespace views

namespace views::test {

class InteractiveViewsTestApi;

namespace internal {

// Provides functionality required by InteractiveViewsTestApi but which needs to
// be hidden from tests inheriting from the API class.
class InteractiveViewsTestPrivate
    : public ui::test::internal::InteractiveTestPrivate {
 public:
  explicit InteractiveViewsTestPrivate(
      std::unique_ptr<ui::test::InteractionTestUtil> test_util);
  ~InteractiveViewsTestPrivate() override;

  // base::test::internal::InteractiveTestPrivate:
  void OnSequenceComplete() override;
  void OnSequenceAborted(
      const ui::InteractionSequence::AbortedData& data) override;
  void DoTestSetUp() override;
  void DoTestTearDown() override;

  InteractionTestUtilMouse& mouse_util() { return *mouse_util_; }

  InteractionTestUtilMouse::GestureParams GetGestureParamsForStep(
      ui::TrackedElement* el,
      const ui::InteractionSequence* seq);

  // Represents a temporary data stucture used when building Views hierarchies
  // into `DebugTreeNode`s.
  struct DebugTreeNodeViews {
    using Element = std::variant<const View*, const Widget*>;
    using List = std::set<DebugTreeNodeViews>;

    DebugTreeNodeViews();
    DebugTreeNodeViews(const View* view, const ui::TrackedElement* view_el);
    explicit DebugTreeNodeViews(const Widget* widget);
    DebugTreeNodeViews(DebugTreeNodeViews&&) noexcept;
    DebugTreeNodeViews& operator=(DebugTreeNodeViews&&) noexcept;
    ~DebugTreeNodeViews();

    Element impl;
    raw_ptr<const ui::TrackedElement> element = nullptr;
    gfx::Rect bounds;

    // The child nodes; implicitly sorted via <=>.
    List children;

    // Used to sort lists of `DebugTreeNodeViews`.
    std::strong_ordering operator<=>(const DebugTreeNodeViews& other) const;

    // Converts to a `DebutTreeNode` using methods of `owner`.
    DebugTreeNode ToNode(const InteractiveViewsTestPrivate& owner) const;
  };

 protected:
  // Retrieves the native window from an element. Used by GetWindowHintFor().
  virtual gfx::NativeWindow GetNativeWindowFromElement(
      ui::TrackedElement* el) const;

  // Retrieves the native window from a context. Used by GetWindowHintFor().
  virtual gfx::NativeWindow GetNativeWindowFromContext(
      ui::ElementContext context) const;

  // Use this to register widget focus suppliers.
  WidgetFocusSupplierFrame::SupplierList& widget_focus_suppliers() {
    return widget_focus_supplier_frame_->supplier_list();
  }

  // Gets a debug description of a widget.
  virtual std::string DebugDumpWidget(const Widget& widget) const;

  // InteractiveTestPrivate:
  DebugTreeNode DebugDumpElement(const ui::TrackedElement* el) const override;
  DebugTreeNode DebugDumpContext(
      const ui::ElementContext context) const override;

 private:
  friend class views::test::InteractiveViewsTestApi;

  class WindowHintCacheEntry;

  // Provides mouse input simulation.
  std::unique_ptr<InteractionTestUtilMouse> mouse_util_;

  // Tracks failures when a mouse operation fails.
  std::string mouse_error_message_;

  // Safely tracks the most recent native window targeted in each context.
  // For actions like ClickMouse() or ReleaseMouse(), a pivot element is used
  // so only the context is known; a NativeWindowTracker must be used to verify
  // that the cached information is still valid.
  std::map<ui::ElementContext, WindowHintCacheEntry> window_hint_cache_;

  std::unique_ptr<WidgetFocusSupplierFrame> widget_focus_supplier_frame_;
};

template <typename T>
concept IsView = std::convertible_to<std::remove_cvref_t<T>*, View*>;

template <size_t N,
          typename F,
          typename V = ui::test::internal::NthArgumentOf<N, F>>
  requires requires(V v) {
    { *base::to_address(v) } -> IsView;
  }
using ViewArgType =
    std::remove_cv_t<typename std::pointer_traits<V>::element_type>;

}  // namespace internal

}  // namespace views::test

#endif  // UI_VIEWS_INTERACTION_INTERACTIVE_VIEWS_TEST_INTERNAL_H_