Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
Fix flattening with @font-face.
Browse files Browse the repository at this point in the history
  • Loading branch information
morlovich authored and crowell committed Jul 25, 2016
1 parent ccea83f commit 8fca3b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions net/instaweb/rewriter/css_flatten_imports_test.cc
Expand Up @@ -931,6 +931,15 @@ TEST_F(CssFlattenImportsTest, FlattenNestedMedia) {
kExpectCached | kNoOtherContexts); 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) { TEST_F(CssFlattenImportsTest, FlattenCacheDependsOnMedia) {
const GoogleString css_screen = const GoogleString css_screen =
StrCat("@media screen{", kSimpleCss, "}"); StrCat("@media screen{", kSimpleCss, "}");
Expand Down
8 changes: 7 additions & 1 deletion net/instaweb/rewriter/css_hierarchy.cc
Expand Up @@ -499,16 +499,22 @@ bool CssHierarchy::RollUpStylesheets() {


if (flattening_succeeded_) { if (flattening_succeeded_) {
// Flattening succeeded so delete our @charset and @import rules then // 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(); stylesheet_->mutable_charsets().clear();
STLDeleteElements(&stylesheet_->mutable_imports()); STLDeleteElements(&stylesheet_->mutable_imports());
Css::Rulesets& target = stylesheet_->mutable_rulesets(); Css::Rulesets& target = stylesheet_->mutable_rulesets();
Css::FontFaces& fonts_target = stylesheet_->mutable_font_faces();
for (int i = n - 1; i >= 0; --i) { // reverse order for (int i = n - 1; i >= 0; --i) { // reverse order
Css::Stylesheet* stylesheet = children_[i]->stylesheet_.get(); Css::Stylesheet* stylesheet = children_[i]->stylesheet_.get();
if (stylesheet != NULL) { // NULL if empty if (stylesheet != NULL) { // NULL if empty
Css::Rulesets& source = stylesheet->mutable_rulesets(); Css::Rulesets& source = stylesheet->mutable_rulesets();
target.insert(target.begin(), source.begin(), source.end()); target.insert(target.begin(), source.begin(), source.end());
source.clear(); 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();
} }
} }
} }
Expand Down

0 comments on commit 8fca3b9

Please sign in to comment.