Ejemplo n.º 1
0
def test_subpackage():
    'Test a package with localization that should pass validation.'

    err = ErrorBundle()
    err.detected_type = PACKAGE_DICTIONARY
    assert l10n.test_xpi(err, None) is None
    err.detected_type = PACKAGE_EXTENSION
    err.push_state()
    assert l10n.test_xpi(err, None) is None
Ejemplo n.º 2
0
def test_invalid_package_type():
    "No such thing as a Conduit theme."
    
    err = ErrorBundle(None, True)
    err.detected_type = PACKAGE_ANY
    assert conduit.test_conduittoolbar(err) is None
    err.detected_type = PACKAGE_THEME
    assert conduit.test_conduittoolbar(err) is None
    err.detected_type = PACKAGE_SEARCHPROV
    assert conduit.test_conduittoolbar(err) is None
Ejemplo n.º 3
0
def test_invalid_package_type():
    """Assert that conduit toolbars can only be extensions."""

    err = ErrorBundle()
    err.detected_type = PACKAGE_ANY
    assert conduit.test_conduittoolbar(err) is None
    err.detected_type = PACKAGE_THEME
    assert conduit.test_conduittoolbar(err) is None
    err.detected_type = PACKAGE_SEARCHPROV
    assert conduit.test_conduittoolbar(err) is None
Ejemplo n.º 4
0
def _do_test(path, test, failure=True,
             require_install=False, set_type=0,
             listed=False, xpi_mode="r"):

    package_data = open(path, "rb")
    package = XPIManager(package_data, mode=xpi_mode, name=path)
    err = ErrorBundle()
    if listed:
        err.save_resource("listed", True)

    # Populate in the dependencies.
    if set_type:
        err.detected_type = set_type # Conduit test requires type
    if require_install:
        err.save_resource("has_install_rdf", True)
        rdf_data = package.read("install.rdf")
        install_rdf = RDFParser(err, rdf_data)
        err.save_resource("install_rdf", install_rdf)

    populate_chrome_manifest(err, package)

    test(err, package)

    print err.print_summary(verbose=True)

    if failure:
        assert err.failed()
    else:
        assert not err.failed()

    return err
Ejemplo n.º 5
0
def _do_test_raw(script,
                 path='foo.js',
                 bootstrap=False,
                 ignore_pollution=True,
                 detected_type=None,
                 jetpack=False,
                 instant=True):
    """Perform a test on a JS file."""

    err = ErrorBundle(instant=instant)
    if jetpack:
        err.metadata['is_jetpack'] = True

    err.handler = OutputHandler(sys.stdout, True)
    err.supported_versions = {}
    if bootstrap:
        err.save_resource('em:bootstrap', True)
    if detected_type:
        err.detected_type = detected_type

    validator.testcases.content._process_file(err, MockXPI(), path, script,
                                              path.lower(),
                                              not ignore_pollution)
    if err.final_context is not None:
        print 'CONTEXT', repr(err.final_context.keys())

    return err
Ejemplo n.º 6
0
def _do_test(path,
             test,
             failure=True,
             require_install=False,
             set_type=0,
             listed=False,
             xpi_mode="r"):

    package_data = open(path, "rb")
    package = XPIManager(package_data, mode=xpi_mode, name=path)
    err = ErrorBundle()
    if listed:
        err.save_resource("listed", True)

    # Populate in the dependencies.
    if set_type:
        err.detected_type = set_type  # Conduit test requires type
    if require_install:
        err.save_resource("has_install_rdf", True)
        rdf_data = package.read("install.rdf")
        install_rdf = RDFParser(err, rdf_data)
        err.save_resource("install_rdf", install_rdf)

    populate_chrome_manifest(err, package)

    test(err, package)

    print err.print_summary(verbose=True)

    if failure:
        assert err.failed()
    else:
        assert not err.failed()

    return err
Ejemplo n.º 7
0
def _run_test_raw(data, failure=True, detected_type=0, listed=True,
                  overrides=None, compat=False):
    "Runs a test on an install.rdf snippet"

    data = data.strip()

    err = ErrorBundle()
    err.detected_type = detected_type
    err.save_resource("listed", listed)
    err.overrides = overrides

    if compat:
        err.save_resource("is_compat_test", True)

    err.save_resource("has_install_rdf", True)
    err.save_resource("install_rdf", RDFParser(err, data))
    installrdf.test_install_rdf_params(err)

    print err.print_summary(verbose=True)

    if failure:  # pragma: no cover
        assert err.failed() or err.notices
    else:
        assert not err.failed() and not err.notices

    return err
Ejemplo n.º 8
0
def test_webapp_bom():
    """Test that a plain webapp with a BOM won't throw errors."""

    err = ErrorBundle(listed=False)
    err.detected_type = validator.constants.PACKAGE_WEBAPP
    validator.webapp.detect_webapp(
            err, "tests/resources/unicodehelper/utf8_webapp.json")
    assert not err.failed()
