Page Speed Optimization Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
net_instaweb::RewriteTestBase Class Reference
Inheritance diagram for net_instaweb::RewriteTestBase:
net_instaweb::RewriteOptionsTestBase< OptionsClass > net_instaweb::HtmlParseTestBaseNoAlloc net_instaweb::CriticalImagesFinderTestBase net_instaweb::CssRewriteTestBase net_instaweb::CustomRewriteTestBase< OptionsClass > net_instaweb::ProxyInterfaceTestBase net_instaweb::RewriteContextTestBase


class  CssLink
 Representation for a CSS <link> tag. More...

Public Types

enum  ActiveServerFlag { kPrimary, kSecondary }

Public Member Functions

 RewriteTestBase (std::pair< TestRewriteDriverFactory *, TestRewriteDriverFactory * > factories)
virtual void SetUp ()
virtual void TearDown ()
virtual bool AddBody () const
virtual TestRewriteDriverFactoryMakeTestFactory ()
void AddRecompressImageFilters ()
void AddFilter (RewriteOptions::Filter filter)
 Add a single rewrite filter to rewrite_driver_.
void AddOtherFilter (RewriteOptions::Filter filter)
 Add a single rewrite filter to other_rewrite_driver_.
void AddRewriteFilter (RewriteFilter *filter)
void AddFetchOnlyRewriteFilter (RewriteFilter *filter)
void AddOtherRewriteFilter (RewriteFilter *filter)
void SetBaseUrlForFetch (const StringPiece &url)
void SetDriverRequestHeaders ()
void SetDownstreamCacheDirectives (StringPiece downstream_cache_purge_method, StringPiece downstream_cache_purge_location_prefix, StringPiece rebeaconing_key)
void SetShouldBeaconHeader (StringPiece rebeaconing_key)
 Set ShouldBeacon request header to the specified value.
ResourcePtr CreateResource (const StringPiece &base, const StringPiece &url)
Timertimer ()
void AppendDefaultHeaders (const ContentType &content_type, GoogleString *text)
 Append default headers to the given string.
void AppendDefaultHeadersWithCanonical (const ContentType &content_type, StringPiece canonical_url, GoogleString *text)
 Like above, but also include a Link: <..>; rel="canonical" header.
void ServeResourceFromManyContexts (const GoogleString &resource_url, const StringPiece &expected_content)
void ServeResourceFromManyContextsWithUA (const GoogleString &resource_url, const StringPiece &expected_content, const StringPiece &user_agent)
void ServeResourceFromNewContext (const GoogleString &resource_url, const StringPiece &expected_content)
virtual RewriteDriverhtml_parse ()
void DefaultResponseHeaders (const ContentType &content_type, int64 ttl_sec, ResponseHeaders *response_headers)
 Set default headers for a resource with content_type and Cache ttl_sec.
bool FetchResource (const StringPiece &path, const StringPiece &filter_id, const StringPiece &name, const StringPiece &ext, GoogleString *content)
bool FetchResource (const StringPiece &path, const StringPiece &filter_id, const StringPiece &name, const StringPiece &ext, GoogleString *content, ResponseHeaders *response)
bool FetchResourceUrl (const StringPiece &url, GoogleString *content, ResponseHeaders *response)
bool FetchResourceUrl (const StringPiece &url, RequestHeaders *request_headers, GoogleString *content, ResponseHeaders *response_headers)
bool FetchResourceUrl (const StringPiece &url, GoogleString *content)
bool TryFetchResource (const StringPiece &url)
 Just check if we can fetch a resource successfully, ignore response.
void SetUseManagedRewriteDrivers (bool use_managed_rewrite_drivers)
GoogleString CssLinkHref (const StringPiece &url)
void CollectCssLinks (const StringPiece &id, const StringPiece &html, StringVector *css_links)
 Collects the hrefs for all CSS <link>s on the page.
void CollectCssLinks (const StringPiece &id, const StringPiece &html, CssLink::Vector *css_links)
 Collects all information about CSS links into a CssLink::Vector.
