Bug 1258916 part 6 - Do not add CDATA wrap for ahem font style for html files. r=dbaron
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 29 Mar 2016 11:18:19 +1100
changeset 293268 eeb6c9316ff31b5a4f2aaed2db678aabdf2a97f1
parent 293267 6a5e55d72b41596d83ab1bb1f9f15c6cce1fac9a
child 293269 6f330fed23146feb54337db0ea94780be788bfc2
push id18749
push usercbook@mozilla.com
push dateFri, 15 Apr 2016 12:01:19 +0000
treeherderfx-team@8f7045b63b07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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()