2013-05-28 12:33:57 -07:00
|
|
|
#!/usr/bin/python
|
2008-02-21 13:08:39 -08:00
|
|
|
#
|
2012-05-21 04:12:37 -07:00
|
|
|
# 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/.
|
2008-02-21 13:08:39 -08:00
|
|
|
|
2013-05-28 12:33:57 -07:00
|
|
|
from mozprofile import FirefoxProfile, Profile, Preferences
|
|
|
|
from mozprofile.permissions import ServerLocations
|
|
|
|
from mozrunner import FirefoxRunner, CLI
|
|
|
|
from mozhttpd import MozHttpd
|
|
|
|
import json
|
2008-02-21 13:08:39 -08:00
|
|
|
import socket
|
|
|
|
import threading
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import shutil
|
2013-05-28 12:33:57 -07:00
|
|
|
import tempfile
|
2008-02-21 13:08:39 -08:00
|
|
|
from datetime import datetime
|
2013-05-28 12:33:57 -07:00
|
|
|
from mozbuild.base import MozbuildObject
|
2008-02-21 13:08:39 -08:00
|
|
|
|
|
|
|
PORT = 8888
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2013-05-28 12:33:57 -07:00
|
|
|
cli = CLI()
|
|
|
|
debug_args, interactive = cli.debugger_arguments()
|
|
|
|
|
|
|
|
build = MozbuildObject.from_environment()
|
|
|
|
httpd = MozHttpd(port=PORT,
|
|
|
|
docroot=os.path.join(build.topsrcdir, "build", "pgo"))
|
|
|
|
httpd.start(block=False)
|
|
|
|
|
|
|
|
locations = ServerLocations()
|
|
|
|
locations.add_host(host='127.0.0.1',
|
|
|
|
port=PORT,
|
|
|
|
options='primary,privileged')
|
|
|
|
|
|
|
|
#TODO: mozfile.TemporaryDirectory
|
|
|
|
profilePath = tempfile.mkdtemp()
|
|
|
|
try:
|
|
|
|
#TODO: refactor this into mozprofile
|
|
|
|
prefpath = os.path.join(build.topsrcdir, "testing", "profiles", "prefs_general.js")
|
|
|
|
prefs = {}
|
|
|
|
prefs.update(Preferences.read_prefs(prefpath))
|
|
|
|
interpolation = { "server": "%s:%d" % httpd.httpd.server_address,
|
|
|
|
"OOP": "false"}
|
|
|
|
prefs = json.loads(json.dumps(prefs) % interpolation)
|
|
|
|
for pref in prefs:
|
|
|
|
prefs[pref] = Preferences.cast(prefs[pref])
|
|
|
|
profile = FirefoxProfile(profile=profilePath,
|
|
|
|
preferences=prefs,
|
2011-05-26 06:07:35 -07:00
|
|
|
addons=[os.path.join(build.distdir, 'xpi-stage', 'quitter')],
|
2013-05-28 12:33:57 -07:00
|
|
|
locations=locations)
|
|
|
|
|
|
|
|
env = os.environ.copy()
|
|
|
|
env["MOZ_CRASHREPORTER_NO_REPORT"] = "1"
|
|
|
|
env["XPCOM_DEBUG_BREAK"] = "warn"
|
|
|
|
jarlog = os.getenv("JARLOG_FILE")
|
|
|
|
if jarlog:
|
|
|
|
env["MOZ_JAR_LOG_FILE"] = os.path.abspath(jarlog)
|
|
|
|
print "jarlog: %s" % env["MOZ_JAR_LOG_FILE"]
|
|
|
|
|
|
|
|
cmdargs = ["http://localhost:%d/index.html" % PORT]
|
|
|
|
runner = FirefoxRunner(profile=profile,
|
|
|
|
binary=build.get_binary_path(where="staged-package"),
|
|
|
|
cmdargs=cmdargs,
|
|
|
|
env=env)
|
|
|
|
runner.start(debug_args=debug_args, interactive=interactive)
|
2013-12-12 14:08:40 -08:00
|
|
|
status = runner.wait()
|
2013-05-28 12:33:57 -07:00
|
|
|
httpd.stop()
|
2013-12-12 14:08:40 -08:00
|
|
|
if status != 0:
|
|
|
|
status = 1 # normalize status, in case it's larger than 127
|
|
|
|
|
|
|
|
# Note: the |finally| block below will always run.
|
|
|
|
# http://docs.python.org/2/library/sys.html#sys.exit says that sys.exit "is
|
|
|
|
# implemented by raising the SystemExit exception, so cleanup actions
|
|
|
|
# specified by finally clauses of try statements are honored".
|
|
|
|
sys.exit(status)
|
2013-05-28 12:33:57 -07:00
|
|
|
finally:
|
|
|
|
shutil.rmtree(profilePath)
|