void EncodePathAndLeaf (const StringPiece &filter_id, const StringPiece &hash, const StringVector &name_vector, const StringPiece &ext, ResourceNamer *namer)
 Encode the given name (path + leaf) using the given pagespeed attributes.
StringVector MultiUrl (const StringPiece &url1)
StringVector MultiUrl (const StringPiece &url1, const StringPiece &url2)
StringVector MultiUrl (const StringPiece &url1, const StringPiece &url2, const StringPiece &url3)
StringVector MultiUrl (const StringPiece &url1, const StringPiece &url2, const StringPiece &url3, const StringPiece &url4)
GoogleString Encode (const StringPiece &path, const StringPiece &filter_id, const StringPiece &hash, const StringPiece &name, const StringPiece &ext)
GoogleString Encode (const StringPiece &path, const StringPiece &filter_id, const StringPiece &hash, const StringVector &name_vector, const StringPiece &ext)
GoogleString EncodeNormal (const StringPiece &path, const StringPiece &filter_id, const StringPiece &hash, const StringPiece &name, const StringPiece &ext)
 Same as Encode but specifically using UrlNamer not TestUrlNamer.
GoogleString EncodeNormal (const StringPiece &path, const StringPiece &filter_id, const StringPiece &hash, const StringVector &name_vector, const StringPiece &ext)
GoogleString EncodeWithBase (const StringPiece &base, const StringPiece &path, const StringPiece &filter_id, const StringPiece &hash, const StringPiece &name, const StringPiece &ext)
GoogleString EncodeWithBase (const StringPiece &base, const StringPiece &path, const StringPiece &filter_id, const StringPiece &hash, const StringVector &name_vector, const StringPiece &ext)
GoogleString EncodeImage (int width, int height, StringPiece filename, StringPiece hash, StringPiece rewritten_ext)
GoogleString AddOptionsToEncodedUrl (const StringPiece &url, const StringPiece &options)
 Takes an already-encoded URL and adds options to to it.
void SetupWaitFetcher ()
void CallFetcherCallbacks ()
void OtherCallFetcherCallbacks ()
RewriteOptionsoptions () const
RewriteOptionsother_options () const
void SetRewriteOptions (RewriteOptions *opts)
 Set the RewriteOptions to be returned by the RewriteOptionsManager.
bool AddDomain (StringPiece domain)
bool AddOriginDomainMapping (StringPiece to_domain, StringPiece from_domain)
bool AddRewriteDomainMapping (StringPiece to_domain, StringPiece from_domain)
bool AddShard (StringPiece domain, StringPiece shards)
void TestServeFiles (const ContentType *content_type, const StringPiece &filter_id, const StringPiece &rewritten_ext, const StringPiece &orig_name, const StringPiece &orig_content, const StringPiece &rewritten_name, const StringPiece &rewritten_content)
 Helper method to test all manner of resource serving from a filter.
void ValidateFallbackHeaderSanitization (StringPiece filter_id)
TestRewriteDriverFactoryfactory ()
TestRewriteDriverFactoryother_factory ()
void UseMd5Hasher ()
void SetDefaultLongCacheHeaders (const ContentType *content_type, ResponseHeaders *header)
void SetFetchResponse (const StringPiece &url, const ResponseHeaders &response_header, const StringPiece &response_body)
void SetResponseWithDefaultHeaders (const StringPiece &relative_url, const ContentType &content_type, const StringPiece &content, int64 ttl_sec)
 Add content to mock fetcher (with default headers).
bool LoadFile (const StringPiece &filename, GoogleString *contents)
void AddFileToMockFetcher (const StringPiece &url, const StringPiece &filename, const ContentType &content_type, int64 ttl_sec)
 Add the contents of a file to mock fetcher (with default headers).
