def _test_xul_raw(data, path, should_fail=False, should_fail_csp=None, type_=None): filename = path.split("/")[-1] extension = filename.split(".")[-1] err = ErrorBundle() err.save_resource("app_type", "certified") if type_: err.set_type(type_) parser = markuptester.MarkupParser(err, debug=True) parser.process(filename, data, extension) print err.print_summary(verbose=True) if should_fail: assert any(m for m in (err.errors + err.warnings) if m["id"][0] != "csp") else: assert not any( m for m in (err.errors + err.warnings) if m["id"][0] != "csp") if should_fail_csp == True: assert any(m for m in (err.errors + err.warnings) if m["id"][0] == "csp") elif should_fail_csp == False: assert not any( m for m in (err.errors + err.warnings) if m["id"][0] == "csp") return err
def test_script_scraping(): """Test that the scripts in a document are collected properly.""" err = ErrorBundle() parser = markuptester.MarkupParser(err, debug=True) parser.process( "foo.xul", """ <doc> <!-- One to be ignored --> <script type="text/javascript"> eval("asdf"); </script> </doc> """, "xul") assert err.errors
def test_local_url_detector(): "Tests that local URLs can be detected." err = ErrorBundle() mp = markuptester.MarkupParser(err) tester = mp._is_url_local assert tester("chrome://xyz/content/abc") assert tester("chrome://whatever/") assert tester("local.xul") assert not tester("http://foo.bar/") assert not tester("https://abc.def/") assert tester(u"chrome://xyz/content/abc") assert tester(u"chrome://whatever/") assert tester(u"local.xul") assert not tester(u"http://foo.bar/") assert not tester(u"https://abc.def/")
def analyze(self, snippet, app_type="web"): self.setup_err() self.err.save_resource("app_type", app_type) markuptester.MarkupParser(self.err, debug=True).process("", snippet)