Bug 1368674 - Remove JS Test support in Marionette Harness r?maja_zf
MozReview-Commit-ID: 11Zc7KL3djD
--- a/testing/marionette/harness/marionette_harness/marionette_test/testcases.py
+++ b/testing/marionette/harness/marionette_harness/marionette_test/testcases.py
@@ -55,23 +55,16 @@ class MetaParameterized(type):
raise KeyError("{0} is already a defined method on {1}"
.format(wrapper.__name__, name))
attrs[wrapper.__name__] = wrapper
del attrs[k]
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
match_re = None
failureException = AssertionError
pydebugger = None
def __init__(self, methodName, marionette_weakref, fixtures, **kwargs):
@@ -230,22 +223,19 @@ class CommonTestCase(unittest.TestCase):
@classmethod
def add_tests_to_suite(cls, mod_name, filepath, suite, testloader, marionette,
fixtures, testvars, **kwargs):
"""Add all the tests in the specified file to the specified suite."""
raise NotImplementedError
@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
# not differ over time. The test name to be used is passed to
# mozlog via the test id, so this is overriden to maintain
# consistency.
return self.test_name
@@ -293,137 +283,16 @@ if (!testUtils.hasOwnProperty("specialPo
.getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.jsm",
testUtils);
testUtils.specialPowersObserver = new testUtils.SpecialPowersObserver();
testUtils.specialPowersObserver.init();
}
""")
- 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,<html>test page</html>')
-
- 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):
match_re = re.compile(r"test_(.*)\.py$")
def __init__(self, marionette_weakref, fixtures, methodName='runTest',
filepath='', **kwargs):
self.filepath = filepath
--- a/testing/marionette/harness/marionette_harness/runner/base.py
+++ b/testing/marionette/harness/marionette_harness/runner/base.py
@@ -178,18 +178,16 @@ class MarionetteTestResult(StructuredTes
return test.test_name
def getDescription(self, test):
doc_first_line = test.shortDescription()
if self.descriptions and doc_first_line:
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):
for testcase in test._tests:
if hasattr(testcase, 'loglines') and testcase.loglines:
# Don't dump loglines to the console if they only contain
# TEST-START and TEST-END.
skip_log = True
@@ -601,17 +599,17 @@ class BaseMarionetteTestRunner(object):
self.gecko_log = gecko_log
self.results = []
@property
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
@property
def testvars(self):
if self._testvars is not None:
return self._testvars
@@ -798,17 +796,17 @@ class BaseMarionetteTestRunner(object):
def _add_tests(self, tests):
for test in tests:
self.add_test(test)
invalid_tests = [t['filepath'] for t in self.tests
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):
filename = os.path.basename(filename)
return self.filename_pattern.match(filename)
def _log_skipped_tests(self):
for test in self.manifest_skipped_tests:
--- 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
@@ -277,29 +277,29 @@ def test_add_test_module(runner):
assert expected in runner.tests
# add_test doesn't validate module names; 'bad_test.py' gets through
assert len(runner.tests) == 3
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
# Need to use side effect to make isdir return True for test_dir and False for tests
with patch('os.path.isdir', side_effect=[True] + [False for t in tests]) as isdir:
with patch('os.walk', return_value=dir_contents) as walk:
runner.add_test(test_dir)
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])
def test_add_test_manifest(mock_runner, manifest_with_tests, monkeypatch, test_files_exist):
monkeypatch.setattr('marionette_harness.runner.base.TestManifest',
manifest_with_tests.manifest_class)
mock_runner.marionette = mock_runner.driverclass()
with patch('marionette_harness.runner.base.os.path.exists', return_value=test_files_exist):
@@ -399,20 +399,20 @@ def test_add_tests(mock_runner):
fake_tests = ["test_" + i + ".py" for i in "abc"]
mock_runner.run_tests(fake_tests)
assert len(mock_runner.tests) == 3
for (test_name, added_test) in zip(fake_tests, mock_runner.tests):
assert added_test['filepath'].endswith(test_name)
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
assert "Test file names must be of the form" in msg
for bad_name in bad_tests:
assert bad_name in msg
for good_name in good_tests:
assert good_name not in msg
deleted file mode 100644
--- 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();
-})();
--- a/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
+++ b/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
@@ -83,17 +83,16 @@ skip-if = appname == 'fennec'
[test_window_type_chrome.py]
skip-if = appname == 'fennec'
[test_implicit_waits.py]
[test_wait.py]
[test_expected.py]
[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]
[test_execute_isolate.py]
[test_click_scrolling.py]
[test_profile_management.py]
skip-if = manage_instance == false || appname == 'fennec' # Bug 1298921 and bug 1322993
[test_quit_restart.py]
--- a/testing/marionette/jar.mn
+++ b/testing/marionette/jar.mn
@@ -8,17 +8,16 @@ marionette.jar:
content/driver.js (driver.js)
content/action.js (action.js)
content/legacyaction.js (legacyaction.js)
content/browser.js (browser.js)
content/interaction.js (interaction.js)
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)
content/error.js (error.js)
content/wait.js (wait.js)
content/message.js (message.js)
content/modal.js (modal.js)
content/proxy.js (proxy.js)