Bug 430723. Don't prematurely detach and reattach the editor object. patch by Chris Pearce, r+sr=jst,a=schrep
authorroc+@cs.cmu.edu
Thu, 01 May 2008 02:00:11 -0700
changeset 14835 b1537476f95bc7e345222a5e50ba4e13501d070e
parent 14834 3bc0d551c0b36943d53f4bd69c7ff739fd048975
child 14836 f516b076843b6593e254d66af1de177d6f17cb88
push idunknown
push userunknown
push dateunknown
reviewersschrep
bugs430723
milestone1.9pre
Bug 430723. Don't prematurely detach and reattach the editor object. patch by Chris Pearce, r+sr=jst,a=schrep
docshell/test/navigation/Makefile.in
docshell/test/navigation/test_bug430723.html
editor/composer/src/nsEditingSession.cpp
--- a/docshell/test/navigation/Makefile.in
+++ b/docshell/test/navigation/Makefile.in
@@ -45,16 +45,17 @@ include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES = \
 		test_bug13871.html \
 		test_bug270414.html \
 		test_bug278916.html \
 		test_bug279495.html \
 		test_bug386782.html \
+		test_bug430723.html \
 		test_child.html \
 		test_grandchild.html \
 		test_sibling-off-domain.html \
 		test_sibling-matching-parent.html \
 		test_opener.html \
 		test_not-opener.html \
 		test_popup-navigates-children.html \
 		test_reserved.html \
