Permalink
Browse files

Fix flattening with @font-face.

  • Loading branch information...
morlovich authored and crowell committed Jul 12, 2016
1 parent ccea83f commit 8fca3b9d3b606cbd83ae34f09c9564be16831862
Showing with 16 additions and 1 deletion.
  1. +9 −0 net/instaweb/rewriter/css_flatten_imports_test.cc
  2. +7 −1 net/instaweb/rewriter/css_hierarchy.cc
@@ -931,6 +931,15 @@ TEST_F(CssFlattenImportsTest, FlattenNestedMedia) {
kExpectCached | kNoOtherContexts);
}

TEST_F(CssFlattenImportsTest, FlattenFontFace) {
const char kStylesFont[] = "@import url(font.css);";
SetResponseWithDefaultHeaders("font.css", kContentTypeCss,
"@font-face { font-family: 'cyborgo'; }", 100);
ValidateRewriteExternalCss("flatten_font_face", kStylesFont,
"@font-face{font-family:'cyborgo'}",
kExpectSuccess | kNoClearFetcher);
}

TEST_F(CssFlattenImportsTest, FlattenCacheDependsOnMedia) {
const GoogleString css_screen =
StrCat("@media screen{", kSimpleCss, "}");
@@ -499,16 +499,22 @@ bool CssHierarchy::RollUpStylesheets() {

if (flattening_succeeded_) {
// Flattening succeeded so delete our @charset and @import rules then
// merge our children's rulesets (only) into ours.
// merge our children's rulesets and @font-faces (only) into ours.
stylesheet_->mutable_charsets().clear();
STLDeleteElements(&stylesheet_->mutable_imports());
Css::Rulesets& target = stylesheet_->mutable_rulesets();
Css::FontFaces& fonts_target = stylesheet_->mutable_font_faces();
for (int i = n - 1; i >= 0; --i) { // reverse order
Css::Stylesheet* stylesheet = children_[i]->stylesheet_.get();
if (stylesheet != NULL) { // NULL if empty
Css::Rulesets& source = stylesheet->mutable_rulesets();
target.insert(target.begin(), source.begin(), source.end());
source.clear();

Css::FontFaces& fonts_source = stylesheet->mutable_font_faces();
fonts_target.insert(fonts_target.begin(),
fonts_source.begin(), fonts_source.end());
fonts_source.clear();
}
}
}

0 comments on commit 8fca3b9

Please sign in to comment.