Bug 1146199 - Return empty string from FontFace.family if the FontFace was constructed with an invalid family name. r=jdaggett
authorCameron McCormack <cam@mcc.id.au>
Tue, 24 Mar 2015 19:34:32 +1100
changeset 264093 0d377a96684ffe46395284f7bd470dc83c0c8bae
parent 264092 6a83dc07c6c85c23ff81271dfdd620307163f0b9
child 264094 aaf374ba062f13185c09a044e419ee5b5438bba4
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett
bugs1146199
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1146199 - Return empty string from FontFace.family if the FontFace was constructed with an invalid family name. r=jdaggett
layout/style/FontFace.cpp
layout/style/test/test_font_loading_api.html
--- a/layout/style/FontFace.cpp
+++ b/layout/style/FontFace.cpp
@@ -396,16 +396,21 @@ FontFace::GetFamily(nsString& aResult)
 {
   mPresContext->FlushUserFontSet();
 
   // Serialize the same way as in nsCSSFontFaceStyleDecl::GetPropertyValue.
   nsCSSValue value;
   GetDesc(eCSSFontDesc_Family, value);
 
   aResult.Truncate();
+
+  if (value.GetUnit() == eCSSUnit_Null) {
+    return;
+  }
+
   nsDependentString family(value.GetStringBufferValue());
   if (!family.IsEmpty()) {
     // The string length can be zero when the author passed an invalid
     // family name or an invalid descriptor to the JS FontFace constructor.
     nsStyleUtil::AppendEscapedCSSString(family, aResult);
   }
 }
 
--- a/layout/style/test/test_font_loading_api.html
+++ b/layout/style/test/test_font_loading_api.html
@@ -48,17 +48,17 @@ var invalidValues = {
   stretch: "wider",
   unicodeRange: "U+1????-2????",
   variant: "inherit",
   featureSettings: "dlig"
 };
 
 // Invalid font family names.
 var invalidFontFamilyNames = [
-  "", "\"\"", "sans-serif", "A, B", "inherit"
+  "", "\"\"", "sans-serif", "A, B", "inherit", "a 1"
 ];
 
 // Will hold an ArrayBuffer containing a valid font.
 var fontData;
 
 var queue = Promise.resolve();
 
 function is_resolved_with(aPromise, aExpectedValue, aDescription, aTestID) {
@@ -288,16 +288,17 @@ function runTest() {
 
     // (TEST 17) Test passing an invalid font family name to the FontFace
     // constructor.
     var familyTests = Promise.resolve();
     invalidFontFamilyNames.forEach(function(aFamilyName) {
       familyTests = familyTests.then(function() {
         var face = new FontFace(aFamilyName, fontData);
         is(face.status, "error", "FontFace should be error immediately after construction with invalid family name " + aFamilyName + " (TEST 17)");
+        is(face.family, "", "FontFace.family should be the empty string after construction with invalid family name " + aFamilyName + " (TEST 17)");
         return face.loaded.then(function() {
           ok(false, "FontFace should not load after invalid family name " + aFamilyName + " specified (TEST 17)");
         }, function(aError) {
           ok(true, "FontFace should not load after invalid family name " + aFamilyName + " specified (TEST 17)");
           is(aError.name, "SyntaxError", "FontFace.loaded with invalid family name " + aFamilyName + " should be rejected with a SyntaxError (TEST 17)");
         });
       });
     });