Ejemplo n.º 9
0
def test_json_constructs():
    """This tests some of the internal JSON stuff so we don't break zamboni."""

    e = ErrorBundle()
    e.detected_type = 1
    e.error(("a", "b", "c"), "Test")
    e.error(("a", "b", "foo"), "Test")
    e.error(("a", "foo", "c"), "Test")
    e.error(("a", "foo", "c"), "Test")
    e.error(("b", "foo", "bar"), "Test")
    e.warning((), "Context test", context=("x", "y", "z"))
    e.warning((),
              "Context test",
              context=ContextGenerator("x\ny\nz\n"),
              line=2,
              column=0)
    e.notice((), "none")
    e.notice((), "line", line=1)
    e.notice((), "column", column=0)
    e.notice((), "line column", line=1, column=1)

    results = e.render_json()
    print results
    j = json.loads(results)

    assert "detected_type" in j
    assert j["detected_type"] == "extension"

    assert "message_tree" in j
    tree = j["message_tree"]

    assert "__errors" not in tree
    assert not tree["a"]["__messages"]
    assert tree["a"]["__errors"] == 4
    assert not tree["a"]["b"]["__messages"]
    assert tree["a"]["b"]["__errors"] == 2
    assert not tree["a"]["b"]["__messages"]
    assert tree["a"]["b"]["c"]["__errors"] == 1
    assert tree["a"]["b"]["c"]["__messages"]

    assert "messages" in j
    for m in (m for m in j["messages"] if m["type"] == "warning"):
        assert m["context"] == ["x", "y", "z"]

    for m in (m for m in j["messages"] if m["type"] == "notice"):
        if "line" in m["message"]:
            assert m["line"] is not None
            assert isinstance(m["line"], int)
            assert m["line"] > 0
        else:
            assert m["line"] is None

        if "column" in m["message"]:
            assert m["column"] is not None
            assert isinstance(m["column"], int)
            assert m["column"] > -1
        else:
            assert m["column"] is None
Ejemplo n.º 10
0
def test_json_constructs():
    """This tests some of the internal JSON stuff so we don't break zamboni."""

    e = ErrorBundle()
    e.detected_type = 1
    e.error(('a', 'b', 'c'), 'Test')
    e.error(('a', 'b', 'foo'), 'Test')
    e.error(('a', 'foo', 'c'), 'Test')
    e.error(('a', 'foo', 'c'), 'Test')
    e.error(('b', 'foo', 'bar'), 'Test')
    e.warning((), 'Context test', context=('x', 'y', 'z'))
    e.warning((),
              'Context test',
              context=ContextGenerator('x\ny\nz\n'),
              line=2,
              column=0)
    e.notice((), 'none')
    e.notice((), 'line', line=1)
    e.notice((), 'column', column=0)
    e.notice((), 'line column', line=1, column=1)

    results = e.render_json()
    print results
    j = json.loads(results)

    assert 'detected_type' in j
    assert j['detected_type'] == 'extension'

    assert 'message_tree' in j
    tree = j['message_tree']

    assert '__errors' not in tree
    assert not tree['a']['__messages']
    assert tree['a']['__errors'] == 4
    assert not tree['a']['b']['__messages']
    assert tree['a']['b']['__errors'] == 2
    assert not tree['a']['b']['__messages']
    assert tree['a']['b']['c']['__errors'] == 1
    assert tree['a']['b']['c']['__messages']

    assert 'messages' in j
    for m in (m for m in j['messages'] if m['type'] == 'warning'):
        assert m['context'] == ['x', 'y', 'z']

    for m in (m for m in j['messages'] if m['type'] == 'notice'):
        if 'line' in m['message']:
            assert m['line'] is not None
            assert isinstance(m['line'], int)
            assert m['line'] > 0
        else:
            assert m['line'] is None

        if 'column' in m['message']:
            assert m['column'] is not None
            assert isinstance(m['column'], int)
            assert m['column'] > -1
        else:
            assert m['column'] is None
Ejemplo n.º 11
0
def test_type():
    """
    Test that detected type is being stored properly in the error bundle.
    """

    bundle = ErrorBundle()

    bundle.detected_type = 5
    assert bundle.detected_type == 5
Ejemplo n.º 12
0
def test_subpackage_metadata_preserved():
    """Tests that metadata is preserved for sub-packages."""

    xpi1 = open('tests/resources/jetpack/jetpack-1.16-outdated.xpi')
    xpi2 = MockXPI({
        'thing.xpi': 'tests/resources/jetpack/jetpack-1.16-outdated.xpi'})

    err1 = ErrorBundle()
    err1.detected_type = PACKAGE_EXTENSION

    err2 = ErrorBundle()
    err2.detected_type = PACKAGE_EXTENSION

    submain.test_package(err1, xpi1, 'jetpack-1.16-outdated.xpi')
    content.test_packed_packages(err2, xpi2)

    assert 'sub_packages' in err2.metadata
    assert err1.metadata == err2.metadata['sub_packages'].get('thing.xpi')
