Bug 1431194 - [WIP] add unit test for flushPrefEnv timeout draft
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 17 Jan 2018 21:52:31 +0100
changeset 721996 431cf53311072731cd48c56493f7d9fa4632a985
parent 721995 1a4a9228df1c0da5e64d76d1a0b34355e923e14d
child 746502 d58bc341960e2f8ff16de265c2a84694ff6ecf2b
push id96023
push userjdescottes@mozilla.com
push dateThu, 18 Jan 2018 09:34:46 +0000
bugs1431194
milestone59.0a1
Bug 1431194 - [WIP] add unit test for flushPrefEnv timeout MozReview-Commit-ID: 7T5huqEIGIY
testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPrefEnv.html
--- a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPrefEnv.html
+++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPrefEnv.html
@@ -16,16 +16,17 @@ function starttest() {
     SpecialPowers.setBoolPref("test.bool", true);
   }
   try {
     SpecialPowers.setIntPref("test.int", true);
   } catch(e) {
     SpecialPowers.setIntPref("test.int", 1);
   }
   SpecialPowers.setCharPref("test.char", 'test');
+  SpecialPowers.setBoolPref("test.cleanup", false);
 
   setTimeout(test1, 0, 0);
 }
 
 SimpleTest.waitForExplicitFinish();
 
 function test1(aCount) {
   if (aCount >= 20) {
@@ -195,17 +196,34 @@ function test11(aCount) {
     SimpleTest.finish();
     return;
   }
 
   try {
     SpecialPowers.getCharPref('test.char');
     setTimeout(test11, 0, ++aCount);
   } catch(e) {
-    SimpleTest.finish();
+    test12(0);
   }
 }
+
+function test12() {
+  // Set test.cleanup to true via pushPrefEnv, while its default value is false.
+  SpecialPowers.pushPrefEnv({"set": [["test.cleanup", true]]}, () => {
+    // Update the preference manually back to its original value.
+    SpecialPowers.setBoolPref("test.cleanup", false);
+    ok(SpecialPowers.getBoolPref("test.cleanup") === false, 'Pref has the default value');
+
+    // Try to flush preferences. Since test.cleanup has manually been set to false, there
+    // will not be any visible update. Check that the flush does not timeout.
+    SpecialPowers.flushPrefEnv(() => {
+      ok(true, 'flushPrefEnv did not time out');
+      SimpleTest.finish();
+    });
+  });
+}
+
 // todo - test non-changing values, test complex values, test mixing of pushprefEnv 'set' and 'clear'
 // When bug 776424 gets fixed, getPref doesn't throw anymore, so this test would have to be changed accordingly
 </script>
 </pre>
 </body>
 </html>