Test for bug 783184. r=jdm
authorChris Jones <jones.chris.g@gmail.com>
Fri, 17 Aug 2012 14:12:57 -0700
changeset 105091 739eef9dbbdded722f8e97ad6ac41283e457350d
parent 105090 5253021171872eada9416ea7294a53588cec7408
child 105092 d7c041240db3ebd46ff2e9cdcda998c8cf27c4d9
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersjdm
bugs783184
milestone17.0a1
Test for bug 783184. r=jdm
modules/libpref/test/unit_ipc/test_user_default_prefs.js
modules/libpref/test/unit_ipc/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/modules/libpref/test/unit_ipc/test_user_default_prefs.js
@@ -0,0 +1,76 @@
+const Ci = Components.interfaces;
+const Cc = Components.classes;
+
+let pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
+
+// This pref is chosen somewhat arbitrarily --- we just need one
+// that's guaranteed to have a default value.
+const kPrefName = 'intl.accept_languages'; // of type char, which we
+                                           // assume below
+let initialValue = null;
+
+function check_child_pref_info_eq(continuation) {
+    sendCommand(
+        'var pb = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);\n'+
+        // Returns concatenation "[value],[isUser]"
+        'pb.getCharPref("'+ kPrefName +'")+ "," +'+
+        'pb.prefHasUserValue("'+ kPrefName +'");',
+        function (info) {
+            let [ value, isUser ] = info.split(',');
+            do_check_eq(pb.getCharPref(kPrefName), value);
+            do_check_eq(pb.prefHasUserValue(kPrefName), isUser == "true");
+            continuation();
+        });
+}
+
+function run_test() {
+    // We finish in clean_up()
+    do_test_pending();
+
+    try {
+        if (pb.getCharPref('dom.ipc.processPrelauch.enabled')) {
+            dump('WARNING: Content process may already have launched, so this test may not be meaningful.');
+        }
+    } catch(e) { }
+
+    initialValue = pb.getCharPref(kPrefName);
+
+    test_user_setting();
+}
+
+function test_user_setting() {
+    // We rely on setting this before the content process starts up.
+    // When it starts up, it should recognize this as a user pref, not
+    // a default pref.
+    pb.setCharPref(kPrefName, 'i-imaginarylanguage');
+    // NB: processing of the value-change notification in the child
+    // process triggered by the above set happens-before the remaining
+    // code here
+    check_child_pref_info_eq(function () {
+            do_check_eq(pb.prefHasUserValue(kPrefName), true);
+
+            test_cleared_is_default();
+        });
+}
+
+function test_cleared_is_default() {
+    pb.clearUserPref(kPrefName);
+    // NB: processing of the value-change notification in the child
+    // process triggered by the above set happens-before the remaining
+    // code here
+    check_child_pref_info_eq(function () {
+            do_check_eq(pb.prefHasUserValue(kPrefName), false);
+
+            clean_up();
+        });
+}
+
+function clean_up() {
+    pb.setCharPref(kPrefName, initialValue);
+    // NB: processing of the value-change notification in the child
+    // process triggered by the above set happens-before the remaining
+    // code here
+    check_child_pref_info_eq(function () {
+            do_test_finished();
+        });
+}
\ No newline at end of file
--- a/modules/libpref/test/unit_ipc/xpcshell.ini
+++ b/modules/libpref/test/unit_ipc/xpcshell.ini
@@ -1,8 +1,9 @@
 [DEFAULT]
 head = 
 tail = 
 
 [test_existing_prefs.js]
 [test_initial_prefs.js]
 [test_observed_prefs.js]
 [test_update_prefs.js]
+[test_user_default_prefs.js]