Exemplo n.º 1
0
def _do_test(path, test, failure=True,
             require_install=False, set_type=0):
    
    package_data = open(path, "rb")
    package = XPIManager(package_data, path)
    contents = package.get_file_data()
    err = ErrorBundle()
    
    # Populate in the dependencies.
    if set_type:
        err.set_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(rdf_data)
        err.save_resource("install_rdf", install_rdf)
    
    test(err, contents, package)
    
    print err.print_summary(verbose=True)
    
    if failure:
        assert err.failed()
    else:
        assert not err.failed()
    
    return err
Exemplo n.º 2
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
Exemplo n.º 3
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
def test_overlay_object():
    """Test that overlay instructions have all its properties."""

    err = ErrorBundle()

    c = chrome_manifest("""
        content namespace /foo/bar
        overlay namespace /uri/goes/here
    """)

    err.save_resource('chrome.manifest', c)
    c.get_applicable_overlays(err)
    assert not err.failed()
    assert not err.notices

    err = ErrorBundle()

    c = chrome_manifest("""
        content namespace /foo/bar
        overlay /uri/goes/here
    """)
    err.save_resource('chrome.manifest', c)
    c.get_applicable_overlays(err)
    assert err.failed()
    assert not err.notices
Exemplo n.º 5
0
def test_notice():
    """Test notice-related functions of the error bundler."""

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

    bundle.notice((), "")

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

    # Run some basic tests
    assert len(output["messages"]) == 1

    print output

    has_ = False

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

        if message["type"] == "notice":
            has_ = True

    assert has_
    assert not bundle.failed()
    assert not bundle.failed(True)
Exemplo n.º 6
0
def test_overlay_object():
    """Test that overlay instructions have all its properties."""

    err = ErrorBundle()

    c = chrome_manifest("""
        content namespace /foo/bar
        overlay namespace /uri/goes/here
    """)

    err.save_resource('chrome.manifest', c)
    c.get_applicable_overlays(err)
    assert not err.failed()
    assert not err.notices

    err = ErrorBundle()

    c = chrome_manifest("""
        content namespace /foo/bar
        overlay /uri/goes/here
    """)
    err.save_resource('chrome.manifest', c)
    c.get_applicable_overlays(err)
    assert err.failed()
    assert not err.notices
Exemplo n.º 7
0
def test_notice():
    """Test notice-related functions of the error bundler."""

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

    bundle.notice((), '')

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

    # Run some basic tests
    assert len(output['messages']) == 1

    print output

    has_ = False

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

        if message['type'] == 'notice':
            has_ = True

    assert has_
    assert not bundle.failed()
    assert not bundle.failed(True)
Exemplo n.º 8
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
Exemplo n.º 9
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
Exemplo n.º 10
0
def test_valid_chrome_manifest():
    "Chrome manifests must only contain certain elements"

    err = ErrorBundle()
    err.save_resource("chrome.manifest", ChromeManifest("locale foo bar", ""))
    langpack.test_langpack_manifest(err, MockXPI())
    assert not err.failed()

    err.save_resource("chrome.manifest", ChromeManifest("foo bar asdf", ""))
    langpack.test_langpack_manifest(err, MockXPI())
    assert err.failed()
def test_no_chromemanifest():
    """
    Chrome manifest tests should not be run if there is no chrome manifest.
    """
    err = ErrorBundle()
    assert tc_chromemanifest.test_categories(err) is None
    assert not err.failed()

    err = ErrorBundle()
    assert tc_chromemanifest.test_resourcemodules(err) is None
    assert not err.failed()