Ejemplo n.º 13
0
def test_subpackage_metadata_preserved():
    """Tests that metadata is preserved for sub-packages."""

    xpi1 = open('tests/resources/jetpack/jetpack-1.16-outdated.xpi')
    xpi2 = MockXPI(
        {'thing.xpi': 'tests/resources/jetpack/jetpack-1.16-outdated.xpi'})

    err1 = ErrorBundle()
    err1.detected_type = PACKAGE_EXTENSION

    err2 = ErrorBundle()
    err2.detected_type = PACKAGE_EXTENSION

    submain.test_package(err1, xpi1, 'jetpack-1.16-outdated.xpi')
    content.test_packed_packages(err2, xpi2)

    assert 'sub_packages' in err2.metadata
    assert err1.metadata == err2.metadata['sub_packages'].get('thing.xpi')
Ejemplo n.º 14
0
def test_type():
    """
    Test that detected type is being stored properly in the error bundle.
    """

    bundle = ErrorBundle()

    bundle.detected_type = 5
    assert bundle.detected_type == 5
Ejemplo n.º 15
0
def test_subpackage_metadata_preserved():
    """Tests that metadata is preserved for sub-packages."""

    xpi1 = open("tests/resources/jetpack/jetpack-1.8-outdated.xpi")
    xpi2 = MockXPI(
        {"thing.xpi": "tests/resources/jetpack/jetpack-1.8-outdated.xpi"})

    err1 = ErrorBundle()
    err1.detected_type = PACKAGE_EXTENSION

    err2 = ErrorBundle()
    err2.detected_type = PACKAGE_EXTENSION

    submain.test_package(err1, xpi1, "jetpack-1.8-outdated.xpi")
    content.test_packed_packages(err2, xpi2)

    assert "sub_packages" in err2.metadata
    eq_(err1.metadata, err2.metadata["sub_packages"].get("thing.xpi"))
Ejemplo n.º 16
0
def test_subpackage_metadata_preserved():
    """Tests that metadata is preserved for sub-packages."""

    xpi1 = open("tests/resources/jetpack/jetpack-1.8-outdated.xpi")
    xpi2 = MockXPI({
        "thing.xpi": "tests/resources/jetpack/jetpack-1.8-outdated.xpi"})

    err1 = ErrorBundle()
    err1.detected_type = PACKAGE_EXTENSION

    err2 = ErrorBundle()
    err2.detected_type = PACKAGE_EXTENSION

    submain.test_package(err1, xpi1, "jetpack-1.8-outdated.xpi")
    content.test_packed_packages(err2, xpi2)

    assert "sub_packages" in err2.metadata
    eq_(err1.metadata, err2.metadata["sub_packages"]
                           .get("thing.xpi"))
Ejemplo n.º 17
0
def test_json_constructs():
    """This tests some of the internal JSON stuff so we don't break zamboni."""

    e = ErrorBundle()
    e.detected_type = 1
    e.error(("a", "b", "c"), "Test")
    e.error(("a", "b", "foo"), "Test")
    e.error(("a", "foo", "c"), "Test")
    e.error(("a", "foo", "c"), "Test")
    e.error(("b", "foo", "bar"), "Test")
    e.warning((), "Context test", context=("x", "y", "z"))
    e.warning((), "Context test", context=ContextGenerator("x\ny\nz\n"), line=2, column=0)
    e.notice((), "none")
    e.notice((), "line", line=1)
    e.notice((), "column", column=0)
    e.notice((), "line column", line=1, column=1)

    results = e.render_json()
    print results
    j = json.loads(results)

    assert "detected_type" in j
    assert j["detected_type"] == "extension"

    assert "message_tree" in j
    tree = j["message_tree"]

    assert "__errors" not in tree
    assert not tree["a"]["__messages"]
    assert tree["a"]["__errors"] == 4
    assert not tree["a"]["b"]["__messages"]
    assert tree["a"]["b"]["__errors"] == 2
    assert not tree["a"]["b"]["__messages"]
    assert tree["a"]["b"]["c"]["__errors"] == 1
    assert tree["a"]["b"]["c"]["__messages"]

    assert "messages" in j
    for m in (m for m in j["messages"] if m["type"] == "warning"):
        assert m["context"] == ["x", "y", "z"]

    for m in (m for m in j["messages"] if m["type"] == "notice"):
        if "line" in m["message"]:
            assert m["line"] is not None
            assert isinstance(m["line"], int)
            assert m["line"] > 0
        else:
            assert m["line"] is None

        if "column" in m["message"]:
            assert m["column"] is not None
            assert isinstance(m["column"], int)
            assert m["column"] > -1
        else:
            assert m["column"] is None
