File: arc_serialization_delegate_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; 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,811; 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 (173 lines) | stat: -rw-r--r-- 6,952 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/arc/accessibility/arc_serialization_delegate.h"

#include <memory>

#include "ash/test/ash_test_base.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ash/arc/accessibility/arc_serialization_delegate.h"
#include "components/exo/client_controlled_shell_surface.h"
#include "components/exo/surface.h"
#include "components/exo/test/shell_surface_builder.h"
#include "components/exo/wm_helper.h"
#include "services/accessibility/android/accessibility_info_data_wrapper.h"
#include "services/accessibility/android/android_accessibility_util.h"
#include "services/accessibility/android/ax_tree_source_android.h"
#include "services/accessibility/android/test/android_accessibility_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace arc {
class TestAccessibilityInfoDataWrapper
    : public ax::android::AccessibilityInfoDataWrapper {
 public:
  explicit TestAccessibilityInfoDataWrapper(
      ax::android::AXTreeSourceAndroid* tree_source_)
      : AccessibilityInfoDataWrapper(tree_source_) {}

  // AccessibilityInfoDataWrapper overrides:
  bool IsNode() const override { return false; }
  ax::android::mojom::AccessibilityNodeInfoData* GetNode() const override {
    return nullptr;
  }
  ax::android::mojom::AccessibilityWindowInfoData* GetWindow() const override {
    return nullptr;
  }
  int32_t GetId() const override { return id_; }
  const gfx::Rect GetBounds() const override { return bounds_; }
  bool IsVisibleToUser() const override { return true; }
  bool IsWebNode() const override { return false; }
  bool IsIgnored() const override { return false; }
  bool IsImportantInAndroid() const override { return true; }
  bool IsFocusableInFullFocusMode() const override { return true; }
  bool IsAccessibilityFocusableContainer() const override { return true; }
  void PopulateAXRole(ui::AXNodeData* out_data) const override {}
  void PopulateAXState(ui::AXNodeData* out_data) const override {}
  std::string ComputeAXName(bool do_recursive) const override { return ""; }
  void GetChildren(
      std::vector<raw_ptr<AccessibilityInfoDataWrapper, VectorExperimental>>*
          children) const override {}
  int32_t GetWindowId() const override { return 1; }

  int32_t id_ = 1;
  gfx::Rect bounds_;
};

class TestTreeSource : public ax::android::AXTreeSourceAndroid {
 public:
  explicit TestTreeSource(aura::Window* window)
      : AXTreeSourceAndroid(nullptr,
                            std::make_unique<ArcSerializationDelegate>(),
                            window) {}
  ax::android::AccessibilityInfoDataWrapper* GetRoot() const override {
    return root_;
  }
  raw_ptr<ax::android::AccessibilityInfoDataWrapper> root_;
};

class ArcSerializationDelegateTest : public ash::AshTestBase {
 public:
  ArcSerializationDelegateTest() = default;

  std::unique_ptr<exo::WMHelper> wm_helper = std::make_unique<exo::WMHelper>();
};

TEST_F(ArcSerializationDelegateTest, NonRootNodeBounds) {
  auto shell_surface = exo::test::ShellSurfaceBuilder({200, 200})
                           .SetGeometry(gfx::Rect(10, 10, 200, 200))
                           .BuildClientControlledShellSurface();

  TestTreeSource tree_source(shell_surface->GetWidget()->GetNativeWindow());
  TestAccessibilityInfoDataWrapper root(&tree_source);
  root.bounds_ = gfx::Rect(10, 10, 200, 200);
  tree_source.root_ = &root;

  TestAccessibilityInfoDataWrapper data(&tree_source);
  data.id_ = 2;
  data.bounds_ = gfx::Rect(20, 20, 30, 40);

  ui::AXNodeData out_data;
  tree_source.serialization_delegate().PopulateBounds(data, out_data);

  EXPECT_EQ(gfx::RectF(10, 10, 30, 40), out_data.relative_bounds.bounds);
}

