Added test for install.rdf doctypes; bug 635092

This commit is contained in:
mattbasta 2011-02-18 05:26:24 -05:00
Родитель 07a14c94ae
Коммит 17031fad54
4 изменённых файлов: 72 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<!DOCTYPE overlay SYSTEM "chrome://helloworld/locale/overlay.dtd">
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:type>2</em:type>
<em:id>bastatestapp1@basta.mozilla.com</em:id>
<em:version>1.2.3.4</em:version>
<em:name>name_value</em:name>
<em:description>description_value</em:description>
<em:creator>creator_value</em:creator>
<em:homepageURL>hompage_url_value</em:homepageURL>
<em:contributor>contributor_1_value</em:contributor>
<em:contributor>contributor_2_value</em:contributor>
<em:contributor>contributor_3_value</em:contributor>
<em:contributor>contributor_4_value</em:contributor>
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.7a5pre</em:minVersion>
<em:maxVersion>0.3</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

Просмотреть файл

@ -67,4 +67,25 @@ def test_load_irdf_expectation():
submain.typedetection.detect_type = lambda x, y, z: PACKAGE_THEME
_run_test("install_rdf.xpi", PACKAGE_EXTENSION, True, True)
submain.typedetection.detect_type = dt
def test_doctype():
"Asserts that install.rdf files with doctypes break validation"
err = ErrorBundle()
xpi = MockXPIManager(
{"install.rdf": "tests/resources/installrdf/doctype.rdf"})
assert isinstance(submain._load_install_rdf(err, xpi, None), ErrorBundle)
assert err.failed()
assert not err.get_resource("has_install_rdf")
assert not err.get_resource("install_rdf")
class MockXPIManager(object):
"Pretends to be a simple XPI manager"
def __init__(self, data):
self.data = data
def read(self, name):
"Simulates a read operation"
assert name in self.data
return open(self.data[name]).read()

Просмотреть файл

@ -1,4 +1,5 @@
import os
import re
import zipfile
@ -142,6 +143,18 @@ def test_package(err, file_, name, expectation=PACKAGE_ANY):
def _load_install_rdf(err, package, expectation):
# Load up the install.rdf file.
install_rdf_data = package.read("install.rdf")
if re.search('<!doctype', install_rdf_data, re.I):
err.save_resource("bad_install_rdf", True)
return err.error(("main",
"test_package",
"doctype_in_installrdf"),
"DOCTYPEs are not permitted in install.rdf",
"The add-on's install.rdf file contains a DOCTYPE. "
"It must be removed before your add-on can be "
"validated.",
filename="install.rdf")
install_rdf = RDFParser(install_rdf_data)
if install_rdf.rdf is None or not install_rdf:
@ -149,7 +162,8 @@ def _load_install_rdf(err, package, expectation):
"test_package",
"cannot_parse_installrdf"),
"Cannot Parse install.rdf",
"The install.rdf file could not be parsed.")
"The install.rdf file could not be parsed.",
filename="install.rdf")
else:
err.save_resource("has_install_rdf", True)
err.save_resource("install_rdf", install_rdf)

Просмотреть файл

@ -97,7 +97,8 @@ def test_layout_all(err, package_contents, xpi_package):
if xpi_package.subpackage:
return
if not err.get_resource("has_install_rdf"):
if not err.get_resource("has_install_rdf") and \
not err.get_resource("bad_install_rdf"):
err.error(("testcases_packagelayout",
"test_layout_all",
"missing_install_rdf"),