diff --git a/.eslintignore b/.eslintignore index c1f0da558791..fca8c2651f54 100644 --- a/.eslintignore +++ b/.eslintignore @@ -220,6 +220,3 @@ tools/tryselect/selectors/chooser/templates/chooser.html # Ignore preprocessed *(P)refs.js files in update-packaging. tools/update-packaging/**/*refs.js - -# Ignore backgroundtasks preferences files. -toolkit/components/backgroundtasks/defaults diff --git a/.prettierignore b/.prettierignore index c4b4c32638c9..24fd18b7f33f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -58,6 +58,3 @@ devtools/client/debugger/src/test/mochitest/examples/ember/quickstart # These are source mapped and the locations are asserted in the test case. devtools/client/webconsole/test/browser/test-mangled-function.* - -# Ignore backgroundtasks preferences files. -toolkit/components/backgroundtasks/defaults diff --git a/browser/installer/Makefile.in b/browser/installer/Makefile.in index ad725c5114b0..b861ad214a64 100644 --- a/browser/installer/Makefile.in +++ b/browser/installer/Makefile.in @@ -98,10 +98,6 @@ ifdef MOZ_DEFAULT_BROWSER_AGENT DEFINES += -DMOZ_DEFAULT_BROWSER_AGENT=1 endif -ifdef MOZ_BACKGROUNDTASKS -DEFINES += -DMOZ_BACKGROUNDTASKS=1 -endif - ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT)) MOZ_PKG_MAC_DSSTORE=$(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/dsstore MOZ_PKG_MAC_BACKGROUND=$(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/background.png diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index ec20499166e8..f060c457cee2 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -305,12 +305,6 @@ ; gre location for now. @RESPATH@/defaults/pref/channel-prefs.js -; Background tasks-specific preferences. These are in the GRE -; location since they apply to all tasks at this time. -#ifdef MOZ_BACKGROUNDTASKS -@RESPATH@/defaults/backgroundtasks/backgroundtasks.js -#endif - ; [Layout Engine Resources] ; Style Sheets, Graphics and other Resources used by the layout engine. @RESPATH@/res/EditorOverride.css diff --git a/extensions/pref/autoconfig/src/components.conf b/extensions/pref/autoconfig/src/components.conf index 41de3526948d..789a44b2e39b 100644 --- a/extensions/pref/autoconfig/src/components.conf +++ b/extensions/pref/autoconfig/src/components.conf @@ -11,11 +11,6 @@ Classes = [ 'type': 'nsReadConfig', 'headers': ['/extensions/pref/autoconfig/src/nsReadConfig.h'], 'init_method': 'Init', - 'categories': { - 'pref-config-startup': { - 'name': 'ReadConfig Module', - 'backgroundtasks': BackgroundTasksSelector.ALL_TASKS, - }, - }, + 'categories': {'pref-config-startup': 'ReadConfig Module'}, }, ] diff --git a/layout/build/components.conf b/layout/build/components.conf index 0b93693449b4..a89a73930172 100644 --- a/layout/build/components.conf +++ b/layout/build/components.conf @@ -96,12 +96,7 @@ Classes = [ 'cid': '{fc886801-e768-11d4-9885-00c04fa0cf4b}', 'contract_ids': ['@mozilla.org/content/document-loader-factory;1'], 'type': 'nsIDocumentLoaderFactory', - 'categories': { - 'Gecko-Content-Viewers': { - 'name': content_types, - 'backgroundtasks': BackgroundTasksSelector.ALL_TASKS, - } - }, + 'categories': {'Gecko-Content-Viewers': content_types}, }, { 'cid': '{0ddf4df8-4dbb-4133-8b79-9afb966514f5}', @@ -294,14 +289,8 @@ Classes = [ 'type': 'nsMixedContentBlocker', 'headers': ['mozilla/dom/nsMixedContentBlocker.h'], 'categories': { - 'content-policy': { - 'name': '@mozilla.org/mixedcontentblocker;1', - 'backgroundtasks': BackgroundTasksSelector.ALL_TASKS, - }, - 'net-channel-event-sinks': { - 'name': '@mozilla.org/mixedcontentblocker;1', - 'backgroundtasks': BackgroundTasksSelector.ALL_TASKS, - }, + 'content-policy': '@mozilla.org/mixedcontentblocker;1', + 'net-channel-event-sinks': '@mozilla.org/mixedcontentblocker;1', }, }, { diff --git a/modules/libpref/Preferences.cpp b/modules/libpref/Preferences.cpp index 2a7f5bacbd83..cfc498d5c250 100644 --- a/modules/libpref/Preferences.cpp +++ b/modules/libpref/Preferences.cpp @@ -86,9 +86,6 @@ #include "plstr.h" #include "prlink.h" #include "xpcpublic.h" -#ifdef MOZ_BACKGROUNDTASKS -# include "mozilla/BackgroundTasks.h" -#endif #ifdef DEBUG # include @@ -4533,13 +4530,6 @@ nsresult Preferences::InitInitialObjects(bool aIsStartup) { rv = pref_ReadDefaultPrefs(jarReader, "defaults/pref/*.js$"); NS_ENSURE_SUCCESS(rv, rv); -#ifdef MOZ_BACKGROUNDTASKS - if (BackgroundTasks::IsBackgroundTaskMode()) { - rv = pref_ReadDefaultPrefs(jarReader, "defaults/backgroundtasks/*.js$"); - NS_ENSURE_SUCCESS(rv, rv); - } -#endif - #ifdef MOZ_WIDGET_ANDROID // Load jar:$gre/omni.jar!/defaults/pref/$MOZ_ANDROID_CPU_ABI/*.js. nsAutoCString path; @@ -4619,25 +4609,6 @@ nsresult Preferences::InitInitialObjects(bool aIsStartup) { NS_WARNING("Error parsing preferences."); } } - -#ifdef MOZ_BACKGROUNDTASKS - if (BackgroundTasks::IsBackgroundTaskMode()) { - rv = appJarReader->FindInit("defaults/backgroundtasks/*.js$", - getter_Transfers(find)); - NS_ENSURE_SUCCESS(rv, rv); - prefEntries.Clear(); - while (NS_SUCCEEDED(find->FindNext(&entryName, &entryNameLen))) { - prefEntries.AppendElement(Substring(entryName, entryNameLen)); - } - prefEntries.Sort(); - for (uint32_t i = prefEntries.Length(); i--;) { - rv = pref_ReadPrefFromJar(appJarReader, prefEntries[i].get()); - if (NS_FAILED(rv)) { - NS_WARNING("Error parsing preferences."); - } - } - } -#endif } nsCOMPtr dirSvc( diff --git a/modules/libpref/moz.build b/modules/libpref/moz.build index d0ccfcff6609..9273ab29dc99 100644 --- a/modules/libpref/moz.build +++ b/modules/libpref/moz.build @@ -167,6 +167,3 @@ else: FINAL_TARGET_PP_FILES += [ "greprefs.js", ] - -if CONFIG["MOZ_BACKGROUNDTASKS"]: - DEFINES["MOZ_BACKGROUNDTASKS"] = True diff --git a/startupcache/StartupCache.cpp b/startupcache/StartupCache.cpp index 81a922a815d3..29832ae42f4b 100644 --- a/startupcache/StartupCache.cpp +++ b/startupcache/StartupCache.cpp @@ -35,9 +35,6 @@ #include "GeckoProfiler.h" #include "nsAppRunner.h" #include "xpcpublic.h" -#ifdef MOZ_BACKGROUNDTASKS -# include "mozilla/BackgroundTasks.h" -#endif #if defined(XP_WIN) # include @@ -118,12 +115,6 @@ StartupCache* StartupCache::GetSingletonNoInit() { } StartupCache* StartupCache::GetSingleton() { -#ifdef MOZ_BACKGROUNDTASKS - if (BackgroundTasks::IsBackgroundTaskMode()) { - return nullptr; - } -#endif - if (!gStartupCache) { if (!XRE_IsParentProcess()) { return nullptr; diff --git a/startupcache/moz.build b/startupcache/moz.build index 37b8d4785f88..a05aebd47299 100644 --- a/startupcache/moz.build +++ b/startupcache/moz.build @@ -31,7 +31,4 @@ XPIDL_SOURCES += [ "nsIStartupCacheInfo.idl", ] -if CONFIG["MOZ_BACKGROUNDTASKS"]: - DEFINES["MOZ_BACKGROUNDTASKS"] = True - FINAL_LIBRARY = "xul" diff --git a/toolkit/components/backgroundtasks/BackgroundTask_exception.jsm b/toolkit/components/backgroundtasks/BackgroundTask_exception.jsm deleted file mode 100644 index 0e7de4b9210e..000000000000 --- a/toolkit/components/backgroundtasks/BackgroundTask_exception.jsm +++ /dev/null @@ -1,12 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -var EXPORTED_SYMBOLS = ["runBackgroundTask"]; - -async function runBackgroundTask() { - console.error("runBackgroundTask: exception"); - - throw new Error("test"); -} diff --git a/toolkit/components/backgroundtasks/BackgroundTask_failure.jsm b/toolkit/components/backgroundtasks/BackgroundTask_failure.jsm deleted file mode 100644 index 553d8cedb2a0..000000000000 --- a/toolkit/components/backgroundtasks/BackgroundTask_failure.jsm +++ /dev/null @@ -1,12 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -var EXPORTED_SYMBOLS = ["runBackgroundTask"]; - -async function runBackgroundTask() { - console.error("runBackgroundTask: failure"); - - return 1; -} diff --git a/toolkit/components/backgroundtasks/BackgroundTask_success.jsm b/toolkit/components/backgroundtasks/BackgroundTask_success.jsm deleted file mode 100644 index e64612c2bb99..000000000000 --- a/toolkit/components/backgroundtasks/BackgroundTask_success.jsm +++ /dev/null @@ -1,12 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -var EXPORTED_SYMBOLS = ["runBackgroundTask"]; - -async function runBackgroundTask() { - console.error("runBackgroundTask: success"); - - return 0; -} diff --git a/toolkit/components/backgroundtasks/BackgroundTasks.h b/toolkit/components/backgroundtasks/BackgroundTasks.h index 3a2d13cc6231..f3cdc50962e7 100644 --- a/toolkit/components/backgroundtasks/BackgroundTasks.h +++ b/toolkit/components/backgroundtasks/BackgroundTasks.h @@ -8,11 +8,9 @@ #include "nsCOMPtr.h" #include "nsIBackgroundTasks.h" -#include "nsIBackgroundTasksManager.h" #include "nsICommandLine.h" #include "nsIFile.h" #include "nsISupports.h" -#include "nsImportModule.h" #include "nsString.h" #include "nsXULAppAPI.h" @@ -113,14 +111,7 @@ class BackgroundTasks final : public nsIBackgroundTasks { return NS_ERROR_NOT_AVAILABLE; } - nsCOMPtr manager = - do_ImportModule("resource://gre/modules/BackgroundTasksManager.jsm", - "BackgroundTasksManager"); - - NS_ENSURE_TRUE(manager, NS_ERROR_FAILURE); - - NS_ConvertASCIItoUTF16 name(task.ref().get()); - Unused << manager->RunBackgroundTaskNamed(name, aCmdLine); + // For now, do nothing. return NS_OK; } diff --git a/toolkit/components/backgroundtasks/BackgroundTasksManager.jsm b/toolkit/components/backgroundtasks/BackgroundTasksManager.jsm deleted file mode 100644 index fa5d644a1ae7..000000000000 --- a/toolkit/components/backgroundtasks/BackgroundTasksManager.jsm +++ /dev/null @@ -1,134 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -var EXPORTED_SYMBOLS = ["BackgroundTasksManager"]; - -const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); -const { XPCOMUtils } = ChromeUtils.import( - "resource://gre/modules/XPCOMUtils.jsm" -); - -XPCOMUtils.defineLazyGetter(this, "log", () => { - let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {}) - .ConsoleAPI; - let consoleOptions = { - // tip: set maxLogLevel to "debug" and use log.debug() to create detailed - // messages during development. See LOG_LEVELS in Console.jsm for details. - maxLogLevel: "error", - maxLogLevelPref: "toolkit.backgroundtasks.loglevel", - prefix: "BackgroundTasksManager", - }; - return new ConsoleAPI(consoleOptions); -}); - -// Map resource://testing-common/ to the shared test modules directory. This is -// a transliteration of `register_modules_protocol_handler` from -// https://searchfox.org/mozilla-central/rev/f081504642a115cb8236bea4d8250e5cb0f39b02/testing/xpcshell/head.js#358-389. -function registerModulesProtocolHandler() { - let env = Cc["@mozilla.org/process/environment;1"].getService( - Ci.nsIEnvironment - ); - let _TESTING_MODULES_URI = env.get("XPCSHELL_TESTING_MODULES_URI", ""); - if (!_TESTING_MODULES_URI) { - return false; - } - - let protocolHandler = Services.io - .getProtocolHandler("resource") - .QueryInterface(Ci.nsIResProtocolHandler); - - protocolHandler.setSubstitution( - "testing-common", - Services.io.newURI(_TESTING_MODULES_URI) - ); - // Log loudly so that when testing, we always actually use the - // console logging mechanism and therefore deterministically load that code. - log.error( - `Substitution set: resource://testing-common aliases ${_TESTING_MODULES_URI}` - ); - - return true; -} - -/** - * Find a JSM named like `backgroundtasks/BackgroundTask_${name}.jsm` - * and return its `runBackgroundTask` function. - * - * When testing, allow to load from `XPCSHELL_TESTING_MODULES_URI`, - * which is registered at `resource://testing-common`, the standard - * location for test-only modules. - * - * @return {function} `runBackgroundTask` function. - * @throws NS_ERROR_NOT_AVAILABLE if a background task with the given `name` is - * not found. - */ -function findRunBackgroundTask(name) { - const subModules = [ - "resource:///modules", // App-specific first. - "resource://gre/modules", // Toolkit/general second. - ]; - - if (registerModulesProtocolHandler()) { - subModules.push("resource://testing-common"); // Test-only third. - } - - for (const subModule of subModules) { - let URI = `${subModule}/backgroundtasks/BackgroundTask_${name}.jsm`; - log.debug(`Looking for background task at URI: ${URI}`); - - try { - const { runBackgroundTask } = ChromeUtils.import(URI); - log.info(`Found background task at URI: ${URI}`); - return runBackgroundTask; - } catch (ex) { - if (ex.result != Cr.NS_ERROR_FILE_NOT_FOUND) { - throw ex; - } - } - } - - log.warn(`No backgroundtask named '${name}' registered`); - throw new Components.Exception( - `No backgroundtask named '${name}' registered`, - Cr.NS_ERROR_NOT_AVAILABLE - ); -} - -var BackgroundTasksManager = { - async runBackgroundTaskNamed(name, commandLine) { - function addMarker(markerName) { - return ChromeUtils.addProfilerMarker(markerName, undefined, name); - } - addMarker("BackgroundTasksManager:AfterRunBackgroundTaskNamed"); - - log.info( - `Running background task named '${name}' (with ${commandLine.length} arguments)` - ); - - let exitCode = 2; - try { - let runBackgroundTask = findRunBackgroundTask(name); - addMarker("BackgroundTasksManager:AfterFindRunBackgroundTask"); - - try { - // TODO: timeout tasks that run too long. - exitCode = await runBackgroundTask(commandLine); - log.info( - `Backgroundtask named '${name}' completed with exit code ${exitCode}` - ); - } catch (e) { - log.error(`Backgroundtask named '${name}' threw exception`, e); - exitCode = 3; - } - } finally { - addMarker("BackgroundTasksManager:AfterAwaitRunBackgroundTask"); - - log.info(`Invoking Services.startup.quit(..., ${exitCode})`); - Services.startup.quit(Ci.nsIAppStartup.eForceQuit, exitCode); - } - - return exitCode; - }, -}; diff --git a/toolkit/components/backgroundtasks/defaults/backgroundtasks.js b/toolkit/components/backgroundtasks/defaults/backgroundtasks.js deleted file mode 100644 index a52c1b117873..000000000000 --- a/toolkit/components/backgroundtasks/defaults/backgroundtasks.js +++ /dev/null @@ -1,27 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -pref("browser.dom.window.dump.enabled", true); -pref("devtools.console.stdout.chrome", true); - -pref("network.process.enabled", false); - -pref("toolkit.telemetry.archive.enabled", false); -pref("toolkit.telemetry.firstShutdownPing.enabled", false); -pref("toolkit.telemetry.healthping.enabled", false); -pref("toolkit.telemetry.newProfilePing.enabled", false); -pref("toolkit.telemetry.eventping.enabled", false); -pref("toolkit.telemetry.ecosystemtelemetry.enabled", false); -pref("toolkit.telemetry.prioping.enabled", false); -pref("datareporting.policy.dataSubmissionEnabled", false); -pref("datareporting.healthreport.uploadEnabled", false); - -pref("browser.cache.offline.enable", false); -pref("browser.cache.offline.storage.enable", false); -pref("browser.cache.disk.enable", false); -pref("permissions.memory_only", true); - -// For testing only: used to test that backgroundtask-specific prefs are -// processed. This just needs to be an unusual integer in the range 0..127. -pref("test.backgroundtask_specific_pref.exitCode", 79); diff --git a/toolkit/components/backgroundtasks/moz.build b/toolkit/components/backgroundtasks/moz.build index 1e2b13731ad7..184b1b4a018a 100644 --- a/toolkit/components/backgroundtasks/moz.build +++ b/toolkit/components/backgroundtasks/moz.build @@ -22,31 +22,8 @@ XPCOM_MANIFESTS += [ XPIDL_SOURCES += [ "nsIBackgroundTasks.idl", - "nsIBackgroundTasksManager.idl", ] XPIDL_MODULE = "toolkit_backgroundtasks" -EXTRA_JS_MODULES += [ - "BackgroundTasksManager.jsm", -] - -EXTRA_JS_MODULES.backgroundtasks += [ - "BackgroundTask_exception.jsm", - "BackgroundTask_failure.jsm", - "BackgroundTask_success.jsm", -] - -BROWSER_CHROME_MANIFESTS += ["tests/browser/browser.ini"] XPCSHELL_TESTS_MANIFESTS += ["tests/xpcshell/xpcshell.ini"] - -TESTING_JS_MODULES.backgroundtasks += [ - "tests/BackgroundTask_backgroundtask_specific_pref.jsm", - "tests/BackgroundTask_crash.jsm", - "tests/BackgroundTask_policies.jsm", - "tests/BackgroundTask_wait.jsm", -] - -FINAL_TARGET_FILES.defaults.backgroundtasks += [ - "defaults/backgroundtasks.js", -] diff --git a/toolkit/components/backgroundtasks/nsIBackgroundTasksManager.idl b/toolkit/components/backgroundtasks/nsIBackgroundTasksManager.idl deleted file mode 100644 index 0bf6ded3698f..000000000000 --- a/toolkit/components/backgroundtasks/nsIBackgroundTasksManager.idl +++ /dev/null @@ -1,28 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsISupports.idl" - -interface nsICommandLine; - -/** - * Import and run named backgroundtask implementations. - */ -[scriptable, function, uuid(4d48c536-e16f-4699-8f9c-add4f28f92f0)] -interface nsIBackgroundTasksManager : nsISupports -{ - /** - * Run the named background task. - * - * @param aTaskName the name of the task to be run. - * @param aCommandLine the command line of this invocation. - * - * This returns a promise which resolves to an integer exit code, 0 when the - * task succeeded, >0 otherwise. The task manager will quit after this - * promise resolves. - */ - void runBackgroundTaskNamed(in AString aTaskName, - in nsICommandLine aCommandLine); -}; diff --git a/toolkit/components/backgroundtasks/tests/BackgroundTask_backgroundtask_specific_pref.jsm b/toolkit/components/backgroundtasks/tests/BackgroundTask_backgroundtask_specific_pref.jsm deleted file mode 100644 index 0fa900f04f5e..000000000000 --- a/toolkit/components/backgroundtasks/tests/BackgroundTask_backgroundtask_specific_pref.jsm +++ /dev/null @@ -1,23 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -var EXPORTED_SYMBOLS = ["runBackgroundTask"]; - -const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); - -async function runBackgroundTask(commandLine) { - let pref = commandLine.length - ? commandLine.getArgument(0) - : "test.backgroundtask_specific_pref.exitCode"; - - // 0, 1, 2, 3 are all meaningful exit codes already. - let exitCode = Services.prefs.getIntPref(pref, 4); - - console.error( - `runBackgroundTask: backgroundtask_specific_pref read pref '${pref}', exiting with exitCode ${exitCode}` - ); - - return exitCode; -} diff --git a/toolkit/components/backgroundtasks/tests/BackgroundTask_crash.jsm b/toolkit/components/backgroundtasks/tests/BackgroundTask_crash.jsm deleted file mode 100644 index b3d7c25705c0..000000000000 --- a/toolkit/components/backgroundtasks/tests/BackgroundTask_crash.jsm +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -var EXPORTED_SYMBOLS = ["runBackgroundTask"]; - -const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); - -async function runBackgroundTask(commandLine) { - // This task depends on `CrashTestUtils.jsm` and requires the - // sibling `testcrasher` library to be in the current working - // directory. Fail right away if we can't find the module or the - // native library. - let testPath = Services.dirsvc.get("CurWorkD", Ci.nsIFile).path; - const { CrashTestUtils } = ChromeUtils.import( - `file://${testPath}/CrashTestUtils.jsm` - ); - - // Get the temp dir. - var env = Cc["@mozilla.org/process/environment;1"].getService( - Ci.nsIEnvironment - ); - var tmpd = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - tmpd.initWithPath(env.get("XPCSHELL_TEST_TEMP_DIR")); - - var crashReporter = Cc["@mozilla.org/toolkit/crash-reporter;1"].getService( - Ci.nsICrashReporter - ); - - // We need to call this or crash events go in an undefined location. - crashReporter.UpdateCrashEventsDir(); - - // Setting the minidump path is not allowed in content processes, - // but background tasks run in the parent. - crashReporter.minidumpPath = tmpd; - - // Arguments are [crashType, key1, value1, key2, value2, ...]. - let i = 0; - let crashType = Number.parseInt(commandLine.getArgument(i)); - i += 1; - while (i + 1 < commandLine.length) { - let key = commandLine.getArgument(i); - let value = commandLine.getArgument(i + 1); - i += 2; - crashReporter.annotateCrashReport(key, value); - } - - console.log(`Crashing with crash type ${crashType}`); - - // Now actually crash. - CrashTestUtils.crash(crashType); - - // This is moot, since we crashed, but... - return 1; -} diff --git a/toolkit/components/backgroundtasks/tests/BackgroundTask_policies.jsm b/toolkit/components/backgroundtasks/tests/BackgroundTask_policies.jsm deleted file mode 100644 index 50261549766d..000000000000 --- a/toolkit/components/backgroundtasks/tests/BackgroundTask_policies.jsm +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -var EXPORTED_SYMBOLS = ["runBackgroundTask"]; - -const { Checker } = ChromeUtils.import( - "resource://gre/modules/UpdateService.jsm" -); -const { EnterprisePolicyTesting } = ChromeUtils.import( - "resource://testing-common/EnterprisePolicyTesting.jsm" -); - -async function runBackgroundTask(commandLine) { - let filePath = commandLine.getArgument(0); - await EnterprisePolicyTesting.setupPolicyEngineWithJson(filePath); - - let checker = new Checker(); - let actual = await checker.getUpdateURL(); - let expected = commandLine.getArgument(1); - - // 0, 1, 2, 3 are all meaningful exit codes already. - let exitCode = expected == actual ? 0 : 4; - console.error( - `runBackgroundTask: policies read AppUpdateURL '${actual}', - expected '${expected}', exiting with exitCode ${exitCode}` - ); - - return exitCode; -} diff --git a/toolkit/components/backgroundtasks/tests/BackgroundTask_wait.jsm b/toolkit/components/backgroundtasks/tests/BackgroundTask_wait.jsm deleted file mode 100644 index b629cbe1ad60..000000000000 --- a/toolkit/components/backgroundtasks/tests/BackgroundTask_wait.jsm +++ /dev/null @@ -1,19 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -var EXPORTED_SYMBOLS = ["runBackgroundTask"]; - -const { setTimeout } = ChromeUtils.import("resource://gre/modules/Timer.jsm"); - -function runBackgroundTask(commandLine) { - let delay = 10; - if (commandLine.length) { - delay = Number.parseInt(commandLine.getArgument(0)); - } - - console.error(`runBackgroundTask: wait ${delay} seconds`); - - return new Promise(resolve => setTimeout(resolve, delay * 1000)); -} diff --git a/toolkit/components/backgroundtasks/tests/browser/browser.ini b/toolkit/components/backgroundtasks/tests/browser/browser.ini deleted file mode 100644 index 1524d431b499..000000000000 --- a/toolkit/components/backgroundtasks/tests/browser/browser.ini +++ /dev/null @@ -1,11 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -[DEFAULT] -skip-if = toolkit == 'android' -head = head.js - -[browser_backgroundtask_specific_pref.js] -[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 deleted file mode 100644 index b80ee2f59376..000000000000 --- a/toolkit/components/backgroundtasks/tests/browser/browser_backgroundtask_specific_pref.js +++ /dev/null @@ -1,23 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * vim: sw=4 ts=4 sts=4 et - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -"use strict"; - -add_task(async function test_backgroundtask_specific_pref() { - // First, verify this pref isn't set in Gecko itself. - Assert.equal( - -1, - Services.prefs.getIntPref("test.backgroundtask_specific_pref.exitCode", -1) - ); - - // Second, verify that this pref is set in background tasks. - // mochitest-chrome tests locally test both unpackaged and packaged - // builds (with `--appname=dist`). - let exitCode = await do_backgroundtask("backgroundtask_specific_pref", { - extraArgs: ["test.backgroundtask_specific_pref.exitCode"], - }); - Assert.equal(79, exitCode); -}); diff --git a/toolkit/components/backgroundtasks/tests/browser/browser_xpcom_graph_wait.js b/toolkit/components/backgroundtasks/tests/browser/browser_xpcom_graph_wait.js deleted file mode 100644 index 16a09044130c..000000000000 --- a/toolkit/components/backgroundtasks/tests/browser/browser_xpcom_graph_wait.js +++ /dev/null @@ -1,450 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * vim: sw=4 ts=4 sts=4 et - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/* This test records code loaded during a dummy background task. - * - * To run this test similar to try server, you need to run: - * ./mach package - * ./mach test --appname=dist - * - * If you made changes that cause this test to fail, it's likely - * because you are changing the application startup process. In - * general, you should prefer to defer loading code as long as you - * can, especially if it's not going to be used in background tasks. - */ - -"use strict"; - -const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm"); - -const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); - -// Shortcuts for conditions. -const LINUX = AppConstants.platform == "linux"; -const WIN = AppConstants.platform == "win"; -const MAC = AppConstants.platform == "macosx"; - -const backgroundtaskPhases = { - AfterRunBackgroundTaskNamed: { - allowlist: { - components: [], // At this time, no phase loads a JS component. - modules: [ - "resource://gre/modules/AppConstants.jsm", - "resource://gre/modules/AsyncShutdown.jsm", - "resource://gre/modules/BackgroundTasksManager.jsm", - { - name: "resource://gre/modules/Console.jsm", - condition: WIN, - }, - "resource://gre/modules/EnterprisePolicies.jsm", - "resource://gre/modules/EnterprisePoliciesParent.jsm", - "resource://gre/modules/PromiseUtils.jsm", - "resource://gre/modules/Services.jsm", - "resource://gre/modules/XPCOMUtils.jsm", - "resource://gre/modules/nsAsyncShutdown.jsm", - ], - // Human-readable contract IDs are many-to-one mapped to CIDs, so this - // list is a little misleading. For example, all of - // "@mozilla.org/xre/app-info;1", "@mozilla.org/xre/runtime;1", and - // "@mozilla.org/toolkit/crash-reporter;1", map to the CID - // {95d89e3e-a169-41a3-8e56-719978e15b12}, but only one is listed here. - // We could be more precise by listing CIDs, but that's a good deal harder - // to read and modify. - services: [ - "@mozilla.org/async-shutdown-service;1", - "@mozilla.org/base/telemetry;1", - "@mozilla.org/categorymanager;1", - "@mozilla.org/chrome/chrome-registry;1", - "@mozilla.org/cookieService;1", - "@mozilla.org/docloaderservice;1", - "@mozilla.org/embedcomp/window-watcher;1", - "@mozilla.org/enterprisepolicies;1", - "@mozilla.org/file/directory_service;1", - "@mozilla.org/intl/stringbundle;1", - "@mozilla.org/layout/content-policy;1", - "@mozilla.org/memory-reporter-manager;1", - "@mozilla.org/network/captive-portal-service;1", - "@mozilla.org/network/effective-tld-service;1", - "@mozilla.org/network/idn-service;1", - "@mozilla.org/network/io-service;1", - "@mozilla.org/network/network-link-service;1", - "@mozilla.org/network/protocol;1?name=chrome", - "@mozilla.org/network/protocol;1?name=file", - "@mozilla.org/network/protocol;1?name=jar", - "@mozilla.org/network/protocol;1?name=resource", - "@mozilla.org/network/socket-transport-service;1", - "@mozilla.org/network/stream-transport-service;1", - "@mozilla.org/network/url-parser;1?auth=maybe", - "@mozilla.org/network/url-parser;1?auth=no", - "@mozilla.org/network/url-parser;1?auth=yes", - "@mozilla.org/observer-service;1", - "@mozilla.org/permissionmanager;1", - "@mozilla.org/power/powermanagerservice;1", - "@mozilla.org/preferences-service;1", - "@mozilla.org/process/environment;1", - "@mozilla.org/storage/service;1", - "@mozilla.org/thirdpartyutil;1", - "@mozilla.org/toolkit/app-startup;1", - "@mozilla.org/toolkit/profile-service;1", - "@mozilla.org/uuid-generator;1", - { - name: "@mozilla.org/widget/appshell/mac;1", - condition: MAC, - }, - { - name: "@mozilla.org/widget/appshell/gtk;1", - condition: LINUX, - }, - { - name: "@mozilla.org/widget/appshell/win;1", - condition: WIN, - }, - "@mozilla.org/xpcom/debug;1", - "@mozilla.org/xre/app-info;1", - ], - }, - }, - AfterFindRunBackgroundTask: { - allowlist: { - components: [], - modules: [ - // We have a profile marker for this, even though it failed to load! - "resource:///modules/backgroundtasks/BackgroundTask_wait.jsm", - { - name: "resource://gre/modules/Console.jsm", - condition: !WIN, - }, - "resource://gre/modules/ConsoleAPIStorage.jsm", - "resource://gre/modules/Timer.jsm", - // We have a profile marker for this, even though it failed to load! - "resource://gre/modules/backgroundtasks/BackgroundTask_wait.jsm", - "resource://testing-common/backgroundtasks/BackgroundTask_wait.jsm", - ], - services: ["@mozilla.org/consoleAPI-storage;1"], - }, - }, - AfterAwaitRunBackgroundTask: { - allowlist: { - components: [], - modules: [], - services: [ - "@mozilla.org/network/protocol/about;1?what=preferences", - "@mozilla.org/network/protocol;1?name=about", - "@mozilla.org/network/protocol;1?name=http", - "@mozilla.org/network/protocol;1?name=https", - ], - }, - }, -}; - -function getStackFromProfile(profile, stack, libs) { - const stackPrefixCol = profile.stackTable.schema.prefix; - const stackFrameCol = profile.stackTable.schema.frame; - const frameLocationCol = profile.frameTable.schema.location; - - let index = 1; - let result = []; - while (stack) { - let sp = profile.stackTable.data[stack]; - let frame = profile.frameTable.data[sp[stackFrameCol]]; - stack = sp[stackPrefixCol]; - frame = profile.stringTable[frame[frameLocationCol]]; - - if (frame.startsWith("0x")) { - try { - let addr = frame.slice("0x".length); - addr = Number.parseInt(addr, 16); - for (let lib of libs) { - if (lib.start <= addr && addr <= lib.end) { - // Only handle two digits for now. - let indexString = index.toString(10); - if (indexString.length == 1) { - indexString = "0" + indexString; - } - let offset = addr - lib.start; - frame = `#${indexString}: ???[${lib.debugPath} ${"+0x" + - offset.toString(16)}]`; - break; - } - } - } catch (e) { - // Fall through. - } - } - - if (frame != "js::RunScript" && !frame.startsWith("next (self-hosted:")) { - result.push(frame); - index += 1; - } - } - return result; -} - -add_task(async function test_xpcom_graph_wait() { - { - let omniJa = Services.dirsvc.get("XCurProcD", Ci.nsIFile); - omniJa.append("omni.ja"); - if (!omniJa.exists()) { - ok( - false, - "This test requires a packaged build, " + - "run 'mach package' and then use --appname=dist" - ); - return; - } - } - - let profilePath = Cc["@mozilla.org/process/environment;1"] - .getService(Ci.nsIEnvironment) - .get("MOZ_UPLOAD_DIR"); - profilePath = - profilePath || - FileUtils.getDir("ProfD", [`testBackgroundTask-${Math.random()}`], true) - .path; - - profilePath = OS.Path.join(profilePath, "profile_backgroundtask_wait.json"); - await IOUtils.remove(profilePath, { ignoreAbsent: true }); - - let extraEnv = { - MOZ_PROFILER_STARTUP: "1", - MOZ_PROFILER_SHUTDOWN: profilePath, - }; - - let exitCode = await do_backgroundtask("wait", { extraEnv }); - Assert.equal(0, exitCode); - - let fileContents = await IOUtils.readUTF8(profilePath); - let rootProfile = JSON.parse(fileContents); - let profile = rootProfile.threads[0]; - - const nameCol = profile.markers.schema.name; - const dataCol = profile.markers.schema.data; - - function newMarkers() { - return { - components: [], // The equivalent of `Cu.loadedComponents`. - modules: [], // The equivalent of `Cu.loadedModules`. - services: [], - }; - } - - let phases = {}; - let markersForCurrentPhase = newMarkers(); - - // If a subsequent phase loads an already loaded resource, that's - // fine. Track all loaded resources to ignore such repeated loads. - let markersForAllPhases = newMarkers(); - - for (let m of profile.markers.data) { - let markerName = profile.stringTable[m[nameCol]]; - if (markerName.startsWith("BackgroundTasksManager:")) { - phases[ - markerName.split("BackgroundTasksManager:")[1] - ] = markersForCurrentPhase; - markersForCurrentPhase = newMarkers(); - continue; - } - - if ( - ![ - "ChromeUtils.import", // JSMs. - "JS XPCOM", // JavaScript XPCOM components. - "GetService", // XPCOM services. - ].includes(markerName) - ) { - continue; - } - - let markerData = m[dataCol]; - if (markerName == "ChromeUtils.import") { - let module = markerData.name; - if (!markersForAllPhases.modules.includes(module)) { - markersForAllPhases.modules.push(module); - markersForCurrentPhase.modules.push(module); - } - } - - if (markerName == "JS XPCOM") { - // The stack will always contain a label like - // `mozJSComponentLoader::LoadModule ...`. Extract the path from that. - let samples = markerData.stack.samples; - let stackId = samples.data[0][samples.schema.stack]; - let stackLines = getStackFromProfile(profile, stackId, rootProfile.libs); - - let component = stackLines - .filter(s => s.startsWith("mozJSComponentLoader::LoadModule"))[0] - .split(" ", 2)[1]; - - // Keep only the file name for components, as the path is an absolute file - // URL rather than a resource:// URL like for modules. - component = component.replace(/.*\//, ""); - - if (!markersForAllPhases.components.includes(component)) { - markersForAllPhases.components.push(component); - markersForCurrentPhase.components.push(component); - } - } - - if (markerName == "GetService") { - // We get a CID from the marker itself, but not a human-readable contract - // ID. Now, most of the time, the stack will contain a label like - // `GetServiceByContractID @...;1`, and we could extract the contract ID - // from that. But there are multiple ways to instantiate services, and - // not all of them are annotated in this manner. Therefore we "go the - // other way" and use the component manager's mapping from contract IDs to - // CIDs. This opens up the possibility for that mapping to be different - // between `--backgroundtask` and `xpcshell`, but that's not an issue - // right at this moment. It's worth noting that one CID can (and - // sometimes does) correspond to more than one contract ID. - let cid = markerData.name; - - if (!markersForAllPhases.services.includes(cid)) { - markersForAllPhases.services.push(cid); - markersForCurrentPhase.services.push(cid); - } - } - } - - // Turn `["1", {name: "2", condition: false}, {name: "3", condition: true}]` - // into `new Set(["1", "3"])`. - function filterConditions(l) { - let set = new Set([]); - for (let entry of l) { - if (typeof entry == "object") { - if ("condition" in entry && !entry.condition) { - continue; - } - entry = entry.name; - } - set.add(entry); - } - return set; - } - - for (let phaseName in backgroundtaskPhases) { - for (let listName in backgroundtaskPhases[phaseName]) { - for (let scriptType in backgroundtaskPhases[phaseName][listName]) { - backgroundtaskPhases[phaseName][listName][ - scriptType - ] = filterConditions( - backgroundtaskPhases[phaseName][listName][scriptType] - ); - } - - // Turn human-readable contract IDs into CIDs. It's worth noting that one - // CID can (and sometimes does) correspond to more than one contract ID. - let services = Array.from( - backgroundtaskPhases[phaseName][listName].services || new Set([]) - ); - services = services - .map(contractID => { - try { - return Cm.contractIDToCID(contractID).toString(); - } catch (e) { - return null; - } - }) - .filter(cid => cid); - services.sort(); - backgroundtaskPhases[phaseName][listName].services = new Set(services); - info( - `backgroundtaskPhases[${phaseName}][${listName}].services = ${JSON.stringify( - services.map(c => c.toString()) - )}` - ); - } - } - - // Turn `{CID}` into `{CID} (@contractID)` or `{CID} (one of - // @contractID1, ..., @contractIDn)` as appropriate. - function renderResource(resource) { - const UUID_PATTERN = /^\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}$/i; - if (UUID_PATTERN.test(resource)) { - let foundContractIDs = []; - for (let contractID of Cm.getContractIDs()) { - try { - if (resource == Cm.contractIDToCID(contractID).toString()) { - foundContractIDs.push(contractID); - } - } catch (e) { - // This can throw for contract IDs that are filtered. The common - // reason is that they're limited to a particular process. - } - } - if (!foundContractIDs.length) { - return `${resource} (CID with no human-readable contract IDs)`; - } else if (foundContractIDs.length == 1) { - return `${resource} (CID with human-readable contract ID ${foundContractIDs[0]})`; - } - foundContractIDs.sort(); - return `${resource} (CID with human-readable contract IDs ${JSON.stringify( - foundContractIDs - )})`; - } - - return resource; - } - - for (let phase in backgroundtaskPhases) { - let loadedList = phases[phase]; - let allowlist = backgroundtaskPhases[phase].allowlist || null; - if (allowlist) { - for (let scriptType in allowlist) { - loadedList[scriptType] = loadedList[scriptType].filter(c => { - if (!allowlist[scriptType].has(c)) { - return true; - } - allowlist[scriptType].delete(c); - return false; - }); - Assert.deepEqual( - loadedList[scriptType], - [], - `${phase}: should have no unexpected ${scriptType} loaded` - ); - - // Present errors in deterministic order. - let unexpected = Array.from(loadedList[scriptType]); - unexpected.sort(); - for (let script of unexpected) { - // It would be nice to show stacks here, but that can be follow-up. - ok( - false, - `${phase}: unexpected ${scriptType}: ${renderResource(script)}` - ); - } - Assert.deepEqual( - allowlist[scriptType].size, - 0, - `${phase}: all ${scriptType} allowlist entries should have been used` - ); - let unused = Array.from(allowlist[scriptType]); - unused.sort(); - for (let script of unused) { - ok( - false, - `${phase}: unused ${scriptType} allowlist entry: ${renderResource( - script - )}` - ); - } - } - } - let denylist = backgroundtaskPhases[phase].denylist || null; - if (denylist) { - for (let scriptType in denylist) { - let resources = denylist[scriptType]; - resources.sort(); - for (let resource of resources) { - let loaded = loadedList[scriptType].includes(resource); - let message = `${phase}: ${renderResource(resource)} is not allowed`; - // It would be nice to show stacks here, but that can be follow-up. - ok(!loaded, message); - } - } - } - } -}); diff --git a/toolkit/components/backgroundtasks/tests/browser/head.js b/toolkit/components/backgroundtasks/tests/browser/head.js deleted file mode 100644 index fb9c3fe123a0..000000000000 --- a/toolkit/components/backgroundtasks/tests/browser/head.js +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * vim: sw=4 ts=4 sts=4 et - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -"use strict"; - -async function do_backgroundtask( - task, - options = { extraArgs: [], extraEnv: {} } -) { - options = Object.assign({}, options); - options.extraArgs = options.extraArgs || []; - options.extraEnv = options.extraEnv || {}; - - let command = Services.dirsvc.get("XREExeF", Ci.nsIFile).path; - let args = ["--backgroundtask", task]; - args.push(...options.extraArgs); - - // Ensure `resource://testing-common` gets mapped. - let protocolHandler = Services.io - .getProtocolHandler("resource") - .QueryInterface(Ci.nsIResProtocolHandler); - - let uri = protocolHandler.getSubstitution("testing-common"); - Assert.ok(uri, "resource://testing-common is not substituted"); - - // The equivalent of _TESTING_MODULES_DIR in xpcshell. - options.extraEnv.XPCSHELL_TESTING_MODULES_URI = uri.spec; - - // Now we can actually invoke the process. - info( - `launching child process ${command} with args: ${args} and extra environment: ${JSON.stringify( - options.extraEnv - )}` - ); - - const { Subprocess } = ChromeUtils.import( - "resource://gre/modules/Subprocess.jsm" - ); - let proc = await Subprocess.call({ - command, - arguments: args, - environment: options.extraEnv, - environmentAppend: true, - stderr: "stdout", - }).then(p => { - p.stdin.close(); - const dumpPipe = async pipe => { - let data = await pipe.readString(); - while (data) { - for (let line of data.split(/\r\n|\r|\n/).slice(0, -1)) { - dump("> " + line + "\n"); - } - data = await pipe.readString(); - } - }; - dumpPipe(p.stdout); - - return p; - }); - - let { exitCode } = await proc.wait(); - return exitCode; -} diff --git a/toolkit/components/backgroundtasks/tests/xpcshell/head.js b/toolkit/components/backgroundtasks/tests/xpcshell/head.js deleted file mode 100644 index 58105a36145f..000000000000 --- a/toolkit/components/backgroundtasks/tests/xpcshell/head.js +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * vim: sw=4 ts=4 sts=4 et - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -"use strict"; - -const { AppConstants } = ChromeUtils.import( - "resource://gre/modules/AppConstants.jsm" -); -const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); -const { Subprocess } = ChromeUtils.import( - "resource://gre/modules/Subprocess.jsm" -); - -function getFirefoxExecutableFilename() { - if (AppConstants.platform === "win") { - return AppConstants.MOZ_APP_NAME + ".exe"; - } - return AppConstants.MOZ_APP_NAME; -} - -// Returns a nsIFile to the firefox.exe (really, application) executable file. -function getFirefoxExecutableFile() { - let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); - file = Services.dirsvc.get("GreBinD", Ci.nsIFile); - - file.append(getFirefoxExecutableFilename()); - return file; -} - -async function do_backgroundtask( - task, - options = { extraArgs: [], extraEnv: {} } -) { - options = Object.assign({}, options); - options.extraArgs = options.extraArgs || []; - options.extraEnv = options.extraEnv || {}; - - let command = getFirefoxExecutableFile().path; - let args = ["--backgroundtask", task]; - args.push(...options.extraArgs); - - // Ensure `resource://testing-common` gets mapped. - let protocolHandler = Services.io - .getProtocolHandler("resource") - .QueryInterface(Ci.nsIResProtocolHandler); - - let uri = protocolHandler.getSubstitution("testing-common"); - Assert.ok(uri, "resource://testing-common is not substituted"); - - // The equivalent of _TESTING_MODULES_DIR in xpcshell. - options.extraEnv.XPCSHELL_TESTING_MODULES_URI = uri.spec; - - // Now we can actually invoke the process. - info( - `launching child process ${command} with args: ${args} and extra environment: ${JSON.stringify( - options.extraEnv - )}` - ); - let proc = await Subprocess.call({ - command, - arguments: args, - environment: options.extraEnv, - environmentAppend: true, - stderr: "stdout", - }).then(p => { - p.stdin.close(); - const dumpPipe = async pipe => { - let data = await pipe.readString(); - while (data) { - for (let line of data.split(/\r\n|\r|\n/).slice(0, -1)) { - dump("> " + line + "\n"); - } - data = await pipe.readString(); - } - }; - dumpPipe(p.stdout); - - return p; - }); - - let { exitCode } = await proc.wait(); - return exitCode; -} diff --git a/toolkit/components/backgroundtasks/tests/xpcshell/test_backgroundtask_exitcodes.js b/toolkit/components/backgroundtasks/tests/xpcshell/test_backgroundtask_exitcodes.js deleted file mode 100644 index b9edf97f7d8f..000000000000 --- a/toolkit/components/backgroundtasks/tests/xpcshell/test_backgroundtask_exitcodes.js +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * vim: sw=4 ts=4 sts=4 et - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -add_task(async function test_success() { - let exitCode = await do_backgroundtask("success"); - Assert.equal(0, exitCode); -}); - -add_task(async function test_failure() { - let exitCode = await do_backgroundtask("failure"); - Assert.equal(1, exitCode); -}); - -add_task(async function test_exception() { - let exitCode = await do_backgroundtask("exception"); - Assert.equal(3, exitCode); -}); - -add_task(async function test_not_found() { - let exitCode = await do_backgroundtask("not_found"); - Assert.equal(2, exitCode); -}); diff --git a/toolkit/components/backgroundtasks/tests/xpcshell/test_backgroundtask_policies.js b/toolkit/components/backgroundtasks/tests/xpcshell/test_backgroundtask_policies.js deleted file mode 100644 index bf4f6199e347..000000000000 --- a/toolkit/components/backgroundtasks/tests/xpcshell/test_backgroundtask_policies.js +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * vim: sw=4 ts=4 sts=4 et - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// In order to use the policy engine inside the xpcshell harness, we need to set -// up a dummy app info. In the backgroundtask itself, the application under -// test will configure real app info. This opens a possibility for some -// incompatibility, but there doesn't appear to be such an issue at this time. -const { updateAppInfo } = ChromeUtils.import( - "resource://testing-common/AppInfo.jsm" -); -updateAppInfo({ - name: "XPCShell", - ID: "xpcshell@tests.mozilla.org", - version: "48", - platformVersion: "48", -}); - -const { EnterprisePolicyTesting } = ChromeUtils.import( - "resource://testing-common/EnterprisePolicyTesting.jsm" -); - -// This initializes the policy engine for xpcshell tests -let policies = Cc["@mozilla.org/enterprisepolicies;1"].getService( - Ci.nsIObserver -); -policies.observe(null, "policies-startup", null); - -add_task(async function test_backgroundtask_policies() { - let url = "https://www.example.com/"; - await EnterprisePolicyTesting.setupPolicyEngineWithJson({ - policies: { - AppUpdateURL: url, - }, - }); - - let filePath = Services.prefs.getStringPref("browser.policies.alternatePath"); - - let exitCode = await do_backgroundtask("policies", { - extraArgs: [filePath, url], - }); - Assert.equal(0, exitCode); -}); diff --git a/toolkit/components/backgroundtasks/tests/xpcshell/test_backgroundtask_specific_pref.js b/toolkit/components/backgroundtasks/tests/xpcshell/test_backgroundtask_specific_pref.js deleted file mode 100644 index 50f85b9becb7..000000000000 --- a/toolkit/components/backgroundtasks/tests/xpcshell/test_backgroundtask_specific_pref.js +++ /dev/null @@ -1,20 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * vim: sw=4 ts=4 sts=4 et - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -add_task(async function test_backgroundtask_specific_pref() { - // First, verify this pref isn't set in Gecko itself. - Assert.equal( - -1, - Services.prefs.getIntPref("test.backgroundtask_specific_pref.exitCode", -1) - ); - - // Second, verify that this pref is set in background tasks. - // xpcshell tests locally test unpackaged builds. - let exitCode = await do_backgroundtask("backgroundtask_specific_pref", { - extraArgs: ["test.backgroundtask_specific_pref.exitCode"], - }); - Assert.equal(79, exitCode); -}); diff --git a/toolkit/components/backgroundtasks/tests/xpcshell/test_manifest_with_backgroundtask.js b/toolkit/components/backgroundtasks/tests/xpcshell/test_manifest_with_backgroundtask.js index f713fe5e782b..5442d1961180 100644 --- a/toolkit/components/backgroundtasks/tests/xpcshell/test_manifest_with_backgroundtask.js +++ b/toolkit/components/backgroundtasks/tests/xpcshell/test_manifest_with_backgroundtask.js @@ -4,6 +4,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); + add_task(async function test_manifest_with_backgroundtask() { let bts = Cc["@mozilla.org/backgroundtasks;1"].getService( Ci.nsIBackgroundTasks diff --git a/toolkit/components/backgroundtasks/tests/xpcshell/test_manifest_without_backgroundtask.js b/toolkit/components/backgroundtasks/tests/xpcshell/test_manifest_without_backgroundtask.js index 422d9a49ff6a..e3d7936feecf 100644 --- a/toolkit/components/backgroundtasks/tests/xpcshell/test_manifest_without_backgroundtask.js +++ b/toolkit/components/backgroundtasks/tests/xpcshell/test_manifest_without_backgroundtask.js @@ -4,6 +4,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); + add_task(async function test_without_backgroundtask() { let bts = Cc["@mozilla.org/backgroundtasks;1"].getService( Ci.nsIBackgroundTasks diff --git a/toolkit/components/backgroundtasks/tests/xpcshell/xpcshell.ini b/toolkit/components/backgroundtasks/tests/xpcshell/xpcshell.ini index c1b42a2ff56c..b39f03003eee 100644 --- a/toolkit/components/backgroundtasks/tests/xpcshell/xpcshell.ini +++ b/toolkit/components/backgroundtasks/tests/xpcshell/xpcshell.ini @@ -3,14 +3,9 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. [DEFAULT] -firefox-appdir = browser skip-if = toolkit == 'android' -head = head.js support-files = CatBackgroundTaskRegistrationComponents.manifest -[test_backgroundtask_exitcodes.js] -[test_backgroundtask_policies.js] -[test_backgroundtask_specific_pref.js] [test_manifest_with_backgroundtask.js] [test_manifest_without_backgroundtask.js] diff --git a/toolkit/crashreporter/test/unit/head_crashreporter.js b/toolkit/crashreporter/test/unit/head_crashreporter.js index d4b9669d2b29..a9a99c171a62 100644 --- a/toolkit/crashreporter/test/unit/head_crashreporter.js +++ b/toolkit/crashreporter/test/unit/head_crashreporter.js @@ -261,89 +261,6 @@ async function do_triggered_content_crash(trigger, callback) { } } -/* - * Run the `crash` backgroundtask subprocess, crashing it in the - * specified manner. - * - * @param crashType Integer `CrashTestUtils.CRASH_...` code. - * @param crashExtras Dictionary of key-value pairs to include in - * minidump extras. - * - * @param callback - * A JavaScript function to be called after the subprocess - * crashes. It will be passed (minidump, extra, extrafile), where - * - minidump is an nsIFile of the minidump file produced, - * - extra is an object containing the key,value pairs from - * the .extra file. - * - extrafile is an nsIFile of the extra file - * - * @param canReturnZero - * If true, the subprocess may return with a zero exit code. - * Certain types of crashes may not cause the process to - * exit with an error. - * - */ -async function do_backgroundtask_crash( - crashType, - crashExtras, - callback, - canReturnZero -) { - Assert.ok(AppConstants.MOZ_BACKGROUNDTASKS); - - // Get full path to application (not xpcshell) - let bin = Services.dirsvc.get("GreBinD", Ci.nsIFile); - if (AppConstants.platform === "win") { - bin.append(AppConstants.MOZ_APP_NAME + ".exe"); - } else { - bin.append(AppConstants.MOZ_APP_NAME); - } - - // run `application --backgroundtask crash ...`. - let process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess); - process.init(bin); - - let args = ["--backgroundtask", "crash"]; - args.push(crashType.toString()); - - // Sorted to be deterministic. - let sorted = Object.entries(crashExtras).sort((a, b) => a[0] < b[0]); - for (let [key, value] of sorted) { - args.push(key); - args.push(value); - } - - let env = Cc["@mozilla.org/process/environment;1"].getService( - Ci.nsIEnvironment - ); - - let crashD = do_get_tempdir(); - crashD.append("crash-events"); - if (!crashD.exists()) { - crashD.create(crashD.DIRECTORY_TYPE, 0o700); - } - - env.set("CRASHES_EVENTS_DIR", crashD.path); - // Used to map resource://testing-common. - env.set("XPCSHELL_TESTING_MODULES_DIR", _TESTING_MODULES_DIR); - - try { - process.run(true, args, args.length); - } catch (ex) { - // on Windows we exit with a -1 status when crashing. - } finally { - env.set("CRASHES_EVENTS_DIR", ""); - env.set("XPCSHELL_TESTING_MODULES_DIR", ""); - } - - if (!canReturnZero) { - // should exit with an error (should have crashed) - Assert.notEqual(process.exitValue, 0); - } - - await handleMinidump(callback); -} - // Import binary APIs via js-ctypes. var { CrashTestUtils } = ChromeUtils.import( "resource://test/CrashTestUtils.jsm" diff --git a/toolkit/crashreporter/test/unit/test_crash_backgroundtask_moz_crash.js b/toolkit/crashreporter/test/unit/test_crash_backgroundtask_moz_crash.js deleted file mode 100644 index 1eb0e0a68869..000000000000 --- a/toolkit/crashreporter/test/unit/test_crash_backgroundtask_moz_crash.js +++ /dev/null @@ -1,22 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -add_task(async function run_test() { - if (!AppConstants.MOZ_BACKGROUNDTASKS) { - return; - } - - // Try crashing background task with a runtime abort - await do_backgroundtask_crash( - CrashTestUtils.CRASH_MOZ_CRASH, - { TestKey: "TestValue" }, - function(mdump, extra) { - Assert.equal(extra.TestKey, "TestValue"); - Assert.equal(false, "OOMAllocationSize" in extra); - Assert.equal(false, "JSOutOfMemory" in extra); - Assert.equal(false, "JSLargeAllocationFailure" in extra); - }, - // process will exit with a zero exit status - true - ); -}); diff --git a/toolkit/crashreporter/test/unit/xpcshell.ini b/toolkit/crashreporter/test/unit/xpcshell.ini index 127c97b73819..65882e7447cd 100644 --- a/toolkit/crashreporter/test/unit/xpcshell.ini +++ b/toolkit/crashreporter/test/unit/xpcshell.ini @@ -39,8 +39,6 @@ skip-if = (os != 'win' && os != 'linux') || (os=='linux' && bits==32) [test_event_files.js] [test_crash_terminator.js] -[test_crash_backgroundtask_moz_crash.js] - [test_crash_heap_corruption.js] skip-if = os != 'win' diff --git a/toolkit/xre/moz.build b/toolkit/xre/moz.build index cf5f7ac50093..edaabb958d98 100644 --- a/toolkit/xre/moz.build +++ b/toolkit/xre/moz.build @@ -285,6 +285,3 @@ if CONFIG["MOZ_IPDL_TESTS"]: if CONFIG["ENABLE_TESTS"]: DIRS += ["test/gtest"] - -if CONFIG["MOZ_BACKGROUNDTASKS"]: - DEFINES["MOZ_BACKGROUNDTASKS"] = True diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 22bc9c076198..e23c1a29eee3 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -248,12 +248,6 @@ # include "nsIPK11Token.h" #endif -#ifdef MOZ_BACKGROUNDTASKS -# include "mozilla/BackgroundTasks.h" -# include "nsIPowerManagerService.h" -# include "nsIStringBundle.h" -#endif - extern uint32_t gRestartMode; extern void InstallSignalHandlers(const char* ProgramName); @@ -2281,15 +2275,6 @@ class ReturnAbortOnError { } // namespace static nsresult ProfileMissingDialog(nsINativeAppSupport* aNative) { -#ifdef MOZ_BACKGROUNDTASKS - if (BackgroundTasks::IsBackgroundTaskMode()) { - // We should never get to this point in background task mode. - Output(false, - "Could not determine any profile running in backgroundtask mode!\n"); - return NS_ERROR_ABORT; - } -#endif - nsresult rv; ScopedXPCOMStartup xpcom; @@ -3476,26 +3461,10 @@ int XREMain::XRE_mainInit(bool* aExitFlag) { DisableAppNap(); #endif -#ifdef MOZ_BACKGROUNDTASKS - Maybe backgroundTask = Nothing(); - const char* backgroundTaskName = nullptr; - if (ARG_FOUND == CheckArg("backgroundtask", &backgroundTaskName)) { - backgroundTask = Some(backgroundTaskName); - } - BackgroundTasks::Init(backgroundTask); - - if (BackgroundTasks::IsBackgroundTaskMode()) { - printf_stderr("*** You are running in background task mode. ***\n"); - } -#endif - #ifndef ANDROID if (PR_GetEnv("MOZ_RUN_GTEST") # ifdef FUZZING || PR_GetEnv("FUZZER") -# endif -# ifdef MOZ_BACKGROUNDTASKS - || BackgroundTasks::IsBackgroundTaskMode() # endif ) { // Enable headless mode and assert that it worked, since gfxPlatform @@ -3843,11 +3812,6 @@ int XREMain::XRE_mainInit(bool* aExitFlag) { if (!safeModeRequested) { return 1; } -#ifdef MOZ_BACKGROUNDTASKS - if (BackgroundTasks::IsBackgroundTaskMode()) { - safeModeRequested = Some(false); - } -#endif gSafeMode = safeModeRequested.value(); @@ -4433,19 +4397,6 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) { return 1; } -#ifdef MOZ_BACKGROUNDTASKS - if (BackgroundTasks::IsBackgroundTaskMode()) { - nsCOMPtr file; - nsresult rv = BackgroundTasks::GetOrCreateTemporaryProfileDirectory( - getter_AddRefs(file)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return 1; - } - - SaveFileToEnv("XRE_PROFILE_PATH", file); - } -#endif - bool wasDefaultSelection; nsCOMPtr profile; rv = SelectProfile(mProfileSvc, mNativeApp, getter_AddRefs(mProfD), @@ -4783,9 +4734,6 @@ nsresult XREMain::XRE_mainRun() { // We need the appStartup pointer to span multiple scopes, so we declare // it here. nsCOMPtr appStartup; - // Ditto with the command line. - nsCOMPtr cmdLine; - { #ifdef XP_MACOSX // In this scope, create an autorelease pool that will leave scope with @@ -5011,6 +4959,8 @@ nsresult XREMain::XRE_mainRun() { appStartup->GetShuttingDown(&mShuttingDown); + nsCOMPtr cmdLine; + nsCOMPtr workingDir; rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR, getter_AddRefs(workingDir)); @@ -5067,13 +5017,6 @@ nsresult XREMain::XRE_mainRun() { Preferences::GetBool("toolkit.lazyHiddenWindow", false); #endif -#ifdef MOZ_BACKGROUNDTASKS - if (BackgroundTasks::IsBackgroundTaskMode()) { - // Background tasks aren't going to load a chrome XUL document. - lazyHiddenWindow = true; - } -#endif - if (!lazyHiddenWindow) { rv = appStartup->CreateHiddenWindow(); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); @@ -5089,26 +5032,18 @@ nsresult XREMain::XRE_mainRun() { SetupLauncherProcessPref(); # endif // defined(MOZ_LAUNCHER_PROCESS) # if defined(MOZ_DEFAULT_BROWSER_AGENT) -# if defined(MOZ_BACKGROUNDTASKS) - // The backgroundtask profile is not a browsing profile, let alone the new - // default profile, so don't mirror its properties into the registry. - if (!BackgroundTasks::IsBackgroundTaskMode()) -# endif // defined(MOZ_BACKGROUNDTASKS) - { - Preferences::RegisterCallbackAndCall( - &OnDefaultAgentTelemetryPrefChanged, - kPrefHealthReportUploadEnabled); - Preferences::RegisterCallbackAndCall( - &OnDefaultAgentTelemetryPrefChanged, kPrefDefaultAgentEnabled); + Preferences::RegisterCallbackAndCall(&OnDefaultAgentTelemetryPrefChanged, + kPrefHealthReportUploadEnabled); + Preferences::RegisterCallbackAndCall(&OnDefaultAgentTelemetryPrefChanged, + kPrefDefaultAgentEnabled); - Preferences::RegisterCallbackAndCall( - &OnDefaultAgentRemoteSettingsPrefChanged, - kPrefServicesSettingsServer); - Preferences::RegisterCallbackAndCall( - &OnDefaultAgentRemoteSettingsPrefChanged, - kPrefSecurityContentSignatureRootHash); - SetDefaultAgentLastRunTime(); - } + Preferences::RegisterCallbackAndCall( + &OnDefaultAgentRemoteSettingsPrefChanged, + kPrefServicesSettingsServer); + Preferences::RegisterCallbackAndCall( + &OnDefaultAgentRemoteSettingsPrefChanged, + kPrefSecurityContentSignatureRootHash); + SetDefaultAgentLastRunTime(); # endif // defined(MOZ_DEFAULT_BROWSER_AGENT) #endif @@ -5220,30 +5155,6 @@ nsresult XREMain::XRE_mainRun() { mProfileSvc->CompleteStartup(); } -#ifdef MOZ_BACKGROUNDTASKS - if (BackgroundTasks::IsBackgroundTaskMode()) { - // In background task mode, we don't fire various delayed initialization - // notifications, which in the regular browser is how startup crash tracking - // is marked as finished. Here, getting this far means we don't have a - // startup crash. - rv = appStartup->TrackStartupCrashEnd(); - NS_ENSURE_SUCCESS(rv, rv); - - // We never open a window, but don't want to exit immediately. - rv = appStartup->EnterLastWindowClosingSurvivalArea(); - NS_ENSURE_SUCCESS(rv, rv); - - // Avoid some small differences in initialization order across platforms. - nsCOMPtr powerManagerService = - do_GetService(POWERMANAGERSERVICE_CONTRACTID); - nsCOMPtr stringBundleService = - do_GetService(NS_STRINGBUNDLE_CONTRACTID); - - rv = BackgroundTasks::RunBackgroundTask(cmdLine); - NS_ENSURE_SUCCESS(rv, rv); - } -#endif - { rv = appStartup->Run(); if (NS_FAILED(rv)) { @@ -5465,10 +5376,6 @@ int XREMain::XRE_main(int argc, char* argv[], const BootstrapConfig& aConfig) { mProfileLock->Unlock(); gProfileLock = nullptr; -#ifdef MOZ_BACKGROUNDTASKS - BackgroundTasks::Shutdown(); -#endif - gLastAppVersion.Truncate(); gLastAppBuildID.Truncate(); diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp index c9ba0f294cb2..d9bcdb1f4e26 100644 --- a/toolkit/xre/nsXREDirProvider.cpp +++ b/toolkit/xre/nsXREDirProvider.cpp @@ -39,9 +39,6 @@ #include "mozilla/dom/ScriptSettings.h" #include "mozilla/AutoRestore.h" -#ifdef MOZ_BACKGROUNDTASKS -# include "mozilla/BackgroundTasks.h" -#endif #include "mozilla/Components.h" #include "mozilla/Services.h" #include "mozilla/Omnijar.h" @@ -853,10 +850,6 @@ static nsresult DeleteDirIfExists(nsIFile* dir) { static const char* const kAppendPrefDir[] = {"defaults", "preferences", nullptr}; -#ifdef MOZ_BACKGROUNDTASKS -static const char* const kAppendBackgroundTasksPrefDir[] = { - "defaults", "backgroundtasks", nullptr}; -#endif nsresult nsXREDirProvider::GetFilesInternal(const char* aProperty, nsISimpleEnumerator** aResult) { @@ -867,12 +860,6 @@ nsresult nsXREDirProvider::GetFilesInternal(const char* aProperty, nsCOMArray directories; LoadDirIntoArray(mXULAppDir, kAppendPrefDir, directories); -#ifdef MOZ_BACKGROUNDTASKS - if (mozilla::BackgroundTasks::IsBackgroundTaskMode()) { - LoadDirIntoArray(mGREDir, kAppendBackgroundTasksPrefDir, directories); - LoadDirIntoArray(mXULAppDir, kAppendBackgroundTasksPrefDir, directories); - } -#endif rv = NS_NewArrayEnumerator(aResult, directories, NS_GET_IID(nsIFile)); } else if (!strcmp(aProperty, NS_APP_CHROME_DIR_LIST)) { @@ -979,21 +966,13 @@ nsXREDirProvider::DoStartup() { mozilla::SandboxBroker::GeckoDependentInitialize(); #endif - bool initExtensionManager = -#ifdef MOZ_BACKGROUNDTASKS - !mozilla::BackgroundTasks::IsBackgroundTaskMode(); -#else - true; -#endif - if (initExtensionManager) { - // Init the Extension Manager - nsCOMPtr em = - do_GetService("@mozilla.org/addons/integration;1"); - if (em) { - em->Observe(nullptr, "addons-startup", nullptr); - } else { - NS_WARNING("Failed to create Addons Manager."); - } + // Init the Extension Manager + nsCOMPtr em = + do_GetService("@mozilla.org/addons/integration;1"); + if (em) { + em->Observe(nullptr, "addons-startup", nullptr); + } else { + NS_WARNING("Failed to create Addons Manager."); } obsSvc->NotifyObservers(nullptr, "profile-after-change", kStartup);