Ejemplo n.º 18
0
def test_langpack():
    'Tests a language pack in the content validator.'

    err = ErrorBundle()
    err.supported_versions = {}
    err.detected_type = PACKAGE_LANGPACK
    mock_package = MockXPI({'foo.dtd': 'tests/resources/content/junk.xpi'})

    content.test_packed_packages(err, mock_package)
    content.testendpoint_langpack.assert_expectation('test_unsafe_html', 1)
    content.testendpoint_langpack.assert_expectation('test_unsafe_html', 0,
                                                     'subpackage')
Ejemplo n.º 19
0
def test_has_rdf(install_rdf):
    "Tests that tests won't be run if there's no install.rdf"

    err = ErrorBundle()

    assert installrdf.test_install_rdf_params(err, None) is None

    err.detected_type = 0
    err.save_resource('install_rdf', RDFParser(err, '<rdf></rdf>'))
    err.save_resource('has_install_rdf', True)

    installrdf.test_install_rdf_params(err, None)
    assert install_rdf.called
Ejemplo n.º 20
0
def test_has_rdf(install_rdf):
    "Tests that tests won't be run if there's no install.rdf"

    err = ErrorBundle()

    assert installrdf.test_install_rdf_params(err, None) is None

    err.detected_type = 0
    err.save_resource("install_rdf", RDFParser(err, "<rdf></rdf>"))
    err.save_resource("has_install_rdf", True)

    installrdf.test_install_rdf_params(err, None)
    assert install_rdf.called
Ejemplo n.º 21
0
def test_langpack():
    "Tests a language pack in the content validator."

    err = ErrorBundle()
    err.supported_versions = {}
    err.detected_type = PACKAGE_LANGPACK
    mock_package = MockXPI({"foo.dtd": "tests/resources/content/junk.xpi"})

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 1
    content.testendpoint_langpack.assert_expectation("test_unsafe_html", 1)
    content.testendpoint_langpack.assert_expectation("test_unsafe_html", 0,
                                                     "subpackage")
def _do_test(unpack=False, contents=None, set_type=0, is_ff4=False):
    'Runs the tests. Handy as hell.'

    if not contents:
        contents = []

    err = ErrorBundle(None, True)
    if set_type:
        err.detected_type = set_type
    err.save_resource('em:unpack', unpack)
    err.save_resource('ff4', is_ff4)
    packagelayout.test_emunpack(
        err, MockXPI(dict(zip(contents, [True for c in contents]))))
    return err
Ejemplo n.º 23
0
def test_langpack():
    "Tests a language pack in the content validator."

    err = ErrorBundle()
    err.supported_versions = {}
    err.detected_type = PACKAGE_LANGPACK
    mock_package = MockXPI({"foo.dtd": "tests/resources/content/junk.xpi"})

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 1
    content.testendpoint_langpack.assert_expectation("test_unsafe_html", 1)
    content.testendpoint_langpack.assert_expectation("test_unsafe_html", 0,
                                                     "subpackage")
Ejemplo n.º 24
0
def _do_test(unpack=False, contents=None, set_type=0, is_ff4=False):
    "Runs the tests. Handy as hell."

    if not contents:
        contents = []

    err = ErrorBundle(None, True)
    if set_type:
        err.detected_type = set_type
    err.save_resource("em:unpack", unpack)
    err.save_resource("ff4", is_ff4)
    packagelayout.test_emunpack(
        err, MockXPI(dict(zip(contents, [True for c in contents]))))
    return err
Ejemplo n.º 25
0
def test_xpi_subpackage():
    "XPIs should never be subpackages; only nested extensions"

    err = ErrorBundle()
    err.detected_type = PACKAGE_EXTENSION
    mock_package = MockXPI(
        {"chrome/package.xpi": "tests/resources/content/subpackage.jar"})

    result = content.test_packed_packages(err, mock_package)

    print result
    assert result == 1
    content.testendpoint_validator.assert_expectation("test_package", 1)
    content.testendpoint_validator.assert_expectation("test_package", 0,
                                                      "subpackage")
Ejemplo n.º 26
0
def test_remote_css():
    """Test that remote CSS references are flagged."""

    snippet = """
    x {foo: url(http://foo.com/bar);}
    """

    err = ErrorBundle()
    csstester.test_css_snippet(err, "x.css", snippet, 0)
    assert not err.failed()

    err = ErrorBundle()
    err.detected_type = PACKAGE_THEME
    csstester.test_css_snippet(err, "x.css", snippet, 0)
    assert err.failed()
