Backed out 8 changesets (bug 1679440, bug 1682069, bug 1667276) for causing failures on browser_all_files_referenced.js. CLOSED TREE

Backed out changeset f1a65c9b3ca2 (bug 1682069)
Backed out changeset 310d2116faf7 (bug 1679440)
Backed out changeset f970ef0897cd (bug 1667276)
Backed out changeset 38c20196aabc (bug 1667276)
Backed out changeset 60c2f2dbc676 (bug 1667276)
Backed out changeset cf52687c4433 (bug 1667276)
Backed out changeset 74580a0f2633 (bug 1667276)
Backed out changeset ab6f830f6e75 (bug 1667276)
This commit is contained in:
Csoregi Natalia 2021-01-26 06:49:04 +02:00
parent b78c5041ef
commit 0b28701943
39 changed files with 29 additions and 1442 deletions

View file

@ -220,6 +220,3 @@ tools/tryselect/selectors/chooser/templates/chooser.html
# Ignore preprocessed *(P)refs.js files in update-packaging. # Ignore preprocessed *(P)refs.js files in update-packaging.
tools/update-packaging/**/*refs.js tools/update-packaging/**/*refs.js
# Ignore backgroundtasks preferences files.
toolkit/components/backgroundtasks/defaults

View file

@ -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. # These are source mapped and the locations are asserted in the test case.
devtools/client/webconsole/test/browser/test-mangled-function.* devtools/client/webconsole/test/browser/test-mangled-function.*
# Ignore backgroundtasks preferences files.
toolkit/components/backgroundtasks/defaults

View file

@ -98,10 +98,6 @@ ifdef MOZ_DEFAULT_BROWSER_AGENT
DEFINES += -DMOZ_DEFAULT_BROWSER_AGENT=1 DEFINES += -DMOZ_DEFAULT_BROWSER_AGENT=1
endif endif
ifdef MOZ_BACKGROUNDTASKS
DEFINES += -DMOZ_BACKGROUNDTASKS=1
endif
ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT)) ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
MOZ_PKG_MAC_DSSTORE=$(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/dsstore MOZ_PKG_MAC_DSSTORE=$(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/dsstore
MOZ_PKG_MAC_BACKGROUND=$(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/background.png MOZ_PKG_MAC_BACKGROUND=$(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/background.png

View file

@ -305,12 +305,6 @@
; gre location for now. ; gre location for now.
@RESPATH@/defaults/pref/channel-prefs.js @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] ; [Layout Engine Resources]
; Style Sheets, Graphics and other Resources used by the layout engine. ; Style Sheets, Graphics and other Resources used by the layout engine.
@RESPATH@/res/EditorOverride.css @RESPATH@/res/EditorOverride.css

View file

@ -11,11 +11,6 @@ Classes = [
'type': 'nsReadConfig', 'type': 'nsReadConfig',
'headers': ['/extensions/pref/autoconfig/src/nsReadConfig.h'], 'headers': ['/extensions/pref/autoconfig/src/nsReadConfig.h'],
'init_method': 'Init', 'init_method': 'Init',
'categories': { 'categories': {'pref-config-startup': 'ReadConfig Module'},
'pref-config-startup': {
'name': 'ReadConfig Module',
'backgroundtasks': BackgroundTasksSelector.ALL_TASKS,
},
},
}, },
] ]

View file

