def test_downloads_indicator_icon_allowed():
    """Test that #downloads-indicator-icon is allowed."""

    err = ErrorBundle(for_appversions=FX27_DEFINITION)
    csstester.test_css_file(err, "x.css",
                            "#downloads-indicator-icon { display: none; }", 0)
    assert not err.failed()
    assert all(val == 0 for val in err.compat_summary.values())
def test_downloads_indicator_unused():
    """Test that #downloads-indicator is not used."""

    err = ErrorBundle(for_appversions=FX27_DEFINITION)
    csstester.test_css_file(err, "x.css",
                            "#downloads-indicator { display: none; }", 0)
    assert err.failed()
    assert err.compat_summary['errors'] == 1
def test_downloads_indicator_unused():
    """Test that #downloads-indicator is not used."""

    err = ErrorBundle(for_appversions=FX27_DEFINITION)
    csstester.test_css_file(err, "x.css",
                            "#downloads-indicator { display: none; }", 0)
    assert err.failed()
    assert err.compat_summary['errors'] == 1
def test_downloads_indicator_icon_allowed():
    """Test that #downloads-indicator-icon is allowed."""

    err = ErrorBundle(for_appversions=FX27_DEFINITION)
    csstester.test_css_file(err, "x.css",
                            "#downloads-indicator-icon { display: none; }", 0)
    assert not err.failed()
    assert all(val == 0 for val in err.compat_summary.values())
def test_downloads_indicator_gecko_16():
    """Test that #downloads-indicator is allowed for an old Gecko."""

    err = ErrorBundle(for_appversions=FX16_DEFINITION)
    csstester.test_css_file(err, "x.css",
                            "#downloads-indicator { display: none; }", 0)
    assert not err.failed()
    assert all(val == 0 for val in err.compat_summary.values())
def test_downloads_indicator_gecko_16():
    """Test that #downloads-indicator is allowed for an old Gecko."""

    err = ErrorBundle(for_appversions=FX16_DEFINITION)
    csstester.test_css_file(err, "x.css",
                            "#downloads-indicator { display: none; }", 0)
    assert not err.failed()
    assert all(val == 0 for val in err.compat_summary.values())
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
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
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
Beispiel #10
0
def _process_file(err, xpi_package, name, file_data, name_lower,
                  pollutable=False):
    """Process a single file's content tests."""

    # If that item is a container file, unzip it and scan it.
    if name_lower.endswith(".jar"):
        # This is either a subpackage or a nested theme.
        is_subpackage = not err.get_resource("is_multipackage")
        # Unpack the package and load it up.
        package = StringIO(file_data)
        try:
            sub_xpi = XPIManager(package, mode="r", name=name,
                                 subpackage=is_subpackage)
        except Exception:
            err.error(("testcases_content",
                       "test_packed_packages",
                       "jar_subpackage_corrupt"),
                      "Subpackage corrupt.",
                      "The subpackage could not be opened due to issues "
                      "with corruption. Ensure that the file is valid.",
                      name)
            return None

        # Let the error bunder know we're in a sub-package.
        err.push_state(name)
        err.detected_type = (PACKAGE_SUBPACKAGE if is_subpackage else
                             PACKAGE_THEME)
        err.set_tier(1)
        supported_versions = (err.supported_versions.copy() if
                              err.supported_versions else
                              err.supported_versions)

        if is_subpackage:
            testendpoint_validator.test_inner_package(err, sub_xpi)
        else:
            testendpoint_validator.test_package(err, package, name)

        err.pop_state()
        err.set_tier(2)

        err.supported_versions = supported_versions

    elif name_lower.endswith(".xpi"):
        # It's not a subpackage, it's a nested extension. These are
        # found in multi-extension packages.

        # Unpack!
        package = StringIO(file_data)

        err.push_state(name_lower)
        err.set_tier(1)

        # There are no expected types for packages within a multi-
        # item package.
        testendpoint_validator.test_package(err, package, name)

        err.pop_state()
        err.set_tier(2)  # Reset to the current tier

    elif name_lower.endswith((".css", ".js", ".jsm")):

        if not file_data:
            return None

        # Convert the file data to unicode
        file_data = unicodehelper.decode(file_data)
        is_js = False

        if name_lower.endswith(".css"):
            testendpoint_css.test_css_file(err, name, file_data)

        elif name_lower.endswith((".js", ".jsm")):
            is_js = True
            testendpoint_js.test_js_file(err, name, file_data,
                                         pollutable=pollutable)

        run_regex_tests(file_data, err, name, is_js=is_js)

        return True

    return False