def test_results_aggregator():
    'Tests that language pack aggregation results are read properly.'

    err = ErrorBundle()
    l10n._aggregate_results(err,
                            [{'type':'missing_files',
                              'filename':'foo.bar'}],
                            {'name': 'en-US',
                             'target': 'foo.bar',
                             'jarred': False})
    assert err.failed()

    err = ErrorBundle()
    l10n._aggregate_results(err,
                            [{'type':'missing_entities',
                              'filename':'foo.bar',
                              'missing_entities':['asdf','ghjk']}],
                            {'name': 'en-US',
                             'target': 'foo.bar',
                             'jarred': False})
    assert err.failed()

    err = ErrorBundle()
    l10n._aggregate_results(err,
                            [{'type':'unchanged_entity',
                              'entities':0,
                              'unchanged_entities':[('asdf', 1), ('ghjk', 1)],
                              'filename':'foo.bar'},
                              {'type':'total_entities',
                               'entities':100}],
                            {'name': 'en-US',
                             'target': 'foo.bar',
                             'jarred': False})
    assert not err.failed()

    err = ErrorBundle()
    l10n._aggregate_results(err,
                            [{'type':'unchanged_entity',
                              'entities':50,
                              'unchanged_entities':[('asdf', 1), ('ghjk', 1)],
                              'filename':'foo.bar'},
                             {'type':'file_entity_count',
                              'filename':'foo.bar',
                              'entities':100},
                             {'type':'total_entities',
                              'entities':100}],
                            {'name': 'en-US',
                             'target': 'foo.bar',
                             'path': '/locale/en-US/',
                             'jarred': True})
    assert not err.failed()
    assert err.notices
    print err.notices
    assert all('//' not in ''.join(m['file']) for m in err.warnings)
Exemplo n.º 13
0
def _do_test(url, failure=True, listed=False):
    err = ErrorBundle()
    results = detect_opensearch(err, open(url), listed=listed)

    if results.failed():
        print results.print_summary()

    if failure:
        assert err.failed()
    else:
        assert not err.failed()
Exemplo n.º 14
0
def test_valid_chrome_manifest():
    'Chrome manifests must only contain certain elements'

    err = ErrorBundle()
    err.save_resource('chrome.manifest', chrome_manifest('locale foo bar'))
    langpack.test_langpack_manifest(err, MockXPI())
    assert not err.failed()

    err.save_resource('chrome.manifest', chrome_manifest('foo bar asdf'))
    langpack.test_langpack_manifest(err, MockXPI())
    assert err.failed()
Exemplo n.º 15
0
def _do_test(url, failure=True, listed=False):
    err = ErrorBundle()
    results = detect_opensearch(err, open(url), listed=listed)

    if results.failed():
        print results.print_summary()

    if failure:
        assert err.failed(), 'Expected failure'
    else:
        assert not err.failed(), 'Expected pass'
def test_no_chromemanifest():
    """
    Chrome manifest tests should not be run if there is no chrome manifest.
    """
    err = ErrorBundle()
    assert tc_chromemanifest.test_categories(err) is None
    assert not err.failed()

    err = ErrorBundle()
    assert tc_chromemanifest.test_resourcemodules(err) is None
    assert not err.failed()
Exemplo n.º 17
0
def _test_value(value, test, failure=True):
    "Tests a value against a test."

    err = ErrorBundle()

    test(err, value)

    if failure:
        return err.failed()
    else:
        return not err.failed()
Exemplo n.º 18
0
def test_valid_chrome_manifest():
    'Chrome manifests must only contain certain elements'

    err = ErrorBundle()
    err.save_resource('chrome.manifest', ChromeManifest('locale foo bar', ''))
    langpack.test_langpack_manifest(err, MockXPI())
    assert not err.failed()

    err.save_resource('chrome.manifest', ChromeManifest('foo bar asdf', ''))
    langpack.test_langpack_manifest(err, MockXPI())
    assert err.failed()
Exemplo n.º 19
0
def test_valid_chrome_manifest():
    "Chrome manifests must only contain certain elements"

    err = ErrorBundle()
    err.save_resource("chrome.manifest", ChromeManifest("locale foo bar", ""))
    langpack.test_langpack_manifest(err, MockXPI())
    assert not err.failed()

    err.save_resource("chrome.manifest", ChromeManifest("foo bar asdf", ""))
    langpack.test_langpack_manifest(err, MockXPI())
    assert err.failed()