@ -96,12 +96,7 @@ Classes = [
'cid': '{fc886801-e768-11d4-9885-00c04fa0cf4b}', 'cid': '{fc886801-e768-11d4-9885-00c04fa0cf4b}',
'contract_ids': ['@mozilla.org/content/document-loader-factory;1'], 'contract_ids': ['@mozilla.org/content/document-loader-factory;1'],
'type': 'nsIDocumentLoaderFactory', 'type': 'nsIDocumentLoaderFactory',
'categories': { 'categories': {'Gecko-Content-Viewers': content_types},
'Gecko-Content-Viewers': {
'name': content_types,
'backgroundtasks': BackgroundTasksSelector.ALL_TASKS,
}
},
}, },
{ {
'cid': '{0ddf4df8-4dbb-4133-8b79-9afb966514f5}', 'cid': '{0ddf4df8-4dbb-4133-8b79-9afb966514f5}',
@ -294,14 +289,8 @@ Classes = [
'type': 'nsMixedContentBlocker', 'type': 'nsMixedContentBlocker',
'headers': ['mozilla/dom/nsMixedContentBlocker.h'], 'headers': ['mozilla/dom/nsMixedContentBlocker.h'],
'categories': { 'categories': {
'content-policy': { 'content-policy': '@mozilla.org/mixedcontentblocker;1',
'name': '@mozilla.org/mixedcontentblocker;1', 'net-channel-event-sinks': '@mozilla.org/mixedcontentblocker;1',
'backgroundtasks': BackgroundTasksSelector.ALL_TASKS,
},
'net-channel-event-sinks': {
'name': '@mozilla.org/mixedcontentblocker;1',
'backgroundtasks': BackgroundTasksSelector.ALL_TASKS,
},
}, },
}, },
{ {

View file

@ -86,9 +86,6 @@
#include "plstr.h" #include "plstr.h"
#include "prlink.h" #include "prlink.h"
#include "xpcpublic.h" #include "xpcpublic.h"
#ifdef MOZ_BACKGROUNDTASKS
# include "mozilla/BackgroundTasks.h"
#endif
#ifdef DEBUG #ifdef DEBUG
# include <map> # include <map>
@ -4533,13 +4530,6 @@ nsresult Preferences::InitInitialObjects(bool aIsStartup) {
rv = pref_ReadDefaultPrefs(jarReader, "defaults/pref/*.js$"); rv = pref_ReadDefaultPrefs(jarReader, "defaults/pref/*.js$");
NS_ENSURE_SUCCESS(rv, rv); 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 #ifdef MOZ_WIDGET_ANDROID
// Load jar:$gre/omni.jar!/defaults/pref/$MOZ_ANDROID_CPU_ABI/*.js. // Load jar:$gre/omni.jar!/defaults/pref/$MOZ_ANDROID_CPU_ABI/*.js.
nsAutoCString path; nsAutoCString path;
@ -4619,25 +4609,6 @@ nsresult Preferences::InitInitialObjects(bool aIsStartup) {
NS_WARNING("Error parsing preferences."); 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<nsIProperties> dirSvc( nsCOMPtr<nsIProperties> dirSvc(

View file

@ -167,6 +167,3 @@ else:
FINAL_TARGET_PP_FILES += [ FINAL_TARGET_PP_FILES += [
"greprefs.js", "greprefs.js",
] ]
if CONFIG["MOZ_BACKGROUNDTASKS"]:
DEFINES["MOZ_BACKGROUNDTASKS"] = True

View file

@ -35,9 +35,6 @@
#include "GeckoProfiler.h" #include "GeckoProfiler.h"
#include "nsAppRunner.h" #include "nsAppRunner.h"
#include "xpcpublic.h" #include "xpcpublic.h"
#ifdef MOZ_BACKGROUNDTASKS
# include "mozilla/BackgroundTasks.h"
#endif
#if defined(XP_WIN) #if defined(XP_WIN)
# include <windows.h> # include <windows.h>
@ -118,12 +115,6 @@ StartupCache* StartupCache::GetSingletonNoInit() {
} }
StartupCache* StartupCache::GetSingleton() { StartupCache* StartupCache::GetSingleton() {
#ifdef MOZ_BACKGROUNDTASKS
if (BackgroundTasks::IsBackgroundTaskMode()) {
return nullptr;
}
#endif
if (!gStartupCache) { if (!gStartupCache) {
if (!XRE_IsParentProcess()) { if (!XRE_IsParentProcess()) {
return nullptr; return nullptr;

View file

@ -31,7 +31,4 @@ XPIDL_SOURCES += [
"nsIStartupCacheInfo.idl", "nsIStartupCacheInfo.idl",
] ]
if CONFIG["MOZ_BACKGROUNDTASKS"]:
DEFINES["MOZ_BACKGROUNDTASKS"] = True
FINAL_LIBRARY = "xul" FINAL_LIBRARY = "xul"

View file

@ -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");
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -8,11 +8,9 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIBackgroundTasks.h" #include "nsIBackgroundTasks.h"
#include "nsIBackgroundTasksManager.h"
#include "nsICommandLine.h" #include "nsICommandLine.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsISupports.h" #include "nsISupports.h"
#include "nsImportModule.h"
#include "nsString.h" #include "nsString.h"
#include "nsXULAppAPI.h" #include "nsXULAppAPI.h"
@ -113,14 +111,7 @@ class BackgroundTasks final : public nsIBackgroundTasks {
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
} }
nsCOMPtr<nsIBackgroundTasksManager> manager = // For now, do nothing.
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);
return NS_OK; return NS_OK;
} }

View file

@ -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;
},
};

View file

@ -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);

View file

@ -22,31 +22,8 @@ XPCOM_MANIFESTS += [
XPIDL_SOURCES += [ XPIDL_SOURCES += [
"nsIBackgroundTasks.idl", "nsIBackgroundTasks.idl",
"nsIBackgroundTasksManager.idl",
] ]
XPIDL_MODULE = "toolkit_backgroundtasks" 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"] 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",
]

View file

@ -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);
};

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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));
}

View file

@ -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.

View file

@ -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);
});

View file

@ -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 <path to test>
*
* 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);
}
}
}
}
});

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);
});

View file

@ -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);
});

View file

@ -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);
});

View file

@ -4,6 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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() { add_task(async function test_manifest_with_backgroundtask() {
let bts = Cc["@mozilla.org/backgroundtasks;1"].getService( let bts = Cc["@mozilla.org/backgroundtasks;1"].getService(
Ci.nsIBackgroundTasks Ci.nsIBackgroundTasks

View file

@ -4,6 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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() { add_task(async function test_without_backgroundtask() {
let bts = Cc["@mozilla.org/backgroundtasks;1"].getService( let bts = Cc["@mozilla.org/backgroundtasks;1"].getService(
Ci.nsIBackgroundTasks Ci.nsIBackgroundTasks

View file

@ -3,14 +3,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
[DEFAULT] [DEFAULT]
firefox-appdir = browser
skip-if = toolkit == 'android' skip-if = toolkit == 'android'
head = head.js
support-files = support-files =
CatBackgroundTaskRegistrationComponents.manifest CatBackgroundTaskRegistrationComponents.manifest
[test_backgroundtask_exitcodes.js]
[test_backgroundtask_policies.js]
[test_backgroundtask_specific_pref.js]
[test_manifest_with_backgroundtask.js] [test_manifest_with_backgroundtask.js]
[test_manifest_without_backgroundtask.js] [test_manifest_without_backgroundtask.js]

View file

@ -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. // Import binary APIs via js-ctypes.
var { CrashTestUtils } = ChromeUtils.import( var { CrashTestUtils } = ChromeUtils.import(
"resource://test/CrashTestUtils.jsm" "resource://test/CrashTestUtils.jsm"

View file

@ -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
);
});

View file

@ -39,8 +39,6 @@ skip-if = (os != 'win' && os != 'linux') || (os=='linux' && bits==32)
[test_event_files.js] [test_event_files.js]
[test_crash_terminator.js] [test_crash_terminator.js]
[test_crash_backgroundtask_moz_crash.js]
[test_crash_heap_corruption.js] [test_crash_heap_corruption.js]
skip-if = os != 'win' skip-if = os != 'win'

View file

@ -285,6 +285,3 @@ if CONFIG["MOZ_IPDL_TESTS"]:
if CONFIG["ENABLE_TESTS"]: if CONFIG["ENABLE_TESTS"]:
DIRS += ["test/gtest"] DIRS += ["test/gtest"]
if CONFIG["MOZ_BACKGROUNDTASKS"]:
DEFINES["MOZ_BACKGROUNDTASKS"] = True

View file

@ -248,12 +248,6 @@
# include "nsIPK11Token.h" # include "nsIPK11Token.h"
#endif #endif
#ifdef MOZ_BACKGROUNDTASKS
# include "mozilla/BackgroundTasks.h"
# include "nsIPowerManagerService.h"
# include "nsIStringBundle.h"
#endif
extern uint32_t gRestartMode; extern uint32_t gRestartMode;
extern void InstallSignalHandlers(const char* ProgramName); extern void InstallSignalHandlers(const char* ProgramName);
@ -2281,15 +2275,6 @@ class ReturnAbortOnError {
} // namespace } // namespace
static nsresult ProfileMissingDialog(nsINativeAppSupport* aNative) { 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; nsresult rv;
ScopedXPCOMStartup xpcom; ScopedXPCOMStartup xpcom;
@ -3476,26 +3461,10 @@ int XREMain::XRE_mainInit(bool* aExitFlag) {
DisableAppNap(); DisableAppNap();
#endif #endif
#ifdef MOZ_BACKGROUNDTASKS
Maybe<nsCString> 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 #ifndef ANDROID
if (PR_GetEnv("MOZ_RUN_GTEST") if (PR_GetEnv("MOZ_RUN_GTEST")
# ifdef FUZZING # ifdef FUZZING
|| PR_GetEnv("FUZZER") || PR_GetEnv("FUZZER")
# endif
# ifdef MOZ_BACKGROUNDTASKS
|| BackgroundTasks::IsBackgroundTaskMode()
# endif # endif
) { ) {
// Enable headless mode and assert that it worked, since gfxPlatform // Enable headless mode and assert that it worked, since gfxPlatform
@ -3843,11 +3812,6 @@ int XREMain::XRE_mainInit(bool* aExitFlag) {
if (!safeModeRequested) { if (!safeModeRequested) {
return 1; return 1;
} }
#ifdef MOZ_BACKGROUNDTASKS
if (BackgroundTasks::IsBackgroundTaskMode()) {
safeModeRequested = Some(false);
}
#endif
gSafeMode = safeModeRequested.value(); gSafeMode = safeModeRequested.value();
@ -4433,19 +4397,6 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) {
return 1; return 1;
} }
#ifdef MOZ_BACKGROUNDTASKS
if (BackgroundTasks::IsBackgroundTaskMode()) {
nsCOMPtr<nsIFile> 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; bool wasDefaultSelection;
nsCOMPtr<nsIToolkitProfile> profile; nsCOMPtr<nsIToolkitProfile> profile;
rv = SelectProfile(mProfileSvc, mNativeApp, getter_AddRefs(mProfD), 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 // We need the appStartup pointer to span multiple scopes, so we declare
// it here. // it here.
nsCOMPtr<nsIAppStartup> appStartup; nsCOMPtr<nsIAppStartup> appStartup;
// Ditto with the command line.
nsCOMPtr<nsICommandLineRunner> cmdLine;
{ {
#ifdef XP_MACOSX #ifdef XP_MACOSX
// In this scope, create an autorelease pool that will leave scope with // In this scope, create an autorelease pool that will leave scope with
@ -5011,6 +4959,8 @@ nsresult XREMain::XRE_mainRun() {
appStartup->GetShuttingDown(&mShuttingDown); appStartup->GetShuttingDown(&mShuttingDown);
nsCOMPtr<nsICommandLineRunner> cmdLine;
nsCOMPtr<nsIFile> workingDir; nsCOMPtr<nsIFile> workingDir;
rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR, rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR,
getter_AddRefs(workingDir)); getter_AddRefs(workingDir));
@ -5067,13 +5017,6 @@ nsresult XREMain::XRE_mainRun() {
Preferences::GetBool("toolkit.lazyHiddenWindow", false); Preferences::GetBool("toolkit.lazyHiddenWindow", false);
#endif #endif
#ifdef MOZ_BACKGROUNDTASKS
if (BackgroundTasks::IsBackgroundTaskMode()) {
// Background tasks aren't going to load a chrome XUL document.
lazyHiddenWindow = true;
}
#endif
if (!lazyHiddenWindow) { if (!lazyHiddenWindow) {
rv = appStartup->CreateHiddenWindow(); rv = appStartup->CreateHiddenWindow();
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
@ -5089,17 +5032,10 @@ nsresult XREMain::XRE_mainRun() {
SetupLauncherProcessPref(); SetupLauncherProcessPref();
# endif // defined(MOZ_LAUNCHER_PROCESS) # endif // defined(MOZ_LAUNCHER_PROCESS)
# if defined(MOZ_DEFAULT_BROWSER_AGENT) # if defined(MOZ_DEFAULT_BROWSER_AGENT)
# if defined(MOZ_BACKGROUNDTASKS) Preferences::RegisterCallbackAndCall(&OnDefaultAgentTelemetryPrefChanged,
// 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); kPrefHealthReportUploadEnabled);
Preferences::RegisterCallbackAndCall( Preferences::RegisterCallbackAndCall(&OnDefaultAgentTelemetryPrefChanged,
&OnDefaultAgentTelemetryPrefChanged, kPrefDefaultAgentEnabled); kPrefDefaultAgentEnabled);
Preferences::RegisterCallbackAndCall( Preferences::RegisterCallbackAndCall(
&OnDefaultAgentRemoteSettingsPrefChanged, &OnDefaultAgentRemoteSettingsPrefChanged,
@ -5108,7 +5044,6 @@ nsresult XREMain::XRE_mainRun() {
&OnDefaultAgentRemoteSettingsPrefChanged, &OnDefaultAgentRemoteSettingsPrefChanged,
kPrefSecurityContentSignatureRootHash); kPrefSecurityContentSignatureRootHash);
SetDefaultAgentLastRunTime(); SetDefaultAgentLastRunTime();
}
# endif // defined(MOZ_DEFAULT_BROWSER_AGENT) # endif // defined(MOZ_DEFAULT_BROWSER_AGENT)
#endif #endif
@ -5220,30 +5155,6 @@ nsresult XREMain::XRE_mainRun() {
mProfileSvc->CompleteStartup(); 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<nsIPowerManagerService> powerManagerService =
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
nsCOMPtr<nsIStringBundleService> stringBundleService =
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
rv = BackgroundTasks::RunBackgroundTask(cmdLine);
NS_ENSURE_SUCCESS(rv, rv);
}
#endif
{ {
rv = appStartup->Run(); rv = appStartup->Run();
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
@ -5465,10 +5376,6 @@ int XREMain::XRE_main(int argc, char* argv[], const BootstrapConfig& aConfig) {
mProfileLock->Unlock(); mProfileLock->Unlock();
gProfileLock = nullptr; gProfileLock = nullptr;
#ifdef MOZ_BACKGROUNDTASKS
BackgroundTasks::Shutdown();
#endif
gLastAppVersion.Truncate(); gLastAppVersion.Truncate();
gLastAppBuildID.Truncate(); gLastAppBuildID.Truncate();

View file

@ -39,9 +39,6 @@
#include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/ScriptSettings.h"
#include "mozilla/AutoRestore.h" #include "mozilla/AutoRestore.h"
#ifdef MOZ_BACKGROUNDTASKS
# include "mozilla/BackgroundTasks.h"
#endif
#include "mozilla/Components.h" #include "mozilla/Components.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
#include "mozilla/Omnijar.h" #include "mozilla/Omnijar.h"
@ -853,10 +850,6 @@ static nsresult DeleteDirIfExists(nsIFile* dir) {
static const char* const kAppendPrefDir[] = {"defaults", "preferences", static const char* const kAppendPrefDir[] = {"defaults", "preferences",
nullptr}; nullptr};
#ifdef MOZ_BACKGROUNDTASKS
static const char* const kAppendBackgroundTasksPrefDir[] = {
"defaults", "backgroundtasks", nullptr};
#endif
nsresult nsXREDirProvider::GetFilesInternal(const char* aProperty, nsresult nsXREDirProvider::GetFilesInternal(const char* aProperty,
nsISimpleEnumerator** aResult) { nsISimpleEnumerator** aResult) {
@ -867,12 +860,6 @@ nsresult nsXREDirProvider::GetFilesInternal(const char* aProperty,
nsCOMArray<nsIFile> directories; nsCOMArray<nsIFile> directories;
LoadDirIntoArray(mXULAppDir, kAppendPrefDir, 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)); rv = NS_NewArrayEnumerator(aResult, directories, NS_GET_IID(nsIFile));
} else if (!strcmp(aProperty, NS_APP_CHROME_DIR_LIST)) { } else if (!strcmp(aProperty, NS_APP_CHROME_DIR_LIST)) {
@ -979,13 +966,6 @@ nsXREDirProvider::DoStartup() {
mozilla::SandboxBroker::GeckoDependentInitialize(); mozilla::SandboxBroker::GeckoDependentInitialize();
#endif #endif
bool initExtensionManager =
#ifdef MOZ_BACKGROUNDTASKS
!mozilla::BackgroundTasks::IsBackgroundTaskMode();
#else
true;
#endif
if (initExtensionManager) {
// Init the Extension Manager // Init the Extension Manager
nsCOMPtr<nsIObserver> em = nsCOMPtr<nsIObserver> em =
do_GetService("@mozilla.org/addons/integration;1"); do_GetService("@mozilla.org/addons/integration;1");
@ -994,7 +974,6 @@ nsXREDirProvider::DoStartup() {
} else { } else {
NS_WARNING("Failed to create Addons Manager."); NS_WARNING("Failed to create Addons Manager.");
} }
}
obsSvc->NotifyObservers(nullptr, "profile-after-change", kStartup); obsSvc->NotifyObservers(nullptr, "profile-after-change", kStartup);