void AddToResponse (const StringPiece &url, const StringPiece &name, const StringPiece &value)
void SetFetchResponse404 (const StringPiece &url)
void SetFetchFailOnUnexpected (bool fail)
void FetcherUpdateDateHeaders ()
void ClearFetcherResponses ()
virtual void ClearStats ()
void ClearRewriteDriver ()
MockUrlFetchermock_url_fetcher ()
Hasherhasher ()
DelayCachedelay_cache ()
LRUCachelru_cache ()
Statisticsstatistics ()
MemFileSystemfile_system ()
HTTPCachehttp_cache ()
PropertyCachepage_property_cache ()
MockMessageHandlermessage_handler ()
RewriteDriverrewrite_driver ()
RewriteDriverother_rewrite_driver ()
MockSchedulermock_scheduler ()
 The scheduler used by rewrite_driver.
int64 start_time_ms () const
bool ReadFile (const char *filename, GoogleString *contents)
bool WriteFile (const char *filename, const StringPiece &contents)
ServerContextserver_context ()
ServerContextother_server_context ()
CountingUrlAsyncFetchercounting_url_async_fetcher ()
void SetMockHashValue (const GoogleString &value)
void SetCacheDelayUs (int64 delay_us)
void SetupWriter () override
RewriteDriverMakeDriver (ServerContext *server_context, RewriteOptions *options)
GoogleString AbsolutifyUrl (const StringPiece &in)
 Converts a potentially relative URL off kTestDomain to absolute if needed.
void TestRetainExtraHeaders (const StringPiece &name, const StringPiece &filter_id, const StringPiece &ext)
const UrlSegmentEncoderFindEncoder (const StringPiece &id) const
void SetUseTestUrlNamer (bool use_test_url_namer)
 Switch url namers as specified.
GoogleString EncodeCssName (const StringPiece &name, bool supports_webp, bool can_inline)
bool ReadIfCached (const ResourcePtr &resource)
void InitiateResourceRead (const ResourcePtr &resource)
HTTPCache::FindResult HttpBlockingFind (const GoogleString &key, HTTPCache *http_cache, HTTPValue *value_out, ResponseHeaders *headers)
HTTPCache::FindResult HttpBlockingFindStatus (const GoogleString &key, HTTPCache *http_cache)
HTTPCache::FindResult HttpBlockingFindWithOptions (const RewriteOptions *options, const GoogleString &key, HTTPCache *http_cache, HTTPValue *value_out, ResponseHeaders *headers)
 Same as above, but with options (for invalidation checks)
void SetXhtmlMimetype ()
 Sets the response-headers Content-Type to "application/xhtml+xml".
void SetHtmlMimetype ()
 Sets the response-headers Content-Type to "text/html".
void SetMimetype (const StringPiece &mimetype)
 Sets the response-headers Content-Type as specified.
void CheckFetchFromHttpCache (StringPiece url, StringPiece expected_contents, int64 expected_expiration_ms)
const PropertyCache::CohortSetupCohort (PropertyCache *cache, const GoogleString &cohort)
 Setup statistics for the given cohort and add it to the give PropertyCache.
void SetupSharedCache ()
MockPropertyPageNewMockPage (const StringPiece &url, const StringPiece &options_signature_hash, UserAgentMatcher::DeviceType device_type)
 Returns a new mock property page for the page property cache.
MockPropertyPageNewMockPage (const StringPiece &url)
void SetMockLogRecord ()
 Sets MockLogRecord in the driver's request_context.
MockLogRecordmock_log_record ()
 Returns the MockLogRecord in the driver.
GoogleString GetLazyloadScriptHtml ()
 Helper methods to return js/html snippets related to lazyload images.
GoogleString GetLazyloadPostscriptHtml ()
void SetCacheInvalidationTimestamp ()
void SetCacheInvalidationTimestampForUrl (StringPiece url, bool ignores_metadata_and_pcache)
void EnableCachePurge ()
void EnableDebug ()
 Enables the debug flag, which is often done on a test-by-test basis.
void DebugWithMessage (StringPiece expected_debug_message)
GoogleString DebugMessage (StringPiece url)
void DisableGzip ()
bool WasGzipped (const ResponseHeaders &response_headers)
 Determines whether a response was originally gzipped.
