Skip to content

Commit

Permalink
Add gzip decompression support for icons
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbasta committed Feb 14, 2013
1 parent 6213473 commit aca5930
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
24 changes: 16 additions & 8 deletions appvalidator/testcases/webappbase.py
@@ -1,4 +1,5 @@
import base64
import gzip
import urlparse
from cStringIO import StringIO

Expand Down Expand Up @@ -241,14 +242,21 @@ def test_icon(err, data, url, size):
try:
icon = Image.open(data)
icon.verify()
except IOError:
err.error(
err_id=("resources", "icon", "ioerror"),
error="Could not read icon file.",
description=["A downloaded icon file could not be opened. It may "
"contain invalid or corrupt data. Icons may be only "
"JPG or PNG images.",
"%dpx icon (%s)" % (size, url)])
except IOError, e:
try:
name = url.split('/')[-1]
data.seek(0) # Rewind the StringIO
with gzip.GzipFile(name, 'rb', fileobj=data) as gzf:
icon = Image.open(gzf)
icon.verify()
except IOError, e:
err.error(
err_id=("resources", "icon", "ioerror"),
error="Could not read icon file.",
description=["A downloaded icon file could not be opened. It "
"may contain invalid or corrupt data. Icons may "
"be only JPG or PNG images.",
"%dpx icon (%s)" % (size, url)])
else:
width, height = icon.size
if width != height:
Expand Down
Binary file added tests/resources/icon-128.png.gz
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/test_webapp_resources.py
Expand Up @@ -318,6 +318,20 @@ def test_pass(self):
self._test_icon("icon-128.png", "128")
self.assert_silent()

def test_pass_gzip(self):
"""
Since we need to use raw sockets to pull in the data, we don't get
gzip-uncompressed data back for servers that proactively compress
assets. This tests that a GZ file can be accepted and pass just the
same as a standard icon file can.
"""

self._test_icon("icon-128.png.gz", 128)
self.assert_silent()

self._test_icon("icon-128.png.gz", "128")
self.assert_silent()

def test_bad_icon(self):
self._test_icon("corrupt.xpi", 128)
self.assert_failed(with_errors=True)
Expand Down

0 comments on commit aca5930

Please sign in to comment.