21 #ifndef PAGESPEED_KERNEL_HTML_HTML_PARSE_TEST_BASE_H_
22 #define PAGESPEED_KERNEL_HTML_HTML_PARSE_TEST_BASE_H_
36 namespace net_instaweb {
41 static const char kTestDomain[];
46 write_to_string_(&output_buffer_),
47 added_filter_(false) {
63 virtual bool AddBody()
const = 0;
76 directive.CopyToString(&doctype_string_);
82 ret =
AddBody() ?
"<html><body>\n" :
"<html>\n";
83 StrAppend(&ret, html, (
AddBody() ?
"</body></html>\n" :
"</html>"));
85 html.CopyToString(&ret);
101 virtual void SetupWriter() {
102 SetupWriter(&html_writer_filter_);
105 void SetupWriter(scoped_ptr<HtmlWriterFilter>* html_writer_filter) {
106 output_buffer_.clear();
107 if (html_writer_filter->get() == NULL) {
108 html_writer_filter->reset(
new HtmlWriterFilter(html_parse()));
109 (*html_writer_filter)->set_writer(&write_to_string_);
110 html_parse()->
AddFilter(html_writer_filter->get());
115 void Parse(StringPiece case_id, StringPiece html_input) {
118 GoogleString dummy_url = StrCat(kTestDomain, case_id,
".html");
123 virtual void ParseUrl(StringPiece url, StringPiece html_input);
129 StringPiece html_input,
130 StringPiece expected);
134 StringPiece html_input,
135 StringPiece expected);
139 StringPiece html_input,
140 StringPiece expected);
146 MockMessageHandler message_handler_;
147 StringWriter write_to_string_;
150 scoped_ptr<HtmlWriterFilter> html_writer_filter_;
161 virtual HtmlParse* html_parse() {
return &html_parse_; }
class GoogleUrl
Definition: google_url.h:58
Definition: html_parse_test_base.h:157
void AddFilter(HtmlFilter *filter)
Application methods for parsing functions and adding filters.
const GoogleUrl & google_url() const
Gets a parsed GoogleUrl& corresponding to url().
Definition: html_parse.h:385
Shared infrastructure for unit-testing the HTML parser.
Definition: html_parse_test_base.h:39
void SetDoctype(StringPiece directive)
Definition: html_parse_test_base.h:75
void ValidateExpectedFail(StringPiece case_id, StringPiece html_input, StringPiece expected)
Fail to ValidateExpected.
Definition: html_parse.h:88
bool ValidateExpectedUrl(StringPiece url, StringPiece html_input, StringPiece expected)
Same as ValidateExpected, but with an explicit URL rather than an id.
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
void ValidateNoChangesFail(StringPiece case_id, StringPiece html_input)
Fail to ValidateNoChanges.
Definition: html_parse_test_base.h:97
bool ValidateExpected(StringPiece case_id, StringPiece html_input, StringPiece expected)
static const char kXhtmlDtd[]
DOCTYPE string for claiming XHTML.
Definition: html_parse_test_base.h:42
Definition: null_mutex.h:29
void ValidateNoChanges(StringPiece case_id, StringPiece html_input)
Definition: html_parse_test_base.h:92
virtual bool AddHtmlTags() const
Definition: html_parse_test_base.h:70
virtual bool AddBody() const =0
void Parse(StringPiece case_id, StringPiece html_input)
Parse html_input, the result is stored in output_buffer_.
Definition: html_parse_test_base.h:115
virtual void ParseUrl(StringPiece url, StringPiece html_input)
Parse given an explicit URL rather than an id to build URL around.