Bug 653741 - You should be able to scoll back to the current anchor by focusing the location bar and pressing <enter>. r=bz
authorJustin Lebar <justin.lebar@gmail.com>
Mon, 09 May 2011 17:59:16 -0400
changeset 70349 575362d9b92e8c065014efc51bf76d692288f817
parent 70348 8e06280639df490436e65c24025a5efc1bae773f
child 70350 9eae975b3d6fb7748fe5a3c0113d449b1c7cc0b2
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs653741
milestone6.0a1
Bug 653741 - You should be able to scoll back to the current anchor by focusing the location bar and pressing <enter>. r=bz
docshell/base/nsDocShell.cpp
docshell/test/Makefile.in
docshell/test/file_bug653741.html
docshell/test/test_bug653741.html
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -8295,18 +8295,20 @@ nsDocShell::InternalLoad(nsIURI * aURI,
             // Save the current URI; we need it if we fire a hashchange later.
             nsCOMPtr<nsIURI> oldURI = mCurrentURI;
 
             // Save the position of the scrollers.
             nscoord cx = 0, cy = 0;
             GetCurScrollPos(ScrollOrientation_X, &cx);
             GetCurScrollPos(ScrollOrientation_Y, &cy);
 
-            // We scroll the window precisely when we fire a hashchange event.
-            if (doHashchange) {
+            // We scroll whenever we're not doing a history load.  Note that
+            // sometimes we might scroll even if we don't fire a hashchange
+            // event!  See bug 653741.
+            if (!aSHEntry) {
                 // Take the '#' off the hashes before passing them to
                 // ScrollToAnchor.
                 nsDependentCSubstring curHashName(curHash, 1);
                 nsDependentCSubstring newHashName(newHash, 1);
                 rv = ScrollToAnchor(curHashName, newHashName, aLoadType);
                 NS_ENSURE_SUCCESS(rv, rv);
             }
 
--- a/docshell/test/Makefile.in
+++ b/docshell/test/Makefile.in
@@ -96,16 +96,18 @@ include $(topsrcdir)/config/rules.mk
 		file_bug590573_2.html \
 		test_bug598895.html \
 		test_bug634834.html \
 		file_bug634834.html \
 		test_bug637644.html \
 		test_bug640387_1.html \
 		test_bug640387_2.html \
 		file_bug640387.html \
+		test_bug653741.html \
+		file_bug653741.html \
 		test_framedhistoryframes.html \
 		test_windowedhistoryframes.html \
 		historyframes.html \
 		$(NULL)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 _TEST_FILES += \
 		test_bug511449.html \
new file mode 100644
--- /dev/null
+++ b/docshell/test/file_bug653741.html
@@ -0,0 +1,13 @@
+<html>
+<body onload='(parent || opener).childLoad()'>
+
+<div style='height:500px; background:yellow'>
+<a id='#top'>Top of the page</a>
+</div>
+
+<div id='bottom'>
+<a id='#bottom'>Bottom of the page</a>
+</div>
+
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/docshell/test/test_bug653741.html
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=653741
+-->
+<head>
+  <title>Test for Bug 653741</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=653741">Mozilla Bug 653741</a>
+
+<script type="application/javascript;version=1.7">
+
+/** Test for Bug 653741 **/
+SimpleTest.waitForExplicitFinish();
+
+function childLoad() {
+  // Spin the event loop so we leave the onload handler.
+  SimpleTest.executeSoon(childLoad2);
+}
+
+function childLoad2() {
+  let cw = $('iframe').contentWindow;
+  
+  // Save the Y offset.  For sanity's sake, make sure it's not 0, because we
+  // should be at the bottom of the page!
+  let origYOffset = cw.pageYOffset;
+  ok(origYOffset != 0, 'Original Y offset is not 0.');
+
+  // Scroll the iframe to the top, then navigate to #bottom again.
+  cw.scrollTo(0, 0);
+
+  // Our current location is #bottom, so this should scroll us down to the
+  // bottom again.
+  cw.location = cw.location + '';
+
+  is(cw.pageYOffset, origYOffset, 'Correct offset after reloading page.');
+  SimpleTest.finish();
+}
+
+</script>
+
+<iframe height='100px' id='iframe' src='file_bug653741.html#bottom'></iframe>
+
+</body>
+</html>