Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
net_instaweb::HtmlParseTestBaseNoAlloc Class Referenceabstract

Shared infrastructure for unit-testing the HTML parser. More...

#include "html_parse_test_base.h"

Inheritance diagram for net_instaweb::HtmlParseTestBaseNoAlloc:
net_instaweb::HtmlParseTestBase net_instaweb::RewriteOptionsTestBase< OptionsClass > net_instaweb::RewriteTestBase net_instaweb::CriticalImagesFinderTestBase net_instaweb::CssRewriteTestBase net_instaweb::CustomRewriteTestBase< OptionsClass > net_instaweb::ProxyInterfaceTestBase net_instaweb::RewriteContextTestBase

Protected Member Functions

virtual bool AddBody () const =0
 
virtual bool AddHtmlTags () const
 
void SetDoctype (StringPiece directive)
 
virtual GoogleString AddHtmlBody (StringPiece html)
 
void ValidateNoChanges (StringPiece case_id, StringPiece html_input)
 
void ValidateNoChangesFail (StringPiece case_id, StringPiece html_input)
 Fail to ValidateNoChanges.
 
virtual void SetupWriter ()
 
void SetupWriter (scoped_ptr< HtmlWriterFilter > *html_writer_filter)
 
void Parse (StringPiece case_id, StringPiece html_input)
 Parse html_input, the result is stored in output_buffer_. More...
 
virtual void ParseUrl (StringPiece url, StringPiece html_input)
 Parse given an explicit URL rather than an id to build URL around.
 
bool ValidateExpected (StringPiece case_id, StringPiece html_input, StringPiece expected)
 
bool ValidateExpectedUrl (StringPiece url, StringPiece html_input, StringPiece expected)
 Same as ValidateExpected, but with an explicit URL rather than an id.
 
void ValidateExpectedFail (StringPiece case_id, StringPiece html_input, StringPiece expected)
 Fail to ValidateExpected.
 
virtual HtmlParsehtml_parse ()=0
 
const GoogleUrlhtml_gurl ()
 

Protected Attributes

MockMessageHandler message_handler_
 
StringWriter write_to_string_
 
GoogleString output_buffer_
 
bool added_filter_
 
scoped_ptr< HtmlWriterFilterhtml_writer_filter_
 
GoogleString doctype_string_
 

Static Protected Attributes

static const char kTestDomain []
 
static const char kXhtmlDtd []
 DOCTYPE string for claiming XHTML.
 

Detailed Description

Shared infrastructure for unit-testing the HTML parser.

Member Function Documentation

virtual bool net_instaweb::HtmlParseTestBaseNoAlloc::AddBody ( ) const
protectedpure 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
inlineprotectedvirtual

If true, prepends "<html>\n" and appends "</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 ( StringPiece  case_id,
StringPiece  html_input 
)
inlineprotected

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 ( StringPiece  directive)
inlineprotected

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 ( StringPiece  case_id,
StringPiece  html_input,
StringPiece  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 ( StringPiece  case_id,
StringPiece  html_input 
)
inlineprotected

Check that the output HTML is serialized to string-compare precisely with the input.


The documentation for this class was generated from the following file: