Permalink
Browse files

Merge pull request #32 from mattbasta/fx5-compat

FX5 compatibility test; fix for 655299 and 654300
  • Loading branch information...
2 parents 9b33a0b + 7e2ca3e commit 052768860cb6026792b47ba7087f2a46aedfb3f1 @mattbasta committed May 11, 2011
Binary file not shown.
@@ -1,4 +1,6 @@
+import validator.constants
import validator.testcases.compatibility as compatibility
+import validator.testcases.scripting as scripting
from validator.errorbundler import ErrorBundle
def test_compat_test():
@@ -7,8 +9,48 @@ def test_compat_test():
err = ErrorBundle()
err.save_resource("supported_versions",
{"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}":
- ["5.0.x"]})
+ ["5.0a2"]})
compatibility.firefox_5_test(err, {}, None)
+ print err.notices
assert err.notices
+ assert err.notices[0]["compatibility_type"] == "notice"
+
+
+def test_versions_after():
+ """
+ Tests that the appropriate versions after the specified versions are
+ returned.
+ """
+
+ av = validator.constants.APPROVED_APPLICATIONS
+
+ new_versions = {"1": {"guid": "foo",
+ "versions": map(str, range(10))}}
+ validator.constants.APPROVED_APPLICATIONS = new_versions
+
+ assert compatibility.versions_after("foo", "8") == ["8", "9"]
+ assert compatibility.versions_after("foo", "5") == ["5", "6", "7", "8",
+ "9"]
+
+ validator.constants.APPROVED_APPLICATIONS = av
+
+
+def test_navigator_language():
+ """
+ Test that 'navigator.language' is flagged as potentially incompatile with FX5.
+ """
+
+ err = ErrorBundle()
+
+ flagged = "alert(navigator.language);"
+ scripting.test_js_snippet(err, flagged, "foo")
+ assert not err.failed()
+
+ print err.print_summary()
+ print err.get_resource("compat_references")
+
+ compatibility.navigator_language(err, {}, None)
+ assert err.failed()
+ assert err.warnings[0]["compatibility_type"] == "error"
View
@@ -1,4 +1,5 @@
import json
+import nose
import sys
from StringIO import StringIO
@@ -309,6 +310,70 @@ def test_json_constructs():
else:
assert m["column"] is None
+
+def test_json_compatibility():
+ """Test compatibility elements in the JSON output."""
+
+ err = ErrorBundle()
+ err.notice(
+ err_id="m1",
+ notice="Compat error",
+ description="Compatibility error 1",
+ compatibility_type="error")
+
+ err.notice(
+ err_id="m2",
+ notice="Compat error",
+ description="Compatibility error 2",
+ compatibility_type="error")
+
+ err.warning(
+ err_id="m3",
+ warning="Compat notice",
+ description="Compatibility notice 1",
+ compatibility_type="notice")
+
+ err.warning(
+ err_id="m4",
+ warning="Compat warning",
+ description="Compatibility warning 1",
+ compatibility_type="warning")
+
+ err.warning(
+ err_id="m5",
+ warning="Compat warning",
+ description="Compatibility warning 1",
+ compatibility_type="warning")
+
+ err.error(
+ err_id="foo",
+ error="Something else",
+ description="An error that has nothign to do with compatibility")
+
+ results = err.render_json()
+ jdata = json.loads(results)
+
+ assert "compatibility_summary" in jdata
+ nose.tools.eq_(jdata["compatibility_summary"],
+ {"errors": 2,
+ "warnings": 2,
+ "notices": 1})
+ reference = {"m1": "error",
+ "m2": "error",
+ "m3": "notice",
+ "m4": "warning",
+ "m5": "warning"}
+
+ assert "messages" in jdata and len(jdata["messages"])
+ for message in jdata["messages"]:
+ if message["id"] in reference:
+ print (message["id"],
+ reference[message["id"]],
+ message["compatibility_type"])
+ nose.tools.eq_(reference[message["id"]],
+ message["compatibility_type"])
+
+
def test_pushable_resources():
"Tests that normal resources are preserved but pushable ones are pushed"
@@ -163,6 +163,16 @@ def test_self_closing_scripts():
</foo>
""", "foo.js")
+def test_dom_mutation():
+ """Test that DOM mutation events are warned against."""
+
+ _do_test_raw("""
+ <foo><bar onzap="" /></foo>
+ """, "foo.js")
+
+ _do_test_raw("""
+ <foo><bar ondomattrmodified="" /></foo>
+ """, "foo.js", should_fail=True)
def test_dom_mutation():
"""Test that DOM mutation events are warned against."""
@@ -7,9 +7,11 @@
from validator.rdf import RDFParser
from helper import _do_test
+
targetapp.APPROVED_APPLICATIONS = \
json.load(open("validator/app_versions.json"))
+
def _do_test_raw(rdf, listed=True):
err = ErrorBundle(listed=listed)
rdf = RDFParser(StringIO(rdf.strip()))
@@ -20,21 +22,28 @@ def _do_test_raw(rdf, listed=True):
print err.print_summary()
return err
-def test_valid_targetapps():
- """Tests that the install.rdf contains only valid entries for
- target applications."""
- print targetapp.APPROVED_APPLICATIONS
+def test_valid_targetapps():
+ """
+ Tests that the install.rdf contains only valid entries for target
+ applications.
+ """
results = _do_test("tests/resources/targetapplication/pass.xpi",
targetapp.test_targetedapplications,
False,
True)
- print results.get_resource("supports")
supports = results.get_resource("supports")
+ print supports
assert "firefox" in supports and "mozilla" in supports
assert len(supports) == 2
+ supported_versions = results.get_resource("supported_versions")
+ print supported_versions
+ assert (supported_versions['{ec8030f7-c20a-464f-9b0e-13a3a9e97384}'] ==
+ ['3.6', '3.6.4', '3.6.*'])
+
+
def test_bad_min_max():
"""Tests that the lower/upper-bound version number for a
targetApplication entry is indeed a valid version number"""
@@ -49,6 +58,7 @@ def test_bad_min_max():
True,
True)
+
def test_bad_order():
"""Tests that the min and max versions are ordered correctly such
that the earlier version is the min and vice-versa."""
View
@@ -1,6 +1,7 @@
import json
from validator.validate import validate as validate
from validator.errorbundler import ErrorBundle
+import validator.constants
import validator.testcases.targetapplication as targetapp
def test_validate():
@@ -38,5 +39,6 @@ def test_app_versions():
"Tests that the validate function properly loads app_versions.json"
validate(path="tests/resources/junk.xpi",
approved_applications="tests/resources/test_app_versions.json")
- assert targetapp.APPROVED_APPLICATIONS["1"]["name"] == "Foo App"
+ print validator.constants.APPROVED_APPLICATIONS
+ assert validator.constants.APPROVED_APPLICATIONS["1"]["name"] == "Foo App"
@@ -14,13 +14,14 @@
"3.0.11", "3.0.12", "3.0.*", "3.1a1pre", "3.1a1", "3.1a2pre", "3.1a2",
"3.1b1pre", "3.1b1", "3.1b2pre", "3.1b2", "3.1b3pre", "3.1b3",
"3.5b4pre", "3.5b4", "3.5b5pre", "3.5", "3.5.*", "3.6a1pre", "3.6a1",
- "3.6a2pre", "3.6b1pre", "3.6b2", "3.6", "3.6.*", "3.7a1pre", "3.7a1",
- "3.7a2pre", "3.7a2", "3.7a3pre", "3.7a3", "3.7a4pre", "3.7a4",
- "3.7a5pre", "3.7a5", "3.7a6pre", "4.0b1", "4.0b2pre", "4.0b2",
- "4.0b3pre", "4.0b3", "4.0b4pre", "4.0b4", "4.0b5pre", "4.0b5",
- "4.0b6pre", "4.0b6", "4.0b7pre", "4.0b7", "4.0b8pre", "4.0b8",
- "4.0b9pre", "4.0b9", "4.0b10pre", "4.0b10", "4.0b11pre", "4.0b11",
- "4.0b12pre", "4.0b12", "4.0", "4.0.*", "4.2a1pre", "5.0a2", "6.0a1"]
+ "3.6a2pre", "3.6b1pre", "3.6b2", "3.6", "3.6.4", "3.6.*", "3.7a1pre",
+ "3.7a1", "3.7a2pre", "3.7a2", "3.7a3pre", "3.7a3", "3.7a4pre",
+ "3.7a4", "3.7a5pre", "3.7a5", "3.7a6pre", "4.0b1", "4.0b2pre",
+ "4.0b2", "4.0b3pre", "4.0b3", "4.0b4pre", "4.0b4", "4.0b5pre",
+ "4.0b5", "4.0b6pre", "4.0b6", "4.0b7pre", "4.0b7", "4.0b8pre",
+ "4.0b8", "4.0b9pre", "4.0b9", "4.0b10pre", "4.0b10", "4.0b11pre",
+ "4.0b11", "4.0b12pre", "4.0b12", "4.0", "4.0.*", "4.2a1pre", "5.0a2",
+ "6.0a1"]
},
"2":{"name":"Mozilla",
"guid":"{86c18b42-e466-45a9-ae7a-9b95ba6f5640}",
View
@@ -1,5 +1,6 @@
"Constants that will be used across files."
+import json
import os
# Package type constants.
@@ -15,6 +16,21 @@
# The "earliest" version number for Firefox 4
FF4_MIN = "3.7a1pre"
+# Application GUIDs
+APPLICATIONS = {
+ "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": "firefox",
+ "{86c18b42-e466-45a9-ae7a-9b95ba6f5640}": "mozilla",
+ "{3550f703-e582-4d05-9a08-453d09bdfdc6}": "thunderbird",
+ "{718e30fb-e89b-41dd-9da7-e25a45638b28}": "sunbird",
+ "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}": "seamonkey",
+ "{a23983c0-fd0e-11dc-95ff-0800200c9a66}": "fennec"
+}
+
+APPROVED_APPLICATIONS = json.loads(
+ open(os.path.join(os.path.dirname(__file__),
+ "app_versions.json")).read())
+
+
SPIDERMONKEY_INSTALLATION = os.environ.get("SPIDERMONKEY_INSTALLATION")
# Graciously provided by @kumar in bug 614574
View
@@ -21,6 +21,10 @@ def __init__(self, determined=True, listed=True):
self.notices = []
self.message_tree = {}
+ self.compat_summary = {"errors": 0,
+ "warnings": 0,
+ "notices": 0}
+
self.ending_tier = 1
self.tier = 1
@@ -40,7 +44,8 @@ def __init__(self, determined=True, listed=True):
def error(self, err_id, error,
description='', filename='', line=None, column=None,
- context=None, tier=None, for_appversions=None):
+ context=None, tier=None, for_appversions=None,
+ compatibility_type=None):
"Stores an error message for the validation process"
self._save_message(self.errors,
"errors",
@@ -51,13 +56,15 @@ def error(self, err_id, error,
"line": line,
"column": column,
"tier": tier,
- "for_appversions": for_appversions},
+ "for_appversions": for_appversions,
+ "compatibility_type": compatibility_type},
context=context)
return self
def warning(self, err_id, warning,
description='', filename='', line=None, column=None,
- context=None, tier=None, for_appversions=None):
+ context=None, tier=None, for_appversions=None,
+ compatibility_type=None):
"Stores a warning message for the validation process"
self._save_message(self.warnings,
"warnings",
@@ -68,13 +75,15 @@ def warning(self, err_id, warning,
"line": line,
"column": column,
"tier": tier,
- "for_appversions": for_appversions},
+ "for_appversions": for_appversions,
+ "compatibility_type": compatibility_type},
context=context)
return self
def notice(self, err_id, notice,
description="", filename="", line=None, column=None,
- context=None, tier=None, for_appversions=None):
+ context=None, tier=None, for_appversions=None,
+ compatibility_type=None):
"Stores an informational message about the validation"
self._save_message(self.notices,
"notices",
@@ -85,7 +94,8 @@ def notice(self, err_id, notice,
"line": line,
"column": column,
"tier": tier,
- "for_appversions": for_appversions},
+ "for_appversions": for_appversions,
+ "compatibility_type": compatibility_type},
context=context)
return self
@@ -118,10 +128,15 @@ def _save_message(self, stack, type_, message, context=None):
stack.append(message)
- # Mark the tier that the error occurred at
+ # Mark the tier that the error occurred at.
if message["tier"] is None:
message["tier"] = self.tier
+ # Build out the compatibility summary if possible.
+ if message["compatibility_type"]:
+ self.compat_summary["%ss" % message["compatibility_type"]] += 1
+
+ # Build out the message tree entry.
if message["id"]:
tree = self.message_tree
last_id = None
@@ -257,6 +272,7 @@ def render_json(self):
"warnings": len(self.warnings),
"notices": len(self.notices),
"message_tree": self.message_tree,
+ "compatibility_summary": self.compat_summary,
"metadata": self.metadata}
messages = output["messages"]
@@ -336,7 +352,7 @@ def _flatten_list(self, data):
if isinstance(data, (str, unicode)):
return data
elif isinstance(data, (list, tuple)):
- return "\n".join([self._flatten_list(x) for x in data])
+ return "\n".join(self._flatten_list(x) for x in data)
def _print_message(self, prefix, message, verbose=True):
"Prints a message and takes care of all sorts of nasty code"
Oops, something went wrong.

0 comments on commit 0527688

Please sign in to comment.