forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1667276 - Part 3: Load a custom prefs file when running a backgro…
…und task. r=mossop,KrisWright There are some complications here to handle unpackaged and packaged builds. In addition, there could be a difference between App prefs and GRE prefs. Since the underlying backgroundtasks code is built as part of Gecko (i.e., `toolkit/...` rather than `browser/...`) I have favoured GRE prefs. I think, however, that what is written will work for App-specific prefs, but I'm not concerned with that detail at this time. This also add tests for backgroundtask-specific prefs, which are structured as both xpcshell and mochitest-chrome tests because locally, the former tests unpackaged builds and the latter can accommodate testing packaged builds. We could use mochitest-chrome for both, but this has been pleasant to work with locally. Differential Revision: https://phabricator.services.mozilla.com/D97510
- Loading branch information
Showing
15 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
toolkit/components/backgroundtasks/defaults/backgroundtasks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
toolkit/components/backgroundtasks/tests/BackgroundTask_backgroundtask_specific_pref.jsm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* -*- 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 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] |
23 changes: 23 additions & 0 deletions
23
toolkit/components/backgroundtasks/tests/browser/browser_backgroundtask_specific_pref.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* -*- 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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* -*- 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; | ||
} |
20 changes: 20 additions & 0 deletions
20
toolkit/components/backgroundtasks/tests/xpcshell/test_backgroundtask_specific_pref.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* -*- 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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters