[orca] Don't descend links with author-provided names



commit 4caae05750af8d51d046232bc3ea1ad71c56c0b4
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Wed Oct 14 15:21:47 2015 -0400

    Don't descend links with author-provided names

 src/orca/scripts/web/script_utilities.py           |   25 ++++++++-
 test/html/pretty-links.html                        |   33 +++++++++++
 .../firefox/line_nav_fontawesome_link.params       |    1 +
 .../firefox/line_nav_fontawesome_link.py           |   60 ++++++++++++++++++++
 4 files changed, 117 insertions(+), 2 deletions(-)
---
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index 7b6a758..12bf4b7 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -54,6 +54,7 @@ class Utilities(script_utilities.Utilities):
         self._isMath = {}
         self._mathNestingLevel = {}
         self._isOffScreenLabel = {}
+        self._hasExplicitName = {}
         self._hasNoSize = {}
         self._hasLongDesc = {}
         self._hasUselessCanvasDescendant = {}
@@ -95,6 +96,7 @@ class Utilities(script_utilities.Utilities):
         self._isMath = {}
         self._mathNestingLevel = {}
         self._isOffScreenLabel = {}
+        self._hasExplicitName = {}
         self._hasNoSize = {}
         self._hasLongDesc = {}
         self._hasUselessCanvasDescendant = {}
@@ -655,7 +657,8 @@ class Utilities(script_utilities.Utilities):
                 rv = None
             if rv and (self.isHidden(obj) or self.isOffScreenLabel(obj)):
                 rv = None
-            if rv and role == pyatspi.ROLE_LINK and self.hasUselessCanvasDescendant(obj):
+            if rv and role == pyatspi.ROLE_LINK \
+               and (self.hasExplicitName(obj) or self.hasUselessCanvasDescendant(obj)):
                 rv = None
 
         self._text[hash(obj)] = rv
@@ -2097,6 +2100,23 @@ class Utilities(script_utilities.Utilities):
         self._isParentOfNullChild[hash(obj)] = rv
         return rv
 
+    def hasExplicitName(self, obj):
+        if not (obj and self.inDocumentContent(obj)):
+            return False
+
+        rv = self._hasExplicitName.get(hash(obj))
+        if rv is not None:
+            return rv
+
+        try:
+            attrs = dict([attr.split(':', 1) for attr in obj.getAttributes()])
+        except:
+            attrs = {}
+
+        rv = attrs.get('explicit-name') == 'true'
+        self._hasExplicitName[hash(obj)] = rv
+        return rv
+
     def hasLongDesc(self, obj):
         if not (obj and self.inDocumentContent(obj)):
             return False
@@ -2411,7 +2431,8 @@ class Utilities(script_utilities.Utilities):
             return True
 
         role = obj.getRole()
-        if role == pyatspi.ROLE_LINK and self.hasUselessCanvasDescendant(obj):
+        if role == pyatspi.ROLE_LINK \
+           and (self.hasExplicitName(obj) or self.hasUselessCanvasDescendant(obj)):
             return True
 
         if self.isTextBlockElement(obj):
diff --git a/test/html/pretty-links.html b/test/html/pretty-links.html
new file mode 100644
index 0000000..38dc3a7
--- /dev/null
+++ b/test/html/pretty-links.html
@@ -0,0 +1,33 @@
+<html>
+<head>
+<style>
+.fa {
+  display: inline-block;
+  font-family: FontAwesome;
+  font-style: normal;
+  font-weight: normal;
+  line-height: 1;
+}
+.fa-twitter::before {
+    content: "\f099";
+}
+.fa-facebook::before {
+    content: "\f09a";
+}
+.fa-google-plus::before {
+    content: "\f0d5";
+}
+</style>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<meta charset="UTF-8">
+<link rel="stylesheet" href="pretty-links_files/style.css">
+</head>
+<body>
+<div>line 1</div>
+<a href="#" aria-label="Facebook"><i class="fa fa-facebook"></i></a>
+<a href="#" aria-label="Twitter"><i class="fa fa-twitter"></i></a>
+<a href="#" aria-label="Google+"><i class="fa fa-google-plus"></i></a>
+</div>
+<div>line 3</div>
+</body>
+</html>
diff --git a/test/keystrokes/firefox/line_nav_fontawesome_link.params 
b/test/keystrokes/firefox/line_nav_fontawesome_link.params
new file mode 100644
index 0000000..cc4aad2
--- /dev/null
+++ b/test/keystrokes/firefox/line_nav_fontawesome_link.params
@@ -0,0 +1 @@
+PARAMS=$TEST_DIR/../../html/pretty-links.html
diff --git a/test/keystrokes/firefox/line_nav_fontawesome_link.py 
b/test/keystrokes/firefox/line_nav_fontawesome_link.py
new file mode 100644
index 0000000..e4faf21
--- /dev/null
+++ b/test/keystrokes/firefox/line_nav_fontawesome_link.py
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+
+from macaroon.playback import *
+import utils
+
+sequence = MacroSequence()
+
+sequence.append(WaitForDocLoad())
+sequence.append(PauseAction(3000))
+
+# Work around some new quirk in Gecko that causes this test to fail if
+# run via the test harness rather than manually.
+sequence.append(KeyComboAction("<Control>r"))
+
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("<Control>Home"))
+sequence.append(utils.AssertPresentationAction(
+    "1. Top of file",
+    ["BRAILLE LINE:  'line 1'",
+     "     VISIBLE:  'line 1', cursor=1",
+     "SPEECH OUTPUT: 'line 1'"]))
+
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("Down"))
+sequence.append(utils.AssertPresentationAction(
+    "2. Line Down",
+    ["BRAILLE LINE:  'Facebook Twitter Google+'",
+     "     VISIBLE:  'Facebook Twitter Google+', cursor=1",
+     "SPEECH OUTPUT: 'Facebook link.'",
+     "SPEECH OUTPUT: 'Twitter link.'",
+     "SPEECH OUTPUT: 'Google+ link.'"]))
+
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("Down"))
+sequence.append(utils.AssertPresentationAction(
+    "3. Line Down",
+    ["BRAILLE LINE:  'line 3'",
+     "     VISIBLE:  'line 3', cursor=1",
+     "SPEECH OUTPUT: 'line 3'"]))
+
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("Up"))
+sequence.append(utils.AssertPresentationAction(
+    "4. Line Up",
+    ["BRAILLE LINE:  'Facebook Twitter Google+'",
+     "     VISIBLE:  'Facebook Twitter Google+', cursor=1",
+     "SPEECH OUTPUT: 'Facebook link.'",
+     "SPEECH OUTPUT: 'Twitter link.'",
+     "SPEECH OUTPUT: 'Google+ link.'"]))
+
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("Up"))
+sequence.append(utils.AssertPresentationAction(
+    "5. Line Up",
+    ["BRAILLE LINE:  'line 1'",
+     "     VISIBLE:  'line 1', cursor=1",
+     "SPEECH OUTPUT: 'line 1'"]))
+
+sequence.append(utils.AssertionSummaryAction())
+sequence.start()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]