mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 21:05:36 +00:00
Bug 1460914 - [xpcshell] Use nsIPrefService.readUserPrefsFromFile to set prefs, r=ted
This uses nsIPrefService.readUserPrefsFromFile to set preferences from a user.js passed in via the python harness. This allows us to use the profiles under testing/profiles like all the other harnesses and will make setting prefs in xpcshell easier to use and understand. Differential Revision: https://phabricator.services.mozilla.com/D9716 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
16a9c62bba
commit
2dfc1e580d
@ -539,6 +539,12 @@ ARCHIVE_FILES = {
|
||||
'pattern': 'automation.py',
|
||||
'dest': 'xpcshell',
|
||||
},
|
||||
{
|
||||
'source': buildconfig.topsrcdir,
|
||||
'base': 'testing/profiles',
|
||||
'pattern': '**',
|
||||
'dest': 'xpcshell/profile_data',
|
||||
},
|
||||
],
|
||||
'updater-dep': [
|
||||
{
|
||||
|
@ -121,6 +121,9 @@ class BaseProfile(object):
|
||||
self.set_preferences(prefs, filename=basename)
|
||||
|
||||
extension_dir = os.path.join(other, 'extensions')
|
||||
if not os.path.isdir(extension_dir):
|
||||
return
|
||||
|
||||
for basename in os.listdir(extension_dir):
|
||||
path = os.path.join(extension_dir, basename)
|
||||
|
||||
|
@ -5,5 +5,6 @@
|
||||
"reftest": ["common", "reftest"],
|
||||
"talos": ["common", "perf"],
|
||||
"valgrind": ["common", "unittest"],
|
||||
"xpcshell": ["xpcshell"],
|
||||
"web-platform-tests": ["common", "unittest", "web-platform"]
|
||||
}
|
||||
|
2
testing/profiles/xpcshell/user.js
Normal file
2
testing/profiles/xpcshell/user.js
Normal file
@ -0,0 +1,2 @@
|
||||
// Base preferences file used by the xpcshell harness
|
||||
/* globals user_pref */
|
@ -12,7 +12,8 @@
|
||||
|
||||
/* defined by the harness */
|
||||
/* globals _HEAD_FILES, _HEAD_JS_PATH, _JSDEBUGGER_PORT, _JSCOV_DIR,
|
||||
_MOZINFO_JS_PATH, _TEST_FILE, _TEST_NAME, _TESTING_MODULES_DIR:true */
|
||||
_MOZINFO_JS_PATH, _TEST_FILE, _TEST_NAME, _TESTING_MODULES_DIR:true,
|
||||
_PREFS_FILE */
|
||||
|
||||
/* defined by XPCShellImpl.cpp */
|
||||
/* globals load, sendCommand */
|
||||
@ -1479,6 +1480,11 @@ function run_next_test() {
|
||||
try {
|
||||
// Set global preferences
|
||||
if (runningInParent) {
|
||||
let prefsFile = Cc["@mozilla.org/file/local;1"]
|
||||
.createInstance(Ci.nsIFile);
|
||||
prefsFile.initWithPath(_PREFS_FILE);
|
||||
_Services.prefs.readUserPrefsFromFile(prefsFile);
|
||||
|
||||
// Always use network provider for geolocation tests
|
||||
// so we bypass the OSX dialog raised by the corelocation provider
|
||||
_Services.prefs.setBoolPref("geo.provider.testing", true);
|
||||
|
@ -348,6 +348,15 @@ class XPCShellRemote(xpcshell.XPCShellTests, object):
|
||||
self.device.chmod(remoteWrapper, root=True)
|
||||
os.remove(localWrapper)
|
||||
|
||||
def buildPrefsFile(self):
|
||||
super(XPCShellRemote, self).buildPrefsFile()
|
||||
|
||||
remotePrefsFile = posixpath.join(self.remoteTestRoot, 'user.js')
|
||||
self.device.push(self.prefsFile, remotePrefsFile)
|
||||
self.device.chmod(remotePrefsFile, root=True)
|
||||
os.remove(self.prefsFile)
|
||||
self.prefsFile = remotePrefsFile
|
||||
|
||||
def buildEnvironment(self):
|
||||
self.buildCoreEnvironment()
|
||||
self.setLD_LIBRARY_PATH()
|
||||
|
@ -76,6 +76,7 @@ from mozlog import commandline
|
||||
import mozcrash
|
||||
import mozfile
|
||||
import mozinfo
|
||||
from mozprofile import Profile
|
||||
from mozrunner.utils import get_stack_fixer_function
|
||||
|
||||
# --------------------------------------------------------------
|
||||
@ -156,6 +157,7 @@ class XPCShellTestThread(Thread):
|
||||
self.log = kwargs.get('log')
|
||||
self.app_dir_key = kwargs.get('app_dir_key')
|
||||
self.interactive = kwargs.get('interactive')
|
||||
self.prefsFile = kwargs.get('prefsFile')
|
||||
|
||||
# only one of these will be set to 1. adding them to the totals in
|
||||
# the harness
|
||||
@ -402,7 +404,6 @@ class XPCShellTestThread(Thread):
|
||||
dbgport = 0 if self.jsDebuggerInfo is None else self.jsDebuggerInfo.port
|
||||
|
||||
return [
|
||||
'-e', 'const _SERVER_ADDR = "localhost"',
|
||||
'-e', 'const _HEAD_FILES = [%s];' % cmdH,
|
||||
'-e', 'const _JSDEBUGGER_PORT = %d;' % dbgport,
|
||||
]
|
||||
@ -448,6 +449,7 @@ class XPCShellTestThread(Thread):
|
||||
'-s',
|
||||
'-e', 'const _HEAD_JS_PATH = "%s";' % self.headJSPath,
|
||||
'-e', 'const _MOZINFO_JS_PATH = "%s";' % self.mozInfoJSPath,
|
||||
'-e', 'const _PREFS_FILE = "%s";' % self.prefsFile.replace('\\', '\\\\'),
|
||||
]
|
||||
|
||||
if self.testingModulesDir:
|
||||
@ -944,6 +946,33 @@ class XPCShellTests(object):
|
||||
if self.mozInfo is None:
|
||||
self.mozInfo = os.path.join(self.testharnessdir, "mozinfo.json")
|
||||
|
||||
def buildPrefsFile(self):
|
||||
# Create the prefs.js file
|
||||
profile_data_dir = os.path.join(SCRIPT_DIR, 'profile_data')
|
||||
|
||||
# If possible, read profile data from topsrcdir. This prevents us from
|
||||
# requiring a re-build to pick up newly added extensions in the
|
||||
# <profile>/extensions directory.
|
||||
if build:
|
||||
path = os.path.join(build.topsrcdir, 'testing', 'profiles')
|
||||
if os.path.isdir(path):
|
||||
profile_data_dir = path
|
||||
|
||||
with open(os.path.join(profile_data_dir, 'profiles.json'), 'r') as fh:
|
||||
base_profiles = json.load(fh)['xpcshell']
|
||||
|
||||
# values to use when interpolating preferences
|
||||
interpolation = {
|
||||
"server": "dummyserver",
|
||||
}
|
||||
|
||||
profile = Profile(profile=self.tempDir, restore=False)
|
||||
for name in base_profiles:
|
||||
path = os.path.join(profile_data_dir, name)
|
||||
profile.merge(path, interpolation=interpolation)
|
||||
|
||||
self.prefsFile = os.path.join(profile.profile, 'user.js')
|
||||
|
||||
def buildCoreEnvironment(self):
|
||||
"""
|
||||
Add environment variables likely to be used across all platforms, including
|
||||
@ -1246,6 +1275,7 @@ class XPCShellTests(object):
|
||||
self.todoCount = 0
|
||||
|
||||
self.setAbsPath()
|
||||
self.buildPrefsFile()
|
||||
self.buildXpcsRunArgs()
|
||||
|
||||
self.event = Event()
|
||||
@ -1316,7 +1346,8 @@ class XPCShellTests(object):
|
||||
'keep_going': self.keepGoing,
|
||||
'log': self.log,
|
||||
'interactive': self.interactive,
|
||||
'app_dir_key': appDirKey
|
||||
'app_dir_key': appDirKey,
|
||||
'prefsFile': self.prefsFile,
|
||||
}
|
||||
|
||||
if self.sequential:
|
||||
|
Loading…
Reference in New Issue
Block a user