Bug 476161 - Session restore incorrectly restores state of some Google Reader elements. r=dietrich
authorSimon Bünzli <zeniko@gmail.com>
Sat, 07 Feb 2009 12:56:34 +0100
changeset 24732 b395701ced5015012f16fe3115c96640383cde40
parent 24731 ca6426f959b380c30e1bc16ca14646daa5b8f38f
child 24733 6e53a81c8e003eab0d63bd52a9c71de4c7e1e067
push idunknown
push userunknown
push dateunknown
reviewersdietrich
bugs476161
milestone1.9.2a1pre
Bug 476161 - Session restore incorrectly restores state of some Google Reader elements. r=dietrich
browser/components/sessionstore/src/nsSessionStore.js
browser/components/sessionstore/test/browser/Makefile.in
browser/components/sessionstore/test/browser/browser_476161.js
browser/components/sessionstore/test/browser/browser_476161_sample.html
--- a/browser/components/sessionstore/src/nsSessionStore.js
+++ b/browser/components/sessionstore/src/nsSessionStore.js
@@ -2012,16 +2012,19 @@ SessionStoreService.prototype = {
         
         let node = key.charAt(0) == "#" ? aDocument.getElementById(key.slice(1)) :
                                           XPathHelper.resolve(aDocument, key);
         if (!node)
           continue;
         
         let value = aData[key];
         if (typeof value == "string" && node.type != "file") {
+          if (node.value == value)
+            continue; // don't dispatch an input event for no change
+          
           node.value = value;
           
           let event = aDocument.createEvent("UIEvents");
           event.initUIEvent("input", true, true, aDocument.defaultView, 0);
           node.dispatchEvent(event);
         }
         else if (typeof value == "boolean")
           node.checked = value;
--- a/browser/components/sessionstore/test/browser/Makefile.in
+++ b/browser/components/sessionstore/test/browser/Makefile.in
@@ -65,12 +65,14 @@ include $(topsrcdir)/config/rules.mk
 	browser_456342_sample.xhtml \
 	browser_463206.js \
 	browser_463206_sample.html \
 	browser_464199.js \
 	browser_465215.js \
 	browser_465223.js \
 	browser_466937.js \
 	browser_466937_sample.html \
+	browser_476161.js \
+	browser_476161_sample.html \
 	$(NULL)
 
 libs:: $(_BROWSER_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser/browser_476161.js
@@ -0,0 +1,66 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is sessionstore test code.
+ *
+ * The Initial Developer of the Original Code is
+ * Simon B├╝nzli <zeniko@gmail.com>.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+function test() {
+  /** Test for Bug 476161 **/
+  
+  waitForExplicitFinish();
+  
+  let testURL = "http://localhost:8888/browser/" +
+    "browser/components/sessionstore/test/browser/browser_476161_sample.html";
+  let tab = gBrowser.addTab(testURL);
+  tab.linkedBrowser.addEventListener("load", function(aEvent) {
+    let doc = tab.linkedBrowser.contentDocument;
+    
+    doc.getElementById("modify1").value += Math.random();
+    doc.getElementById("modify2").value += " " + Date.now();
+    
+    let tab2 = gBrowser.duplicateTab(tab);
+    tab2.linkedBrowser.addEventListener("load", function(aEvent) {
+      let doc = tab2.linkedBrowser.contentDocument;
+      let changed = doc.getElementById("changed").textContent.trim().split();
+      
+      is(changed.sort().join(" "), "modify1 modify2",
+         "input events were only dispatched for modified text fields");
+      
+      // clean up
+      gBrowser.removeTab(tab2);
+      gBrowser.removeTab(tab);
+      
+      finish();
+    }, true);
+  }, true);
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser/browser_476161_sample.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<title>Test for bug 476161</title>
+
+<script>
+
+document.addEventListener("input", function(aEvent) {
+  var inputEl = aEvent.originalTarget;
+  var changedEl = document.getElementById("changed");
+  
+  changedEl.textContent += " " + inputEl.id;
+}, false);
+
+</script>
+
+<h3>Text fields with changed text</h3>
+<input type="text" id="modify1">
+<input type="text" id="modify2" value="preset value">
+
+<h3>Text fields with unchanged text</h3>
+<input type="text" id="unchanged1">
+<input type="text" id="unchanged2" value="preset value">
+
+<h3>Changed field IDs</h3>
+<div id="changed"></div>