21 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CSS_REWRITE_TEST_BASE_H_
22 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_REWRITE_TEST_BASE_H_
24 #include "base/logging.h"
33 namespace net_instaweb {
40 num_blocks_rewritten_ =
41 statistics()->
GetVariable(CssFilter::kBlocksRewritten);
42 num_fallback_rewrites_ =
43 statistics()->
GetVariable(CssFilter::kFallbackRewrites);
44 num_parse_failures_ = statistics()->
GetVariable(CssFilter::kParseFailures);
45 num_rewrites_dropped_ =
46 statistics()->
GetVariable(CssFilter::kRewritesDropped);
48 CssFilter::kTotalBytesSaved);
49 total_original_bytes_ =
50 statistics()->
GetVariable(CssFilter::kTotalOriginalBytes);
51 num_uses_ = statistics()->
GetVariable(CssFilter::kUses);
52 num_flatten_imports_charset_mismatch_ =
53 statistics()->
GetVariable(CssFilter::kCharsetMismatch);
54 num_flatten_imports_invalid_url_ =
56 num_flatten_imports_limit_exceeded_ =
57 statistics()->
GetVariable(CssFilter::kLimitExceeded);
58 num_flatten_imports_minify_failed_ =
59 statistics()->
GetVariable(CssFilter::kMinifyFailed);
60 num_flatten_imports_recursion_ =
62 num_flatten_imports_complex_queries_ =
63 statistics()->
GetVariable(CssFilter::kComplexQueries);
67 virtual void SetUp() {
68 RewriteTestBase::SetUp();
69 options()->set_always_rewrite_css(
true);
91 kLinkCharsetIsUTF8 = 1<<8,
92 kLinkScreenMedia = 1<<9,
93 kLinkPrintMedia = 1<<10,
95 kMetaCharsetUTF8 = 1<<11,
96 kMetaCharsetISO88591 = 1<<12,
97 kMetaHttpEquiv = 1<<13,
98 kMetaHttpEquivUnquoted = 1<<14,
102 kFlattenImportsInvalidUrl = 1<<16,
103 kFlattenImportsLimitExceeded = 1<<17,
104 kFlattenImportsMinifyFailed = 1<<18,
105 kFlattenImportsRecursion = 1<<19,
106 kFlattenImportsComplexQueries = 1<<20,
113 static bool ExactlyOneTrue(
bool a,
bool b) {
116 static bool ExactlyOneTrue(
bool a,
bool b,
bool c) {
117 return ExactlyOneTrue(a, ExactlyOneTrue(b, c));
119 static bool ExactlyOneTrue(
bool a,
bool b,
bool c,
bool d) {
120 return ExactlyOneTrue(a, ExactlyOneTrue(b, c, d));
122 static bool ExactlyOneTrue(
bool a,
bool b,
bool c,
bool d,
bool e) {
123 return ExactlyOneTrue(a, ExactlyOneTrue(b, c, d, e));
127 return (flags & f) != 0;
141 StringPiece css_input,
142 StringPiece expected_css_output,
145 void GetNamerForCss(StringPiece
id,
146 StringPiece expected_css_output,
152 StringPiece expected_css_output);
156 StringPiece css_input,
157 StringPiece expected_css_output,
159 ValidateRewriteExternalCssUrl(
id, StrCat(kTestDomain,
id,
".css"),
160 css_input, expected_css_output, flags);
163 void ValidateRewriteExternalCssUrl(StringPiece
id,
165 StringPiece css_input,
166 StringPiece expected_css_output,
171 bool insert_debug_message);
183 StringPiece css_input,
184 StringPiece gold_output,
187 css_input, gold_output, flags)) {
190 css_input, gold_output, flags);
194 void ValidateFailParse(StringPiece
id, StringPiece css_input) {
204 StringPiece html_input, StringPiece expected_html_output,
205 StringPiece css_input, StringPiece expected_css_output,
211 Variable* num_blocks_rewritten_;
212 Variable* num_fallback_rewrites_;
213 Variable* num_parse_failures_;
214 Variable* num_rewrites_dropped_;
215 UpDownCounter* total_bytes_saved_;
216 Variable* total_original_bytes_;
218 Variable* num_flatten_imports_charset_mismatch_;
219 Variable* num_flatten_imports_invalid_url_;
220 Variable* num_flatten_imports_limit_exceeded_;
221 Variable* num_flatten_imports_minify_failed_;
222 Variable* num_flatten_imports_recursion_;
223 Variable* num_flatten_imports_complex_queries_;
CSS parser succeeds and URL should be rewritten.
Definition: css_rewrite_test_base.h:76
CSS parser fails, fallback failed or disabled.
Definition: css_rewrite_test_base.h:82
Variable * GetVariable(const StringPiece &name) const
Find a variable from a name, aborting if not found.
Definition: statistics.h:379
bool ValidateRewriteInlineCss(StringPiece id, StringPiece css_input, StringPiece expected_css_output, int flags)
Check that inline CSS gets rewritten correctly.
Definition: css_rewrite_test_base.h:37
void TestCorruptUrl(const char *junk)
Helper to test for how we handle trailing junk.
void CheckFlags(int flags)
Sanity check on flags passed in.
Definition: css_rewrite_test_base.h:131
bool ValidateWithStats(StringPiece id, StringPiece html_input, StringPiece expected_html_output, StringPiece css_input, StringPiece expected_css_output, int flags)
Validate HTML rewrite as well as checking statistics.
Definition: rewrite_test_base.h:90
GoogleString MakeIndentedCssWithImage(StringPiece image_url)
Makes a CSS body with an external image link, with nice indentation.
Flags to the check various import flattening failure statistics.
Definition: css_rewrite_test_base.h:101
ValidationFlags
Definition: css_rewrite_test_base.h:73
Definition: css_rewrite_test_base.h:89
Definition: css_rewrite_test_base.h:87
CSS parser fails, fallback succeeds.
Definition: css_rewrite_test_base.h:81
UpDownCounter * GetUpDownCounter(const StringPiece &name) const
Find a variable from a name, aborting if not found.
Definition: statistics.h:364
void ValidateRewrite(StringPiece id, StringPiece css_input, StringPiece gold_output, int flags)
Definition: css_rewrite_test_base.h:182
GoogleString MakeHtmlWithExternalCssLink(StringPiece css_url, int flags, bool insert_debug_message)
Makes an HTML document with an external CSS link.
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
GoogleString MakeMinifiedCssWithImage(StringPiece image_url)
Makes a minified CSS body with an external image link.
Definition: css_rewrite_test_base.h:79
Definition: css_rewrite_test_base.h:85
void ResetStats()
Reset all Variables.
Flags to allow methods to know if the HTML is the test input or output.
Definition: css_rewrite_test_base.h:109
GoogleString ExtractCssBackgroundImage(StringPiece in_css)
Extract the background image from the css text.
Definition: css_rewrite_test_base.h:77
Definition: resource_namer.h:32
void ValidateRewriteExternalCss(StringPiece id, StringPiece css_input, StringPiece expected_css_output, int flags)
Check that external CSS gets rewritten correctly.
Definition: css_rewrite_test_base.h:155
void AddFilter(RewriteOptions::Filter filter)
Add a single rewrite filter to rewrite_driver_.