[orca] Work around broken lists in web content



commit 8f62e26732f049a6fb2f05fa5c8f5580db245ef4
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Wed Oct 14 21:35:22 2015 -0400

    Work around broken lists in web content

 src/orca/scripts/web/script_utilities.py           |   21 ++++-
 test/html/bogus-ol.html                            |   16 ++++
 .../firefox/line_nav_lists_broken.params           |    1 +
 test/keystrokes/firefox/line_nav_lists_broken.py   |   87 ++++++++++++++++++++
 4 files changed, 122 insertions(+), 3 deletions(-)
---
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index fdc9a8a..e062c49 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -78,6 +78,8 @@ class Utilities(script_utilities.Utilities):
         self._currentWordContents = None
         self._currentCharacterContents = None
 
+        self._validChildRoles = {pyatspi.ROLE_LIST: [pyatspi.ROLE_LIST_ITEM]}
+
     def _cleanupContexts(self):
         toRemove = []
         for key, [obj, offset] in self._caretContexts.items():
@@ -1375,6 +1377,9 @@ class Utilities(script_utilities.Utilities):
         return rv
 
     def treatAsDiv(self, obj):
+        if not (obj and self.inDocumentContent(obj)):
+            return False
+
         rv = self._treatAsDiv.get(hash(obj))
         if rv is not None:
             return rv
@@ -1388,8 +1393,18 @@ class Utilities(script_utilities.Utilities):
             return False
 
         rv = False
-        if role == pyatspi.ROLE_LIST:
-            rv = not (childCount and obj[0].getRole() == pyatspi.ROLE_LIST_ITEM)
+
+        validRoles = self._validChildRoles.get(role)
+        if validRoles:
+            if not childCount:
+                rv = True
+            else:
+                rv = bool([x for x in obj if x and x.getRole() not in validRoles])
+
+        if not rv:
+            validRoles = self._validChildRoles.get(obj.parent)
+            if validRoles:
+                rv = bool([x for x in obj.parent if x and x.getRole() not in validRoles])
 
         self._treatAsDiv[hash(obj)] = rv
         return rv
@@ -2530,7 +2545,7 @@ class Utilities(script_utilities.Utilities):
                        pyatspi.ROLE_INTERNAL_FRAME,
                        pyatspi.ROLE_TABLE,
                        pyatspi.ROLE_TABLE_ROW]
-        if role in lookInChild and obj.childCount:
+        if role in lookInChild and obj.childCount and not self.treatAsDiv(obj):
             msg = "WEB: First caret context for %s, %i will look in child %s" % (obj, offset, obj[0])
             debug.println(debug.LEVEL_INFO, msg)
             return self.findFirstCaretContext(obj[0], 0)
diff --git a/test/html/bogus-ol.html b/test/html/bogus-ol.html
new file mode 100644
index 0000000..98a2f77
--- /dev/null
+++ b/test/html/bogus-ol.html
@@ -0,0 +1,16 @@
+<html>
+<head>
+<title></title>
+</head>
+<body>
+<div>Line 1</div>
+<ol>
+<dl>
+<dt>Line 2</dt>
+<dd>Line 3</dd>
+</dl>
+Line 4
+</ol>
+<div>Line 5</div>
+</body>
+</html>
diff --git a/test/keystrokes/firefox/line_nav_lists_broken.params 
b/test/keystrokes/firefox/line_nav_lists_broken.params
new file mode 100644
index 0000000..a0ffd92
--- /dev/null
+++ b/test/keystrokes/firefox/line_nav_lists_broken.params
@@ -0,0 +1 @@
+PARAMS=$TEST_DIR/../../html/bogus-ol.html
diff --git a/test/keystrokes/firefox/line_nav_lists_broken.py 
b/test/keystrokes/firefox/line_nav_lists_broken.py
new file mode 100644
index 0000000..c3e4472
--- /dev/null
+++ b/test/keystrokes/firefox/line_nav_lists_broken.py
@@ -0,0 +1,87 @@
+#!/usr/bin/python
+
+from macaroon.playback import *
+import utils
+
+sequence = MacroSequence()
+
+sequence.append(WaitForDocLoad())
+
+# 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:  'Line 2'",
+     "     VISIBLE:  'Line 2', cursor=1",
+     "SPEECH OUTPUT: 'Line 2.'"]))
+
+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("Down"))
+sequence.append(utils.AssertPresentationAction(
+    "4. Line Down",
+    ["BRAILLE LINE:  'Line 4'",
+     "     VISIBLE:  'Line 4', cursor=1",
+     "SPEECH OUTPUT: 'Line 4'"]))
+
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("Down"))
+sequence.append(utils.AssertPresentationAction(
+    "5. Line Down",
+    ["BRAILLE LINE:  'Line 5'",
+     "     VISIBLE:  'Line 5', cursor=1",
+     "SPEECH OUTPUT: 'Line 5'"]))
+
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("Up"))
+sequence.append(utils.AssertPresentationAction(
+    "6. Line Up",
+    ["BRAILLE LINE:  'Line 4'",
+     "     VISIBLE:  'Line 4', cursor=1",
+     "SPEECH OUTPUT: 'Line 4'"]))
+
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("Up"))
+sequence.append(utils.AssertPresentationAction(
+    "7. Line Up",
+    ["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(
+    "8. Line Up",
+    ["BRAILLE LINE:  'Line 2'",
+     "     VISIBLE:  'Line 2', cursor=1",
+     "SPEECH OUTPUT: 'Line 2.'"]))
+
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("Up"))
+sequence.append(utils.AssertPresentationAction(
+    "9. 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]