Commit 82c6957b authored by David Tseng's avatar David Tseng Committed by Commit Bot

Fix image annotations output in ChromeVox

The change
https://chromium-review.googlesource.com/c/chromium/src/+/2112512

inadvertently changed the way undefined names were exposed. Previously an AXNode
without a name would return |undefined| to the js layer. With the above change,
it returns |''|.

Fix this to once again return undefined.

AX-Relnotes: Makes ChromeVox output automatic image labels once again.
Fixed: 1126176
Change-Id: I08a84059065452c95114b2a2b38bdc1d7d554ac0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401970
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806050}
parent 604c575e
......@@ -2921,8 +2921,8 @@ TEST_F('ChromeVoxBackgroundTest', 'AudioVideo', function() {
assertNotNullNorUndefined(audio);
assertNotNullNorUndefined(video);
assertEquals('', audio.name);
assertEquals('', video.name);
assertEquals(undefined, audio.name);
assertEquals(undefined, video.name);
assertEquals(undefined, audio.firstChild);
assertEquals(undefined, video.firstChild);
......@@ -3060,3 +3060,43 @@ TEST_F('ChromeVoxBackgroundTest', 'DialogAutoSummaryTextContent', function() {
.replay();
});
});
TEST_F('ChromeVoxBackgroundTest', 'ImageAnnotations', function() {
const mockFeedback = this.createMockFeedback();
this.runWithLoadedTree(
`
<p>start</p>
<img alt="bar" src="data:image/png;base64,iVBORw0KGgoAAAANS">
<img src="data:image/png;base64,iVBORw0KGgoAAAANS">
`,
function(root) {
const [namedImg, unnamedImg] = root.findAll({role: RoleType.IMAGE});
assertNotNullNorUndefined(namedImg);
assertNotNullNorUndefined(unnamedImg);
assertEquals('bar', namedImg.name);
assertEquals(undefined, unnamedImg.name);
// Fake the image annotation.
Object.defineProperty(namedImg, 'imageAnnotation', {
get() {
return 'foo';
}
});
Object.defineProperty(unnamedImg, 'imageAnnotation', {
get() {
return 'foo';
}
});
mockFeedback.call(doCmd('nextObject'))
.expectSpeech('start')
.expectNextSpeechUtteranceIsNot('foo')
.expectSpeech('bar', 'Image')
.call(doCmd('nextObject'))
.expectNextSpeechUtteranceIsNot('bar')
.expectSpeech('foo', 'Image')
.replay();
});
});
......@@ -1049,14 +1049,16 @@ editing.EditableLine = class {
if (!AutomationPredicate.text(startNode) ||
(this.start_.node != startNode &&
this.start_.node.parent != startNode)) {
startIndex = this.start_.index == cursors.NODE_INDEX ?
startIndex =
(this.start_.index == cursors.NODE_INDEX && this.start_.node.name) ?
this.start_.node.name.length :
this.start_.index;
}
if (!AutomationPredicate.text(endNode) ||
(this.end_.node != endNode && this.end_.node.parent != endNode)) {
endIndex = this.end_.index == cursors.NODE_INDEX ?
endIndex =
(this.end_.index == cursors.NODE_INDEX && this.end_.node.name) ?
this.end_.node.name.length :
this.end_.index;
}
......
......@@ -49,7 +49,7 @@ const hasActionableDescendant = function(node) {
const nodeNameContainedInStaticTextChildren = function(node) {
const name = node.name;
let child = node.firstChild;
if (!child) {
if (name === undefined || !child) {
return false;
}
let nameIndex = 0;
......
......@@ -1156,8 +1156,7 @@ void AutomationInternalCustomBindings::AddRoutes() {
AutomationAXTreeWrapper* tree_wrapper,
ui::AXNode* node) {
const ui::AXNodeData& node_data = node->data();
const char* name =
node_data.GetStringAttribute(ax::mojom::StringAttribute::kName).c_str();
const char* name = nullptr;
if (node_data.role == ax::mojom::Role::kPortal &&
node_data.GetNameFrom() == ax::mojom::NameFrom::kNone) {
if (GetRootOfChildTree(&node, &tree_wrapper)) {
......@@ -1166,6 +1165,14 @@ void AutomationInternalCustomBindings::AddRoutes() {
.c_str();
}
}
if (!name &&
node_data.HasStringAttribute(ax::mojom::StringAttribute::kName)) {
name = node_data.GetStringAttribute(ax::mojom::StringAttribute::kName)
.c_str();
}
if (name)
result.Set(v8::String::NewFromUtf8(isolate, name).ToLocalChecked());
});
RouteNodeIDFunction(
......
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