def test_scripting_snippet():
    'Assert that JS snippets are treated equally.'

    err = ErrorBundle()
    err.supported_versions = {}
    scripting.test_js_snippet(err, 'alert(1 + 1 == 2)', 'bar.zap')
    assert not err.failed()

    err = ErrorBundle()
    err.supported_versions = {}
    scripting.test_js_snippet(err, "eval('foo');", 'bar.zap')
    assert err.failed()
Exemplo n.º 21
0
def test_webapp_installs_allowed_from_missing_listed():
    """Test that installs_allowed_from is present when listed.."""

    err = ErrorBundle(listed=False)
    data = _get_json()
    del data["installs_allowed_from"]
    _detect(err, data)
    assert not err.failed()

    err = ErrorBundle(listed=True)
    _detect(err, data)
    assert err.failed()
def test_scripting_snippet():
    "Asserts that JS snippets are treated equally"

    err = ErrorBundle()
    err.supported_versions = {}
    scripting.test_js_snippet(err, "alert(1 + 1 == 2)", "bar.zap")
    assert not err.failed()

    err = ErrorBundle()
    err.supported_versions = {}
    scripting.test_js_snippet(err, "eval('foo');", "bar.zap")
    assert err.failed()
Exemplo n.º 23
0
def test_scripting_snippet():
    'Assert that JS snippets are treated equally.'

    err = ErrorBundle()
    err.supported_versions = {}
    scripting.test_js_snippet(err, 'alert(1 + 1 == 2)', 'bar.zap')
    assert not err.failed()

    err = ErrorBundle()
    err.supported_versions = {}
    scripting.test_js_snippet(err, "eval('foo');", 'bar.zap')
    assert err.failed()
Exemplo n.º 24
0
def test_scripting_snippet():
    "Asserts that JS snippets are treated equally"

    err = ErrorBundle()
    err.supported_versions = {}
    scripting.test_js_snippet(err, "alert(1 + 1 == 2)", "bar.zap")
    assert not err.failed()

    err = ErrorBundle()
    err.supported_versions = {}
    scripting.test_js_snippet(err, "eval('foo');", "bar.zap")
    assert err.failed()
def test_content_instructions():
    """Test that banned content namespaces are banned."""

    err = ErrorBundle()
    c = chrome_manifest('content foo bar')
    err.save_resource('chrome.manifest', c)
    tc_chromemanifest.test_content_instructions(err)
    assert not err.failed()

    c = chrome_manifest('content godlikea bar')
    err.save_resource('chrome.manifest', c)
    tc_chromemanifest.test_content_instructions(err)
    assert err.failed()
def test_content_instructions():
    """Test that banned content namespaces are banned."""

    err = ErrorBundle()
    c = ChromeManifest("content foo bar", "chrome.manifest")
    err.save_resource("chrome.manifest", c)
    tc_chromemanifest.test_content_instructions(err)
    assert not err.failed()

    c = ChromeManifest("content godlikea bar", "chrome.manifest")
    err.save_resource("chrome.manifest", c)
    tc_chromemanifest.test_content_instructions(err)
    assert err.failed()
Exemplo n.º 27
0
def test_prepare_package_xml(test_search):
    'Tests that the prepare_package function passes with search providers'

    err = ErrorBundle()
    submain.prepare_package(err, 'tests/resources/main/foo.xml')

    assert not err.failed()
    assert test_search.called

    test_search.side_effect = lambda err, *args: err.error(('x'), 'Failed')
    submain.prepare_package(err, 'tests/resources/main/foo.xml')

    assert err.failed()
Exemplo n.º 28
0
def test_prepare_package_xml(test_search):
    'Tests that the prepare_package function passes with search providers'

    err = ErrorBundle()
    submain.prepare_package(err, 'tests/resources/main/foo.xml')

    assert not err.failed()
    assert test_search.called

    test_search.side_effect = lambda err, *args: err.error(('x'), 'Failed')
    submain.prepare_package(err, 'tests/resources/main/foo.xml')

    assert err.failed()