TEST_F(ArcSerializationDelegateTest, RootNodeBounds) {
  UpdateDisplay("400x300");
  auto shell_surface = exo::test::ShellSurfaceBuilder({200, 200})
                           .SetGeometry(gfx::Rect(10, 10, 200, 200))
                           .BuildClientControlledShellSurface();

  TestTreeSource tree_source(shell_surface->GetWidget()->GetNativeWindow());
  TestAccessibilityInfoDataWrapper data(&tree_source);
  data.bounds_ = gfx::Rect(10, 10, 200, 200);
  tree_source.root_ = &data;

  ui::AXNodeData out_data;
  tree_source.serialization_delegate().PopulateBounds(data, out_data);

  EXPECT_EQ(gfx::RectF(0, 0, 200, 200), out_data.relative_bounds.bounds);
}

TEST_F(ArcSerializationDelegateTest, RootNodeBoundsOnExternalDisplay) {
  UpdateDisplay("400x300,600x500");

  auto shell_surface = exo::test::ShellSurfaceBuilder({200, 200})
                           .SetGeometry(gfx::Rect(410, 10, 200, 200))
                           .BuildClientControlledShellSurface();

  TestTreeSource tree_source(shell_surface->GetWidget()->GetNativeWindow());
  TestAccessibilityInfoDataWrapper data(&tree_source);
  data.bounds_ = gfx::Rect(10, 10, 200, 200);
  tree_source.root_ = &data;

  ui::AXNodeData out_data;
  tree_source.serialization_delegate().PopulateBounds(data, out_data);

  EXPECT_EQ(gfx::RectF(0, 0, 200, 200), out_data.relative_bounds.bounds);
}

TEST_F(ArcSerializationDelegateTest, BoundsScalingPiArc) {
  UpdateDisplay("400x300*2");  // 2x device scale factor.

  // With default_scale_cancellation, Android has default (1x) scale factor.
  wm_helper->SetDefaultScaleCancellation(true);
  auto shell_surface = exo::test::ShellSurfaceBuilder()
                           .SetGeometry(gfx::Rect(10, 10, 100, 100))
                           .EnableDefaultScaleCancellation()
                           .BuildClientControlledShellSurface();

  TestTreeSource tree_source(shell_surface->GetWidget()->GetNativeWindow());
  TestAccessibilityInfoDataWrapper data(&tree_source);
  data.bounds_ = gfx::Rect(10, 10, 100, 100);  // PX in Android.
  tree_source.root_ = &data;

  ui::AXNodeData out_data;
  tree_source.serialization_delegate().PopulateBounds(data, out_data);

  EXPECT_EQ(gfx::RectF(0, 0, 200, 200), out_data.relative_bounds.bounds);
}

TEST_F(ArcSerializationDelegateTest, BoundsScalingFromRvcArcAndLater) {
  UpdateDisplay("400x300*2");  // 2x device scale factor.

  // Without default_scale_cancellation, Android use the same (2x) scale factor.
  wm_helper->SetDefaultScaleCancellation(false);
  auto shell_surface = exo::test::ShellSurfaceBuilder({200, 200})
                           .SetGeometry(gfx::Rect(10, 10, 200, 200))
                           .BuildClientControlledShellSurface();

  TestTreeSource tree_source(shell_surface->GetWidget()->GetNativeWindow());
  TestAccessibilityInfoDataWrapper data(&tree_source);
  data.bounds_ = gfx::Rect(20, 20, 200, 200);  // PX in Android.
  tree_source.root_ = &data;

  ui::AXNodeData out_data;
  tree_source.serialization_delegate().PopulateBounds(data, out_data);

  EXPECT_EQ(gfx::RectF(0, 0, 200, 200), out_data.relative_bounds.bounds);
}

}  // namespace arc