From d83f55e0703fd53a6f88999bac1ff8be8fd86bed Mon Sep 17 00:00:00 2001 From: David Burns Date: Tue, 30 May 2017 15:07:19 +0100 Subject: [PATCH] Bug 1368674 - Remove JS Test support in Marionette Harness r=maja_zf MozReview-Commit-ID: 11Zc7KL3djD --HG-- extra : rebase_source : de8274b3948abcbe0e0aa404dad9b02b87b9119f --- .../marionette_test/testcases.py | 137 +----------------- .../harness/marionette_harness/runner/base.py | 6 +- .../harness_unit/test_marionette_runner.py | 14 +- .../tests/unit/test_chrome_async_finish.js | 6 - .../tests/unit/unit-tests.ini | 1 - testing/marionette/jar.mn | 1 - 6 files changed, 12 insertions(+), 153 deletions(-) delete mode 100644 testing/marionette/harness/marionette_harness/tests/unit/test_chrome_async_finish.js diff --git a/testing/marionette/harness/marionette_harness/marionette_test/testcases.py b/testing/marionette/harness/marionette_harness/marionette_test/testcases.py index 5051e3351eeb..d4d1bfac4012 100644 --- a/testing/marionette/harness/marionette_harness/marionette_test/testcases.py +++ b/testing/marionette/harness/marionette_harness/marionette_test/testcases.py @@ -60,13 +60,6 @@ class MetaParameterized(type): return type.__new__(cls, name, bases, attrs) -class JSTest: - head_js_re = re.compile(r"MARIONETTE_HEAD_JS(\s*)=(\s*)['|\"](.*?)['|\"];") - context_re = re.compile(r"MARIONETTE_CONTEXT(\s*)=(\s*)['|\"](.*?)['|\"];") - timeout_re = re.compile(r"MARIONETTE_TIMEOUT(\s*)=(\s*)(\d+);") - inactivity_timeout_re = re.compile(r"MARIONETTE_INACTIVITY_TIMEOUT(\s*)=(\s*)(\d+);") - - class CommonTestCase(unittest.TestCase): __metaclass__ = MetaParameterized @@ -235,12 +228,9 @@ class CommonTestCase(unittest.TestCase): @property def test_name(self): - if hasattr(self, 'jsFile'): - return os.path.basename(self.jsFile) - else: - return '{0}.py {1}.{2}'.format(self.__class__.__module__, - self.__class__.__name__, - self._testMethodName) + return '{0}.py {1}.{2}'.format(self.__class__.__module__, + self.__class__.__name__, + self._testMethodName) def id(self): # TBPL starring requires that the "test name" field of a failure message @@ -298,127 +288,6 @@ if (!testUtils.hasOwnProperty("specialPowersObserver")) { } """) - def run_js_test(self, filename, marionette=None): - """Run a JavaScript test file. - - It collects its set of assertions into the current test's results. - - :param filename: The path to the JavaScript test file to execute. - May be relative to the current script. - :param marionette: The Marionette object in which to execute the test. - Defaults to self.marionette. - """ - marionette = marionette or self.marionette - if not os.path.isabs(filename): - # Find the caller's filename and make the path relative to that. - caller_file = sys._getframe(1).f_globals.get('__file__', '') - caller_file = os.path.abspath(caller_file) - filename = os.path.join(os.path.dirname(caller_file), filename) - self.assert_(os.path.exists(filename), - 'Script "{}" must exist' .format(filename)) - original_test_name = self.marionette.test_name - self.marionette.test_name = os.path.basename(filename) - f = open(filename, 'r') - js = f.read() - args = [] - - head_js = JSTest.head_js_re.search(js) - if head_js: - head_js = head_js.group(3) - head = open(os.path.join(os.path.dirname(filename), head_js), 'r') - js = head.read() + js - - context = JSTest.context_re.search(js) - if context: - context = context.group(3) - else: - context = 'content' - - if 'SpecialPowers' in js: - self.setup_SpecialPowers_observer() - - if context == 'content': - js = "var SpecialPowers = window.wrappedJSObject.SpecialPowers;\n" + js - else: - marionette.execute_script(""" - if (typeof(SpecialPowers) == 'undefined') { - let loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"] - .getService(Components.interfaces.mozIJSSubScriptLoader); - loader.loadSubScript("chrome://specialpowers/content/specialpowersAPI.js"); - loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserverAPI.js"); - loader.loadSubScript("chrome://specialpowers/content/ChromePowers.js"); - } - """) - - marionette.set_context(context) - - if context != 'chrome': - marionette.navigate('data:text/html,test page') - - timeout = JSTest.timeout_re.search(js) - if timeout: - ms = timeout.group(3) - marionette.timeout.script = int(ms) / 1000.0 - - inactivity_timeout = JSTest.inactivity_timeout_re.search(js) - if inactivity_timeout: - inactivity_timeout = int(inactivity_timeout.group(3)) - - try: - results = marionette.execute_js_script( - js, - args, - inactivity_timeout=inactivity_timeout, - filename=os.path.basename(filename) - ) - - self.assertTrue('timeout' not in filename, - 'expected timeout not triggered') - - if 'fail' in filename: - self.assertTrue(len(results['failures']) > 0, - "expected test failures didn't occur") - else: - for failure in results['failures']: - diag = "" if failure.get('diag') is None else failure['diag'] - name = ("got false, expected true" if failure.get('name') is None else - failure['name']) - self.logger.test_status(self.test_name, name, 'FAIL', - message=diag) - for failure in results['expectedFailures']: - diag = "" if failure.get('diag') is None else failure['diag'] - name = ("got false, expected false" if failure.get('name') is None else - failure['name']) - self.logger.test_status(self.test_name, name, 'FAIL', - expected='FAIL', message=diag) - for failure in results['unexpectedSuccesses']: - diag = "" if failure.get('diag') is None else failure['diag'] - name = ("got true, expected false" if failure.get('name') is None else - failure['name']) - self.logger.test_status(self.test_name, name, 'PASS', - expected='FAIL', message=diag) - self.assertEqual(0, len(results['failures']), - '{} tests failed' .format(len(results['failures']))) - if len(results['unexpectedSuccesses']) > 0: - raise _UnexpectedSuccess('') - if len(results['expectedFailures']) > 0: - raise _ExpectedFailure((AssertionError, AssertionError(''), None)) - - self.assertTrue(results['passed'] + - len(results['failures']) + - len(results['expectedFailures']) + - len(results['unexpectedSuccesses']) > 0, - 'no tests run') - - except ScriptTimeoutException: - if 'timeout' in filename: - # expected exception - pass - else: - self.loglines = marionette.get_logs() - raise - self.marionette.test_name = original_test_name - class MarionetteTestCase(CommonTestCase): diff --git a/testing/marionette/harness/marionette_harness/runner/base.py b/testing/marionette/harness/marionette_harness/runner/base.py index 54c3be59eb06..0be2b3ada3a6 100644 --- a/testing/marionette/harness/marionette_harness/runner/base.py +++ b/testing/marionette/harness/marionette_harness/runner/base.py @@ -183,8 +183,6 @@ class MarionetteTestResult(StructuredTestResult, TestResultCollection): return '\n'.join((str(test), doc_first_line)) else: desc = str(test) - if hasattr(test, 'jsFile'): - desc = "{0}, {1}".format(test.jsFile, desc) return desc def printLogs(self, test): @@ -606,7 +604,7 @@ class BaseMarionetteTestRunner(object): def filename_pattern(self): if self._filename_pattern is None: self._filename_pattern = re.compile( - "^test(((_.+?)+?\.((py)|(js)))|(([A-Z].*?)+?\.js))$") + "^test(((_.+?)+?\.((py))))$") return self._filename_pattern @@ -803,7 +801,7 @@ class BaseMarionetteTestRunner(object): if not self._is_filename_valid(t['filepath'])] if invalid_tests: raise Exception("Test file names must be of the form " - "'test_something.py', 'test_something.js', or 'testSomething.js'." + "'test_something.py'." " Invalid test names:\n {}".format('\n '.join(invalid_tests))) def _is_filename_valid(self, filename): diff --git a/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_runner.py b/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_runner.py index f309fe7a1734..bc7373bc0b61 100644 --- a/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_runner.py +++ b/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_runner.py @@ -282,8 +282,8 @@ def test_add_test_module(runner): def test_add_test_directory(runner): test_dir = 'path/to/tests' dir_contents = [ - (test_dir, ('subdir',), ('test_a.py', 'test_a.js', 'bad_test_a.py', 'bad_test_a.js')), - (test_dir + '/subdir', (), ('test_b.py', 'test_b.js', 'bad_test_b.py', 'bad_test_b.js')), + (test_dir, ('subdir',), ('test_a.py', 'bad_test_a.py')), + (test_dir + '/subdir', (), ('test_b.py', 'bad_test_b.py')), ] tests = list(dir_contents[0][2] + dir_contents[1][2]) assert len(runner.tests) == 0 @@ -294,7 +294,7 @@ def test_add_test_directory(runner): assert isdir.called and walk.called for test in runner.tests: assert test_dir in test['filepath'] - assert len(runner.tests) == 4 + assert len(runner.tests) == 2 @pytest.mark.parametrize("test_files_exist", [True, False]) @@ -404,10 +404,10 @@ def test_add_tests(mock_runner): def test_catch_invalid_test_names(runner): - good_tests = [u'test_ok.py', u'test_is_ok.py', u'test_is_ok.js', u'testIsOk.js'] - bad_tests = [u'bad_test.py', u'testbad.py', u'_test_bad.py', u'testBad.notjs', - u'test_bad.notpy', u'test_bad', u'testbad.js', u'badtest.js', - u'test.py', u'test_.py', u'test.js', u'test_.js'] + good_tests = [u'test_ok.py', u'test_is_ok.py'] + bad_tests = [u'bad_test.py', u'testbad.py', u'_test_bad.py', + u'test_bad.notpy', u'test_bad', + u'test.py', u'test_.py'] with pytest.raises(Exception) as exc: runner._add_tests(good_tests + bad_tests) msg = exc.value.message diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_chrome_async_finish.js b/testing/marionette/harness/marionette_harness/tests/unit/test_chrome_async_finish.js deleted file mode 100644 index 8d2df3ac26ba..000000000000 --- a/testing/marionette/harness/marionette_harness/tests/unit/test_chrome_async_finish.js +++ /dev/null @@ -1,6 +0,0 @@ -MARIONETTE_TIMEOUT = 60000; -MARIONETTE_CONTEXT = "chrome"; -ok(true); -(function () { - finish(); -})(); diff --git a/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini b/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini index baba489cb9f0..5bd2556765c4 100644 --- a/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini +++ b/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini @@ -89,7 +89,6 @@ skip-if = appname == 'fennec' [test_date_time_value.py] [test_getactiveframe_oop.py] skip-if = true # Bug 925688 -[test_chrome_async_finish.js] [test_screen_orientation.py] [test_errors.py] diff --git a/testing/marionette/jar.mn b/testing/marionette/jar.mn index 998ada6fcb65..ac4f98a3d724 100644 --- a/testing/marionette/jar.mn +++ b/testing/marionette/jar.mn @@ -13,7 +13,6 @@ marionette.jar: content/accessibility.js (accessibility.js) content/listener.js (listener.js) content/element.js (element.js) - content/simpletest.js (simpletest.js) content/frame.js (frame.js) content/cert.js (cert.js) content/event.js (event.js)