Commit d5e03bd4 authored by Aaron Leventhal's avatar Aaron Leventhal Committed by Commit Bot

Long text should not be truncated in a11y container name

Bug: 896359
Change-Id: Idf548dee9fe65183a9093132560741dee9ae4029
Reviewed-on: https://chromium-review.googlesource.com/c/1388552
Commit-Queue: Aaron Leventhal <aleventhal@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618680}
parent 7097bea9
...@@ -1604,6 +1604,10 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityListMarkers) { ...@@ -1604,6 +1604,10 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityListMarkers) {
RunHtmlTest(FILE_PATH_LITERAL("list-markers.html")); RunHtmlTest(FILE_PATH_LITERAL("list-markers.html"));
} }
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityLongText) {
RunHtmlTest(FILE_PATH_LITERAL("long-text.html"));
}
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityMain) { IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityMain) {
RunHtmlTest(FILE_PATH_LITERAL("main.html")); RunHtmlTest(FILE_PATH_LITERAL("main.html"));
} }
......
...@@ -483,8 +483,11 @@ void BlinkAXTreeSource::SerializeNode(WebAXObject src, ...@@ -483,8 +483,11 @@ void BlinkAXTreeSource::SerializeNode(WebAXObject src,
blink::WebString web_name = src.GetName(nameFrom, nameObjects); blink::WebString web_name = src.GetName(nameFrom, nameObjects);
if ((!web_name.IsEmpty() && !web_name.IsNull()) || if ((!web_name.IsEmpty() && !web_name.IsNull()) ||
nameFrom == ax::mojom::NameFrom::kAttributeExplicitlyEmpty) { nameFrom == ax::mojom::NameFrom::kAttributeExplicitlyEmpty) {
int max_length = dst->role == ax::mojom::Role::kStaticText
? kMaxStaticTextLength
: kMaxStringAttributeLength;
TruncateAndAddStringAttribute(dst, ax::mojom::StringAttribute::kName, TruncateAndAddStringAttribute(dst, ax::mojom::StringAttribute::kName,
web_name.Utf8()); web_name.Utf8(), max_length);
dst->SetNameFrom(nameFrom); dst->SetNameFrom(nameFrom);
AddIntListAttributeFromWebObjects( AddIntListAttributeFromWebObjects(
ax::mojom::IntListAttribute::kLabelledbyIds, nameObjects, dst); ax::mojom::IntListAttribute::kLabelledbyIds, nameObjects, dst);
...@@ -1011,11 +1014,11 @@ WebAXObject BlinkAXTreeSource::ComputeRoot() const { ...@@ -1011,11 +1014,11 @@ WebAXObject BlinkAXTreeSource::ComputeRoot() const {
void BlinkAXTreeSource::TruncateAndAddStringAttribute( void BlinkAXTreeSource::TruncateAndAddStringAttribute(
AXContentNodeData* dst, AXContentNodeData* dst,
ax::mojom::StringAttribute attribute, ax::mojom::StringAttribute attribute,
const std::string& value) const { const std::string& value,
if (value.size() > BlinkAXTreeSource::kMaxStringAttributeLength) { uint32_t max_len) const {
if (value.size() > max_len) {
std::string truncated; std::string truncated;
base::TruncateUTF8ToByteSize( base::TruncateUTF8ToByteSize(value, max_len, &truncated);
value, BlinkAXTreeSource::kMaxStringAttributeLength, &truncated);
dst->AddStringAttribute(attribute, truncated); dst->AddStringAttribute(attribute, truncated);
} else { } else {
dst->AddStringAttribute(attribute, value); dst->AddStringAttribute(attribute, value);
......
...@@ -110,10 +110,16 @@ class BlinkAXTreeSource ...@@ -110,10 +110,16 @@ class BlinkAXTreeSource
blink::WebAXObject ComputeRoot() const; blink::WebAXObject ComputeRoot() const;
uint32_t kMaxStringAttributeLength = 10000; // Max length for attributes such as aria-label.
void TruncateAndAddStringAttribute(AXContentNodeData* dst, static const uint32_t kMaxStringAttributeLength = 10000;
ax::mojom::StringAttribute attribute, // Max length for a static text name.
const std::string& value) const; // Length of War and Peace (http://www.gutenberg.org/files/2600/2600-0.txt).
static const uint32_t kMaxStaticTextLength = 3227574;
void TruncateAndAddStringAttribute(
AXContentNodeData* dst,
ax::mojom::StringAttribute attribute,
const std::string& value,
uint32_t max_len = kMaxStringAttributeLength) const;
RenderFrameImpl* render_frame_; RenderFrameImpl* render_frame_;
......
<body>
<pre style="word-wrap: break-word; white-space: pre-wrap;"><script>
for (let count = 1; count <= 250; count ++)
document.write('' + count + '. The quick brown fox jumps over the lazy dog.\n');
</script></pre>
</body>
<!DOCTYPE HTML>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<pre id="pre" style="word-wrap: break-word; white-space: pre-wrap;"><script>
for (let count = 1; count <= 250; count ++)
document.write('' + count + '. The quick brown fox jumps over the lazy dog. ');
</script></pre>
</body>
<script>
test(function(t) {
var axPre = accessibilityController.accessibleElementById("pre");
var axStaticText = axPre.childAtIndex(0);
console.log(axStaticText.name);
assert_equals(axStaticText.name.substr(-50), "250. The quick brown fox jumps over the lazy dog. ");
}, "Accessible name should not be truncated.");
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment