Index: test/keystrokes/firefox/bug_568768.py
===================================================================
--- test/keystrokes/firefox/bug_568768.py	(revision 0)
+++ test/keystrokes/firefox/bug_568768.py	(revision 0)
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/python
+
+"""Test of the fix for bug 568768"""
+
+from macaroon.playback import *
+import utils
+
+sequence = MacroSequence()
+
+########################################################################
+# We wait for the focus to be on a blank Firefox window.
+#
+sequence.append(WaitForWindowActivate(utils.firefoxFrameNames, None))
+
+########################################################################
+# Load the local "simple form" test case.
+#
+sequence.append(KeyComboAction("<Control>l"))
+sequence.append(WaitForFocus(acc_role=pyatspi.ROLE_ENTRY))
+
+sequence.append(TypeAction(utils.htmlURLPrefix + "orca-wiki.html#head-a269540f0f3a25d25e08216f0438ee743a3ebe88"))
+sequence.append(KeyComboAction("Return"))
+
+sequence.append(WaitForDocLoad())
+
+########################################################################
+# Down Arrow to the next line, which should be the line after the
+# About heading.
+#
+sequence.append(utils.StartRecordingAction())
+sequence.append(KeyComboAction("Down"))
+sequence.append(utils.AssertPresentationAction(
+    "Line Down",
+    ["BRAILLE LINE:  'Orca is a free, open source, flexible, extensible, and powerful assistive'",
+     "     VISIBLE:  'Orca is a free, open source, fle', cursor=1",
+     "SPEECH OUTPUT: 'Orca is a free, open source, flexible, extensible, and powerful assistive'"]))
+
+########################################################################
+# 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.
+#
+sequence.append(KeyComboAction("<Control>l"))
+sequence.append(WaitForFocus(acc_role=pyatspi.ROLE_ENTRY))
+
+sequence.append(TypeAction("about:blank"))
+sequence.append(KeyComboAction("Return"))
+
+sequence.append(WaitForDocLoad())
+
+# Just a little extra wait to let some events get through.
+#
+sequence.append(PauseAction(3000))
+
+sequence.append(utils.AssertionSummaryAction())
+
+sequence.start()
Index: test/keystrokes/firefox/bug_552887a.py
===================================================================
--- test/keystrokes/firefox/bug_552887a.py	(revision 4488)
+++ test/keystrokes/firefox/bug_552887a.py	(working copy)
@@ -31,9 +31,12 @@
 sequence.append(KeyComboAction("<Control>Home"))
 sequence.append(utils.AssertPresentationAction(
     "Top of file",
-    ["BRAILLE LINE:  ''",
+    ["BUG? - In this test, the text is extremely small and probably appears to be on the same line, so we're speaking more than we should be",
+     "BRAILLE LINE:  ''",
      "     VISIBLE:  '', cursor=1",
-     "SPEECH OUTPUT: 'blank'"]))
+     "SPEECH OUTPUT: '",
+     " Line 1",
+     "'"]))
 
 ########################################################################
 # Down Arrow to the bottom.
Index: src/orca/scripts/toolkits/Gecko/script.py
===================================================================
--- src/orca/scripts/toolkits/Gecko/script.py	(revision 4488)
+++ src/orca/scripts/toolkits/Gecko/script.py	(working copy)
@@ -4964,6 +4964,36 @@
 
         return attrs
 
+    def searchForCaretLocation(self, acc):
+        """Attempts to locate the caret on the page independent of our
+        caret context. This functionality is needed when a page loads
+        and the URL is for a fragment (anchor, id, named object) within
+        that page.
+
+        Arguments:
+        - acc: The top-level accessible in which we suspect to find the
+          caret (most likely the document frame).
+
+        Returns the [obj, caretOffset] containing the caret if it can
+        be determined. Otherwise [None, -1] is returned.
+        """
+
+        context = [None, -1]
+        while acc:
+            try:
+                offset = acc.queryText().caretOffset
+            except:
+                acc = None
+            else:
+                context = [acc, offset]
+                childIndex = self.getChildIndex(acc, offset)
+                if childIndex >= 0:
+                    acc = acc[childIndex]
+                else:
+                    break
+
+        return context
+
     def getCaretContext(self, includeNonText=True):
         """Returns the current [obj, caretOffset] if defined.  If not,
         it returns the first [obj, caretOffset] found by an in order
@@ -4981,9 +5011,14 @@
         try:
             return self._documentFrameCaretContext[hash(documentFrame)]
         except:
+            # If we don't have a context, we should attempt to see if we
+            # can find the caret first. Failing that, we'll start at the
+            # top.
+            #
+            [obj, caretOffset] = self.searchForCaretLocation(documentFrame)
             self._documentFrameCaretContext[hash(documentFrame)] = \
-                self.findNextCaretInOrder(None,
-                                          -1,
+                self.findNextCaretInOrder(obj,
+                                          max(-1, caretOffset - 1),
                                           includeNonText)
 
         [obj, caretOffset] = \
