示例#1
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_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()
示例#3
0
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()
示例#4
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()
示例#5
0
def test_packed_scripts_no_pollution():
    """
    Test that packed scripts test for pollution without being overzealous.
    """

    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', 'subsubpackage']
    }])
    err.save_resource('marked_scripts', set(['chrome://otherns/foo/bar.js']))

    content.test_packed_scripts(err, x)

    eq_(err.package_stack, [])

    assert not err.failed()
示例#6
0
def test_reverse_lookup():
    """Test that the chrome reverse lookup function works properly."""

    c = ChromeManifest(
        """
    content ns1 /dir1/
    content ns2 /dir2/foo/
    content nsbad1 /dir3
    content ns3 jar:foo.jar!/subdir1/
    content ns3 jar:zap.jar!/altdir1/
    content ns4 jar:bar.jar!/subdir2
    """, "chrome.manifest")

    eq_(c.reverse_lookup(MockPackStack(), "random.js"), None)
    eq_(c.reverse_lookup(MockPackStack(), "/dir1/x.js"), "chrome://ns1/x.js")
    eq_(c.reverse_lookup(MockPackStack(), "/dir2/x.js"), None)
    eq_(c.reverse_lookup(MockPackStack(), "/dir2/foo/x.js"),
        "chrome://ns2/x.js")
    eq_(c.reverse_lookup(MockPackStack(), "/dir3/x.js"),
        "chrome://nsbad1/x.js")
    eq_(c.reverse_lookup(MockPackStack(["foo.jar"]), "/x.js"),
        "chrome://ns3/subdir1/x.js")
    eq_(c.reverse_lookup(MockPackStack(["foo.jar"]), "/zap/x.js"),
        "chrome://ns3/subdir1/zap/x.js")
    eq_(c.reverse_lookup(MockPackStack(["bar.jar"]), "/x.js"),
        "chrome://ns4/subdir2/x.js")
    eq_(c.reverse_lookup(MockPackStack(["zap.jar"]), "/x.js"),
        "chrome://ns3/altdir1/x.js")
示例#7
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()
示例#8
0
def test_packed_scripts_no_pollution():
    """
    Test that packed scripts test for pollution without being overzealous.
    """

    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", "subsubpackage"]}])
    err.save_resource("marked_scripts", set(["chrome://otherns/foo/bar.js"]))

    content.test_packed_scripts(err, x)

    eq_(err.package_stack, [])

    assert not err.failed()
def test_reverse_lookup():
    """Test that the chrome reverse lookup function works properly."""

    c = ChromeManifest(
        """
    content ns1 /dir1/
    content ns2 /dir2/foo/
    content nsbad1 /dir3
    content ns3 jar:foo.jar!/subdir1/
    content ns3 jar:zap.jar!/altdir1/
    content ns4 jar:bar.jar!/subdir2
    """, 'chrome.manifest')

    assert c.reverse_lookup(MockPackStack(), 'random.js') is None
    assert c.reverse_lookup(MockPackStack(),
                            '/dir1/x.js') == 'chrome://ns1/x.js'
    assert c.reverse_lookup(MockPackStack(), '/dir2/x.js') is None
    assert c.reverse_lookup(MockPackStack(),
                            '/dir2/foo/x.js') == 'chrome://ns2/x.js'
    assert c.reverse_lookup(MockPackStack(),
                            '/dir3/x.js') == 'chrome://nsbad1/x.js'
    assert c.reverse_lookup(MockPackStack(['foo.jar']),
                            '/x.js') == 'chrome://ns3/subdir1/x.js'
    assert c.reverse_lookup(MockPackStack(['foo.jar']),
                            '/zap/x.js') == 'chrome://ns3/subdir1/zap/x.js'
    assert c.reverse_lookup(MockPackStack(['bar.jar']),
                            '/x.js') == 'chrome://ns4/subdir2/x.js'
    assert c.reverse_lookup(MockPackStack(['zap.jar']),
                            '/x.js') == 'chrome://ns3/altdir1/x.js'
示例#10
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)

    eq_(err.package_stack, [])

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

    eq_(err.warnings[0]["file"],
        ['subpackage.jar', 'subsubpackage', 'foo/bar.js'])
示例#11
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'
    ]
