diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 1431530bcaac..ee03c52e83b5 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -203,6 +203,13 @@ pref("app.update.langpack.enabled", true); // The amount of time, in seconds, before background tasks time out and exit. // Tasks can override this default (10 minutes). pref("toolkit.backgroundtasks.defaultTimeoutSec", 600); + + #if defined(ENABLE_TESTS) + // Test prefs to verify background tasks inheret and override browser prefs + // correctly. + pref("toolkit.backgroundtasks.tests.browserPrefsInherited", 15); + pref("toolkit.backgroundtasks.tests.browserPrefsOverriden", 16); + #endif #endif // Symmetric (can be overridden by individual extensions) update preferences. diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 65a992c24e07..af6780e2e689 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -4187,3 +4187,10 @@ pref("extensions.webcompat.useScriptingAPI", true); pref("privacy.fingerprintingProtection.WebCompatService.logLevel", "Error"); // To test strip on share site specific parameters by enabling a different list to be used pref("privacy.query_stripping.strip_on_share.enableTestMode", false); + +#if defined(MOZ_BACKGROUNDTASKS) && defined(ENABLE_TESTS) + // Test prefs to verify background tasks inheret and override gecko prefs + // correctly. + pref("toolkit.backgroundtasks.tests.geckoPrefsInherited", 17); + pref("toolkit.backgroundtasks.tests.geckoPrefsOverriden", 18); +#endif diff --git a/toolkit/components/backgroundtasks/defaults/backgroundtasks.js b/toolkit/components/backgroundtasks/defaults/backgroundtasks.js index 43a937def42e..f1f9b334e565 100644 --- a/toolkit/components/backgroundtasks/defaults/backgroundtasks.js +++ b/toolkit/components/backgroundtasks/defaults/backgroundtasks.js @@ -54,3 +54,8 @@ pref("app.update.background.automaticRestartEnabled", true); #else pref("app.update.background.automaticRestartEnabled", false); #endif + +#if defined(ENABLE_TESTS) + // Test prefs to verify background tasks override gecko prefs correctly. + pref("toolkit.backgroundtasks.tests.geckoPrefsOverriden", 28); +#endif diff --git a/toolkit/components/backgroundtasks/defaults/backgroundtasks_browser.js b/toolkit/components/backgroundtasks/defaults/backgroundtasks_browser.js index 8ce1e5bc5e2d..f80295f59458 100644 --- a/toolkit/components/backgroundtasks/defaults/backgroundtasks_browser.js +++ b/toolkit/components/backgroundtasks/defaults/backgroundtasks_browser.js @@ -45,3 +45,8 @@ pref("app.normandy.run_interval_seconds", 0); // Use a separate Nimbus application ID from regular Firefox Desktop. // This prevents enrolling in regular desktop experiments. pref("nimbus.appId", "firefox-desktop-background-task"); + +#if defined(ENABLE_TESTS) + // Test prefs to verify background tasks override browser prefs correctly. + pref("toolkit.backgroundtasks.tests.browserPrefsOverriden", 26); +#endif diff --git a/toolkit/components/backgroundtasks/tests/browser/browser.toml b/toolkit/components/backgroundtasks/tests/browser/browser.toml index 80bc7282946d..53706e03efa1 100644 --- a/toolkit/components/backgroundtasks/tests/browser/browser.toml +++ b/toolkit/components/backgroundtasks/tests/browser/browser.toml @@ -3,6 +3,7 @@ skip-if = ["os == 'android'"] head = "head.js" ["browser_backgroundtask_specific_pref.js"] +run-if = ["appname == 'firefox'"] # Prefs are Firefox specific, e.g. not Thunderbird ["browser_xpcom_graph_wait.js"] skip-if = ["tsan"] # TSan times out on pretty much all profiler-consuming tests. diff --git a/toolkit/components/backgroundtasks/tests/browser/browser_backgroundtask_specific_pref.js b/toolkit/components/backgroundtasks/tests/browser/browser_backgroundtask_specific_pref.js index b80ee2f59376..872224837337 100644 --- a/toolkit/components/backgroundtasks/tests/browser/browser_backgroundtask_specific_pref.js +++ b/toolkit/components/backgroundtasks/tests/browser/browser_backgroundtask_specific_pref.js @@ -21,3 +21,71 @@ add_task(async function test_backgroundtask_specific_pref() { }); Assert.equal(79, exitCode); }); + +add_task(async function test_backgroundtask_browser_pref_inherited() { + // First, verify this pref is set in Firefox. + Assert.equal( + 15, + Services.prefs.getIntPref( + "toolkit.backgroundtasks.tests.browserPrefsInherited", + -1 + ) + ); + + // Second, verify that this pref is set in background tasks. + let exitCode = await do_backgroundtask("backgroundtask_specific_pref", { + extraArgs: ["toolkit.backgroundtasks.tests.browserPrefsInherited"], + }); + Assert.equal(15, exitCode); +}); + +add_task(async function test_backgroundtask_gecko_pref_overridden() { + // First, verify this pref is set in Firefox. + Assert.equal( + 16, + Services.prefs.getIntPref( + "toolkit.backgroundtasks.tests.browserPrefsOverriden", + -1 + ) + ); + + // Second, verify that this pref is overridden in background tasks. + let exitCode = await do_backgroundtask("backgroundtask_specific_pref", { + extraArgs: ["toolkit.backgroundtasks.tests.browserPrefsOverriden"], + }); + Assert.equal(26, exitCode); +}); + +add_task(async function test_backgroundtask_gecko_pref_inherited() { + // First, verify this pref is set in Gecko. + Assert.equal( + 17, + Services.prefs.getIntPref( + "toolkit.backgroundtasks.tests.geckoPrefsInherited", + -1 + ) + ); + + // Second, verify that this pref is set in background tasks. + let exitCode = await do_backgroundtask("backgroundtask_specific_pref", { + extraArgs: ["toolkit.backgroundtasks.tests.geckoPrefsInherited"], + }); + Assert.equal(17, exitCode); +}); + +add_task(async function test_backgroundtask_gecko_pref_overridden() { + // First, verify this pref is set in Gecko. + Assert.equal( + 18, + Services.prefs.getIntPref( + "toolkit.backgroundtasks.tests.geckoPrefsOverriden", + -1 + ) + ); + + // Second, verify that this pref is overridden in background tasks. + let exitCode = await do_backgroundtask("backgroundtask_specific_pref", { + extraArgs: ["toolkit.backgroundtasks.tests.geckoPrefsOverriden"], + }); + Assert.equal(28, exitCode); +});