Ejemplo n.º 27
0
def _do_real_test_raw(script, path="foo.js", versions=None, detected_type=None,
                      metadata=None, resources=None):
    """Perform a JS test using a non-mock bundler."""

    err = ErrorBundle()
    if detected_type:
        err.detected_type = detected_type
    err.supported_versions = versions or {}
    if metadata is not None:
        err.metadata = metadata
    if resources is not None:
        err.resources = resources

    validator.testcases.content._process_file(err, MockXPI(), path, script)
    return err
Ejemplo n.º 28
0
def test_remote_css():
    """Test that remote CSS references are flagged."""

    snippet = """
    x {foo: url(http://foo.com/bar);}
    """

    err = ErrorBundle()
    csstester.test_css_snippet(err, 'x.css', snippet, 0)
    assert not err.failed()

    err = ErrorBundle()
    err.detected_type = PACKAGE_THEME
    csstester.test_css_snippet(err, 'x.css', snippet, 0)
    assert err.failed()
def _do_test(path, should_fail=False, detected_type=None):

    data = open(path).read()
    err = ErrorBundle()
    if detected_type is not None:
        err.detected_type = detected_type

    csstester.test_css_file(err, 'css.css', data)
    err.print_summary(True)

    if should_fail:
        assert err.failed()
    else:
        assert not err.failed()

    return err
Ejemplo n.º 30
0
def test_remote_css_ignored():
    """Test that suspicious but innocuous css-isms are ignored."""

    snippet = """
    @namespace url(http://foo.bar/asdf);
    @namespace url("http://foo.bar/asdf");
    """

    err = ErrorBundle()
    csstester.test_css_snippet(err, "x.css", snippet, 0)
    assert not err.failed()

    err = ErrorBundle()
    err.detected_type = PACKAGE_THEME
    csstester.test_css_snippet(err, "x.css", snippet, 0)
    assert not err.failed()
Ejemplo n.º 31
0
def test_remote_css_ignored():
    """Test that suspicious but innocuous css-isms are ignored."""

    snippet = """
    @namespace url(http://foo.bar/asdf);
    @namespace url("http://foo.bar/asdf");
    """

    err = ErrorBundle()
    csstester.test_css_snippet(err, 'x.css', snippet, 0)
    assert not err.failed()

    err = ErrorBundle()
    err.detected_type = PACKAGE_THEME
    csstester.test_css_snippet(err, 'x.css', snippet, 0)
    assert not err.failed()
Ejemplo n.º 32
0
def _do_test(path, should_fail=False, detected_type=None):

    data = open(path).read()
    err = ErrorBundle()
    if detected_type is not None:
        err.detected_type = detected_type

    csstester.test_css_file(err, "css.css", data)
    err.print_summary(True)

    if should_fail:
        assert err.failed()
    else:
        assert not err.failed()

    return err
Ejemplo n.º 33
0
def test_has_rdf():
    "Tests that tests won't be run if there's no install.rdf"
    
    err = ErrorBundle()
    err.detected_type = 0
    err.save_resource("install_rdf", "test")
    err.save_resource("has_install_rdf", True)
    testrdf = installrdf._test_rdf
    installrdf._test_rdf = lambda x, y: y
    
    result = installrdf.test_install_rdf_params(err, None, None)
    installrdf._test_rdf = testrdf
    
    print result
    assert result

    return err
Ejemplo n.º 34
0
def _do_real_test_raw(script, path='foo.js', versions=None, detected_type=None,
                      metadata=None, resources=None, jetpack=False):
    """Perform a JS test using a non-mock bundler."""

    err = ErrorBundle(for_appversions=versions or {})
    if detected_type:
        err.detected_type = detected_type
    if metadata is not None:
        err.metadata = metadata
    if resources is not None:
        err.resources = resources
    if jetpack:
        err.metadata['is_jetpack'] = True

    validator.testcases.content._process_file(err, MockXPI(), path, script,
                                              path.lower())
    return err
Ejemplo n.º 35
0
def test_xpi_subpackage():
    'XPIs should never be subpackages; only nested extensions'

    err = ErrorBundle()
    err.detected_type = PACKAGE_EXTENSION
    mock_package = MockXPI(
        {'chrome/package.xpi':
         'tests/resources/content/subpackage.jar'})

    result = content.test_packed_packages(err, mock_package)

    print result
    assert result == 1
    content.testendpoint_validator.assert_expectation(
        'test_package', 1)
    content.testendpoint_validator.assert_expectation(
        'test_package', 0, 'subpackage')
