Bug 739531 - Can't duplicate a tab with designMode and no body; r=ttaubert

This commit is contained in:
Paul O’Shannessy 2012-05-25 10:43:19 +02:00
parent 144c63410e
commit 8baec9cd74
4 changed files with 77 additions and 3 deletions

View File

@ -2228,9 +2228,9 @@ SessionStoreService.prototype = {
delete aData.formdata;
}
}
// designMode is undefined e.g. for XUL documents (as about:config)
if ((aContent.document.designMode || "") == "on") {
if ((aContent.document.designMode || "") == "on" && aContent.document.body) {
if (aData.innerHTML === undefined && !aFullData) {
// we get no "input" events from iframes - listen for keypress here
let _this = this;
@ -3412,7 +3412,8 @@ SessionStoreService.prototype = {
if (aData.innerHTML) {
aWindow.setTimeout(function() {
if (aContent.document.designMode == "on" &&
hasExpectedURL(aContent.document, aData.url)) {
hasExpectedURL(aContent.document, aData.url) &&
aContent.document.body) {
aContent.document.body.innerHTML = aData.innerHTML;
}
}, 0);

View File

@ -132,6 +132,8 @@ _BROWSER_TEST_FILES = \
browser_701377.js \
browser_705597.js \
browser_707862.js \
browser_739531.js \
browser_739531_sample.html \
browser_739805.js \
$(NULL)

View File

@ -0,0 +1,47 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// This test ensures that attempts made to save/restore ("duplicate") pages
// using designmode AND make changes to document structure (remove body)
// don't result in uncaught errors and a broken browser state.
function test() {
waitForExplicitFinish();
let testURL = "http://mochi.test:8888/browser/" +
"browser/components/sessionstore/test/browser_739531_sample.html";
let loadCount = 0;
let tab = gBrowser.addTab(testURL);
tab.linkedBrowser.addEventListener("load", function onLoad(aEvent) {
// make sure both the page and the frame are loaded
if (++loadCount < 2)
return;
tab.linkedBrowser.removeEventListener("load", onLoad, true);
// executeSoon to allow the JS to execute on the page
executeSoon(function() {
let tab2;
let caughtError = false;
try {
tab2 = ss.duplicateTab(window, tab);
}
catch (e) {
caughtError = true;
info(e);
}
is(gBrowser.tabs.length, 3, "there should be 3 tabs")
ok(!caughtError, "duplicateTab didn't throw");
// if the test fails, we don't want to try to close a tab that doesn't exist
if (tab2)
gBrowser.removeTab(tab2);
gBrowser.removeTab(tab);
finish();
});
}, true);
}

View File

@ -0,0 +1,24 @@
<!-- originally a crash test for bug 713417
https://bug713417.bugzilla.mozilla.org/attachment.cgi?id=584240 -->
<!DOCTYPE html>
<html>
<head>
<script>
function boom()
{
var w = document.getElementById("f").contentWindow;
var d = w.document;
d.designMode = 'on';
var r = d.documentElement;
d.removeChild(r);
document.adoptNode(r);
}
</script>
</head>
<body onload="boom();">
<iframe src="data:text/html,1" id="f"></iframe>
</body>
</html>