From 4c60fb3eaece486dba8b7377f4fe5298ffa7f12f Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Thu, 26 Jun 2014 15:55:16 +0200 Subject: [PATCH] Bug 1030719 - Properly restore form data for contenteditables r=smacleod --- .../sessionstore/test/browser_formdata.js | 20 +++++++++++++++---- toolkit/modules/sessionstore/FormData.jsm | 19 ++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/browser/components/sessionstore/test/browser_formdata.js b/browser/components/sessionstore/test/browser_formdata.js index 279cc45b4d23..44e14a34f1ea 100644 --- a/browser/components/sessionstore/test/browser_formdata.js +++ b/browser/components/sessionstore/test/browser_formdata.js @@ -204,9 +204,22 @@ add_task(function test_design_mode() { // Modify the document content. yield sendMessage(browser, "ss-test:sendKeyEvent", {key: "m"}); - // Duplicate the modified tab. - let tab2 = gBrowser.duplicateTab(tab); - yield promiseTabRestored(tab2); + // Close and restore the tab. + gBrowser.removeTab(tab); + tab = ss.undoCloseTab(window, 0); + browser = tab.linkedBrowser; + yield promiseTabRestored(tab); + + // Check that the innerHTML value was restored. + let html = yield getInnerHTML(browser); + let expected = "

Mmozilla

"; + is(html, expected, "editable document has been restored correctly"); + + // Close and restore the tab. + gBrowser.removeTab(tab); + tab = ss.undoCloseTab(window, 0); + browser = tab.linkedBrowser; + yield promiseTabRestored(tab); // Check that the innerHTML value was restored. let html = yield getInnerHTML(browser); @@ -214,7 +227,6 @@ add_task(function test_design_mode() { is(html, expected, "editable document has been restored correctly"); // Cleanup. - gBrowser.removeTab(tab2); gBrowser.removeTab(tab); }); diff --git a/toolkit/modules/sessionstore/FormData.jsm b/toolkit/modules/sessionstore/FormData.jsm index 20e27c812aae..e9389a82332a 100644 --- a/toolkit/modules/sessionstore/FormData.jsm +++ b/toolkit/modules/sessionstore/FormData.jsm @@ -226,6 +226,7 @@ let FormDataInternal = { setTimeout(() => { if (doc.body && doc.designMode == "on" && doc.documentURI == savedURL) { doc.body.innerHTML = data.innerHTML; + this.fireEvent(doc.body, "input"); } }); } @@ -311,13 +312,23 @@ let FormDataInternal = { // Fire events for this node if applicable if (eventType) { - let doc = aNode.ownerDocument; - let event = doc.createEvent("UIEvents"); - event.initUIEvent(eventType, true, true, doc.defaultView, 0); - aNode.dispatchEvent(event); + this.fireEvent(aNode, eventType); } }, + /** + * Dispatches an event of type |type| to the given |node|. + * + * @param node (DOMNode) + * @param type (string) + */ + fireEvent: function (node, type) { + let doc = node.ownerDocument; + let event = doc.createEvent("UIEvents"); + event.initUIEvent(type, true, true, doc.defaultView, 0); + node.dispatchEvent(event); + }, + /** * Restores form data for the current frame hierarchy starting at |root| * using the given form |data|.