Add appcache presence test (bug 895391)

This commit is contained in:
Matt Basta 2013-08-07 18:21:05 -07:00
Родитель db1222d8a6
Коммит 83fa8b7640
3 изменённых файлов: 61 добавлений и 5 удалений

Просмотреть файл

@ -0,0 +1,14 @@
from appvalidator.python.HTMLParser import HTMLParser
class RemoteHTMLParser(HTMLParser):
def __init__(self, err):
HTMLParser.__init__(self)
self.err = err
def handle_starttag(self, tag, attrs):
if tag == "html":
attrs = dict(attrs)
if "manifest" in attrs:
self.err.metadata["appcache"] = attrs["manifest"]

Просмотреть файл

@ -9,9 +9,10 @@ from PIL import Image
from . import register_test from . import register_test
from .. import constants from .. import constants
from ..webapp import detect_webapp_string from ..webapp import detect_webapp_string
from markup.remote import RemoteHTMLParser
TYPE_URL = "https://developer.mozilla.org/en-US/docs/Apps/Manifest#type" MANIFEST_URL = "https://developer.mozilla.org/docs/Web/Apps/Manifest#%s"
HEADERS = { HEADERS = {
"User-Agent": "Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0" "User-Agent": "Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0"
} }
@ -54,7 +55,7 @@ def test_permissions(err, package):
error="App requested unavailable permission", error="App requested unavailable permission",
description=["A permission requested by the app is not available " description=["A permission requested by the app is not available "
"for the app's type. See %s for more information." % "for the app's type. See %s for more information." %
TYPE_URL, MANIFEST_URL % "type",
"Requested permission: %s" % permission, "Requested permission: %s" % permission,
"App's type: %s" % app_type], "App's type: %s" % app_type],
filename="manifest.webapp" if packaged else "") filename="manifest.webapp" if packaged else "")
@ -360,9 +361,25 @@ def test_app_resources(err, package):
icon_urls.add(url) icon_urls.add(url)
if "launch_path" in manifest: if "launch_path" in manifest:
try_get_resource(err, package, manifest["launch_path"], launch_page = try_get_resource(
filename="manifest.webapp", err, package, manifest["launch_path"], filename="manifest.webapp",
resource_type="launch_path", max_size=False) resource_type="launch_path", max_size=False)
if launch_page and not err.get_resource("packaged"):
parser = RemoteHTMLParser(err)
parser.feed(launch_page)
if ("appcache" in err.metadata and
not manifest.get("appcache_path")):
err.warning(
err_id=("resources", "appcache", "found_hosted"),
warning="Appcache manifest found",
description=[
"An appcache manifest was found in the remote "
"`launch_path`, but there was no `appcache_path` "
"listed in the manifest. Without an `appcache_path`, "
"the app will not be available to users offline.",
"Found appcache: %s" % err.metadata["appcache"],
"See more: %s" % MANIFEST_URL % "appcache_path"])
if "appcache_path" in manifest: if "appcache_path" in manifest:
try_get_resource(err, package, manifest["appcache_path"], try_get_resource(err, package, manifest["appcache_path"],

Просмотреть файл

@ -228,6 +228,7 @@ class TestResourcePolling(TestCase):
self.setup_err() self.setup_err()
manifest = {} manifest = {}
self.err.save_resource("manifest", manifest) self.err.save_resource("manifest", manifest)
self.err.save_resource("packaged", True)
return manifest return manifest
@patch("appvalidator.testcases.webappbase.test_icon") @patch("appvalidator.testcases.webappbase.test_icon")
@ -269,13 +270,37 @@ class TestResourcePolling(TestCase):
@patch("appvalidator.testcases.webappbase.try_get_resource") @patch("appvalidator.testcases.webappbase.try_get_resource")
def test_launch_path(self, tgr): def test_launch_path(self, tgr):
tgr.return_value = False
self.setup_manifest()["launch_path"] = "fizz" self.setup_manifest()["launch_path"] = "fizz"
self.err.save_resource('packaged', False)
appbase.test_app_resources(self.err, None) appbase.test_app_resources(self.err, None)
eq_(tgr.call_args[0][2], "fizz") eq_(tgr.call_args[0][2], "fizz")
# Test that we don't warn the dev that their origin exceeds a size # Test that we don't warn the dev that their origin exceeds a size
# limit. # limit.
eq_(tgr.call_args[1]["max_size"], False) eq_(tgr.call_args[1]["max_size"], False)
@patch("appvalidator.testcases.webappbase.try_get_resource")
def test_launch_path_no_appcache(self, tgr):
tgr.return_value = """
<html haldo="trogdor"></html>
"""
self.setup_manifest()["launch_path"] = "fizz"
self.err.save_resource('packaged', False)
appbase.test_app_resources(self.err, None)
eq_(tgr.call_args[0][2], "fizz")
assert not self.err.failed()
@patch("appvalidator.testcases.webappbase.try_get_resource")
def test_launch_path_appcache(self, tgr):
tgr.return_value = """
<html manifest="hello"></html>
"""
self.setup_manifest()["launch_path"] = "fizz"
self.err.save_resource('packaged', False)
appbase.test_app_resources(self.err, None)
eq_(tgr.call_args[0][2], "fizz")
assert self.err.failed(fail_on_warnings=True)
@patch("appvalidator.testcases.webappbase.try_get_resource") @patch("appvalidator.testcases.webappbase.try_get_resource")
def test_root_developer_absent(self, tgr): def test_root_developer_absent(self, tgr):
self.setup_manifest()["developer"] = {} self.setup_manifest()["developer"] = {}