Ejemplo n.º 36
0
def _do_test_raw(script, path="foo.js", bootstrap=False, ignore_pollution=True,
                 detected_type=None):
    "Performs a test on a JS file"

    err = ErrorBundle(instant=True)
    err.handler = OutputHandler(sys.stdout, True)
    err.supported_versions = {}
    if bootstrap:
        err.save_resource("em:bootstrap", True)
    if detected_type:
        err.detected_type = detected_type

    validator.testcases.content._process_file(
            err, MockXPI(), path, script, path.lower(), not ignore_pollution)
    if err.final_context is not None:
        print err.final_context.output()

    return err
Ejemplo n.º 37
0
def _run_test(filename, failure=True, detected_type=0):
    "Runs a test on an install.rdf file"
    
    err = ErrorBundle()
    err.detected_type = detected_type
    
    data = open(filename).read()
    
    parser = RDFParser(data)
    installrdf._test_rdf(err, parser)
    
    print err.print_summary()

    if failure: # pragma: no cover
        assert err.failed() or err.notices
    else:
        assert not err.failed() and not err.notices
    
    return err
Ejemplo n.º 38
0
def test_jar_nonsubpackage():
    'Tests XPI files that are not subpackages.'

    err = ErrorBundle()
    err.detected_type = PACKAGE_MULTI
    err.save_resource('is_multipackage', True)
    mock_package = MockXPI({
        'foo.jar':
        'tests/resources/content/subpackage.jar',
        'chrome/bar.jar':
        'tests/resources/content/subpackage.jar'
    })

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation('test_package', 2)
    content.testendpoint_validator.assert_expectation('test_package', 0,
                                                      'subpackage')
Ejemplo n.º 39
0
def test_jar_nonsubpackage():
    "Tests XPI files that are not subpackages."

    err = ErrorBundle()
    err.detected_type = PACKAGE_MULTI
    err.save_resource("is_multipackage", True)
    mock_package = MockXPI({
        "foo.jar":
        "tests/resources/content/subpackage.jar",
        "chrome/bar.jar":
        "tests/resources/content/subpackage.jar"
    })

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation("test_package", 2)
    content.testendpoint_validator.assert_expectation("test_package", 0,
                                                      "subpackage")
Ejemplo n.º 40
0
def test_jar_subpackage():
    "Tests JAR files that are subpackages."

    err = ErrorBundle()
    err.detected_type = PACKAGE_EXTENSION
    err.supported_versions = {"foo": ["1.2.3"]}
    mock_package = MockXPI({
        "chrome/subpackage.jar":
        "tests/resources/content/subpackage.jar",
        "subpackage.jar":
        "tests/resources/content/subpackage.jar"
    })

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation("test_inner_package", 2)
    content.testendpoint_validator.assert_expectation("test_inner_package", 2,
                                                      "subpackage")
    assert err.supported_versions == {"foo": ["1.2.3"]}
def _test_xul_raw(data, path, should_fail=False, type_=None):
    filename = path.split("/")[-1]
    extension = filename.split(".")[-1]

    err = ErrorBundle()
    err.supported_versions = {}
    if type_:
        err.detected_type = type_

    parser = markuptester.MarkupParser(err, debug=True)
    parser.process(filename, data, extension)

    print err.print_summary(verbose=True)

    if should_fail:
        assert err.failed()
    else:
        assert not err.failed(fail_on_warnings=False)

    return err
def _test_xul_raw(data, path, should_fail=False, type_=None):
    filename = path.split("/")[-1]
    extension = filename.split(".")[-1]

    err = ErrorBundle()
    err.supported_versions = {}
    if type_:
        err.detected_type = type_

    parser = markuptester.MarkupParser(err, debug=True)
    parser.process(filename, data, extension)

    print err.print_summary(verbose=True)

    if should_fail:
        assert err.failed()
    else:
        assert not err.failed(fail_on_warnings=False)

    return err
Ejemplo n.º 43
0
def test_jar_subpackage():
    'Tests JAR files that are subpackages.'

    err = ErrorBundle()
    err.detected_type = PACKAGE_EXTENSION
    err.supported_versions = {'foo': ['1.2.3']}
    mock_package = MockXPI({
        'chrome/subpackage.jar':
        'tests/resources/content/subpackage.jar',
        'subpackage.jar':
        'tests/resources/content/subpackage.jar'
    })

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation('test_inner_package', 2)
    content.testendpoint_validator.assert_expectation('test_inner_package', 2,
                                                      'subpackage')
    assert err.supported_versions == {'foo': ['1.2.3']}