Beispiel #11
0
def _process_file(err, xpi_package, name, file_data, name_lower,
                  pollutable=False):
    """Process a single file's content tests."""

    # If that item is a container file, unzip it and scan it.
    if name_lower.endswith('.jar'):
        # This is either a subpackage or a nested theme.
        is_subpackage = not err.get_resource('is_multipackage')
        # Unpack the package and load it up.
        package = StringIO(file_data)
        try:
            sub_xpi = XPIManager(package, mode='r', name=name,
                                 subpackage=is_subpackage)
        except BadZipfile:
            err.error(('testcases_content',
                       'test_packed_packages',
                       'jar_subpackage_corrupt'),
                      'Subpackage corrupt.',
                      'The subpackage appears to be corrupt, and could not '
                      'be opened.',
                      name)
            return None

        # Let the error bunder know we're in a sub-package.
        err.push_state(name)
        err.detected_type = (PACKAGE_SUBPACKAGE if is_subpackage else
                             PACKAGE_THEME)
        err.set_tier(1)
        supported_versions = (err.supported_versions.copy() if
                              err.supported_versions else
                              err.supported_versions)

        if is_subpackage:
            testendpoint_validator.test_inner_package(err, sub_xpi)
        else:
            testendpoint_validator.test_package(err, package, name)

        err.pop_state()
        err.set_tier(2)

        err.supported_versions = supported_versions

    elif name_lower.endswith('.xpi'):
        # It's not a subpackage, it's a nested extension. These are
        # found in multi-extension packages.

        # Unpack!
        package = StringIO(file_data)

        err.push_state(name_lower)
        err.set_tier(1)

        # There are no expected types for packages within a multi-
        # item package.
        testendpoint_validator.test_package(err, package, name)

        err.pop_state()
        err.set_tier(2)  # Reset to the current tier

    elif name_lower.endswith(('.css', '.js', '.jsm')):

        if not file_data:
            return None

        # Convert the file data to unicode
        file_data = unicodehelper.decode(file_data)
        is_js = name_lower.endswith(('.js', '.jsm'))

        if name_lower.endswith('.css'):
            testendpoint_css.test_css_file(err, name, file_data)

        elif is_js:
            testendpoint_js.test_js_file(err, name, file_data,
                                         pollutable=pollutable)

        run_regex_tests(file_data, err, name, is_js=is_js)

        return True

    else:
        if file_data:
            file_data = unicodehelper.decode(file_data)
            run_regex_tests(file_data, err, name, explicit=True)

    return False
Beispiel #12
0
    def handle_endtag(self, tag):

        tag = tag.lower()
        if tag == "xul:script":
            tag = "script"

        if tag == "script" and len(self.xml_buffer[-1]) > 1000:
            self.err.warning(("markup", "complex_script"),
                             "Long inline script",
                             "Please store complex scripts in .js files "
                             "rather than inline script nodes.",
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)

        if DEBUG:  # pragma: no cover
            print "E: ", tag, self.xml_state

        if not self.xml_state:
            if "closing_tags" in self.reported or not self.strict:
                if DEBUG:
                    print "Unstrict; extra closing tags ------"
                return
            self.err.warning(("markup", "endtag", "extra_closing_tags"),
                             "Markup parsing error",
                             "The markup file has more closing tags than it "
                             "has opening tags.",
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)
            self.reported.add("closing_tags")
            if DEBUG:  # pragma: no cover
                print "Too many closing tags ------"
            return

        elif "script" in self.xml_state[:-1]:
            # If we're in a script tag, nothing else matters. Just rush
            # everything possible into the xml buffer.

            self._save_to_buffer("</" + tag + ">")
            if DEBUG:
                print "Markup as text in script ------"
            return

        elif tag not in self.xml_state:
            # If the tag we're processing isn't on the stack, then
            # something is wrong.
            self.err.warning(
                ("markup", "endtag", "extra_closing_tags"),
                "Parse error: tag closed before opened", [
                    "Markup tags cannot be closed before they are "
                    "opened. Perhaps you were just a little "
                    "overzealous with forward-slashes?",
                    'Tag "%s" closed before it was opened' % tag
                ],
                self.filename,
                line=self.line,
                context=self.context,
                tier=2)
            if DEBUG:  # pragma: no cover
                print "Tag closed before opened ------"
            return

        data_buffer = self.xml_buffer.pop()
        old_state = self.xml_state.pop()
        old_line = self.xml_line_stack.pop()
        script_type = True
        if old_state == "script":
            script_type = self.xml_state_scripts.pop()

        # If the tag on the stack isn't what's being closed and it also
        # classifies as a self-closing tag, we just recursively close
        # down to the level of the tag we're actualy closing.
        if old_state != tag and old_state in SELF_CLOSING_TAGS:
            if DEBUG:
                print "Self closing tag cascading down ------"
            return self.handle_endtag(tag)

        # If this is an XML-derived language, everything must nest
        # properly. No overlapping tags.
        if (old_state != tag and self.extension[0] == 'x' and not self.strict):

            self.err.warning(("markup", "endtag", "invalid_nesting"),
                             "Markup invalidly nested",
                             "It has been determined that the document "
                             "invalidly nests its tags. This is not permitted "
                             "in the specified document type.",
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)
            if DEBUG:  # pragma: no cover
                print "Invalid markup nesting ------"

        data_buffer = data_buffer.strip()

        # Perform analysis on collected data.
        if data_buffer:
            if tag == "script" and not script_type:
                scripting.test_js_snippet(err=self.err,
                                          data=data_buffer,
                                          filename=self.filename,
                                          line=old_line,
                                          context=self.context)
            elif tag == "style":
                csstester.test_css_file(self.err, self.filename, data_buffer,
                                        old_line)
Beispiel #13
0
def test_packed_packages(err, package_contents=None, xpi_package=None):
    "Tests XPI and JAR files for naughty content."
    
    processed_files = 0

    hash_whitelist = [x[:-1] for x in
                      open(os.path.join(os.path.dirname(__file__),
                                        'whitelist_hashes.txt')).readlines()]
    
    # Iterate each item in the package.
    for name, data in package_contents.items():
        
        if name.startswith("__MACOSX") or \
           name.startswith(".DS_Store"):
            continue
        
        if name.split("/")[-1].startswith("._"):
            err.notice(("testcases_content",
                        "test_packed_packages",
                        "macintosh_junk"),
                       "Garbage file found.",
                       ["""A junk file has been detected. It may cause
                        problems with proper operation of the add-on down the
                        road.""",
                        "It is recommended that you delete the file"],
                       name)
        
        try:
            file_data = xpi_package.read(name)
        except KeyError: # pragma: no cover
            _read_error(err, name)

        # Skip over whitelisted hashes
        hash = hashlib.sha1(file_data).hexdigest()
        if hash in hash_whitelist:
            continue

        processed = False
        # If that item is a container file, unzip it and scan it.
        if data["extension"] == "jar":
            # This is either a subpackage or a nested theme.
            
            # Whether this is a subpackage or a nested theme is
            # determined by whether it is in the root folder or not.
            # Subpackages are always found in a directory such as
            # /chrome or /content.
            is_subpackage = name.count("/") > 0
            
            # Unpack the package and load it up.
            package = StringIO(file_data)
            sub_xpi = XPIManager(package, name, is_subpackage)
            if not sub_xpi.zf:
                err.error(("testcases_content",
                           "test_packed_packages",
                           "jar_subpackage_corrupt"),
                          "Subpackage corrupt.",
                          """The subpackage could not be opened due to
                          issues with corruption. Ensure that the file
                          is valid.""",
                          name)
                continue
            
            temp_contents = sub_xpi.get_file_data()
            
            # Let the error bunder know we're in a sub-package.
            err.push_state(data["name_lower"])
            err.set_type(PACKAGE_SUBPACKAGE) # Subpackage
            testendpoint_validator.test_inner_package(err,
                                                      temp_contents,
                                                      sub_xpi)
            err.tier = 2
            package.close()
            err.pop_state()
            
        elif data["extension"] == "xpi":
            # It's not a subpackage, it's a nested extension. These are
            # found in multi-extension packages.
            
            # Unpack!
            package = StringIO(file_data)
            
            err.push_state(data["name_lower"])
            

            # There are no expected types for packages within a multi-
            # item package.
            testendpoint_validator.test_package(err, package, name)
            err.tier = 2 # Reset to the current tier
            
            package.close()
            err.pop_state()
            
        elif data["extension"] in ("xul", "xml", "html", "xhtml"):
            
            parser = testendpoint_markup.MarkupParser(err)
            parser.process(name,
                           charsethelper.decode(file_data),
                           data["extension"])
            
            processed = True
                
            
        elif data["extension"] in ("css", "js", "jsm"):
            
            if not file_data:
                continue
            file_data = charsethelper.decode(file_data)
            
            if data["extension"] == "css":
                testendpoint_css.test_css_file(err,
                                               name,
                                               file_data)
            elif data["extension"] in ("js", "jsm"):
                testendpoint_js.test_js_file(err,
                                             name,
                                             file_data)
        # This is tested in test_langpack.py
        if err.detected_type == PACKAGE_LANGPACK and not processed:
            
            testendpoint_langpack.test_unsafe_html(err,
                                                   name,
                                                   file_data)
        
        # This aids in creating unit tests.
        processed_files += 1
            
    return processed_files
