services/common/tests/run_server.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 #!/usr/bin/python
     3 # This Source Code Form is subject to the terms of the Mozilla Public
     4 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
     5 # You can obtain one at http://mozilla.org/MPL/2.0/.
     7 from argparse import ArgumentParser
     8 from shutil import rmtree
     9 from subprocess import Popen
    10 from sys import argv
    11 from sys import exit
    12 from tempfile import mkdtemp
    14 DEFAULT_PORT = 8080
    15 DEFAULT_HOSTNAME = 'localhost'
    17 def run_server(srcdir, objdir, js_file, hostname=DEFAULT_HOSTNAME,
    18         port=DEFAULT_PORT):
    20     dist_dir = '%s/dist' % objdir
    21     head_dir = '%s/services/common/tests/unit' % srcdir
    23     head_paths = [
    24         'head_global.js',
    25         'head_helpers.js',
    26         'head_http.js',
    27     ]
    29     head_paths = ['"%s/%s"' % (head_dir, path) for path in head_paths]
    31     args = [
    32         '%s/bin/xpcshell' % dist_dir,
    33         '-g', '%s/bin' % dist_dir,
    34         '-a', '%s/bin' % dist_dir,
    35         '-r', '%s/bin/components/httpd.manifest' % dist_dir,
    36         '-m',
    37         '-n',
    38         '-s',
    39         '-f', '%s/testing/xpcshell/head.js' % srcdir,
    40         '-e', 'const _SERVER_ADDR = "%s";' % hostname,
    41         '-e', 'const _TESTING_MODULES_DIR = "%s/_tests/modules";' % objdir,
    42         '-e', 'const SERVER_PORT = "%s";' % port,
    43         '-e', 'const INCLUDE_FILES = [%s];' % ', '.join(head_paths),
    44         '-e', '_register_protocol_handlers();',
    45         '-e', 'for each (let name in INCLUDE_FILES) load(name);',
    46         '-e', '_fakeIdleService.activate();',
    47         '-f', '%s/services/common/tests/%s' % (srcdir, js_file)
    48     ]
    50     profile_dir = mkdtemp()
    51     print 'Created profile directory: %s' % profile_dir
    53     try:
    54         env = {'XPCSHELL_TEST_PROFILE_DIR': profile_dir}
    55         proc = Popen(args, env=env)
    57         return proc.wait()
    59     finally:
    60         print 'Removing profile directory %s' % profile_dir
    61         rmtree(profile_dir)
    63 if __name__ == '__main__':
    64     parser = ArgumentParser(description="Run a standalone JS server.")
    65     parser.add_argument('srcdir',
    66         help="Root directory of Firefox source code.")
    67     parser.add_argument('objdir',
    68         help="Root directory object directory created during build.")
    69     parser.add_argument('js_file',
    70         help="JS file (in this directory) to execute.")
    71     parser.add_argument('--port', default=DEFAULT_PORT, type=int,
    72         help="Port to run server on.")
    73     parser.add_argument('--address', default=DEFAULT_HOSTNAME,
    74         help="Hostname to bind server to.")
    76     args = parser.parse_args()
    78     exit(run_server(args.srcdir, args.objdir, args.js_file, args.address,
    79         args.port))

mercurial