def test_server_locations_callback(self): class CallbackTest(object): last_locations = None def callback(self, locations): self.last_locations = locations c = CallbackTest() f = self.create_temp_file(self.locations) locations = ServerLocations(f.name, c.callback) # callback should be for all locations in file self.assertEqual(len(c.last_locations), 6) # validate arbitrary one self.compare_location(c.last_locations[2], 'http', '127.0.0.1', '8888', ['privileged']) locations.add_host('a.b.c') # callback should be just for one location self.assertEqual(len(c.last_locations), 1) self.compare_location(c.last_locations[0], 'http', 'a.b.c', '80', ['privileged']) # read a second file, which should generate a callback with both # locations. f = self.create_temp_file(self.locations_no_primary) locations.read(f.name) self.assertEqual(len(c.last_locations), 2)
def test_server_locations_callback(create_temp_file): class CallbackTest(object): last_locations = None def callback(self, locations): self.last_locations = locations c = CallbackTest() f = create_temp_file(LOCATIONS) locations = ServerLocations(f, c.callback) # callback should be for all locations in file assert len(c.last_locations) == 6 # validate arbitrary one compare_location(c.last_locations[2], 'http', '127.0.0.1', '8888', ['privileged']) locations.add_host('a.b.c') # callback should be just for one location assert len(c.last_locations) == 1 compare_location(c.last_locations[0], 'http', 'a.b.c', '80', ['privileged']) # read a second file, which should generate a callback with both # locations. f = create_temp_file(LOCATIONS_NO_PRIMARY) locations.read(f) assert len(c.last_locations) == 2
def test_server_locations_callback(self): class CallbackTest(object): last_locations = None def callback(self, locations): self.last_locations = locations c = CallbackTest() f = self.create_temp_file(self.locations) locations = ServerLocations(f.name, c.callback) # callback should be for all locations in file self.assertEqual(len(c.last_locations), 6) # validate arbitrary one self.compare_location(c.last_locations[2], 'http', '127.0.0.1', '8888', ['privileged']) locations.add_host('a.b.c') # callback should be just for one location self.assertEqual(len(c.last_locations), 1) self.compare_location(c.last_locations[0], 'http', 'a.b.c', '80', ['privileged']) # read a second file, which should generate a callback with both # locations. f = self.create_temp_file(self.locations_no_primary) locations.read(f.name) self.assertEqual(len(c.last_locations), 2)
def __init__(self, options, **kwargs): self.options = options self.server = None self.logger = mozlog.getLogger('PEP') # create the profile enable_proxy = False locations = ServerLocations() if self.options.proxyLocations: if not self.options.serverPath: self.logger.warning('Can\'t set up proxy without server path') else: enable_proxy = True for proxyLocation in self.options.proxyLocations: locations.read(proxyLocation, False) locations.add_host(host='127.0.0.1', port=self.options.serverPort, options='primary,privileged') self.profile = self.profile_class( profile=self.options.profilePath, addons=[os.path.join(here, 'extension')], locations=locations, proxy=enable_proxy) # fork a server to serve the test related files if self.options.serverPath: self.runServer() tests = [] # TODO is there a better way of doing this? if self.options.testPath.endswith('.js'): # a single test file was passed in testObj = {} testObj['path'] = os.path.realpath(self.options.testPath) testObj['name'] = os.path.basename(self.options.testPath) testObj['here'] = os.path.dirname(testObj['path']) tests.append(testObj) else: # a test manifest was passed in # open and convert the manifest to json manifest = TestManifest() manifest.read(self.options.testPath) tests = manifest.get() # create a manifest object to be read by the JS side manifestObj = {} manifestObj['tests'] = tests manifestObj['options'] = options.__dict__ # write manifest to a JSON file jsonManifest = open(os.path.join(here, 'manifest.json'), 'w') jsonManifest.write(json.dumps(manifestObj)) jsonManifest.close() # setup environment env = os.environ.copy() env['MOZ_INSTRUMENT_EVENT_LOOP'] = '1' env['MOZ_INSTRUMENT_EVENT_LOOP_THRESHOLD'] = str( options.tracerThreshold) env['MOZ_INSTRUMENT_EVENT_LOOP_INTERVAL'] = str(options.tracerInterval) env['MOZ_CRASHREPORTER_NO_REPORT'] = '1' # construct the browser arguments cmdargs = [] # TODO Make browserArgs a list cmdargs.extend(self.options.browserArgs) cmdargs.extend(['-pep-start', os.path.realpath(jsonManifest.name)]) # run with managed process handler self.runner = self.runner_class(profile=self.profile, binary=self.options.binary, cmdargs=cmdargs, env=env, process_class=PepProcess)
def __init__(self, options, **kwargs): self.options = options self.server = None self.logger = mozlog.getLogger('PEP') # create the profile enable_proxy = False locations = ServerLocations() if self.options.proxyLocations: if not self.options.serverPath: self.logger.warning('Can\'t set up proxy without server path') else: enable_proxy = True for proxyLocation in self.options.proxyLocations: locations.read(proxyLocation, False) locations.add_host(host='127.0.0.1', port=self.options.serverPort, options='primary,privileged') self.profile = self.profile_class(profile=self.options.profilePath, addons=[os.path.join(here, 'extension')], locations=locations, proxy=enable_proxy) # fork a server to serve the test related files if self.options.serverPath: self.runServer() tests = [] # TODO is there a better way of doing this? if self.options.testPath.endswith('.js'): # a single test file was passed in testObj = {} testObj['path'] = os.path.realpath(self.options.testPath) testObj['name'] = os.path.basename(self.options.testPath) testObj['here'] = os.path.dirname(testObj['path']) tests.append(testObj) else: # a test manifest was passed in # open and convert the manifest to json manifest = TestManifest() manifest.read(self.options.testPath) tests = manifest.get() # create a manifest object to be read by the JS side manifestObj = {} manifestObj['tests'] = tests manifestObj['options'] = options.__dict__ # write manifest to a JSON file jsonManifest = open(os.path.join(here, 'manifest.json'), 'w') jsonManifest.write(json.dumps(manifestObj)) jsonManifest.close() # setup environment env = os.environ.copy() env['MOZ_INSTRUMENT_EVENT_LOOP'] = '1' env['MOZ_INSTRUMENT_EVENT_LOOP_THRESHOLD'] = str(options.tracerThreshold) env['MOZ_INSTRUMENT_EVENT_LOOP_INTERVAL'] = str(options.tracerInterval) env['MOZ_CRASHREPORTER_NO_REPORT'] = '1' # construct the browser arguments cmdargs = [] # TODO Make browserArgs a list cmdargs.extend(self.options.browserArgs) cmdargs.extend(['-pep-start', os.path.realpath(jsonManifest.name)]) # run with managed process handler self.runner = self.runner_class(profile=self.profile, binary=self.options.binary, cmdargs=cmdargs, env=env, process_class=PepProcess)
def __init__(self, options, **kwargs): self.options = options self.server = None self.logger = mozlog.getLogger("PEP") # create the profile enable_proxy = False locations = ServerLocations() if self.options.proxyLocations: if not self.options.serverPath: self.logger.warning("Can't set up proxy without server path") else: enable_proxy = True locations.read(self.options.proxyLocations, False) locations.add_host(host="127.0.0.1", port=self.options.serverPort, options="primary,privileged") self.profile = self.profile_class( profile=self.options.profilePath, addons=[os.path.join(here, "extension")], locations=locations, proxy=enable_proxy, ) # fork a server to serve the test related files if self.options.serverPath: self.runServer() tests = [] # TODO is there a better way of doing this? if self.options.testPath.endswith(".js"): # a single test file was passed in testObj = {} testObj["path"] = os.path.realpath(self.options.testPath) testObj["name"] = os.path.basename(self.options.testPath) testObj["here"] = os.path.dirname(testObj["path"]) tests.append(testObj) else: # a test manifest was passed in # open and convert the manifest to json manifest = TestManifest() manifest.read(self.options.testPath) tests = manifest.get() # create a manifest object to be read by the JS side manifestObj = {} manifestObj["tests"] = tests manifestObj["options"] = options.__dict__ # write manifest to a JSON file jsonManifest = open(os.path.join(here, "manifest.json"), "w") jsonManifest.write(json.dumps(manifestObj)) jsonManifest.close() # setup environment env = os.environ.copy() env["MOZ_INSTRUMENT_EVENT_LOOP"] = "1" env["MOZ_INSTRUMENT_EVENT_LOOP_THRESHOLD"] = str(options.tracerThreshold) env["MOZ_INSTRUMENT_EVENT_LOOP_INTERVAL"] = str(options.tracerInterval) env["MOZ_CRASHREPORTER_NO_REPORT"] = "1" # construct the browser arguments cmdargs = [] # TODO Make browserArgs a list cmdargs.extend(self.options.browserArgs) cmdargs.extend(["-pep-start", os.path.realpath(jsonManifest.name)]) # run with managed process handler self.runner = self.runner_class( profile=self.profile, binary=self.options.binary, cmdargs=cmdargs, env=env, process_class=PepProcess )