Ejemplo n.º 44
0
def _do_test(path,
             test,
             failure=True,
             require_install=False,
             set_type=0,
             listed=False,
             xpi_mode='r'):

    package_data = open(path, 'rb')
    package = XPIManager(package_data, mode=xpi_mode, name=path)
    err = ErrorBundle()
    if listed:
        err.save_resource('listed', True)

    # Populate in the dependencies.
    if set_type:
        err.detected_type = set_type  # Conduit test requires type
    if require_install:
        if 'install.rdf' in package:
            err.save_resource('has_install_rdf', True)
            rdf_data = package.read('install.rdf')
            install_rdf = RDFParser(err, rdf_data)
            err.save_resource('install_rdf', install_rdf)
        elif 'manifest.json' in package:
            err.save_resource('has_manifest_json', True)
            manifest_data = package.read('manifest.json')
            manifest_json = ManifestJsonParser(err, manifest_data)
            err.save_resource('install_rdf', manifest_json)

    populate_chrome_manifest(err, package)

    test(err, package)

    print err.print_summary(verbose=True)

    if failure:
        assert err.failed()
    else:
        assert not err.failed()

    return err
Ejemplo n.º 45
0
def test_json():
    """Test the JSON output capability of the error bundler."""

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle()
    bundle.detected_type = 4
    bundle.set_tier(4)
    bundle.set_tier(3)

    bundle.error((), "error", "description")
    bundle.warning((), "warning", "description")
    bundle.notice((), "notice", "description")

    results = json.loads(bundle.render_json())

    print results

    assert len(results["messages"]) == 3
    assert results["detected_type"] == "langpack"
    assert not results["success"]
    assert results["ending_tier"] == 4
Ejemplo n.º 46
0
def test_json():
    """Test the JSON output capability of the error bundler."""

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle()  # No color since no output
    bundle.detected_type = 4
    bundle.set_tier(4)
    bundle.set_tier(3)

    bundle.error((), "error", "description")
    bundle.warning((), "warning", "description")
    bundle.notice((), "notice", "description")

    results = json.loads(bundle.render_json())

    print results

    assert len(results["messages"]) == 3
    assert results["detected_type"] == 'langpack'
    assert not results["success"]
    assert results["ending_tier"] == 4
Ejemplo n.º 47
0
def test_json():
    """Test the JSON output capability of the error bundler."""

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle()  # No color since no output
    bundle.detected_type = 4
    bundle.set_tier(4)
    bundle.set_tier(3)

    bundle.error((), 'error', 'description')
    bundle.warning((), 'warning', 'description')
    bundle.notice((), 'notice', 'description')

    results = json.loads(bundle.render_json())

    print results

    assert len(results['messages']) == 3
    assert results['detected_type'] == 'langpack'
    assert not results['success']
    assert results['ending_tier'] == 4
Ejemplo n.º 48
0
def _do_test_raw(script, path='foo.js', bootstrap=False, ignore_pollution=True,
                 detected_type=None, jetpack=False, instant=True):
    """Perform a test on a JS file."""

    err = ErrorBundle(instant=instant)
    if jetpack:
        err.metadata['is_jetpack'] = True

    err.handler = OutputHandler(sys.stdout, True)
    err.supported_versions = {}
    if bootstrap:
        err.save_resource('em:bootstrap', True)
    if detected_type:
        err.detected_type = detected_type

    validator.testcases.content._process_file(
        err, MockXPI(), path, script, path.lower(), not ignore_pollution)
    if err.final_context is not None:
        print 'CONTEXT', repr(err.final_context.keys())

    return err
def test_json():
    """Test the JSON output capability of the error bundler."""

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle()  # No color since no output
    bundle.detected_type = 4
    bundle.set_tier(4)
    bundle.set_tier(3)

    bundle.error((), 'error', 'description')
    bundle.warning((), 'warning', 'description')
    bundle.notice((), 'notice', 'description')

    results = json.loads(bundle.render_json())

    print results

    assert len(results['messages']) == 3
    assert results['detected_type'] == 'langpack'
    assert not results['success']
    assert results['ending_tier'] == 4
Ejemplo n.º 50
0
def _run_test_raw(data, failure=True, detected_type=0, listed=True,
                  overrides=None):
    "Runs a test on an install.rdf snippet"

    data = data.strip()

    err = ErrorBundle()
    err.detected_type = detected_type
    err.save_resource("listed", listed)
    err.overrides = overrides

    parser = RDFParser(data)
    installrdf._test_rdf(err, parser)

    print err.print_summary(verbose=True)

    if failure: # pragma: no cover
        assert err.failed() or err.notices
    else:
        assert not err.failed() and not err.notices

    return err
Ejemplo n.º 51
0
def _do_test_raw(script, path="foo.js", bootstrap=False, ignore_pollution=True,
                 detected_type=None, jetpack=False):
    "Performs a test on a JS file"

    err = ErrorBundle(instant=True)
    err.save_resource("SPIDERMONKEY", False)
    if jetpack:
        err.metadata["is_jetpack"] = True

    err.handler = OutputHandler(sys.stdout, True)
    err.supported_versions = {}
    if bootstrap:
        err.save_resource("em:bootstrap", True)
    if detected_type:
        err.detected_type = detected_type

    validator.testcases.content._process_file(
            err, MockXPI(), path, script, path.lower(), not ignore_pollution)
    if err.final_context is not None:
        print err.final_context.output()

    return err
