Bug 1431194 - [WIP] add unit test for flushPrefEnv timeout
MozReview-Commit-ID: 7T5huqEIGIY
--- 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>