зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1368674 - Remove JS Test support in Marionette Harness r=maja_zf
MozReview-Commit-ID: 11Zc7KL3djD --HG-- extra : rebase_source : de8274b3948abcbe0e0aa404dad9b02b87b9119f
This commit is contained in:
Родитель
db1c923084
Коммит
d83f55e070
|
@ -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,9 +228,6 @@ 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)
|
||||
|
@ -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,<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):
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_CONTEXT = "chrome";
|
||||
ok(true);
|
||||
(function () {
|
||||
finish();
|
||||
})();
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче