# HG changeset patch # User RĂ©mi Cardona # Date 1406914124 -7200 # Node ID 3905682ece112fce77d674e38c1786e36d4efa97 # Parent 3e7f1e9f3adc5926cafee804e98e5a4d730b1c5a [devtools] Fix Firefox launcher in QUnitTestCase (closes #4294727) The main changes are: - stop creating the profile, firefox will create it - point firefox to a profile directory instead of giving it a profile name (this has the added bonus of not polluting the user's profile list) - start firefox once and kill it 5 seconds later to let it finish its profile creation (along with system-wide extensions setup) diff -r 3e7f1e9f3adc -r 3905682ece11 devtools/qunit.py --- a/devtools/qunit.py Thu Sep 25 17:38:51 2014 +0200 +++ b/devtools/qunit.py Fri Aug 01 19:28:44 2014 +0200 @@ -62,34 +62,18 @@ def __init__(self, url=None): self._process = None - self._tmp_dir = mkdtemp(prefix='cwtest-ffxprof-') - self._profile_data = {'uid': uuid4()} - self._profile_name = self.profile_name_mask % self._profile_data - stdout = TemporaryFile() - stderr = TemporaryFile() + self._profile_dir = mkdtemp(prefix='cwtest-ffxprof-') self.firefox_cmd = ['firefox', '-no-remote'] if os.name == 'posix': self.firefox_cmd = [osp.join(osp.dirname(__file__), 'data', 'xvfb-run.sh'), '-a', '-s', '-noreset -screen 0 640x480x8'] + self.firefox_cmd - try: - home = osp.expanduser('~') - user = getlogin() - assert os.access(home, os.W_OK), \ - 'No write access to your home directory, Firefox will crash.'\ - ' Are you sure "%s" is a valid home for user "%s"' % (home, user) - check_call(self.firefox_cmd + ['-CreateProfile', - '%s %s' % (self._profile_name, self._tmp_dir)], - stdout=stdout, stderr=stderr) - except CalledProcessError as cpe: - stdout.seek(0) - stderr.seek(0) - raise VerboseCalledProcessError(cpe.returncode, cpe.cmd, stdout.read(), stderr.read()) def start(self, url): self.stop() - fnull = open(os.devnull, 'w') - self._process = Popen(self.firefox_cmd + ['-P', self._profile_name, url], - stdout=fnull, stderr=fnull) + cmd = self.firefox_cmd + ['-silent', '--profile', self._profile_dir, + '-url', url] + with open(os.devnull, 'w') as fnull: + self._process = Popen(cmd, stdout=fnull, stderr=fnull) def stop(self): if self._process is not None: @@ -100,7 +84,7 @@ def __del__(self): self.stop() - rmtree(self._tmp_dir) + rmtree(self._profile_dir) class QUnitTestCase(CubicWebServerTC): @@ -169,6 +153,12 @@ self.test_queue.get(False) browser = FirefoxHelper() + # start firefox once to let it init the profile (and run system-wide + # add-ons post setup, blegh), and then kill it ... + browser.start('about:blank') + import time; time.sleep(5) + browser.stop() + # ... then actually run the test file browser.start(html_test_file.name) test_count = 0 error = False