Exemplo n.º 29
0
def test_xpcnativewrappers():
    'Tests that xpcnativewrappers is not in the chrome.manifest'

    err = ErrorBundle()
    assert content.test_xpcnativewrappers(err, None) is None

    err.save_resource('chrome.manifest', chrome_manifest('foo bar'))
    content.test_xpcnativewrappers(err, None)
    assert not err.failed()

    err.save_resource('chrome.manifest',
                      chrome_manifest('xpcnativewrappers on'))
    content.test_xpcnativewrappers(err, None)
    assert err.failed()
Exemplo n.º 30
0
def _do_test(path, should_fail=False):

    data = open(path).read()
    err = ErrorBundle()

    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
Exemplo n.º 31
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()
Exemplo n.º 32
0
def test_webapp_invalid_locale_keys():
    """Test that locales only contain valid keys."""

    err = ErrorBundle()
    data = _get_json()
    # Banned locale element.
    data["locales"]["es"]["default_locale"] = "foo"
    _detect(err, data)
    assert err.failed()

    err = ErrorBundle()
    data = _get_json()
    del data["locales"]["es"]["name"]
    _detect(err, data)
    assert not err.failed()
Exemplo n.º 33
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
Exemplo n.º 35
0
 def test_structure(structure):
     err = ErrorBundle()
     err.supported_versions = {}
     mock_package = MockXPI(structure)
     content.test_packed_packages(err, mock_package)
     print err.print_summary(verbose=True)
     assert err.failed()
Exemplo n.º 36
0
def test_prepare_package_xml():
    "Tests that the prepare_package function passes with search providers"
    
    submain.test_search = lambda err,y,z: True
    
    err = ErrorBundle(None, True)
    submain.prepare_package(err, "tests/resources/main/foo.xml")
    
    assert not err.failed()
    assert not err.reject
    
    submain.test_search = lambda err,y,z: err.error(("x"), "Failed")
    submain.prepare_package(err, "tests/resources/main/foo.xml")
    
    assert err.failed()
    assert not err.reject # prepare_package has no authority to reject XML.
Exemplo n.º 37
0
def test_xpcnativewrappers():
    "Tests that xpcnativewrappers is not in the chrome.manifest"

    err = ErrorBundle()
    assert content.test_xpcnativewrappers(err, None) is None

    err.save_resource("chrome.manifest",
                      ChromeManifest("foo bar", "chrome.manifest"))
    content.test_xpcnativewrappers(err, None)
    assert not err.failed()

    err.save_resource(
        "chrome.manifest",
        ChromeManifest("xpcnativewrappers on", "chrome.manifest"))
    content.test_xpcnativewrappers(err, None)
    assert err.failed()
Exemplo n.º 38
0
def test_webapp_pass():
    """Test that a bland webapp file throws no errors."""

    err = ErrorBundle()
    _detect(err, _get_json())
    print err.print_summary(verbose=True)
    assert not err.failed()
def test_fail_resourcemodules():
    """'resource modules' should fail validation."""
    c = chrome_manifest('resource modules foo')
    err = ErrorBundle()
    err.save_resource('chrome.manifest', c)

    tc_chromemanifest.test_resourcemodules(err)
    assert err.failed()

    # Fail even if it's just a prefix.
    c = chrome_manifest('resource modulesfoo')
    err = ErrorBundle()
    err.save_resource('chrome.manifest', c)

    tc_chromemanifest.test_resourcemodules(err)
    assert err.failed()
def test_content_instructions_trailing_slash():
    """Test that trailing slashes are necessary for content instructions."""

    err = ErrorBundle()
    c = chrome_manifest('content namespace /uri/goes/here')
    err.save_resource('chrome.manifest', c)
    tc_chromemanifest.test_content_instructions(err)
    assert not err.failed()
    assert err.notices

    err = ErrorBundle()
    c = chrome_manifest('content namespace /uri/goes/here/ flag=true')
    err.save_resource('chrome.manifest', c)
    tc_chromemanifest.test_content_instructions(err)
    assert not err.failed()
    assert not err.notices
