Bug 840877 - Handle null undoManager in absence of documentElement. r=ehsan
authorWilliam Chen <wchen@mozilla.com>
Tue, 11 Jun 2013 18:26:11 -0700
changeset 134722 022cb8f500a8fa81d972682d6e1715e7037c5c03
parent 134721 e83053c14672e08ebb0cbff9e0633828e1f8904b
child 134723 4c18bf4337fab3a54d60b368f40f46e5c7ec7c23
push id24812
push useremorley@mozilla.com
push dateWed, 12 Jun 2013 12:48:33 +0000
treeherdermozilla-central@f8a5db121ab8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs840877
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 840877 - Handle null undoManager in absence of documentElement. r=ehsan
content/html/content/src/UndoManager.cpp
content/html/content/test/Makefile.in
content/html/content/test/test_bug840877.html
--- a/content/html/content/src/UndoManager.cpp
+++ b/content/html/content/src/UndoManager.cpp
@@ -612,16 +612,19 @@ UndoMutationObserver::IsManagerForMutati
   }
 
   if (!undoManager) {
     // Check against document UndoManager if we were unable to find an
     // UndoManager in an ancestor element.
     nsIDocument* doc = aContent->OwnerDoc();
     NS_ENSURE_TRUE(doc, false);
     undoManager = doc->GetUndoManager();
+    // The document will not have an undoManager if the
+    // documentElement is removed.
+    NS_ENSURE_TRUE(undoManager, false);
   }
 
   // Check if the nsITransactionManager is the same for both the
   // mutation observer and the nsIContent.
   return undoManager->GetTransactionManager() == mTxnManager;
 }
 
 UndoMutationObserver::UndoMutationObserver(nsITransactionManager* aTxnManager)
--- a/content/html/content/test/Makefile.in
+++ b/content/html/content/test/Makefile.in
@@ -268,16 +268,17 @@ MOCHITEST_FILES = \
 		test_bug780993.html \
 		test_bug797113.html \
 		test_bug787134.html \
 		test_bug803677.html \
 		test_bug827126.html \
 		test_bug827426.html \
 		test_bug838582.html \
 		test_bug839913.html \
+		test_bug840877.html \
 		test_bug841466.html \
 		test_iframe_sandbox_inheritance.html \
 		file_iframe_sandbox_a_if1.html \
 		file_iframe_sandbox_a_if2.html \
 		file_iframe_sandbox_a_if3.html \
 		file_iframe_sandbox_a_if4.html \
 		file_iframe_sandbox_a_if5.html \
 		file_iframe_sandbox_a_if6.html \
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/test_bug840877.html
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=840877
+-->
+<head>
+  <title>Test for Bug 840877</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.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=840877">Mozilla Bug 840877</a>
+<p id="display"></p>
+<div id="content"></div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 840877 **/
+
+var root = document.documentElement;
+var undoMan = document.undoManager;
+var newChild = document.createElement("div");
+// Removing the documentElement from the document removes the element from the document's undo scope.
+document.removeChild(root);
+undoMan.transact({ executeAutomatic: function() { root.appendChild(newChild); }}, true);
+// Append the document element back so that we don't break mochitests.
+document.appendChild(root);
+// Element appended by executeAutomatic should be a child of the documentElement.
+is(root.childNodes[root.childNodes.length - 1], newChild, "Document element should have child appened by transaction.");
+
+</script>
+</pre>
+</body>
+</html>
+