Index: test/keystrokes/firefox/html_struct_nav_bug_567984.py
===================================================================
--- test/keystrokes/firefox/html_struct_nav_bug_567984.py	(revision 4441)
+++ test/keystrokes/firefox/html_struct_nav_bug_567984.py	(working copy)
@@ -118,6 +118,29 @@
      "SPEECH OUTPUT: 'Hamarosan újraindul a gázszállítás link heading level 3'"]))
 
 ########################################################################
+# Down Arrow to move to some text in the document frame
+#
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("Down"))
+sequence.append(utils.AssertPresentationAction(
+    "9. Down",
+    ["BRAILLE LINE:  'Megállapodott Putyin és Tyimosenko az orosz-ukrán szerzõdésrõl. Amint lepapírozzák, jön a gáz.'",
+     "     VISIBLE:  'Megállapodott Putyin és Tyimosen', cursor=1",
+     "SPEECH OUTPUT: 'Megállapodott Putyin és Tyimosenko az orosz-ukrán szerzõdésrõl. Amint lepapírozzák, jön a gáz.'"]))
+
+########################################################################
+# Shift+ H to move to the previous heading. It should NOT be the last
+# heading.
+#
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("<Shift>h"))
+sequence.append(utils.AssertPresentationAction(
+    "10. Shift+h",
+    ["BRAILLE LINE:  'Hamarosan újraindul a gázszállítás h3'",
+     "     VISIBLE:  'Hamarosan újraindul a gázszállít', cursor=1",
+     "SPEECH OUTPUT: 'Hamarosan újraindul a gázszállítás link heading level 3'"]))
+
+########################################################################
 # Move to the location bar by pressing Control+L.  When it has focus
 # type "about:blank" and press Return to restore the browser to the
 # conditions at the test's start.
Index: src/orca/structural_navigation.py
===================================================================
--- src/orca/structural_navigation.py	(revision 4440)
+++ src/orca/structural_navigation.py	(working copy)
@@ -930,6 +930,16 @@
         """
 
         currentObj = currentObj or self.getCurrentObject()
+        document = self._getDocument()
+
+        # If the current object is the document itself, find an actual
+        # object to use as the starting point. Otherwise we're in
+        # danger of skipping over the objects in between our present
+        # location and top of the document.
+        #
+        if self._script.isSameObject(currentObj, document):
+            currentObj = self._findNextObject(currentObj, document)
+
         ancestors = []
         obj = currentObj.parent
         if obj.getRole() in [pyatspi.ROLE_LIST, pyatspi.ROLE_TABLE]:
@@ -939,7 +949,6 @@
                 ancestors.append(obj)
                 obj = obj.parent
 
-        document = self._getDocument()
         match, wrapped = None, False
         results = collection.getMatchesTo(currentObj,
                                           matchRule,
@@ -1062,6 +1071,16 @@
         """
 
         currentObj = currentObj or self.getCurrentObject()
+        document = self._getDocument()
+
+        # If the current object is the document itself, find an actual
+        # object to use as the starting point. Otherwise we're in
+        # danger of skipping over the objects in between our present
+        # location and top of the document.
+        #
+        if self._script.isSameObject(currentObj, document):
+            currentObj = self._findNextObject(currentObj, document)
+
         ancestors = []
         nestableRoles = [pyatspi.ROLE_LIST, pyatspi.ROLE_TABLE]
         obj = currentObj.parent
@@ -1069,7 +1088,6 @@
             ancestors.append(obj)
             obj = obj.parent
 
-        document = self._getDocument()
         obj = self._findPreviousObject(currentObj, document)
         wrapped = obj is None
         match = None