Ejemplo n.º 52
0
def test_jar_nonsubpackage():
    'Tests XPI files that are not subpackages.'

    err = ErrorBundle()
    err.detected_type = PACKAGE_MULTI
    err.save_resource('is_multipackage', True)
    mock_package = MockXPI(
        {'foo.jar':
         'tests/resources/content/subpackage.jar',
         'chrome/bar.jar':
         'tests/resources/content/subpackage.jar'})

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation(
                                    'test_package',
                                    2)
    content.testendpoint_validator.assert_expectation(
                                    'test_package',
                                    0,
                                    'subpackage')
Ejemplo n.º 53
0
def test_jar_nonsubpackage():
    "Tests XPI files that are not subpackages."

    err = ErrorBundle()
    err.detected_type = PACKAGE_MULTI
    err.save_resource("is_multipackage", True)
    mock_package = MockXPI(
        {"foo.jar":
             "tests/resources/content/subpackage.jar",
         "chrome/bar.jar":
             "tests/resources/content/subpackage.jar"})

    result = content.test_packed_packages(err, mock_package)
    print result
    assert result == 2
    content.testendpoint_validator.assert_expectation(
                                    "test_package",
                                    2)
    content.testendpoint_validator.assert_expectation(
                                    "test_package",
                                    0,
                                    "subpackage")
Ejemplo n.º 54
0
def test_states():
    """Test that detected type is preserved, even in subpackages."""

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle()

    # Populate the bundle with some test data.
    bundle.detected_type = 4
    bundle.error((), 'error')
    bundle.warning((), 'warning')
    bundle.notice((), 'notice')
    bundle.save_resource('test', True)

    # Push a state
    bundle.push_state('test.xpi')

    bundle.detected_type = 2
    bundle.error((), 'nested error')
    bundle.warning((), 'nested warning')
    bundle.notice((), 'nested notice')

    # Push another state
    bundle.push_state('test2.xpi')

    bundle.detected_type = 3
    bundle.error((), 'super nested error')
    bundle.warning((), 'super nested warning')
    bundle.notice((), 'super nested notice')

    # Test that nested compatibility messages retain various # properties.
    bundle.notice('comp',
                  'Compat Test notice',
                  compatibility_type='error',
                  editors_only=True,
                  signing_severity='high')

    bundle.pop_state()

    bundle.pop_state()

    # Load the JSON output as an object.
    output = json.loads(bundle.render_json())

    # Run some basic tests
    assert output['detected_type'] == 'langpack'
    assert len(output['messages']) == 10

    messages = [
        'error', 'warning', 'notice', 'nested error', 'nested warning',
        'nested notice', 'super nested error', 'super nested warning',
        'super nested notice', 'Compat Test notice'
    ]

    for message in output['messages']:
        assert message['message'] in messages
        messages.remove(message['message'])

        assert message['message'].endswith(message['type'])

        if message['id'] == 'comp':
            assert message['compatibility_type'] == 'error'
            assert message['editors_only'] == True
            assert message['signing_severity'] == 'high'

    assert not messages

    assert bundle.get_resource('test')
Ejemplo n.º 55
0
def test_states():
    """Test that detected type is preserved, even in subpackages."""

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle()

    # Populate the bundle with some test data.
    bundle.detected_type = 4
    bundle.error((), "error")
    bundle.warning((), "warning")
    bundle.notice((), "notice")
    bundle.save_resource("test", True)

    # Push a state
    bundle.push_state("test.xpi")

    bundle.detected_type = 2
    bundle.error((), "nested error")
    bundle.warning((), "nested warning")
    bundle.notice((), "nested notice")

    # Push another state
    bundle.push_state("test2.xpi")

    bundle.detected_type = 3
    bundle.error((), "super nested error")
    bundle.warning((), "super nested warning")
    bundle.notice((), "super nested notice")

    # Test that nested compatibility messages retain their value
    bundle.notice("comp", "Compat Test notice", compatibility_type="error")

    bundle.pop_state()

    bundle.pop_state()

    # Load the JSON output as an object.
    output = json.loads(bundle.render_json())

    # Run some basic tests
    assert output["detected_type"] == "langpack"
    assert len(output["messages"]) == 10

    print output

    messages = [
        "error", "warning", "notice", "nested error", "nested warning",
        "nested notice", "super nested error", "super nested warning",
        "super nested notice", "Compat Test notice"
    ]

    for message in output["messages"]:
        print message

        assert message["message"] in messages
        messages.remove(message["message"])

        assert message["message"].endswith(message["type"])

        if message["id"] == "comp":
            assert message["compatibility_type"] == "error"

    assert not messages

    assert bundle.get_resource("test")