Exemplo n.º 41
0
def test_proper_linked_manifest_relative():
    """
    Test that linked manifests are imported relatively when using relative
    paths.
    """

    err = ErrorBundle()
    package = MockXPI({
        'chrome.manifest':
        'tests/resources/submain/linkman/subdir.manifest',
        'dir/level2.manifest':
        'tests/resources/submain/linkman/foosub.manifest',
        'dir/foo.manifest':
        'tests/resources/submain/linkman/base2.manifest'
    })

    submain.populate_chrome_manifest(err, package)
    chrome = err.get_resource('chrome.manifest')
    assert chrome

    assert not err.failed() or err.notices

    # From the linked manifest:
    zaps = list(chrome.get_triples(subject='zap'))
    assert zaps
    assert zaps[0]['filename'] == 'dir/foo.manifest'
    assert zaps[0]['context'].data == ['zap baz', '']
Exemplo n.º 42
0
def test_prepare_package_missing():
    'Tests that the prepare_package function fails when file is not found'

    err = ErrorBundle()
    submain.prepare_package(err, 'foo/bar/asdf/qwerty.xyz')

    assert err.failed()
Exemplo n.º 43
0
def test_prepare_package(test_package):
    """Tests that the prepare_package does not raise any errors when given
    a valid add-on."""

    err = ErrorBundle()
    submain.prepare_package(err, 'tests/resources/main/foo.xpi')
    assert not err.failed()
Exemplo n.º 44
0
def test_marking_overlays_subdir():
    """
    Mark an overlay in a subdirectory, then test that it marks the scripts
    within the overlay. Make sure it properly figures out relative URLs.
    """

    err = ErrorBundle()
    err.supported_versions = {}
    c = ChromeManifest("""
    content ns1 foo/
    overlay chrome://foo chrome://ns1/content/subdir/main.xul
    """, 'chrome.manifest')
    err.save_resource('chrome.manifest', c)
    err.save_resource('chrome.manifest_nopush', c)

    xpi = MockXPI({'foo/subdir/main.xul':
                       'tests/resources/content/script_list.xul'})

    content.test_packed_packages(err, xpi)
    assert not err.failed()

    marked_scripts = err.get_resource('marked_scripts')
    print marked_scripts
    assert marked_scripts

    eq_(marked_scripts, set(['chrome://ns1/subdir/foo.js', 'chrome://ns1/bar.js',
                             'chrome://asdf/foo.js']))
Exemplo n.º 45
0
def test_duplicate_files():
    """Test that duplicate files in a package are caught."""

    err = ErrorBundle()
    err.save_resource("has_install_rdf", True)
    packagelayout.test_layout_all(err, MockDupeXPI())
    assert err.failed()
Exemplo n.º 46
0
def test_blacklisted_files():
    """
    Tests the validator's ability to hash each individual file and (based on
    this information) determine whether the addon passes or fails the
    validation process.
    """

    package_data = open('tests/resources/libraryblacklist/blocked.xpi')
    package = XPIManager(package_data, mode='r', name='blocked.xpi')
    err = ErrorBundle()

    test_content.test_packed_packages(err, package)

    print err.print_summary()

    assert err.notices
    assert not err.failed()
    eq_(
        err.metadata.get('identified_files'), {
            'test.js': {
                'path':
                'This file is a false script to facilitate '
                'testing of library blacklisting.'
            }
        })
Exemplo n.º 47
0
def test_packed_scripts_pollution():
    """Test that packed scripts test for pollution properly."""

    x = MockXPI({'foo/bar.js': 'tests/resources/content/pollution_error.js'})

    err = ErrorBundle()
    err.supported_versions = {}

    c = ChromeManifest("""
    content ns jar:subpackage.jar!/
    """, 'chrome.manifest')

    err.save_resource('chrome.manifest_nopush', c, pushable=False)

    err.save_resource('scripts', [{
        'scripts': ['foo/bar.js'],
        'package': x,
        'state': ['subpackage.jar', 'subsubpackage']
    }])
    err.save_resource('marked_scripts', set(['chrome://ns/foo/bar.js']))

    content.test_packed_scripts(err, x)

    assert err.package_stack == []

    assert err.failed()
    assert err.warnings
    assert not err.errors

    assert err.warnings[0]['file'] == [
        'subpackage.jar', 'subsubpackage', 'foo/bar.js'
    ]