new file mode 100644
--- /dev/null
+++ b/docshell/test/navigation/test_bug430723.html
@@ -0,0 +1,114 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=430723
+-->
+<head>
+  <title>Test for Bug 430723</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.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=430723">Mozilla Bug 430723</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+//<![CDATA[
+
+/** Test for Bug 430723 **/
+
+var gTallRedBoxURI = "data:text/html;charset=utf-8;base64,PGh0bWw%2BPGhlYWQ%2BPHNjcmlwdD53aW5kb3cuYWRkRXZlbnRMaXN0ZW5lcigncGFnZXNob3cnLCBmdW5jdGlvbigpe29wZW5lci5uZXh0VGVzdCgpO30sIGZhbHNlKTs8L3NjcmlwdD48L2hlYWQ%2BPGJvZHk%2BPGRpdiBzdHlsZT0icG9zaXRpb246YWJzb2x1dGU7IGxlZnQ6MHB4OyB0b3A6MHB4OyB3aWR0aDo1MCU7IGhlaWdodDoxNTAlOyBiYWNrZ3JvdW5kLWNvbG9yOnJlZCI%2BPHA%2BVGhpcyBpcyBhIHZlcnkgdGFsbCByZWQgYm94LjwvcD48L2Rpdj48L2JvZHk%2BPC9odG1sPg%3D%3D";
+// <html><head>
+// < script > window.addEventListener("pageshow", function(){opener.nextTest();}, false); < /script > 
+// </head><body>
+// <div style="position:absolute; left:0px; top:0px; width:50%; height:150%; background-color:red">
+// <p>This is a very tall red box.</p>
+// </div></body></html>
+
+var gTallBlueBoxURI = "data:text/html;charset=utf-8;base64,PGh0bWw%2BPGhlYWQ%2BPHNjcmlwdD53aW5kb3cuYWRkRXZlbnRMaXN0ZW5lcigncGFnZXNob3cnLCBmdW5jdGlvbigpe29wZW5lci5uZXh0VGVzdCgpO30sIGZhbHNlKTs8L3NjcmlwdD48L2hlYWQ%2BPGJvZHk%2BPGRpdiBzdHlsZT0icG9zaXRpb246YWJzb2x1dGU7IGxlZnQ6MHB4OyB0b3A6MHB4OyB3aWR0aDo1MCU7IGhlaWdodDoxNTAlOyBiYWNrZ3JvdW5kLWNvbG9yOmJsdWUiPjxwPlRoaXMgaXMgYSB2ZXJ5IHRhbGwgYmx1ZSBib3guPC9wPjwvZGl2PjwvYm9keT48L2h0bWw%2B";
+// <html><head>
+// < script > window.addEventListener("pageshow", function(){opener.nextTest();}, false); < /script > 
+// </head><body>
+// <div style="position:absolute; left:0px; top:0px; width:50%; height:150%; background-color:blue">
+// <p>This is a very tall blue box.</p>
+// </div></body></html>
+
+
+window.onload = runTest;
+
+var testWindow;
+var testNum = 0;
+
+function runTest() {
+  testWindow = window.open(gTallRedBoxURI, "testWindow", "width=300,height=300,location=yes,scrollbars=yes");
+}
+
+var nextTest =function() {
+  testNum++;
+  switch (testNum) {
+    case 1: setTimeout(step1, 0); break;
+    case 2: setTimeout(step2, 0); break;
+    case 3: setTimeout(step3, 0); break;
+  };
+}
+
+var step1 =function() {
+  window.is(testWindow.location, gTallRedBoxURI, "Ensure red page loaded.");
+  
+  // Navigate down and up.
+  is(testWindow.document.body.scrollTop, 0,
+     "Page1: Ensure we scrollpane is at the top before we start scrolling.");
+  sendKey('DOWN', testWindow);
+  sendKey('UP', testWindow);
+  is(testWindow.document.body.scrollTop, 0,
+     "Page1: Ensure we can scroll down and up, back to the top.");  
+  
+  // Nav to blue box page. This should fire step2.
+  testWindow.location = gTallBlueBoxURI;
+}
+
+
+var step2 =function() {    
+  window.is(testWindow.location, gTallBlueBoxURI, "Ensure blue page loaded.");
+
+  // Scroll around a bit.
+  is(testWindow.document.body.scrollTop, 0,
+     "Page2: Ensure we scrollpane is at the top before we start scrolling.");
+  sendKey('DOWN', testWindow);
+  sendKey('DOWN', testWindow);
+  sendKey('DOWN', testWindow);
+  isnot(testWindow.document.body.scrollTop, 0,
+        "Page2: Ensure we could scrol.");  
+  
+  // Navigate backwards. This should fire step3.
+  testWindow.history.back();
+}
+
+var step3 =function() {
+  window.is(testWindow.location, gTallRedBoxURI,
+            "Ensure red page restored from history.");
+
+  // Check we can still scroll with the keys.
+  is(testWindow.document.body.scrollTop, 0,
+     "Page1Again: Ensure scroll pane at top before we scroll.");  
+  sendKey('DOWN', testWindow);
+  isnot(testWindow.document.body.scrollTop, 0,
+        "Page2Again: Ensure we can still scroll.");  
+  
+  testWindow.close();
+  window.SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+
+//]]>
+</script>
+</pre>
+</body>
+</html>
+
--- a/editor/composer/src/nsEditingSession.cpp
+++ b/editor/composer/src/nsEditingSession.cpp
@@ -1389,16 +1389,19 @@ nsEditingSession::RestoreAnimationMode(n
     if (utils)
       utils->SetImageAnimationMode(mImageAnimationMode);
   }
 }
 
 nsresult
 nsEditingSession::DetachFromWindow(nsIDOMWindow* aWindow)
 {
+  if (!mDoneSetup)
+    return NS_OK;
+
   NS_ASSERTION(mEditorFlags != 0, "mEditorFlags should not be 0");
   NS_ASSERTION(mStateMaintainer, "mStateMaintainer should exist.");
 
   // Kill any existing reload timer
   if (mLoadBlankDocTimer)
   {
     mLoadBlankDocTimer->Cancel();
     mLoadBlankDocTimer = nsnull;
@@ -1416,16 +1419,19 @@ nsEditingSession::DetachFromWindow(nsIDO
   mWindowToBeEdited = nsnull;
 
   return NS_OK;
 }
 
 nsresult
 nsEditingSession::ReattachToWindow(nsIDOMWindow* aWindow)
 {
+  if (!mDoneSetup)
+    return NS_OK;
+
   NS_ASSERTION(mEditorFlags != 0, "mEditorFlags should still be valid...");
   NS_ASSERTION(mStateMaintainer, "mStateMaintainer should exist.");
 
   // Imitate nsEditorDocShell::MakeEditable() to reattach the
   // old editor ot the window.
   nsresult rv;
 
   mWindowToBeEdited = do_GetWeakReference(aWindow);