diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/marionette/harness/marionette_harness/runner/mixins/browsermob.py | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/marionette/harness/marionette_harness/runner/mixins/browsermob.py')
-rw-r--r-- | testing/marionette/harness/marionette_harness/runner/mixins/browsermob.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/testing/marionette/harness/marionette_harness/runner/mixins/browsermob.py b/testing/marionette/harness/marionette_harness/runner/mixins/browsermob.py new file mode 100644 index 000000000..e4c3cb545 --- /dev/null +++ b/testing/marionette/harness/marionette_harness/runner/mixins/browsermob.py @@ -0,0 +1,80 @@ +# 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/. + +import os + +from browsermobproxy import Server +from marionette_harness import MarionetteTestCase + + +class BrowserMobProxyArguments(object): + name = 'Browsermob Proxy' + args = [ + [['--browsermob-script'], + {'help': 'path to the browsermob-proxy shell script or batch file', + }], + [['--browsermob-port'], + {'type': int, + 'help': 'port to run the browsermob proxy on', + }], + ] + + def verify_usage_handler(self, args): + if args.browsermob_script is not None: + if not os.path.exists(args.browsermob_script): + raise ValueError('{} not found'.format(args.browsermob_script)) + + +class BrowserMobProxyTestCaseMixin(object): + + def __init__(self, *args, **kwargs): + self.browsermob_server = None + self.browsermob_port = kwargs.pop('browsermob_port') + self.browsermob_script = kwargs.pop('browsermob_script') + + def setUp(self): + options = {} + if self.browsermob_port: + options['port'] = self.browsermob_port + if not self.browsermob_script: + raise ValueError('Must specify --browsermob-script in order to ' + 'run browsermobproxy tests') + self.browsermob_server = Server( + self.browsermob_script, options=options) + self.browsermob_server.start() + + def create_browsermob_proxy(self): + client = self.browsermob_server.create_proxy() + with self.marionette.using_context('chrome'): + self.marionette.execute_script(""" + Components.utils.import("resource://gre/modules/Preferences.jsm"); + Preferences.set("network.proxy.type", 1); + Preferences.set("network.proxy.http", "localhost"); + Preferences.set("network.proxy.http_port", {port}); + Preferences.set("network.proxy.ssl", "localhost"); + Preferences.set("network.proxy.ssl_port", {port}); + """.format(port=client.port)) + return client + + def tearDown(self): + if self.browsermob_server: + self.browsermob_server.stop() + self.browsermob_server = None + + __del__ = tearDown + + +class BrowserMobTestCase(MarionetteTestCase, BrowserMobProxyTestCaseMixin): + + def __init__(self, *args, **kwargs): + MarionetteTestCase.__init__(self, *args, **kwargs) + BrowserMobProxyTestCaseMixin.__init__(self, *args, **kwargs) + + def setUp(self): + MarionetteTestCase.setUp(self) + BrowserMobProxyTestCaseMixin.setUp(self) + + def tearDown(self): + BrowserMobProxyTestCaseMixin.tearDown(self) + MarionetteTestCase.tearDown(self) |