Beispiel #14
0
    def handle_endtag(self, tag):

        tag = tag.lower()
        if tag == 'xul:script':
            tag = 'script'

        if tag == 'script' and len(self.xml_buffer[-1]) > 1000:
            self.err.warning(('markup', 'complex_script'),
                             'Long inline script',
                             'Please store complex scripts in .js files '
                             'rather than inline script nodes.',
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)

        if DEBUG:  # pragma: no cover
            print 'E: ', tag, self.xml_state

        if not self.xml_state:
            if 'closing_tags' in self.reported or not self.strict:
                if DEBUG:
                    print 'Unstrict; extra closing tags ------'
                return
            self.err.warning(('markup', 'endtag', 'extra_closing_tags'),
                             'Markup parsing error',
                             'The markup file has more closing tags than it '
                             'has opening tags.',
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)
            self.reported.add('closing_tags')
            if DEBUG:  # pragma: no cover
                print 'Too many closing tags ------'
            return

        elif 'script' in self.xml_state[:-1]:
            # If we're in a script tag, nothing else matters. Just rush
            # everything possible into the xml buffer.

            self._save_to_buffer('</' + tag + '>')
            if DEBUG:
                print 'Markup as text in script ------'
            return

        elif tag not in self.xml_state:
            # If the tag we're processing isn't on the stack, then
            # something is wrong.
            self.err.warning(
                ('markup', 'endtag', 'extra_closing_tags'),
                'Parse error: tag closed before opened', [
                    'Markup tags cannot be closed before they are '
                    'opened. Perhaps you were just a little '
                    'overzealous with forward-slashes?',
                    'Tag "%s" closed before it was opened' % tag
                ],
                self.filename,
                line=self.line,
                context=self.context,
                tier=2)
            if DEBUG:  # pragma: no cover
                print 'Tag closed before opened ------'
            return

        data_buffer = self.xml_buffer.pop()
        old_state = self.xml_state.pop()
        old_line = self.xml_line_stack.pop()
        old_position = self.xml_position_stack.pop() or (old_line, 0)
        script_type = True
        if old_state == 'script':
            script_type = self.xml_state_scripts.pop()

        # If the tag on the stack isn't what's being closed and it also
        # classifies as a self-closing tag, we just recursively close
        # down to the level of the tag we're actualy closing.
        if old_state != tag and old_state in SELF_CLOSING_TAGS:
            if DEBUG:
                print 'Self closing tag cascading down ------'
            return self.handle_endtag(tag)

        # If this is an XML-derived language, everything must nest
        # properly. No overlapping tags.
        #
        # ^ Oh, basta, you really have no idea, do you...
        if (old_state != tag and self.extension[0] == 'x' and not self.strict):

            self.err.warning(('markup', 'endtag', 'invalid_nesting'),
                             'Markup invalidly nested',
                             'It has been determined that the document '
                             'invalidly nests its tags. This is not permitted '
                             'in the specified document type.',
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)
            if DEBUG:  # pragma: no cover
                print 'Invalid markup nesting ------'

        # Perform analysis on collected data.
        if data_buffer:
            if tag == 'script' and not script_type:
                self.err.add_script_load(self.filename, self.filename)
                scripting.test_js_file(err=self.err,
                                       data=data_buffer,
                                       filename=self.filename,
                                       line=old_position[0],
                                       column=old_position[1] + 1,
                                       context=self.context)
            elif tag == 'style':
                csstester.test_css_file(self.err, self.filename, data_buffer,
                                        old_line)