Exemplo n.º 48
0
def test_prepare_package_bad_file():
    'Tests that the prepare_package function fails for unknown files'

    err = ErrorBundle()
    submain.prepare_package(err, 'tests/resources/main/foo.bar')

    assert err.failed()
Exemplo n.º 49
0
def test_prepare_package_missing():
    'Tests that the prepare_package function fails when file is not found'

    err = ErrorBundle()
    submain.prepare_package(err, 'foo/bar/asdf/qwerty.xyz')

    assert err.failed()
def _run_test(filename, expectation, should_fail=True):

    name = "tests/resources/submain/%s" % filename
    pack = open(name)
    xpi = XPIManager(pack, mode="r", name=name)
    err = ErrorBundle(None, True)

    submain._load_install_rdf(err, xpi, expectation)

    if should_fail:
        assert err.failed()
    else:
        assert not err.failed()
        assert err.get_resource("install_rdf")

    return err
Exemplo n.º 51
0
def test_xpcnativewrappers():
    "Tests that xpcnativewrappers is not in the chrome.manifest"

    err = ErrorBundle()
    assert content.test_xpcnativewrappers(err, None) is None

    err.save_resource("chrome.manifest",
                      ChromeManifest("foo bar", "chrome.manifest"))
    content.test_xpcnativewrappers(err, None)
    assert not err.failed()

    err.save_resource("chrome.manifest",
                      ChromeManifest("xpcnativewrappers on",
                                     "chrome.manifest"))
    content.test_xpcnativewrappers(err, None)
    assert err.failed()
Exemplo n.º 52
0
def test_prepare_package_bad_file():
    'Tests that the prepare_package function fails for unknown files'

    err = ErrorBundle()
    submain.prepare_package(err, 'tests/resources/main/foo.bar')

    assert err.failed()
Exemplo n.º 53
0
def test_duplicate_files():
    """Test that duplicate files in a package are caught."""

    err = ErrorBundle()
    err.save_resource('has_install_rdf', True)
    packagelayout.test_layout_all(err, MockDupeXPI())
    assert err.failed()
def test_fail_resourcemodules():
    """'resource modules' should fail validation."""
    c = ChromeManifest("resource modules foo", "chrome.manifest")
    err = ErrorBundle()
    err.save_resource("chrome.manifest", c)

    tc_chromemanifest.test_resourcemodules(err)
    assert err.failed()

    # Fail even if it's just a prefix.
    c = ChromeManifest("resource modulesfoo", "chrome.manifest")
    err = ErrorBundle()
    err.save_resource("chrome.manifest", c)

    tc_chromemanifest.test_resourcemodules(err)
    assert err.failed()
Exemplo n.º 55
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
Exemplo n.º 56
0
def test_prepare_package_xml():
    "Tests that the prepare_package function passes with search providers"

    smts = submain.test_search
    submain.test_search = lambda err, y, z: True

    err = ErrorBundle()
    submain.prepare_package(err, "tests/resources/main/foo.xml")

    assert not err.failed()

    submain.test_search = lambda err, y, z: err.error(("x"), "Failed")
    submain.prepare_package(err, "tests/resources/main/foo.xml")

    assert err.failed()
    submain.test_search = smts
Exemplo n.º 57
0
def test_marking_overlays():
    """
    Mark an overlay, then test that it marks the scripts within the overlay.
    """

    err = ErrorBundle()
    err.supported_versions = {}
    c = ChromeManifest("""
    content ns1 foo/
    overlay chrome://foo chrome://ns1/content/main.xul
    """, "chrome.manifest")
    err.save_resource("chrome.manifest", c)
    err.save_resource("chrome.manifest_nopush", c)

    xpi = MockXPI({"foo/main.xul": "tests/resources/content/script_list.xul"})

    content.test_packed_packages(err, xpi)
    assert not err.failed()

    marked_scripts = err.get_resource("marked_scripts")
    print marked_scripts
    assert marked_scripts

    eq_(marked_scripts, set(["chrome://ns1/foo.js",
                             "chrome://ns1/bar.js",
                             "chrome://asdf/foo.js"]))