- Public Member Functions inherited from net_instaweb::RewriteOptionsTestBase< OptionsClass >
ThreadSystemthread_system ()
OptionsClass * NewOptions ()

Static Public Member Functions

static GoogleString ChangeSuffix (StringPiece old_url, bool append_new_suffix, StringPiece old_suffix, StringPiece new_suffix)
static const ProcessContextprocess_context ()

Static Public Attributes

static const char kTestData []
 Testdata directory.
static const char kConfiguredBeaconingKey []
 Beaconing key values used when downstream caching is enabled.
static const char kWrongBeaconingKey []

Protected Member Functions

void Init ()
virtual RequestContextPtr CreateRequestContext ()
void CallFetcherCallbacksForDriver (WaitUrlAsyncFetcher *fetcher, RewriteDriver *driver)
void PopulateDefaultHeaders (const ContentType &content_type, int64 original_content_length, ResponseHeaders *headers)
void SetActiveServer (ActiveServerFlag server_to_use)
void AdvanceTimeUs (int64 delay_ms)
void AdvanceTimeMs (int64 delay_ms)
void SetTimeUs (int64 time_us)
void SetTimeMs (int64 time_ms)
void AdjustTimeUsWithoutWakingAlarms (int64 time_us)
 Adjusts time ignoring any scheduler callbacks. Use with caution.
const RequestTimingInfotiming_info ()
 Accessor for TimingInfo.
RequestTimingInfomutable_timing_info ()
virtual RequestContextPtr request_context ()
LoggingInfo * logging_info ()
const MetadataCacheInfo & metadata_cache_info ()
 Convenience method to extract read-only metadata_cache_info.
GoogleString AppliedRewriterStringFromLog ()
void VerifyRewriterInfoEntry (AbstractLogRecord *log_record, const GoogleString &id, int url_index, int rewriter_info_index, int rewriter_info_size, int url_list_size, const GoogleString &url)
void SetCurrentUserAgent (const StringPiece &user_agent)
 Sets current_user_agent_.
void SetupForWebp ()
 Sets up user-agent and request-header to allow webp processing.
void SetupForWebpLossless ()
void SetupForWebpAnimated ()
void AddRequestAttribute (StringPiece name, StringPiece value)
void PopulateRequestHeaders (RequestHeaders *request_headers)
 Populates a RequestHeaders* object with al.
virtual void ParseUrl (StringPiece url, StringPiece html_input)
GoogleString ExpectedNonce ()
GoogleString HttpCacheKey (StringPiece url)
int TimedValue (StringPiece name)
 Returns the value of a TimedVariable, specified by name.
- Protected Member Functions inherited from net_instaweb::HtmlParseTestBaseNoAlloc
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.
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...
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.
const GoogleUrlhtml_gurl ()

Protected Attributes

const HTTPCache::FindResult kFoundResult
 Common values for HttpBlockingFind* result.
const HTTPCache::FindResult kNotFoundResult
MockUrlFetcher mock_url_fetcher_
scoped_ptr< Statisticsstatistics_
< TestRewriteDriverFactory
< TestRewriteDriverFactory
scoped_ptr< HtmlWriterFilterother_html_writer_filter_
ActiveServerFlag active_server_
bool use_managed_rewrite_drivers_
StringPiece current_user_agent_
StringVector request_attribute_names_
StringVector request_attribute_values_
MD5Hasher md5_hasher_
 owned by rewrite_driver_.
 owned by other_rewrite_driver_.
UrlSegmentEncoder default_encoder_
ResponseHeaders response_headers_
const GoogleString kEtag0
 Etag with a 0 hash.
uint64 expected_nonce_
GoogleString debug_message_
 Message used by DebugMessage.
- Protected Attributes inherited from net_instaweb::HtmlParseTestBaseNoAlloc
MockMessageHandler message_handler_
StringWriter write_to_string_
GoogleString output_buffer_
bool added_filter_
scoped_ptr< HtmlWriterFilterhtml_writer_filter_
GoogleString doctype_string_

Additional Inherited Members

