Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rewrite_test_base.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
20 
21 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_TEST_BASE_H_
22 #define NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_TEST_BASE_H_
23 
24 #include <utility>
25 #include <vector>
26 
29 #include "net/instaweb/http/public/logging_proto.h"
30 #include "net/instaweb/http/public/logging_proto_impl.h"
32 #include "net/instaweb/http/public/request_context.h"
40 #include "net/instaweb/util/public/mock_property_page.h"
41 #include "net/instaweb/util/public/property_cache.h"
62 #include "pagespeed/kernel/http/user_agent_matcher.h"
65 
66 
67 
68 namespace net_instaweb {
69 
70 class AbstractLogRecord;
71 class CountingUrlAsyncFetcher;
72 class DelayCache;
73 class LRUCache;
74 class MockLogRecord;
75 class MockScheduler;
76 class ProcessContext;
77 class RewriteFilter;
78 class WaitUrlAsyncFetcher;
79 
80 class RewriteOptionsTestBase : public HtmlParseTestBaseNoAlloc {
81  protected:
82  RewriteOptionsTestBase() {
84  }
85  ~RewriteOptionsTestBase() {
86  RewriteOptions::Terminate();
87  }
88 };
89 
91  public:
92  static const char kTestData[];
93 
95  static const char kConfiguredBeaconingKey[];
96  static const char kWrongBeaconingKey[];
97 
107  };
108 
109  RewriteTestBase();
110 
116  explicit RewriteTestBase(std::pair<TestRewriteDriverFactory*,
117  TestRewriteDriverFactory*> factories);
118  virtual ~RewriteTestBase();
119 
120  virtual void SetUp();
121  virtual void TearDown();
122 
126  virtual bool AddBody() const { return false; }
127 
138 
142 
144  void AddFilter(RewriteOptions::Filter filter);
145 
148 
151  void AddRewriteFilter(RewriteFilter* filter);
152 
156 
159  void AddOtherRewriteFilter(RewriteFilter* filter);
160 
163  void SetBaseUrlForFetch(const StringPiece& url);
164 
169 
173  StringPiece downstream_cache_purge_method,
174  StringPiece downstream_cache_purge_location_prefix,
175  StringPiece rebeaconing_key);
176 
178  void SetShouldBeaconHeader(StringPiece rebeaconing_key);
179 
180  ResourcePtr CreateResource(const StringPiece& base, const StringPiece& url);
181 
186  Timer* timer() { return factory()->mock_timer(); }
187 
189  void AppendDefaultHeaders(const ContentType& content_type,
190  GoogleString* text);
191 
193  void AppendDefaultHeadersWithCanonical(const ContentType& content_type,
194  StringPiece canonical_url,
195  GoogleString* text);
196 
197  void ServeResourceFromManyContexts(const GoogleString& resource_url,
198  const StringPiece& expected_content);
199 
200  void ServeResourceFromManyContextsWithUA(
201  const GoogleString& resource_url,
202  const StringPiece& expected_content,
203  const StringPiece& user_agent);
204 
208  const GoogleString& resource_url,
209  const StringPiece& expected_content);
210 
214  virtual RewriteDriver* html_parse() { return rewrite_driver_; }
215 
217  void DefaultResponseHeaders(const ContentType& content_type, int64 ttl_sec,
218  ResponseHeaders* response_headers);
219 
223  bool FetchResource(const StringPiece& path, const StringPiece& filter_id,
224  const StringPiece& name, const StringPiece& ext,
225  GoogleString* content);
226  bool FetchResource(const StringPiece& path, const StringPiece& filter_id,
227  const StringPiece& name, const StringPiece& ext,
228  GoogleString* content, ResponseHeaders* response);
229 
230  bool FetchResourceUrl(const StringPiece& url, GoogleString* content,
231  ResponseHeaders* response);
232  bool FetchResourceUrl(const StringPiece& url,
233  RequestHeaders* request_headers,
234  GoogleString* content,
235  ResponseHeaders* response_headers);
236  bool FetchResourceUrl(const StringPiece& url, GoogleString* content);
237 
239  bool TryFetchResource(const StringPiece& url);
240 
247  void SetUseManagedRewriteDrivers(bool use_managed_rewrite_drivers);
248 
249  GoogleString CssLinkHref(const StringPiece& url) {
250  return StrCat("<link rel=stylesheet href=", url, ">");
251  }
252 
254  class CssLink {
255  public:
256  CssLink(const StringPiece& url, const StringPiece& content,
257  const StringPiece& media, bool supply_mock);
258 
260  class Vector : public std::vector<CssLink*> {
261  public:
262  ~Vector();
263  void Add(const StringPiece& url, const StringPiece& content,
264  const StringPiece& media, bool supply_mock);
265  };
266 
269  bool DecomposeCombinedUrl(StringPiece base_url, GoogleString* base,
270  StringVector* segments, MessageHandler* handler);
271 
272  GoogleString url_;
273  GoogleString content_;
274  GoogleString media_;
275  bool supply_mock_;
276  };
277 
279  void CollectCssLinks(const StringPiece& id, const StringPiece& html,
280  StringVector* css_links);
281 
283  void CollectCssLinks(const StringPiece& id, const StringPiece& html,
284  CssLink::Vector* css_links);
285 
287  void EncodePathAndLeaf(const StringPiece& filter_id,
288  const StringPiece& hash,
289  const StringVector& name_vector,
290  const StringPiece& ext,
291  ResourceNamer* namer);
292 
293  StringVector MultiUrl(const StringPiece& url1) {
294  StringVector v;
295  v.push_back(url1.as_string());
296  return v;
297  }
298 
299  StringVector MultiUrl(const StringPiece& url1, const StringPiece& url2) {
300  StringVector v;
301  v.push_back(url1.as_string());
302  v.push_back(url2.as_string());
303  return v;
304  }
305 
306  StringVector MultiUrl(const StringPiece& url1, const StringPiece& url2,
307  const StringPiece& url3) {
308  StringVector v;
309  v.push_back(url1.as_string());
310  v.push_back(url2.as_string());
311  v.push_back(url3.as_string());
312  return v;
313  }
314 
315  StringVector MultiUrl(const StringPiece& url1, const StringPiece& url2,
316  const StringPiece& url3, const StringPiece& url4) {
317  StringVector v;
318  v.push_back(url1.as_string());
319  v.push_back(url2.as_string());
320  v.push_back(url3.as_string());
321  v.push_back(url4.as_string());
322  return v;
323  }
324 
327  GoogleString Encode(const StringPiece& path,
328  const StringPiece& filter_id,
329  const StringPiece& hash,
330  const StringPiece& name,
331  const StringPiece& ext) {
332  return Encode(path, filter_id, hash, MultiUrl(name), ext);
333  }
334  GoogleString Encode(const StringPiece& path,
335  const StringPiece& filter_id,
336  const StringPiece& hash,
337  const StringVector& name_vector,
338  const StringPiece& ext);
339 
341  GoogleString EncodeNormal(const StringPiece& path,
342  const StringPiece& filter_id,
343  const StringPiece& hash,
344  const StringPiece& name,
345  const StringPiece& ext) {
346  return EncodeNormal(path, filter_id, hash, MultiUrl(name), ext);
347  }
348  GoogleString EncodeNormal(const StringPiece& path,
349  const StringPiece& filter_id,
350  const StringPiece& hash,
351  const StringVector& name_vector,
352  const StringPiece& ext);
353 
356  GoogleString EncodeWithBase(const StringPiece& base,
357  const StringPiece& path,
358  const StringPiece& filter_id,
359  const StringPiece& hash,
360  const StringPiece& name,
361  const StringPiece& ext) {
362  return EncodeWithBase(base, path, filter_id, hash, MultiUrl(name), ext);
363  }
364  GoogleString EncodeWithBase(const StringPiece& base,
365  const StringPiece& path,
366  const StringPiece& filter_id,
367  const StringPiece& hash,
368  const StringVector& name_vector,
369  const StringPiece& ext);
370 
373  GoogleString EncodeImage(int width, int height,
374  StringPiece filename, StringPiece hash,
375  StringPiece rewritten_ext);
376 
378  GoogleString AddOptionsToEncodedUrl(const StringPiece& url,
379  const StringPiece& options);
380 
385  static GoogleString ChangeSuffix(
386  StringPiece old_url, bool append_new_suffix,
387  StringPiece old_suffix, StringPiece new_suffix);
388 
393  void SetupWaitFetcher();
394  void CallFetcherCallbacks();
395  void OtherCallFetcherCallbacks();
396  RewriteOptions* options() const { return options_; }
397  RewriteOptions* other_options() const { return other_options_; }
398 
400  void SetRewriteOptions(RewriteOptions* opts);
401 
404  bool AddDomain(StringPiece domain);
405 
408  bool AddOriginDomainMapping(StringPiece to_domain, StringPiece from_domain);
409 
412  bool AddRewriteDomainMapping(StringPiece to_domain, StringPiece from_domain);
413 
416  bool AddShard(StringPiece domain, StringPiece shards);
417 
419  void TestServeFiles(const ContentType* content_type,
420  const StringPiece& filter_id,
421  const StringPiece& rewritten_ext,
422  const StringPiece& orig_name,
423  const StringPiece& orig_content,
424  const StringPiece& rewritten_name,
425  const StringPiece& rewritten_content);
426 
429  void ValidateFallbackHeaderSanitization(StringPiece filter_id);
430 
431  TestRewriteDriverFactory* factory() { return factory_.get(); }
432  TestRewriteDriverFactory* other_factory() { return other_factory_.get(); }
433 
434  void UseMd5Hasher() {
435  server_context_->set_hasher(&md5_hasher_);
436  server_context_->http_cache()->set_hasher(&md5_hasher_);
437  other_server_context_->set_hasher(&md5_hasher_);
438  other_server_context_->http_cache()->set_hasher(&md5_hasher_);
439  }
440 
441 
442  void SetDefaultLongCacheHeaders(const ContentType* content_type,
443  ResponseHeaders* header) {
444  server_context_->SetDefaultLongCacheHeaders(
445  content_type, StringPiece(), StringPiece(), header);
446  }
447 
448  void SetFetchResponse(const StringPiece& url,
449  const ResponseHeaders& response_header,
450  const StringPiece& response_body) {
451  mock_url_fetcher()->SetResponse(url, response_header, response_body);
452  }
453 
455  void SetResponseWithDefaultHeaders(const StringPiece& relative_url,
456  const ContentType& content_type,
457  const StringPiece& content,
458  int64 ttl_sec);
459 
462  bool LoadFile(const StringPiece& filename, GoogleString* contents);
463 
465  void AddFileToMockFetcher(const StringPiece& url,
466  const StringPiece& filename,
467  const ContentType& content_type, int64 ttl_sec);
468 
469  void AddToResponse(const StringPiece& url,
470  const StringPiece& name,
471  const StringPiece& value) {
472  mock_url_fetcher()->AddToResponse(url, name, value);
473  }
474 
475  void SetFetchResponse404(const StringPiece& url);
476 
477  void SetFetchFailOnUnexpected(bool fail) {
478  mock_url_fetcher()->set_fail_on_unexpected(fail);
479  }
480  void FetcherUpdateDateHeaders() {
481  mock_url_fetcher()->set_timer(timer());
482  mock_url_fetcher()->set_update_date_headers(true);
483  }
484  void ClearFetcherResponses() { mock_url_fetcher()->Clear(); }
485 
486  virtual void ClearStats();
487 
492  void ClearRewriteDriver();
493 
494  MockUrlFetcher* mock_url_fetcher() {
495  return &mock_url_fetcher_;
496  }
497  Hasher* hasher() { return server_context_->hasher(); }
498  DelayCache* delay_cache() { return factory_->delay_cache(); }
499  LRUCache* lru_cache() { return factory_->lru_cache(); }
500  Statistics* statistics() { return factory_->statistics(); }
501  MemFileSystem* file_system() { return factory_->mem_file_system(); }
502  HTTPCache* http_cache() { return server_context_->http_cache(); }
503  PropertyCache* page_property_cache() {
504  return server_context_->page_property_cache();
505  }
506  MockMessageHandler* message_handler() {
507  return factory_->mock_message_handler();
508  }
509 
517  RewriteDriver* rewrite_driver() { return rewrite_driver_; }
518  RewriteDriver* other_rewrite_driver() { return other_rewrite_driver_; }
519 
521  MockScheduler* mock_scheduler() { return factory_->mock_scheduler(); }
522 
523  int64 start_time_ms() const { return factory_->kStartTimeMs; }
524 
525  bool ReadFile(const char* filename, GoogleString* contents) {
526  return file_system()->ReadFile(filename, contents, message_handler());
527  }
528  bool WriteFile(const char* filename, const StringPiece& contents) {
529  return file_system()->WriteFile(filename, contents, message_handler());
530  }
531 
532  ServerContext* server_context() { return server_context_; }
533  ServerContext* other_server_context() { return other_server_context_; }
534  CountingUrlAsyncFetcher* counting_url_async_fetcher() {
535  return factory_->counting_url_async_fetcher();
536  }
537  void SetMockHashValue(const GoogleString& value) {
538  factory_->mock_hasher()->set_hash_value(value);
539  }
540 
541  void SetCacheDelayUs(int64 delay_us);
542 
543  void SetupWriter() override;
544 
549  RewriteDriver* MakeDriver(ServerContext* server_context,
550  RewriteOptions* options);
551 
553  GoogleString AbsolutifyUrl(const StringPiece& in);
554 
559  void TestRetainExtraHeaders(const StringPiece& name,
560  const StringPiece& filter_id,
561  const StringPiece& ext);
562 
566  const UrlSegmentEncoder* FindEncoder(const StringPiece& id) const;
567 
569  void SetUseTestUrlNamer(bool use_test_url_namer);
570 
573  GoogleString EncodeCssName(const StringPiece& name,
574  bool supports_webp,
575  bool can_inline);
576 
580  bool ReadIfCached(const ResourcePtr& resource);
581 
586  void InitiateResourceRead(const ResourcePtr& resource);
587 
591  HTTPCache::FindResult HttpBlockingFind(
592  const GoogleString& key, HTTPCache* http_cache, HTTPValue* value_out,
593  ResponseHeaders* headers);
594 
597  HTTPCache::FindResult HttpBlockingFindStatus(
598  const GoogleString& key, HTTPCache* http_cache);
599 
601  HTTPCache::FindResult HttpBlockingFindWithOptions(
602  const RewriteOptions* options,
603  const GoogleString& key, HTTPCache* http_cache, HTTPValue* value_out,
604  ResponseHeaders* headers);
605 
607  void SetXhtmlMimetype() { SetMimetype("application/xhtml+xml"); }
608 
610  void SetHtmlMimetype() { SetMimetype("text/html"); }
611 
613  void SetMimetype(const StringPiece& mimetype);
614 
618  StringPiece url,
619  StringPiece expected_contents,
620  int64 expected_expiration_ms);
621 
624  PropertyCache* cache, const GoogleString& cohort) {
625  return factory()->SetupCohort(cache, cohort);
626  }
627 
630  void SetupSharedCache();
631 
633  MockPropertyPage* NewMockPage(const StringPiece& url,
634  const StringPiece& options_signature_hash,
635  UserAgentMatcher::DeviceType device_type) {
636  return new MockPropertyPage(
637  server_context_->thread_system(),
638  server_context_->page_property_cache(),
639  url,
640  options_signature_hash,
642  }
643 
644  MockPropertyPage* NewMockPage(const StringPiece& url) {
645  return NewMockPage(url, "hash", UserAgentMatcher::kDesktop);
646  }
647 
649  void SetMockLogRecord();
650 
652  MockLogRecord* mock_log_record();
653 
656  GoogleString GetLazyloadPostscriptHtml();
657 
664 
668  StringPiece url, bool ignores_metadata_and_pcache);
669 
673  void EnableCachePurge();
674 
676  void EnableDebug();
677 
681  void DebugWithMessage(StringPiece expected_debug_message) {
682  EnableDebug();
683 
684  expected_debug_message.CopyToString(&debug_message_);
685  }
686 
691  GoogleString DebugMessage(StringPiece url);
692 
695  static const ProcessContext& process_context();
696 
699  void DisableGzip();
700 
702  bool WasGzipped(const ResponseHeaders& response_headers);
703 
704  protected:
707  const HTTPCache::FindResult kNotFoundResult;
708 
709  void Init();
710 
714 
718  RewriteDriver* driver);
719 
722  void PopulateDefaultHeaders(const ContentType& content_type,
723  int64 original_content_length,
724  ResponseHeaders* headers);
725 
728  void SetActiveServer(ActiveServerFlag server_to_use);
729 
732  void AdvanceTimeUs(int64 delay_ms);
733  void AdvanceTimeMs(int64 delay_ms) { AdvanceTimeUs(delay_ms * Timer::kMsUs); }
734  void SetTimeUs(int64 time_us);
735  void SetTimeMs(int64 time_ms) { SetTimeUs(time_ms * Timer::kMsUs); }
736 
738  void AdjustTimeUsWithoutWakingAlarms(int64 time_us);
739 
741  const RequestTimingInfo& timing_info();
742  RequestTimingInfo* mutable_timing_info();
743 
749  virtual RequestContextPtr request_context();
750 
755  LoggingInfo* logging_info();
756 
758  const MetadataCacheInfo& metadata_cache_info() {
759  return logging_info()->metadata_cache_info();
760  }
761 
765 
769  const GoogleString& id,
770  int url_index,
771  int rewriter_info_index,
772  int rewriter_info_size,
773  int url_list_size,
774  const GoogleString& url);
775 
777  void SetCurrentUserAgent(const StringPiece& user_agent) {
778  current_user_agent_ = user_agent;
779  }
780 
782  void SetupForWebp() {
783  SetCurrentUserAgent("webp");
784  AddRequestAttribute(HttpAttributes::kAccept, "image/webp");
785  }
786 
787  void SetupForWebpLossless() {
788  SetCurrentUserAgent("webp-la");
789  AddRequestAttribute(HttpAttributes::kAccept, "image/webp");
790  }
791 
792  void SetupForWebpAnimated() {
793  SetCurrentUserAgent("webp-animated");
794  AddRequestAttribute(HttpAttributes::kAccept, "image/webp");
795  }
796 
800  void AddRequestAttribute(StringPiece name, StringPiece value);
801 
803  void PopulateRequestHeaders(RequestHeaders* request_headers);
804 
807  virtual void ParseUrl(StringPiece url, StringPiece html_input);
808 
809  GoogleString ExpectedNonce();
810 
813  GoogleString HttpCacheKey(StringPiece url) {
814  return http_cache()->CompositeKey(url, rewrite_driver_->CacheFragment());
815  }
816 
818  int TimedValue(StringPiece name);
819 
823  scoped_ptr<Statistics> statistics_;
824 
832  ServerContext* server_context_;
833  RewriteDriver* rewrite_driver_;
834  ServerContext* other_server_context_;
835  RewriteDriver* other_rewrite_driver_;
836  scoped_ptr<HtmlWriterFilter> other_html_writer_filter_;
837  ActiveServerFlag active_server_;
838  bool use_managed_rewrite_drivers_;
839  StringPiece current_user_agent_;
840  StringVector request_attribute_names_;
841  StringVector request_attribute_values_;
842 
843  MD5Hasher md5_hasher_;
844 
847  UrlSegmentEncoder default_encoder_;
848  ResponseHeaders response_headers_;
850  uint64 expected_nonce_;
851 
853 
854  private:
855  void ValidateFallbackHeaderSanitizationHelper(
856  StringPiece filter_id, StringPiece origin_content_type, bool expect_load);
857 };
858 
859 }
860 
861 #endif
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.
Definition: test_rewrite_driver_factory.h:67
void AddFetchOnlyRewriteFilter(RewriteFilter *filter)
virtual RewriteDriver * html_parse()
Definition: rewrite_test_base.h:214
void SetActiveServer(ActiveServerFlag server_to_use)
void SetCurrentUserAgent(const StringPiece &user_agent)
Sets current_user_agent_.
Definition: rewrite_test_base.h:777
HTTPCache::FindResult HttpBlockingFind(const GoogleString &key, HTTPCache *http_cache, HTTPValue *value_out, ResponseHeaders *headers)
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.
void CollectCssLinks(const StringPiece &id, const StringPiece &html, StringVector *css_links)
Collects the hrefs for all CSS <link>s on the page.
GoogleString HttpCacheKey(StringPiece url)
Definition: rewrite_test_base.h:813
Definition: md5_hasher.h:28
GoogleString EncodeImage(int width, int height, StringPiece filename, StringPiece hash, StringPiece rewritten_ext)
Use the normal data members.
Definition: rewrite_test_base.h:105
bool FetchResource(const StringPiece &path, const StringPiece &filter_id, const StringPiece &name, const StringPiece &ext, GoogleString *content)
GoogleString Encode(const StringPiece &path, const StringPiece &filter_id, const StringPiece &hash, const StringPiece &name, const StringPiece &ext)
Definition: rewrite_test_base.h:327
void AdjustTimeUsWithoutWakingAlarms(int64 time_us)
Adjusts time ignoring any scheduler callbacks. Use with caution.
virtual RequestContextPtr request_context()
Definition: mock_scheduler.h:39
int TimedValue(StringPiece name)
Returns the value of a TimedVariable, specified by name.
When a lookup is done in the HTTP Cache, it returns one of these values.
Definition: http_cache.h:98
static const ProcessContext & process_context()
void CheckFetchFromHttpCache(StringPiece url, StringPiece expected_contents, int64 expected_expiration_ms)
bool AddRewriteDomainMapping(StringPiece to_domain, StringPiece from_domain)
void SetDefaultLongCacheHeaders(const ContentType *content_type, StringPiece charset, StringPiece cache_control_suffix, ResponseHeaders *header) const
void SetMimetype(const StringPiece &mimetype)
Sets the response-headers Content-Type as specified.
Read/write API for HTTP request (RequestHeaders is a misnomer).
Definition: request_headers.h:32
Definition: property_cache.h:186
Definition: mock_property_page.h:32
RewriteOptions * other_options_
owned by other_rewrite_driver_.
Definition: rewrite_test_base.h:846
void ServeResourceFromNewContext(const GoogleString &resource_url, const StringPiece &expected_content)
MockPropertyPage * NewMockPage(const StringPiece &url, const StringPiece &options_signature_hash, UserAgentMatcher::DeviceType device_type)
Returns a new mock property page for the page property cache.
Definition: rewrite_test_base.h:633
void AppendDefaultHeadersWithCanonical(const ContentType &content_type, StringPiece canonical_url, GoogleString *text)
Like above, but also include a Link: <..>; rel="canonical" header.
void DebugWithMessage(StringPiece expected_debug_message)
Definition: rewrite_test_base.h:681
HTTPCache::FindResult HttpBlockingFindStatus(const GoogleString &key, HTTPCache *http_cache)
Adds property-semantics to a raw cache API.
Definition: property_cache.h:180
void AddToResponse(const StringPiece &url, const StringPiece &name, const StringPiece &value)
bool ReadIfCached(const ResourcePtr &resource)
bool LoadFile(const StringPiece &filename, GoogleString *contents)
void AppendDefaultHeaders(const ContentType &content_type, GoogleString *text)
Append default headers to the given string.
GoogleString EncodeWithBase(const StringPiece &base, const StringPiece &path, const StringPiece &filter_id, const StringPiece &hash, const StringPiece &name, const StringPiece &ext)
Definition: rewrite_test_base.h:356
Definition: rewrite_test_base.h:90
void AddOtherRewriteFilter(RewriteFilter *filter)
RewriteDriver * rewrite_driver()
Definition: rewrite_test_base.h:517
static const char kConfiguredBeaconingKey[]
Beaconing key values used when downstream caching is enabled.
Definition: rewrite_test_base.h:95
void SetCacheInvalidationTimestampForUrl(StringPiece url, bool ignores_metadata_and_pcache)
GoogleString CompositeKey(StringPiece key, StringPiece fragment) const
Definition: http_cache.h:373
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 SetResponseWithDefaultHeaders(const StringPiece &relative_url, const ContentType &content_type, const StringPiece &content, int64 ttl_sec)
Add content to mock fetcher (with default headers).
void SetRewriteOptions(RewriteOptions *opts)
Set the RewriteOptions to be returned by the RewriteOptionsManager.
GoogleString AppliedRewriterStringFromLog()
static GoogleString ChangeSuffix(StringPiece old_url, bool append_new_suffix, StringPiece old_suffix, StringPiece new_suffix)
Read/write API for HTTP response headers.
Definition: response_headers.h:37
void AddOtherFilter(RewriteOptions::Filter filter)
Add a single rewrite filter to other_rewrite_driver_.
Definition: log_record.h:59
const UrlSegmentEncoder * FindEncoder(const StringPiece &id) const
void set_fail_on_unexpected(bool x)
Definition: mock_url_fetcher.h:113
virtual bool WriteFile(const char *filename, const StringPiece &buffer, MessageHandler *handler)
Non-atomic. Use WriteFileAtomic() for atomic version.
void PopulateRequestHeaders(RequestHeaders *request_headers)
Populates a RequestHeaders* object with al.
GoogleString debug_message_
Message used by DebugMessage.
Definition: rewrite_test_base.h:852
MockScheduler * mock_scheduler()
The scheduler used by rewrite_driver.
Definition: rewrite_test_base.h:521
const HTTPCache::FindResult kFoundResult
Common values for HttpBlockingFind* result.
Definition: rewrite_test_base.h:706
RewriteOptions * options_
owned by rewrite_driver_.
Definition: rewrite_test_base.h:845
void SetHtmlMimetype()
Sets the response-headers Content-Type to "text/html".
Definition: rewrite_test_base.h:610
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 SetupForWebp()
Sets up user-agent and request-header to allow webp processing.
Definition: rewrite_test_base.h:782
Definition: scoped_ptr.h:30
virtual void ParseUrl(StringPiece url, StringPiece html_input)
void SetMockLogRecord()
Sets MockLogRecord in the driver's request_context.
GoogleString GetLazyloadScriptHtml()
Helper methods to return js/html snippets related to lazyload images.
scoped_ptr< TestRewriteDriverFactory > factory_
Definition: rewrite_test_base.h:830
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).
GoogleString EncodeCssName(const StringPiece &name, bool supports_webp, bool can_inline)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
void PopulateDefaultHeaders(const ContentType &content_type, int64 original_content_length, ResponseHeaders *headers)
const PropertyCache::Cohort * SetupCohort(PropertyCache *cache, const GoogleString &cohort)
Setup statistics for the given cohort and add it to the give PropertyCache.
Definition: rewrite_test_base.h:623
void InitiateResourceRead(const ResourcePtr &resource)
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)
bool AddShard(StringPiece domain, StringPiece shards)
static StringPiece DeviceTypeSuffix(DeviceType device_type)
Returns the suffix for the given device_type.
void EnableDebug()
Enables the debug flag, which is often done on a test-by-test basis.
bool AddOriginDomainMapping(StringPiece to_domain, StringPiece from_domain)
Definition: rewrite_filter.h:35
virtual bool AddBody() const
Definition: rewrite_test_base.h:126
Definition: mock_url_fetcher.h:41
void set_update_date_headers(bool x)
Definition: mock_url_fetcher.h:120
Use all the other_ data members.
Definition: rewrite_test_base.h:106
void AddRewriteFilter(RewriteFilter *filter)
Filter
Definition: rewrite_options.h:106
bool WasGzipped(const ResponseHeaders &response_headers)
Determines whether a response was originally gzipped.
Definition: rewrite_driver.h:100
Definition: server_context.h:99
Definition: content_type.h:31
void SetXhtmlMimetype()
Sets the response-headers Content-Type to "application/xhtml+xml".
Definition: rewrite_test_base.h:607
MockUrlFetcher mock_url_fetcher_
Definition: rewrite_test_base.h:822
Definition: process_context.h:35
virtual bool ReadFile(const char *filename, int64 max_file_size, Writer *writer, MessageHandler *handler)
MockLogRecord * mock_log_record()
Returns the MockLogRecord in the driver.
void AddRequestAttribute(StringPiece name, StringPiece value)
Definition: wait_url_async_fetcher.h:37
void ValidateFallbackHeaderSanitization(StringPiece filter_id)
void Clear()
Clear all set responses.
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.
Definition: rewrite_test_base.h:341
const MetadataCacheInfo & metadata_cache_info()
Convenience method to extract read-only metadata_cache_info.
Definition: rewrite_test_base.h:758
virtual TestRewriteDriverFactory * MakeTestFactory()
const RequestTimingInfo & timing_info()
Accessor for TimingInfo.
void SetBaseUrlForFetch(const StringPiece &url)
Definition: url_segment_encoder.h:33
const GoogleString & CacheFragment() const
bool TryFetchResource(const StringPiece &url)
Just check if we can fetch a resource successfully, ignore response.
void SetUseTestUrlNamer(bool use_test_url_namer)
Switch url namers as specified.
Definition: rewrite_options_test_base.h:32
Definition: message_handler.h:39
DeviceType
Definition: user_agent_matcher.h:49
const GoogleString kEtag0
Etag with a 0 hash.
Definition: rewrite_test_base.h:849
Hasher * hasher() const
Definition: server_context.h:173
void SetShouldBeaconHeader(StringPiece rebeaconing_key)
Set ShouldBeacon request header to the specified value.
virtual RequestContextPtr CreateRequestContext()
GoogleString DebugMessage(StringPiece url)
ActiveServerFlag
Definition: rewrite_test_base.h:104
static const char kTestData[]
Testdata directory.
Definition: rewrite_test_base.h:92
void TestRetainExtraHeaders(const StringPiece &name, const StringPiece &filter_id, const StringPiece &ext)
RewriteDriver * MakeDriver(ServerContext *server_context, RewriteOptions *options)
Definition: rewrite_options.h:84
GoogleString AddOptionsToEncodedUrl(const StringPiece &url, const StringPiece &options)
Takes an already-encoded URL and adds options to to it.
void CallFetcherCallbacksForDriver(WaitUrlAsyncFetcher *fetcher, RewriteDriver *driver)
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
void AdvanceTimeUs(int64 delay_ms)
Timer * timer()
Definition: rewrite_test_base.h:186
void set_hasher(Hasher *hasher)
Setters should probably only be used in testing.
Definition: server_context.h:306
void SetUseManagedRewriteDrivers(bool use_managed_rewrite_drivers)
GoogleString AbsolutifyUrl(const StringPiece &in)
Converts a potentially relative URL off kTestDomain to absolute if needed.
const PropertyCache::Cohort * SetupCohort(PropertyCache *cache, const GoogleString &cohort_name)
Sets up the cohort in the PropertyCache provided.
Definition: resource_namer.h:32
void AddFilter(RewriteOptions::Filter filter)
Add a single rewrite filter to rewrite_driver_.
void SetDownstreamCacheDirectives(StringPiece downstream_cache_purge_method, StringPiece downstream_cache_purge_location_prefix, StringPiece rebeaconing_key)