Beispiel #15
0
    def handle_endtag(self, tag):

        tag = tag.lower()
        if tag == 'xul:script':
            tag = 'script'

        if tag == 'script' and len(self.xml_buffer[-1]) > 1000:
            self.err.warning(('markup', 'complex_script'),
                             'Long inline script',
                             'Please store complex scripts in .js files '
                             'rather than inline script nodes.',
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)

        if DEBUG:  # pragma: no cover
            print 'E: ', tag, self.xml_state

        if not self.xml_state:
            if 'closing_tags' in self.reported or not self.strict:
                if DEBUG:
                    print 'Unstrict; extra closing tags ------'
                return
            self.err.warning(('markup',
                              'endtag',
                              'extra_closing_tags'),
                             'Markup parsing error',
                             'The markup file has more closing tags than it '
                             'has opening tags.',
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)
            self.reported.add('closing_tags')
            if DEBUG:  # pragma: no cover
                print 'Too many closing tags ------'
            return

        elif 'script' in self.xml_state[:-1]:
            # If we're in a script tag, nothing else matters. Just rush
            # everything possible into the xml buffer.

            self._save_to_buffer('</' + tag + '>')
            if DEBUG:
                print 'Markup as text in script ------'
            return

        elif tag not in self.xml_state:
            # If the tag we're processing isn't on the stack, then
            # something is wrong.
            self.err.warning(('markup',
                              'endtag',
                              'extra_closing_tags'),
                             'Parse error: tag closed before opened',
                             ['Markup tags cannot be closed before they are '
                              'opened. Perhaps you were just a little '
                              'overzealous with forward-slashes?',
                              'Tag "%s" closed before it was opened' % tag],
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)
            if DEBUG:  # pragma: no cover
                print 'Tag closed before opened ------'
            return

        data_buffer = self.xml_buffer.pop()
        old_state = self.xml_state.pop()
        old_line = self.xml_line_stack.pop()
        old_position = self.xml_position_stack.pop() or (old_line, 0)
        script_type = True
        if old_state == 'script':
            script_type = self.xml_state_scripts.pop()

        # If the tag on the stack isn't what's being closed and it also
        # classifies as a self-closing tag, we just recursively close
        # down to the level of the tag we're actualy closing.
        if old_state != tag and old_state in SELF_CLOSING_TAGS:
            if DEBUG:
                print 'Self closing tag cascading down ------'
            return self.handle_endtag(tag)

        # If this is an XML-derived language, everything must nest
        # properly. No overlapping tags.
        #
        # ^ Oh, basta, you really have no idea, do you...
        if (old_state != tag and
                self.extension[0] == 'x' and
                not self.strict):

            self.err.warning(('markup',
                              'endtag',
                              'invalid_nesting'),
                             'Markup invalidly nested',
                             'It has been determined that the document '
                             'invalidly nests its tags. This is not permitted '
                             'in the specified document type.',
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)
            if DEBUG:  # pragma: no cover
                print 'Invalid markup nesting ------'

        # Perform analysis on collected data.
        if data_buffer:
            if tag == 'script' and not script_type:
                self.err.add_script_load(self.filename, self.filename)
                scripting.test_js_file(err=self.err, data=data_buffer,
                                       filename=self.filename,
                                       line=old_position[0],
                                       column=old_position[1] + 1,
                                       context=self.context)
            elif tag == 'style':
                csstester.test_css_file(self.err, self.filename, data_buffer,
                                        old_line)
    def handle_endtag(self, tag):

        tag = tag.lower()
        if tag == "xul:script":
            tag = "script"

        if DEBUG:  # pragma: no cover
            print "E: ", tag, self.xml_state

        if not self.xml_state:
            if "closing_tags" in self.reported or not self.strict:
                if DEBUG:
                    print "Unstrict; extra closing tags ------"
                return
            self.err.warning(("testcases_markup_markuptester",
                              "handle_endtag",
                              "extra_closing_tags"),
                             "Markup parsing error",
                             "The markup file has more closing tags than it "
                             "has opening tags.",
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)
            self.reported.add("closing_tags")
            if DEBUG:  # pragma: no cover
                print "Too many closing tags ------"
            return

        elif "script" in self.xml_state[:-1]:
            # If we're in a script tag, nothing else matters. Just rush
            # everything possible into the xml buffer.

            self._save_to_buffer("</" + tag + ">")
            if DEBUG:
                print "Markup as text in script ------"
            return

        elif tag not in self.xml_state:
            # If the tag we're processing isn't on the stack, then
            # something is wrong.
            self.err.warning(("testcases_markup_markuptester",
                              "handle_endtag",
                              "extra_closing_tags"),
                             "Parse error: tag closed before opened",
                             ["Markup tags cannot be closed before they are "
                              "opened. Perhaps you were just a little "
                              "overzealous with forward-slashes?",
                              'Tag "%s" closed before it was opened' % tag],
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)
            if DEBUG:  # pragma: no cover
                print "Tag closed before opened ------"
            return

        data_buffer = self.xml_buffer.pop()
        old_state = self.xml_state.pop()
        old_line = self.xml_line_stack.pop()

        # If the tag on the stack isn't what's being closed and it also
        # classifies as a self-closing tag, we just recursively close
        # down to the level of the tag we're actualy closing.
        if old_state != tag and old_state in SELF_CLOSING_TAGS:
            if DEBUG:
                print "Self closing tag cascading down ------"
            return self.handle_endtag(tag)

        # If this is an XML-derived language, everything must nest
        # properly. No overlapping tags.
        if (old_state != tag and
            self.extension[0] == 'x' and
            not self.strict):

            self.err.warning(("testcases_markup_markuptester",
                              "handle_endtag",
                              "invalid_nesting"),
                             "Markup invalidly nested",
                             "It has been determined that the document "
                             "invalidly nests its tags. This is not permitted "
                             "in the specified document type.",
                             self.filename,
                             line=self.line,
                             context=self.context,
                             tier=2)
            if DEBUG:  # pragma: no cover
                print "Invalid markup nesting ------"

        data_buffer = data_buffer.strip()

        # Perform analysis on collected data.
        if data_buffer:
            if tag == "script":
                scripting.test_js_snippet(err=self.err, data=data_buffer,
                                          filename=self.filename,
                                          line=old_line, context=self.context)
            elif tag == "style":
                csstester.test_css_file(self.err, self.filename, data_buffer,
                                        old_line)
Beispiel #17
0
def _process_file(err,
                  xpi_package,
                  name,
                  file_data,
                  name_lower,
                  pollutable=False):
    """Process a single file's content tests."""

    extension = os.path.splitext(name_lower)[1]

    # If that item is a container file, unzip it and scan it.
    if extension == '.jar':
        # This is either a subpackage or a nested theme.
        is_subpackage = not err.get_resource('is_multipackage')
        # Unpack the package and load it up.
        package = StringIO(file_data)
        try:
            sub_xpi = XPIManager(package,
                                 mode='r',
                                 name=name,
                                 subpackage=is_subpackage)
        except BadZipfile:
            err.error(('testcases_content', 'test_packed_packages',
                       'jar_subpackage_corrupt'), 'Subpackage corrupt.',
                      'The subpackage appears to be corrupt, and could not '
                      'be opened.', name)
            return

        # Let the error bunder know we're in a sub-package.
        err.push_state(name)
        err.detected_type = (PACKAGE_SUBPACKAGE
                             if is_subpackage else PACKAGE_THEME)
        err.set_tier(1)
        supported_versions = (err.supported_versions.copy()
                              if err.supported_versions else
                              err.supported_versions)

        if is_subpackage:
            testendpoint_validator.test_inner_package(err, sub_xpi)
        else:
            testendpoint_validator.test_package(err, package, name)

        err.pop_state()
        err.set_tier(2)

        err.supported_versions = supported_versions

    elif extension == '.xpi':
        # It's not a subpackage, it's a nested extension. These are
        # found in multi-extension packages.

        # Unpack!
        package = StringIO(file_data)

        err.push_state(name_lower)
        err.set_tier(1)

        # There are no expected types for packages within a multi-
        # item package.
        testendpoint_validator.test_package(err, package, name)

        err.pop_state()
        err.set_tier(2)  # Reset to the current tier

    else:

        if not file_data:
            return

        # Convert the file data to unicode.
        file_data = unicodehelper.decode(file_data)

        if extension in ('.js', '.jsm'):
            testendpoint_js.test_js_file(err,
                                         name,
                                         file_data,
                                         pollutable=pollutable)
        elif extension == '.css':
            testendpoint_css.test_css_file(err, name, file_data)

        run_regex_tests(file_data, err, filename=name)
Beispiel #18
0
def _process_file(err,
                  xpi_package,
                  name,
                  file_data,
                  name_lower,
                  pollutable=False):
    """Process a single file's content tests."""

    # If that item is a container file, unzip it and scan it.
    if name_lower.endswith(".jar"):
        # This is either a subpackage or a nested theme.
        is_subpackage = not err.get_resource("is_multipackage")
        # Unpack the package and load it up.
        package = StringIO(file_data)
        try:
            sub_xpi = XPIManager(package,
                                 mode="r",
                                 name=name,
                                 subpackage=is_subpackage)
        except Exception:
            err.error(("testcases_content", "test_packed_packages",
                       "jar_subpackage_corrupt"), "Subpackage corrupt.",
                      "The subpackage could not be opened due to issues "
                      "with corruption. Ensure that the file is valid.", name)
            return None

        # Let the error bunder know we're in a sub-package.
        err.push_state(name)
        err.detected_type = (PACKAGE_SUBPACKAGE
                             if is_subpackage else PACKAGE_THEME)
        err.set_tier(1)
        supported_versions = (err.supported_versions.copy()
                              if err.supported_versions else
                              err.supported_versions)

        if is_subpackage:
            testendpoint_validator.test_inner_package(err, sub_xpi)
        else:
            testendpoint_validator.test_package(err, package, name)

        err.pop_state()
        err.set_tier(2)

        err.supported_versions = supported_versions

    elif name_lower.endswith(".xpi"):
        # It's not a subpackage, it's a nested extension. These are
        # found in multi-extension packages.

        # Unpack!
        package = StringIO(file_data)

        err.push_state(name_lower)
        err.set_tier(1)

        # There are no expected types for packages within a multi-
        # item package.
        testendpoint_validator.test_package(err, package, name)

        err.pop_state()
        err.set_tier(2)  # Reset to the current tier

    elif name_lower.endswith((".css", ".js", ".jsm")):

        if not file_data:
            return None

        # Convert the file data to unicode
        file_data = unicodehelper.decode(file_data)
        is_js = False

        if name_lower.endswith(".css"):
            testendpoint_css.test_css_file(err, name, file_data)

        elif name_lower.endswith((".js", ".jsm")):
            is_js = True
            testendpoint_js.test_js_file(err,
                                         name,
                                         file_data,
                                         pollutable=pollutable)

        run_regex_tests(file_data, err, name, is_js=is_js)

        return True

    return False