Bug 507186, check source of command events so that checkboxes with an attached command will update preferences properly, r=neil
authorNeil Deakin <neil@mozilla.com>
Tue, 06 Sep 2011 10:44:55 -0400
changeset 77912 db2ec1f8df574db9f67b3c7cddbe609545cf7ad2
parent 77911 016189c2245a2f62fb7ea4915c866d0a2a820c41
child 77913 2dc945c5c66e3a39e4596e7cbbe10fe26593f777
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs507186
milestone9.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 507186, check source of command events so that checkboxes with an attached command will update preferences properly, r=neil
toolkit/content/tests/chrome/Makefile.in
toolkit/content/tests/chrome/test_preferences.xul
toolkit/content/tests/chrome/window_preferences_commandretarget.xul
toolkit/content/widgets/preferences.xml
--- a/toolkit/content/tests/chrome/Makefile.in
+++ b/toolkit/content/tests/chrome/Makefile.in
@@ -79,16 +79,17 @@ include $(topsrcdir)/config/rules.mk
 		window_largemenu.xul \
 		test_popup_anchor.xul \
 		window_popup_anchor.xul \
 		frame_popup_anchor.xul \
 		test_preferences.xul \
 		window_preferences.xul \
 		window_preferences2.xul \
 		window_preferences3.xul \
+		window_preferences_commandretarget.xul \
 		test_autocomplete2.xul \
 		test_autocomplete3.xul \
 		test_autocomplete4.xul \
 		test_keys.xul \
 		window_keys.xul \
 		test_showcaret.xul \
 		window_showcaret.xul \
 		test_righttoleft.xul \
--- a/toolkit/content/tests/chrome/test_preferences.xul
+++ b/toolkit/content/tests/chrome/test_preferences.xul
@@ -416,16 +416,24 @@
       ok(GetXULElement(aPrefWindow, "tests.static_preference_file"   ).hasUserValue === false, "non-instant reset hasUserValue file"   );
     }
 
     function RunNonInstantPrefTestClose(aPrefWindow)
     {
       WritePrefsToPreferences(aPrefWindow, kPrefValueSet2);
     }
 
+    function RunCheckCommandRedirect(aPrefWindow)
+    {
+      GetXULElement(aPrefWindow, "checkbox").click();
+      ok(GetXULElement(aPrefWindow, "tests.static_preference_bool").value, "redirected command bool");
+      GetXULElement(aPrefWindow, "checkbox").click();
+      ok(!GetXULElement(aPrefWindow, "tests.static_preference_bool").value, "redirected command bool");
+    }
+
     function RunResetPrefTest(aPrefWindow)
     {
       // try resetting the prefs to default values
       GetXULElement(aPrefWindow, "tests.static_preference_int"    ).reset();
       GetXULElement(aPrefWindow, "tests.static_preference_bool"   ).reset();
       GetXULElement(aPrefWindow, "tests.static_preference_string" ).reset();
       GetXULElement(aPrefWindow, "tests.static_preference_wstring").reset();
       GetXULElement(aPrefWindow, "tests.static_preference_unichar").reset();
@@ -497,20 +505,26 @@
       ok(found.int          === expected.int,          "non-instant reset deferred int"    );
       ok(found.bool         === expected.bool,         "non-instant reset deferred bool"   );
       ok(found.string       === expected.string,       "non-instant reset deferred string" );
       ok(found.wstring_data === expected.wstring_data, "non-instant reset deferred wstring");
       ok(found.unichar_data === expected.unichar_data, "non-instant reset deferred unichar");
       ok(found.file_data    === expected.file_data,    "non-instant reset deferred file"   );
     }
 
+    function RunTestCommandRedirect()
+    {
+      openDialog("window_preferences_commandretarget.xul", "", "modal", RunCheckCommandRedirect, true);
+    }
+
     function RunTest()
     {
       RunTestInstant();
       RunTestNonInstant();
+      RunTestCommandRedirect();
       SimpleTest.finish();
     }
   ]]>
   </script>
 
   <body xmlns="http://www.w3.org/1999/xhtml">
     <p id="display"></p>
     <div id="content" style="display: none"></div>
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/chrome/window_preferences_commandretarget.xul
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<!--
+  XUL Widget Test for preferences window. This particular test ensures that
+  a checkbox with a command attribute properly updates even though the command
+  event gets retargeted.
+-->
+<prefwindow xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+            title="preferences window"
+            windowtype="test:preferences"
+            buttons="accept,cancel"
+            onload="RunTest(window.arguments)">
+  <script type="application/javascript">
+  <![CDATA[
+    function RunTest(aArgs)
+    {
+      aArgs[0](this);
+      document.documentElement.cancelDialog();
+    }
+  ]]>
+  </script>
+
+  <prefpane id="sample_pane" label="Sample Prefpane">
+    <preferences id="sample_preferences">
+      <preference id="tests.static_preference_bool"
+                  name="tests.static_preference_bool"
+                  type="bool"/>
+    </preferences>
+
+    <commandset>
+      <command id="cmd_test" preference="tests.static_preference_bool"/>
+    </commandset>
+
+    <checkbox id="checkbox" label="Enable Option" preference="tests.static_preference_bool" command="cmd_test"/>
+  </prefpane>
+</prefwindow>
--- a/toolkit/content/widgets/preferences.xml
+++ b/toolkit/content/widgets/preferences.xml
@@ -1248,17 +1248,19 @@
       </property>
       <field name="_content">
         document.getAnonymousElementByAttribute(this, "class", "content-box");
       </field>
     </implementation>
     <handlers>
       <handler event="command">
         // This "command" event handler tracks changes made to preferences by 
-        // the user in this window. 
+        // the user in this window.
+        if (event.sourceEvent)
+          event = event.sourceEvent;
         this.userChangedValue(event.target);
       </handler>
       <handler event="select">
         // This "select" event handler tracks changes made to colorpicker 
         // preferences by the user in this window.
         if (event.target.localName == "colorpicker") 
           this.userChangedValue(event.target);
       </handler>