- Public Attributes inherited from net_instaweb::RewriteOptionsTestBase< OptionsClass >
scoped_ptr< ThreadSystemthread_system_
- Static Protected Attributes inherited from net_instaweb::HtmlParseTestBaseNoAlloc
static const char kTestDomain []
static const char kXhtmlDtd []
 DOCTYPE string for claiming XHTML.

Member Enumeration Documentation

Specifies which server should be "active" in that rewrites and fetches will use it. The data members affected are those returned by:

  • factory() / other_factory()
  • server_context() / other_server_context()
  • rewrite_driver() / other_rewrite_driver()
  • options() / other_options()

Use the normal data members.


Use all the other_ data members.

Constructor & Destructor Documentation

net_instaweb::RewriteTestBase::RewriteTestBase ( std::pair< TestRewriteDriverFactory *, TestRewriteDriverFactory * >  factories)

Specifies alternate factories to be initialized on construction. By default, TestRewriteDriverFactory is used, but you can employ your own subclass of TestRewriteDriverFactory using this constructor. If you do, you probably also want to override MakeTestFactory.

Member Function Documentation

virtual bool net_instaweb::RewriteTestBase::AddBody ( ) const

In this set of tests, we will provide explicit body tags, so the test harness should not add them in for our convenience. It can go ahead and add the <html> and </html>, however.

Implements net_instaweb::HtmlParseTestBaseNoAlloc.

Reimplemented in net_instaweb::RewriteContextTestBase.

void net_instaweb::RewriteTestBase::AddFetchOnlyRewriteFilter ( RewriteFilter filter)

Adds a custom rewriter filter but does not register it for HTML rewriting, only for fetches.

