Page Speed Optimization Libraries
1.5.27.2
|
Shared infrastructure for unit-testing the HTML parser. More...
#include "html_parse_test_base.h"
Protected Member Functions | |
virtual bool | AddBody () const =0 |
virtual bool | AddHtmlTags () const |
void | SetDoctype (const StringPiece &directive) |
virtual GoogleString | AddHtmlBody (const StringPiece &html) |
void | ValidateNoChanges (const StringPiece &case_id, const GoogleString &html_input) |
void | ValidateNoChangesFail (const StringPiece &case_id, const GoogleString &html_input) |
Fail to ValidateNoChanges. | |
void | SetupWriter () |
void | SetupWriter (scoped_ptr< HtmlWriterFilter > *html_writer_filter) |
void | Parse (const StringPiece &case_id, const GoogleString &html_input) |
Parse html_input, the result is stored in output_buffer_. | |
virtual void | ParseUrl (const StringPiece &url, const StringPiece &html_input) |
Parse given an explicit URL rather than an id to build URL around. | |
bool | ValidateExpected (const StringPiece &case_id, const GoogleString &html_input, const GoogleString &expected) |
bool | ValidateExpectedUrl (const StringPiece &url, const GoogleString &html_input, const GoogleString &expected) |
Same as ValidateExpected, but with an explicit URL rather than an id. | |
void | ValidateExpectedFail (const StringPiece &case_id, const GoogleString &html_input, const GoogleString &expected) |
Fail to ValidateExpected. | |
virtual HtmlParse * | html_parse ()=0 |
Protected Attributes | |
MockMessageHandler | message_handler_ |
StringWriter | write_to_string_ |
GoogleString | output_buffer_ |
bool | added_filter_ |
scoped_ptr< HtmlWriterFilter > | html_writer_filter_ |
GoogleString | doctype_string_ |
Static Protected Attributes | |
static const char | kTestDomain [] |
static const char | kXhtmlDtd [] |
DOCTYPE string for claiming XHTML. |
Shared infrastructure for unit-testing the HTML parser.
virtual bool net_instaweb::HtmlParseTestBaseNoAlloc::AddBody | ( | ) | const [protected, pure virtual] |
To make the tests more concise, we generally omit the <html>...</html> tags bracketing the input. The libxml parser will add those in if we don't have them. To avoid having that make the test data more verbose, we automatically add them in the test infrastructure, both for stimulus and expected response.
This flag controls whether we also add <body>...</body> tags. In the case html_parse_test, we go ahead and add them in. In the case of the rewriter tests, we want to explicitly control/observe the head and the body so we don't add the body tags in automatically. So classes that derive from HtmlParseTestBase must override this variable to indicate which they prefer.
Implemented in net_instaweb::RewriteContextTestBase, and net_instaweb::RewriteTestBase.
virtual bool net_instaweb::HtmlParseTestBaseNoAlloc::AddHtmlTags | ( | ) | const [inline, protected, virtual] |
If true, prepends "<html>\n" and appends "\n</html>" to input text prior to parsing it. This was originally done for consistency with libxml2 but that's long since been made irrelevant and we should probably just stop doing it. Adding the virtual function here should help us incrementally update tests & their gold results.
void net_instaweb::HtmlParseTestBaseNoAlloc::Parse | ( | const StringPiece & | case_id, |
const GoogleString & | html_input | ||
) | [inline, protected] |
Parse html_input, the result is stored in output_buffer_.
HtmlParser needs a valid HTTP URL to evaluate relative paths, so we create a dummy URL.
void net_instaweb::HtmlParseTestBaseNoAlloc::SetDoctype | ( | const StringPiece & | directive | ) | [inline, protected] |
Set a doctype string (e.g. "<!doctype html>") to be inserted before the rest of the document (for the current test only). If none is set, it defaults to the empty string.
bool net_instaweb::HtmlParseTestBaseNoAlloc::ValidateExpected | ( | const StringPiece & | case_id, |
const GoogleString & | html_input, | ||
const GoogleString & | expected | ||
) | [protected] |
Validate that the output HTML serializes as specified in 'expected', which might not be identical to the input. Also, returns true if result came out as expected.
void net_instaweb::HtmlParseTestBaseNoAlloc::ValidateNoChanges | ( | const StringPiece & | case_id, |
const GoogleString & | html_input | ||
) | [inline, protected] |
Check that the output HTML is serialized to string-compare precisely with the input.