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
|
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/accessibility/ax_layout_object.h"
#include "third_party/blink/renderer/core/layout/layout_list_item.h"
#include "third_party/blink/renderer/core/layout/ng/list/layout_ng_list_item.h"
#include "third_party/blink/renderer/modules/accessibility/testing/accessibility_test.h"
namespace blink {
class AXLayoutObjectTest : public AccessibilityTest {
protected:
static LayoutObject* GetListMarker(const LayoutObject& list_item) {
if (list_item.IsListItem())
return ToLayoutListItem(list_item).Marker();
if (list_item.IsLayoutNGListItem())
return ToLayoutNGListItem(list_item).Marker();
NOTREACHED();
return nullptr;
}
};
TEST_F(AXLayoutObjectTest, IsEditableInsideListmarker) {
SetBodyInnerHTML("<div contenteditable><li id=t>ab");
// The layout tree is:
// LayoutNGBlockFlow {DIV} at (0,0) size 784x20
// LayoutNGListItem {LI} at (0,0) size 784x20
// LayoutNGInsideListMarker {::marker} at (-1,0) size 7x19
// LayoutText (anonymous) at (-1,0) size 7x19
// text run at (-1,0) width 7: "\x{2022} "
// LayoutText {#text} at (22,0) size 15x19
// text run at (22,0) width 15: "ab"
LayoutObject& list_item = *GetElementById("t")->GetLayoutObject();
LayoutObject& list_marker = *GetListMarker(list_item);
const AXObject* ax_list_item = GetAXObject(&list_item);
ASSERT_NE(nullptr, ax_list_item);
EXPECT_TRUE(IsA<AXLayoutObject>(ax_list_item));
EXPECT_TRUE(ax_list_item->IsEditable());
EXPECT_TRUE(ax_list_item->IsRichlyEditable());
const AXObject* ax_list_marker = GetAXObject(&list_marker);
ASSERT_NE(nullptr, ax_list_marker);
EXPECT_TRUE(IsA<AXLayoutObject>(ax_list_item));
EXPECT_TRUE(ax_list_marker->IsEditable());
EXPECT_TRUE(ax_list_marker->IsRichlyEditable());
}
TEST_F(AXLayoutObjectTest, IsEditableOutsideListmarker) {
SetBodyInnerHTML("<ol contenteditable><li id=t>ab");
// THe layout tree is:
// LayoutNGBlockFlow {OL} at (0,0) size 784x20
// LayoutNGListItem {LI} at (40,0) size 744x20
// LayoutNGOutsideListMarker {::marker} at (-16,0) size 16x20
// LayoutText (anonymous) at (0,0) size 16x19
// text run at (0,0) width 16: "1. "
// LayoutText {#text} at (0,0) size 15x19
// text run at (0,0) width 15: "ab"
LayoutObject& list_item = *GetElementById("t")->GetLayoutObject();
LayoutObject& list_marker = *GetListMarker(list_item);
const AXObject* ax_list_item = GetAXObject(&list_item);
ASSERT_NE(nullptr, ax_list_item);
EXPECT_TRUE(IsA<AXLayoutObject>(ax_list_item));
EXPECT_TRUE(ax_list_item->IsEditable());
EXPECT_TRUE(ax_list_item->IsRichlyEditable());
const AXObject* ax_list_marker = GetAXObject(&list_marker);
ASSERT_NE(nullptr, ax_list_marker);
EXPECT_TRUE(IsA<AXLayoutObject>(ax_list_item));
EXPECT_TRUE(ax_list_marker->IsEditable());
EXPECT_TRUE(ax_list_marker->IsRichlyEditable());
}
TEST_F(AXLayoutObjectTest, StringValueTextTransform) {
SetBodyInnerHTML(
"<select id='t' style='text-transform:uppercase'>"
"<option>abc</select>");
const AXObject* ax_select = GetAXObjectByElementId("t");
ASSERT_NE(nullptr, ax_select);
EXPECT_TRUE(IsA<AXLayoutObject>(ax_select));
EXPECT_EQ("ABC", ax_select->StringValue());
}
TEST_F(AXLayoutObjectTest, StringValueTextSecurity) {
SetBodyInnerHTML(
"<select id='t' style='-webkit-text-security:disc'>"
"<option>abc</select>");
const AXObject* ax_select = GetAXObjectByElementId("t");
ASSERT_NE(nullptr, ax_select);
EXPECT_TRUE(IsA<AXLayoutObject>(ax_select));
// U+2022 -> \xE2\x80\xA2 in UTF-8
EXPECT_EQ("\xE2\x80\xA2\xE2\x80\xA2\xE2\x80\xA2",
ax_select->StringValue().Utf8());
}
// Test if AX takes 'Retarget' described from
// https://dom.spec.whatwg.org/#retarget after hit-testing.
TEST_F(AXLayoutObjectTest, AccessibilityHitTest) {
SetBodyInnerHTML(
"<style>\
.A{display:flex;flex:100%;margin-top:-37px;height:34px}\
.B{display:flex;flex:1;flex-wrap:wrap}\
.C{flex:100%;height:34px}\
</style>\
<div class='B'>\
<div class='C'></div>\
<input class='A' aria-label='Search' role='combobox'>\
</div>");
const AXObject* ax_root = GetAXRootObject();
ASSERT_NE(nullptr, ax_root);
const IntPoint position(8, 5);
AXObject* hit_test_result = ax_root->AccessibilityHitTest(position);
EXPECT_NE(nullptr, hit_test_result);
EXPECT_EQ(hit_test_result->RoleValue(),
ax::mojom::Role::kTextFieldWithComboBox);
}
} // namespace blink
|