bool net_instaweb::RewriteTestBase::AddOriginDomainMapping ( StringPiece  to_domain,
StringPiece  from_domain 

Adds an origin domain mapping to options()->domain_lawyer(), recomputing the options signature if necessary.

void net_instaweb::RewriteTestBase::AddOtherRewriteFilter ( RewriteFilter filter)

Add a custom rewrite filter (one without a corresponding option) to other_rewrite_driver and enable it.

void net_instaweb::RewriteTestBase::AddRecompressImageFilters ( )

Adds kRecompressJpeg, kRecompressPng, kRecompressWebp, kConvertPngToJpeg, kConvertJpegToWebp and kConvertGifToPng.

void net_instaweb::RewriteTestBase::AddRequestAttribute ( StringPiece  name,
StringPiece  value 

Adds an attribute to be populated later into a RequestHeaders* object, along with the user-agent. Note that these attributes stay in the test-class until ClearRewriteDriver is called.

bool net_instaweb::RewriteTestBase::AddRewriteDomainMapping ( StringPiece  to_domain,
StringPiece  from_domain 

Adds a rewrite domain mapping to options()->domain_lawyer(), recomputing the options signature if necessary.

void net_instaweb::RewriteTestBase::AddRewriteFilter ( RewriteFilter filter)

Add a custom rewrite filter (one without a corresponding option) to rewrite_driver and enable it.

bool net_instaweb::RewriteTestBase::AddShard ( StringPiece  domain,
StringPiece  shards 

Adds a shard to options()->domain_lawyer(), recomputing the options signature if necessary.

void net_instaweb::RewriteTestBase::AdvanceTimeUs ( int64  delay_ms)

Advances time forward using the mock scheduler. Note that time is not advanced directly in the mock_timer; the scheduler must be used.

GoogleString net_instaweb::RewriteTestBase::AppliedRewriterStringFromLog ( )

Convenience method for retrieving the computed applied rewriters string from the current request context's log record. Thread-safe.

void net_instaweb::RewriteTestBase::CallFetcherCallbacksForDriver ( WaitUrlAsyncFetcher fetcher,
RewriteDriver driver 

Calls callbacks on given wait fetcher, making sure to properly synchronize with async rewrite flows given driver.

static GoogleString net_instaweb::RewriteTestBase::ChangeSuffix ( StringPiece  old_url,
bool  append_new_suffix,
StringPiece  old_suffix,
StringPiece  new_suffix 

If append_new_suffix is true, appends new_suffix to old_url. If append_new_suffix is false, replaces old_suffix at the end of old_url with new_suffix. Either way, precondition: old_url ends with old_suffix

void net_instaweb::RewriteTestBase::CheckFetchFromHttpCache ( StringPiece  url,
StringPiece  expected_contents,
int64  expected_expiration_ms 

Verifies that the specified URL can be fetched from HTTP cache, and that its cache TTL and contents are as specified.

void net_instaweb::RewriteTestBase::ClearRewriteDriver ( )

Calls Clear() on the rewrite driver and does any other necessary clean-up so the driver is okay for a test to reuse.

Removes pending request-header attributes added via AddRequestAttribute.

virtual RequestContextPtr net_instaweb::RewriteTestBase::CreateRequestContext ( )

Override this if the test fixture needs to use a different RequestContext subclass.

GoogleString net_instaweb::RewriteTestBase::DebugMessage ( StringPiece  url)

Return the debug message if it was set by DebugWithMessage, empty string otherwise. Inserts url for url% if needed, attempting to resolve it against kTestDomain first, and using url exactly as passed if resolving it doesn't return a valid url.

void net_instaweb::RewriteTestBase::DebugWithMessage ( StringPiece  expected_debug_message)

Enable debugging and set expected_debug_message used by DebugMessage. Occurrences of url% in the message will be replaced by the argument to DebugMessage.

void net_instaweb::RewriteTestBase::DisableGzip ( )

Turns off gzip capability in the cache. Note that requests will still be formulated with Accept-Encoding:gzip.

void net_instaweb::RewriteTestBase::EnableCachePurge ( )

Changes the way cache-purges are implemented for non-wildcards to avoid flushing the entire metadata cache and instead match each metadata Input against the invalidation-set.

GoogleString net_instaweb::RewriteTestBase::Encode ( const StringPiece &  path,
const StringPiece &  filter_id,
const StringPiece &  hash,
const StringPiece &  name,
const StringPiece &  ext 

Helper function to encode a resource name from its pieces using whatever encoding we are testing, either UrlNamer or TestUrlNamer.

GoogleString net_instaweb::RewriteTestBase::EncodeCssName ( const StringPiece &  name,
bool  supports_webp,
bool  can_inline 

Helper function which instantiates an encoder, collects the required arguments and calls the virtual Encode().

GoogleString net_instaweb::RewriteTestBase::EncodeImage ( int  width,
int  height,
StringPiece  filename,
StringPiece  hash,
StringPiece  rewritten_ext 

Encode image with width and height. Use -1 for either width or height to omit it from the encoding.

GoogleString net_instaweb::RewriteTestBase::EncodeWithBase ( const StringPiece &  base,
const StringPiece &  path,
const StringPiece &  filter_id,
const StringPiece &  hash,
const StringPiece &  name,
const StringPiece &  ext 

Same as Encode but specifying the base URL (which is used by TestUrlNamer but is unused by UrlNamer so for it results in exactly the same as Encode).

bool net_instaweb::RewriteTestBase::FetchResource ( const StringPiece &  path,
const StringPiece &  filter_id,
const StringPiece &  name,
const StringPiece &  ext,
GoogleString content 

Helper function to test resource fetching, returning true if the fetch succeeded, and modifying content. It is up to the caller to EXPECT_TRUE on the status and EXPECT_EQ on the content.

const UrlSegmentEncoder* net_instaweb::RewriteTestBase::FindEncoder ( const StringPiece &  id) const

Find the segment-encoder for the filter found via 'id'. Some test filters are not registered with RewriteDriver so for those we use the default encoder.

virtual RewriteDriver* net_instaweb::RewriteTestBase::html_parse ( )

This definition is required by HtmlParseTestBase which defines this as pure abstract, so that the test subclass can define how it instantiates HtmlParse.

Implements net_instaweb::HtmlParseTestBaseNoAlloc.

HTTPCache::FindResult net_instaweb::RewriteTestBase::HttpBlockingFind ( const GoogleString key,
HTTPCache http_cache,
HTTPValue value_out,
ResponseHeaders headers 

While our production cache model is non-blocking, we use an in-memory LRU for tests that calls its callback directly from Get. Thus we can make a convenient blocking cache wrapper to make it easier to write tests.

HTTPCache::FindResult net_instaweb::RewriteTestBase::HttpBlockingFindStatus ( const GoogleString key,
HTTPCache http_cache 

The same as the above function, but doesn't need an HTTPValue or ResponseHeaders.

GoogleString net_instaweb::RewriteTestBase::HttpCacheKey ( StringPiece  url)

When reaching into a cache that backs an HTTP cache you need a cache key that includes the fragment.

void net_instaweb::RewriteTestBase::InitiateResourceRead ( const ResourcePtr resource)

Variation on ReadIfCached that is used when we expect the resource not to be in present in cache, but instead we are looking to initiate the resource-rewrite process so that a subsequent call to ReadIfCached succeeds.

bool net_instaweb::RewriteTestBase::LoadFile ( const StringPiece &  filename,
GoogleString contents 

Load a test file (from testdata/) into 'contents', returning false on failure.

LoggingInfo* net_instaweb::RewriteTestBase::logging_info ( )

Convenience method to pull the logging info proto out of the current request context's log record. The request context owns the log record, and if the log record has a non-NULL mutex, it will need to be locked for this call.

RewriteDriver* net_instaweb::RewriteTestBase::MakeDriver ( ServerContext server_context,
RewriteOptions options 

Creates a RewriteDriver using the passed-in options, object, but does not finalize the driver. This gives individual files the chance to add filters to the options prior to calling driver->AddFilters().

virtual TestRewriteDriverFactory* net_instaweb::RewriteTestBase::MakeTestFactory ( )

Makes a TestRewriteDriverFactory. This can be overridden in subclasses if you need a factory with special properties.

TODO(jmarantz): This is currently only used in ServeResourceFromNewContext, but should be used for factory_ and other_factory_. This would requuire a refactor, because those are created at construction; too early for subclass overrides to take effect. To deal with that, an alternate constructor is provided above so that the proper sort of factories can be passed in.

Reimplemented in net_instaweb::CustomRewriteTestBase< OptionsClass >.

virtual void net_instaweb::RewriteTestBase::ParseUrl ( StringPiece  url,
StringPiece  html_input 

Override HtmlParseTestBaseNoAlloc::ParseUrl to populate the request-headers into rewrite_driver_ before running filters.

Reimplemented from net_instaweb::HtmlParseTestBaseNoAlloc.

void net_instaweb::RewriteTestBase::PopulateDefaultHeaders ( const ContentType content_type,
int64  original_content_length,
ResponseHeaders headers 

Populate the given headers based on the content type and original content length information.

static const ProcessContext& net_instaweb::RewriteTestBase::process_context ( )

Returns a process context needed for any tests to instantiate factories explicitly.

bool net_instaweb::RewriteTestBase::ReadIfCached ( const ResourcePtr resource)

Helper function for legacy tests that used this now-extinct interface. In general we don't support this flow in production but we rely on it in tests for obliquely covering some cases relating to resource pathnames.

virtual RequestContextPtr net_instaweb::RewriteTestBase::request_context ( )

Returns the current request context. The default implementation takes the request context from rewrite_driver(). ProxyInterfaceTestBase overrides.

This method check-fails if the current request-context is null.

Reimplemented in net_instaweb::ProxyInterfaceTestBase.

RewriteDriver* net_instaweb::RewriteTestBase::rewrite_driver ( )
TODO(jmarantz): These abstractions are not satisfactory long-term where we want to have driver-lifetime in tests be reflective of how servers work. But for now we use these accessors.

Note that the *rewrite_driver() methods are not valid during construction, so any test classes that need to use them must do so from SetUp() methods.

void net_instaweb::RewriteTestBase::ServeResourceFromNewContext ( const GoogleString resource_url,
const StringPiece &  expected_content 

Test that a resource can be served from an new server that has not already constructed it.

void net_instaweb::RewriteTestBase::SetActiveServer ( ActiveServerFlag  server_to_use)

Set the "active" server to that specified; the active server is used for rewriting and serving pages.

void net_instaweb::RewriteTestBase::SetBaseUrlForFetch ( const StringPiece &  url)

Sets the active context URL for purposes of XS checks of fetches on the main rewrite driver.

void net_instaweb::RewriteTestBase::SetCacheInvalidationTimestamp ( )

Sets the server-scoped invalidation timestamp. Time is advanced by 1 second both before and after invalidation. E.g. if the current time is 100000 milliseconds at the time this is called, the invalidation timestamp will be at 101000 milliseconds, and time will be rolled forward to 102000 on exit from this function.

void net_instaweb::RewriteTestBase::SetCacheInvalidationTimestampForUrl ( StringPiece  url,
bool  ignores_metadata_and_pcache 

Sets the invalidation timestamp for a URL pattern. Time is advanced by in the same manner as for SetCacheInvalidationTimestamp above.

void net_instaweb::RewriteTestBase::SetDownstreamCacheDirectives ( StringPiece  downstream_cache_purge_method,
StringPiece  downstream_cache_purge_location_prefix,
StringPiece  rebeaconing_key 

Enable downstream caching feature and set up the downstream cache rebeaconing key.

void net_instaweb::RewriteTestBase::SetDriverRequestHeaders ( )

Populates request-headers based on the current user-agent and the attributes added via AddRequestAttribute and installs them into rewrite_driver_.

void net_instaweb::RewriteTestBase::SetupSharedCache ( )

Configure the other_server_context_ to use the same LRU cache as the primary server context.

void net_instaweb::RewriteTestBase::SetupWaitFetcher ( )

Overrides the async fetcher on the primary context to be a wait fetcher which permits delaying callback invocation. CallFetcherCallbacks can then be called to let the fetches complete and call the callbacks.

void net_instaweb::RewriteTestBase::SetUseManagedRewriteDrivers ( bool  use_managed_rewrite_drivers)

Use managed rewrite drivers for the test so that we see the same behavior in tests that we see in real servers. By default, tests use unmanaged drivers so that files can add options after the driver was created and before the filters are added. Note that this will only clean them up via shutdown codepath if you don't actually use them, unless an explicit Cleanup() call is made.

void net_instaweb::RewriteTestBase::TestRetainExtraHeaders ( const StringPiece &  name,
const StringPiece &  filter_id,
const StringPiece &  ext 

Tests that non-caching-related response-header attributes are propagated to output resources.

'name' is the name of the resource.

Timer* net_instaweb::RewriteTestBase::timer ( )

Returns the main factory Timer*, which can be used for calling NowUs and NowMs. To set the time, use (Advance|Set)Time(Ms|Us), which wake up any scheduler alarms. See also AdjustTimeUsWithoutWakingAlarms which should be used with extreme care.

void net_instaweb::RewriteTestBase::ValidateFallbackHeaderSanitization ( StringPiece  filter_id)

Check that when we have a cache miss for a pagespeed resource we set headers to reduce the chance of it being interpreted as html.

void net_instaweb::RewriteTestBase::VerifyRewriterInfoEntry ( AbstractLogRecord log_record,
const GoogleString id,
int  url_index,
int  rewriter_info_index,
int  rewriter_info_size,
int  url_list_size,
const GoogleString url 

Convenience method for verifying that the rewriter info entries have expected values.

Member Data Documentation

scoped_ptr<TestRewriteDriverFactory> net_instaweb::RewriteTestBase::factory_

We have two independent RewriteDrivers representing two completely separate servers for the same domain (say behind a load-balancer).

Server A runs rewrite_driver_ and will be used to rewrite pages and serves the rewritten resources.

MockUrlFetcher net_instaweb::RewriteTestBase::mock_url_fetcher_

The mock fetchers & stats are global across all Factories used in the tests.

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