Bug 1258916 part 6 - Do not add CDATA wrap for ahem font style for html files. r=dbaron draft
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 29 Mar 2016 11:18:19 +1100
changeset 350727 f7319874041429a590ed823c4bd98a1c04c963ee
parent 350726 9489b25f5b142aceef8fd3863674bb63625ac75c
child 518390 9911ce559a45141048e3617d1784bffc5de75fa4
push id15401
push userxquan@mozilla.com
push dateThu, 14 Apr 2016 07:33:24 +0000
reviewersdbaron
bugs1258916
milestone48.0a1
Bug 1258916 part 6 - Do not add CDATA wrap for ahem font style for html files. r=dbaron MozReview-Commit-ID: 2O1EDfVnIZ0
layout/reftests/w3c-css/import-tests.py
--- a/layout/reftests/w3c-css/import-tests.py
+++ b/layout/reftests/w3c-css/import-tests.py
@@ -168,19 +168,22 @@ def load_flags_for(fn, spec):
     destname = os.path.join(spec, os.path.basename(fn))
     gTestFlags[destname] = []
 
     for meta in document.getElementsByTagName("meta"):
         name = meta.getAttribute("name")
         if name == "flags":
             gTestFlags[destname] = meta.getAttribute("content").split()
 
+def is_html(fn):
+    return fn.endswith(".htm") or fn.endswith(".html")
+
 def get_document_for(fn):
     document = None # an xml.dom.minidom document
-    if fn.endswith(".htm") or fn.endswith(".html"):
+    if is_html(fn):
         # An HTML file
         f = open(fn, "rb")
         parser = html5lib.HTMLParser(tree=html5lib.treebuilders.getTreeBuilder("dom"))
         document = parser.parse(f)
         f.close()
     else:
         # An XML file
         document = xml.dom.minidom.parse(fn)
@@ -213,33 +216,43 @@ def add_test_items(fn, spec):
     for notref in notrefs:
         tests.append(["!=", map_file(fn, spec), map_file(notref, spec)])
     # Add chained references too
     for ref in refs:
         add_test_items(ref, spec=spec)
     for notref in notrefs:
         add_test_items(notref, spec=spec)
 
+AHEM_DECL_CONTENT = """@font-face {
+  font-family: Ahem;
+  src: url("../../../fonts/Ahem.ttf");
+}"""
+AHEM_DECL_HTML = """<style type="text/css">
+""" + AHEM_DECL_CONTENT + """
+</style>
+"""
+AHEM_DECL_XML = """<style type="text/css"><![CDATA[
+""" + AHEM_DECL_CONTENT + """
+]]></style>
+"""
+
 def copy_and_prefix(test, aSourceFileName, aDestFileName, aProps, isSupportFile=False):
     global gTestFlags
     newFile = open(aDestFileName, 'wb')
     unPrefixedFile = open(aSourceFileName, 'rb')
     testName = aDestFileName[len(gDestPath)+1:]
     ahemFontAdded = False
     for line in unPrefixedFile:
         replacementLine = line
         searchRegex = "\s*<style\s*"
 
         if not isSupportFile and not ahemFontAdded and 'ahem' in gTestFlags[test] and re.search(searchRegex, line):
             # First put our ahem font declation before the first <style>
             # element
-            ahemFontDecl = "<style type=\"text/css\"><![CDATA[\n@font-face "\
-                           "{\n  font-family: Ahem;\n  src: url("\
-                           "\"../../../fonts/Ahem.ttf\");\n}\n]]></style>\n"
-            newFile.write(ahemFontDecl)
+            newFile.write(AHEM_DECL_HTML if is_html(aDestFileName) else AHEM_DECL_XML)
             ahemFontAdded = True
 
         for rule in aProps:
             replacementLine = replacementLine.replace(rule, "-moz-" + rule)
         newFile.write(replacementLine)
 
     newFile.close()
     unPrefixedFile.close()