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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
// Copyright 2020 The Chromium Authors
// 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_node_object.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/modules/accessibility/ax_object-inl.h"
#include "third_party/blink/renderer/modules/accessibility/testing/accessibility_test.h"
namespace blink {
namespace test {
TEST_F(AccessibilityTest, TextOffsetInFormattingContextWithLayoutReplaced) {
SetBodyInnerHTML(R"HTML(
<p>
Before <img id="replaced" alt="alt"> after.
</p>)HTML");
const AXObject* ax_replaced = GetAXObjectByElementId("replaced");
ASSERT_NE(nullptr, ax_replaced);
ASSERT_EQ(ax::mojom::Role::kImage, ax_replaced->RoleValue());
ASSERT_EQ("alt", ax_replaced->ComputedName());
// After white space is compressed, the word "before" plus a single white
// space is of length 7.
EXPECT_EQ(7, ax_replaced->TextOffsetInFormattingContext(0));
EXPECT_EQ(8, ax_replaced->TextOffsetInFormattingContext(1));
}
TEST_F(AccessibilityTest, TextOffsetInFormattingContextWithLayoutInline) {
SetBodyInnerHTML(R"HTML(
<p>
Before <a id="inline" href="#">link</a> after.
</p>)HTML");
const AXObject* ax_inline = GetAXObjectByElementId("inline");
ASSERT_NE(nullptr, ax_inline);
ASSERT_EQ(ax::mojom::Role::kLink, ax_inline->RoleValue());
ASSERT_EQ("link", ax_inline->ComputedName());
// After white space is compressed, the word "before" plus a single white
// space is of length 7.
EXPECT_EQ(7, ax_inline->TextOffsetInFormattingContext(0));
EXPECT_EQ(8, ax_inline->TextOffsetInFormattingContext(1));
}
TEST_F(AccessibilityTest,
TextOffsetInFormattingContextWithLayoutBlockFlowAtInlineLevel) {
SetBodyInnerHTML(R"HTML(
<p>
Before
<b id="block-flow" style="display: inline-block;">block flow</b>
after.
</p>)HTML");
const AXObject* ax_block_flow = GetAXObjectByElementId("block-flow");
ASSERT_NE(nullptr, ax_block_flow);
ASSERT_EQ(ax::mojom::Role::kGenericContainer, ax_block_flow->RoleValue());
// After white space is compressed, the word "before" plus a single white
// space is of length 7.
EXPECT_EQ(7, ax_block_flow->TextOffsetInFormattingContext(0));
EXPECT_EQ(8, ax_block_flow->TextOffsetInFormattingContext(1));
}
TEST_F(AccessibilityTest,
TextOffsetInFormattingContextWithLayoutBlockFlowAtBlockLevel) {
// OffsetMapping does not support block flow objects that are at
// block-level, so we do not support them as well.
SetBodyInnerHTML(R"HTML(
<p>
Before
<b id="block-flow" style="display: block;">block flow</b>
after.
</p>)HTML");
const AXObject* ax_block_flow = GetAXObjectByElementId("block-flow");
ASSERT_NE(nullptr, ax_block_flow);
ASSERT_EQ(ax::mojom::Role::kGenericContainer, ax_block_flow->RoleValue());
// Since block-level elements do not expose a count of the number of
// characters from the beginning of their formatting context, we return the
// same offset that was passed in.
EXPECT_EQ(0, ax_block_flow->TextOffsetInFormattingContext(0));
EXPECT_EQ(1, ax_block_flow->TextOffsetInFormattingContext(1));
}
TEST_F(AccessibilityTest, TextOffsetInFormattingContextWithLayoutText) {
SetBodyInnerHTML(R"HTML(
<p>
Before <span id="span">text</span> after.
</p>)HTML");
const AXObject* ax_text =
GetAXObjectByElementId("span")->FirstChildIncludingIgnored();
ASSERT_NE(nullptr, ax_text);
ASSERT_EQ(ax::mojom::Role::kStaticText, ax_text->RoleValue());
ASSERT_EQ("text", ax_text->ComputedName());
// After white space is compressed, the word "before" plus a single white
// space is of length 7.
EXPECT_EQ(7, ax_text->TextOffsetInFormattingContext(0));
EXPECT_EQ(8, ax_text->TextOffsetInFormattingContext(1));
}
TEST_F(AccessibilityTest, TextOffsetInFormattingContextWithLayoutBr) {
SetBodyInnerHTML(R"HTML(
<p>
Before <br id="br"> after.
</p>)HTML");
const AXObject* ax_br = GetAXObjectByElementId("br");
ASSERT_NE(nullptr, ax_br);
ASSERT_EQ(ax::mojom::Role::kLineBreak, ax_br->RoleValue());
ASSERT_EQ("\n", ax_br->ComputedName());
// After white space is compressed, the word "before" is of length 6.
EXPECT_EQ(6, ax_br->TextOffsetInFormattingContext(0));
EXPECT_EQ(7, ax_br->TextOffsetInFormattingContext(1));
}
TEST_F(AccessibilityTest, TextOffsetInFormattingContextWithLayoutFirstLetter) {
SetBodyInnerHTML(R"HTML(
<style>
q::first-letter {
color: red;
}
</style>
<p>
Before
<q id="first-letter">1. Remaining part</q>
after.
</p>)HTML");
const AXObject* ax_first_letter = GetAXObjectByElementId("first-letter");
ASSERT_NE(nullptr, ax_first_letter);
ASSERT_EQ(ax::mojom::Role::kGenericContainer, ax_first_letter->RoleValue());
// After white space is compressed, the word "before" plus a single white
// space is of length 7.
EXPECT_EQ(7, ax_first_letter->TextOffsetInFormattingContext(0));
EXPECT_EQ(8, ax_first_letter->TextOffsetInFormattingContext(1));
}
TEST_F(AccessibilityTest,
TextOffsetInFormattingContextWithCSSGeneratedContent) {
SetBodyInnerHTML(R"HTML(
<style>
q::before {
content: "<";
color: blue;
}
q::after {
content: ">";
color: red;
}
</style>
<p>
Before <q id="css-generated">CSS generated</q> after.
</p>)HTML");
const AXObject* ax_css_generated = GetAXObjectByElementId("css-generated");
ASSERT_NE(nullptr, ax_css_generated);
ASSERT_EQ(ax::mojom::Role::kGenericContainer, ax_css_generated->RoleValue());
// After white space is compressed, the word "before" plus a single white
// space is of length 7.
EXPECT_EQ(7, ax_css_generated->TextOffsetInFormattingContext(0));
EXPECT_EQ(8, ax_css_generated->TextOffsetInFormattingContext(1));
}
TEST_F(AccessibilityTest, ScrollButtonAccessibilityRole) {
SetBodyInnerHTML(R"HTML(
<style>
#carousel {
scroll-marker-group: after;
&::scroll-button(inline-start) {
content: '<';
}
&::scroll-button(inline-end) {
content: '>' / 'next';
}
}
</style>
<div id=carousel>
<div>One</div>
<div>Two</div>
</div>)HTML");
const AXObject* left_button =
GetAXObjectByElementId("carousel", kPseudoIdScrollButtonInlineStart);
ASSERT_NE(nullptr, left_button);
ASSERT_EQ(ax::mojom::Role::kButton, left_button->RoleValue());
const AXObject* right_button =
GetAXObjectByElementId("carousel", kPseudoIdScrollButtonInlineEnd);
ASSERT_NE(nullptr, right_button);
ASSERT_EQ(ax::mojom::Role::kButton, right_button->RoleValue());
}
TEST_F(AccessibilityTest, ScrollButtonAndMarkerGroupParent) {
SetBodyInnerHTML(R"HTML(
<style>
#carousel {
scroll-marker-group: after;
overflow: scroll;
&::scroll-button(inline-start) {
content: '<';
}
& > .item {
&::scroll-marker {
content: '';
}
}
}
</style>
<div id=wrapper>
<div id=carousel>
<div class=item>One</div>
<div class=item>Two</div>
</div>
</div>)HTML");
const AXObject* wrapper = GetAXObjectByElementId("wrapper");
ASSERT_NE(nullptr, wrapper);
// Check that button's parent is wrapper.
const AXObject* button =
GetAXObjectByElementId("carousel", kPseudoIdScrollButtonInlineStart);
ASSERT_NE(nullptr, button);
const Node* button_parent = AXObject::GetParentNodeForComputeParent(
button->AXObjectCache(), button->GetNode());
EXPECT_EQ(button_parent, wrapper->GetNode());
// Check that marker group's parent is wrapper.
const AXObject* marker_group =
GetAXObjectByElementId("carousel", kPseudoIdScrollMarkerGroupAfter);
ASSERT_NE(nullptr, marker_group);
const Node* marker_group_parent = AXObject::GetParentNodeForComputeParent(
marker_group->AXObjectCache(), marker_group->GetNode());
EXPECT_EQ(marker_group_parent, wrapper->GetNode());
}
} // namespace test
} // namespace blink
|