示例#12
0
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()
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"]))
示例#14
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']))
def test_applicable_overlays():
    """
    Test that overlays that apply to the current chrome context are returned
    with proper paths.
    """

    c = ChromeManifest(
        """
    content ns1 jar:foo.jar!/content/junk/
    content ns1 jar:bar.jar!/content/stuff/
    content ns2 jar:zap.jar!/
    content ns3 /baz/

    overlay chrome://foo.xul chrome://ns1/content/junk/o1.xul
    overlay chrome://foo.xul chrome://ns1/content/junk/o2.xul
    overlay chrome://foo.xul chrome://ns1/content/stuff/o3.xul
    overlay chrome://foo.xul chrome://ns2/content/dir/o4.xul
    overlay chrome://foo.xul chrome://ns3/content/root/dir/o5.xul
    overlay chrome://foo.xul chrome://ns1/content/invalid/o6.xul
    """, 'chrome.manifest')

    gac = c.get_applicable_overlays

    assert gac(MockPackStack()) == set(['/baz/root/dir/o5.xul'])
    assert gac(MockPackStack(['foo.jar'])) == set(['/o1.xul', '/o2.xul'])
    assert gac(MockPackStack(['bar.jar'])) == set(['/o3.xul'])
    assert gac(MockPackStack(['zap.jar'])) == set(['/content/dir/o4.xul'])
示例#16
0
def test_applicable_overlays():
    """
    Test that overlays that apply to the current chrome context are returned
    with proper paths.
    """

    c = ChromeManifest(
        """
    content ns1 jar:foo.jar!/content/junk/
    content ns1 jar:bar.jar!/content/stuff/
    content ns2 jar:zap.jar!/
    content ns3 /baz/

    overlay chrome://foo.xul chrome://ns1/content/junk/o1.xul
    overlay chrome://foo.xul chrome://ns1/content/junk/o2.xul
    overlay chrome://foo.xul chrome://ns1/content/stuff/o3.xul
    overlay chrome://foo.xul chrome://ns2/content/dir/o4.xul
    overlay chrome://foo.xul chrome://ns3/content/root/dir/o5.xul
    overlay chrome://foo.xul chrome://ns1/content/invalid/o6.xul
    """, "chrome.manifest")

    gac = c.get_applicable_overlays

    eq_(gac(MockPackStack()), set(["/baz/root/dir/o5.xul"]))
    eq_(gac(MockPackStack(["foo.jar"])), set(["/o1.xul", "/o2.xul"]))
    eq_(gac(MockPackStack(["bar.jar"])), set(["/o3.xul"]))
    eq_(gac(MockPackStack(["zap.jar"])), set(["/content/dir/o4.xul"]))
示例#17
0
def test_content_instructions_trailing_slash():
    """Test that trailing slashes are necessary for content instructions."""

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

    err = ErrorBundle()
    c = ChromeManifest('content namespace /uri/goes/here/ flag=true',
                       'chrome.manifest')
    err.save_resource('chrome.manifest', c)
    tc_chromemanifest.test_content_instructions(err)
    assert not err.failed()
    assert not err.notices
示例#18
0
def test_js_categories_gecko1():
    """Test that JS categories raise problems for space-delimited values."""
    c = ChromeManifest('category JavaScript global foo bar', 'chrome.manifest')
    err = ErrorBundle()
    err.save_resource('chrome.manifest', c)

    tc_chromemanifest.test_categories(err)
    assert err.failed()
示例#19
0
def test_content_missing_information():
    """Test that incomplete information in a content instruction fails."""

    err = ErrorBundle()
    c = ChromeManifest('content foo', 'chrome.manifest')
    err.save_resource('chrome.manifest', c)
    tc_chromemanifest.test_content_instructions(err)
    assert err.failed()
示例#20
0
def test_pass():
    """Test that standard category subjects pass."""

    c = ChromeManifest('category foo bar', 'chrome.manifest')
    err = ErrorBundle()
    err.save_resource('chrome.manifest', c)

    tc_chromemanifest.test_categories(err)
    assert not err.failed()
def test_js_categories_gecko2():
    """Test that JS categories raise problems for hyphenated values."""
    c = ChromeManifest("category JavaScript-DOM-class foo bar",
                       "chrome.manifest")
    err = ErrorBundle()
    err.save_resource("chrome.manifest", c)

    tc_chromemanifest.test_categories(err)
    assert err.failed()
示例#22
0
def populate_chrome_manifest(err, xpi_package):
    "Loads the chrome.manifest if it's present"

    if 'chrome.manifest' in xpi_package:
        chrome = ChromeManifest(xpi_package, 'chrome.manifest', err)

        # Create a reference so we can get the chrome manifest later, but make
        # it pushable so we don't run chrome manifests in JAR files.
        err.save_resource('chrome.manifest', chrome, pushable=True)
        # Create a non-pushable reference for tests that need to access the
        # chrome manifest from within JAR files.
        err.save_resource('chrome.manifest_nopush', chrome, pushable=False)
示例#23
0
    def test_newTab_xul(self):
        """Tests that the newTab.xul overlay is not in the chrome.manifest."""

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

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

        err.save_resource(
            'chrome.manifest',
            ChromeManifest(
                ('overlay chrome://browser/content/newtab/newTab.xul '
                 'chrome://ch/content/newtab/index.xul'), 'chrome.manifest'))
        content.test_newTab_xul(err, None)
        assert err.failed()
        assert not err.errors
        assert len(err.warnings) == 1
        assert err.warnings[0]['compatibility_type'] == 'error'
示例#24
0
def _list_locales(err, xpi_package=None):
    'Returns a raw list of locales from chrome.manifest'

    chrome = None
    if xpi_package is not None:
        # Handle a reference XPI
        chrome = ChromeManifest(xpi_package, 'chrome.manifest', err)
    else:
        # Handle the current XPI
        chrome = err.get_resource('chrome.manifest')
    if not chrome:
        return None

    return list(chrome.get_entries('locale'))
示例#25
0
        def get_linked_manifest(path, from_path, from_chrome, from_triple):

            if path in chrome_recursion_buster:
                err.warning(
                    err_id=("submain", "populate_chrome_manifest",
                            "recursion"),
                    warning="Linked manifest recursion detected.",
                    description="A chrome registration file links back to "
                    "itself. This can cause a multitude of "
                    "issues.",
                    filename=path)
                return

            # Make sure the manifest is properly linked
            if path not in xpi_package:
                err.notice(err_id=("submain", "populate_chrome_manifest",
                                   "linkerr"),
                           notice="Linked manifest could not be found.",
                           description=[
                               "A linked manifest file could not be found "
                               "in the package.",
                               "Path: %s" % path
                           ],
                           filename=from_path,
                           line=from_triple["line"],
                           context=from_chrome.context)
                return

            chrome_recursion_buster.add(path)

            manifest = ChromeManifest(xpi_package.read(path), path)
            for triple in manifest.triples:
                yield triple

                if triple["subject"] == "manifest":
                    subpath = triple["predicate"]
                    # If the path is relative, make it relative to the current
                    # file.
                    if not subpath.startswith("/"):
                        subpath = "%s/%s" % ("/".join(
                            path.split("/")[:-1]), subpath)

                    subpath = subpath.lstrip("/")

                    for subtriple in get_linked_manifest(
                            subpath, path, manifest, triple):
                        yield subtriple

            chrome_recursion_buster.discard(path)
def test_overlay_object():
    """Test that overlay instructions have all its properties."""

    err = ErrorBundle()
    c = ChromeManifest(
        """
    content namespace /foo/bar
    overlay namespace /uri/goes/here
    """, 'chrome.manifest')
    err.save_resource('chrome.manifest', c)
    c.get_applicable_overlays(err)
    assert not err.failed()
    assert not err.notices

    err = ErrorBundle()
    c = ChromeManifest(
        """
    content namespace /foo/bar
    overlay /uri/goes/here
    """, 'chrome.manifest')
    err.save_resource('chrome.manifest', c)
    c.get_applicable_overlays(err)
    assert err.failed()
    assert not err.notices
示例#27
0
def test_duplicate_subjects():
    """Test that two triplets with the same subject can be retrieved."""

    c = ChromeManifest(
        """
    foo bar abc
    foo bar def
    foo bam test
    oof rab cba
    """, "chrome.manifest")

    assert len(list(c.get_triples(subject="foo"))) == 3
    assert len(list(c.get_triples(subject="foo", predicate="bar"))) == 2
    assert len(
        list(c.get_triples(subject="foo", predicate="bar",
                           object_="abc"))) == 1
示例#28
0
def _list_locales(err, xpi_package=None):
    "Returns a raw list of locales from chrome.manifest"

    chrome = None
    if xpi_package is not None:
        # Handle a reference XPI
        chrome = ChromeManifest(xpi_package.read("chrome.manifest"),
                                "chrome.manifest")
    else:
        # Handle the current XPI
        chrome = err.get_resource("chrome.manifest")
    if not chrome:
        return None

    pack_locales = chrome.get_triples("locale")
    return list(pack_locales)
def test_lines():
    """Test that the correct line numbers are given in a chrome.manifest."""

    c = ChromeManifest(
        """
    zero foo bar
    one bar foo
    two abc def
    #comment
    four def abc
    """.strip(), 'chrome.manifest')

    assert list(c.get_triples(subject='zero'))[0]['line'] == 1
    assert list(c.get_triples(subject='one'))[0]['line'] == 2
    assert list(c.get_triples(subject='two'))[0]['line'] == 3
    assert list(c.get_triples(subject='four'))[0]['line'] == 5
def test_duplicate_subjects():
    """Test that two triplets with the same subject can be retrieved."""

    c = ChromeManifest(
        """
    foo bar abc
    foo bar def
    foo bam test
    oof rab cba
    """, 'chrome.manifest')

    assert len(list(c.get_triples(subject='foo'))) == 3
    assert len(list(c.get_triples(subject='foo', predicate='bar'))) == 2
    assert len(
        list(c.get_triples(subject='foo', predicate='bar',
                           object_='abc'))) == 1