Page Speed Optimization Libraries  1.11.33.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends 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"
41 #include "net/instaweb/util/public/mock_property_page.h"
42 #include "net/instaweb/util/public/property_cache.h"
43 #include "pagespeed/kernel/base/basictypes.h"
44 #include "pagespeed/kernel/base/hasher.h"
45 #include "pagespeed/kernel/base/md5_hasher.h"
46 #include "pagespeed/kernel/base/mem_file_system.h"
47 #include "pagespeed/kernel/base/message_handler.h"
48 #include "pagespeed/kernel/base/mock_hasher.h"
49 #include "pagespeed/kernel/base/mock_message_handler.h"
51 #include "pagespeed/kernel/base/mock_timer.h"
52 #include "pagespeed/kernel/base/scoped_ptr.h"
53 #include "pagespeed/kernel/base/statistics.h"
54 #include "pagespeed/kernel/base/string.h"
55 #include "pagespeed/kernel/base/string_util.h"
56 #include "pagespeed/kernel/base/timer.h"
57 #include "pagespeed/kernel/html/html_parse_test_base.h"
58 #include "pagespeed/kernel/html/html_writer_filter.h"
59 #include "pagespeed/kernel/http/content_type.h"
60 #include "pagespeed/kernel/http/http_names.h"
61 #include "pagespeed/kernel/http/request_headers.h"
62 #include "pagespeed/kernel/http/response_headers.h"
63 #include "pagespeed/kernel/http/user_agent_matcher.h"
64 #include "pagespeed/kernel/util/url_segment_encoder.h"
65 #include "pagespeed/opt/logging/request_timing_info.h"
66 
67 
68 
69 namespace net_instaweb {
70 
71 class AbstractLogRecord;
72 class CountingUrlAsyncFetcher;
73 class DelayCache;
74 class LRUCache;
75 class MockLogRecord;
76 class MockScheduler;
77 class ProcessContext;
78 class RewriteFilter;
79 class WaitUrlAsyncFetcher;
80 
81 class RewriteOptionsTestBase : public HtmlParseTestBaseNoAlloc {
82  protected:
83  RewriteOptionsTestBase() {
85  }
86  ~RewriteOptionsTestBase() {
87  RewriteOptions::Terminate();
88  }
89 };
90 
92  public:
93  static const char kTestData[];
94 
96  static const char kConfiguredBeaconingKey[];
97  static const char kWrongBeaconingKey[];
98 
108  };
109 
110  RewriteTestBase();
111 
117  explicit RewriteTestBase(std::pair<TestRewriteDriverFactory*,
118  TestRewriteDriverFactory*> factories);
119  virtual ~RewriteTestBase();
120 
121  virtual void SetUp();
122  virtual void TearDown();
123 
127  virtual bool AddBody() const { return false; }
128 
139 
143 
145  void AddFilter(RewriteOptions::Filter filter);
146 
149 
152  void AddRewriteFilter(RewriteFilter* filter);
153 
157 
160  void AddOtherRewriteFilter(RewriteFilter* filter);
161 
164  void SetBaseUrlForFetch(const StringPiece& url);
165 
170 
174  StringPiece downstream_cache_purge_method,
175  StringPiece downstream_cache_purge_location_prefix,
176  StringPiece rebeaconing_key);
177 
179  void SetShouldBeaconHeader(StringPiece rebeaconing_key);
180 
181  ResourcePtr CreateResource(const StringPiece& base, const StringPiece& url);
182 
187  Timer* timer() { return factory()->mock_timer(); }
188 
190  void AppendDefaultHeaders(const ContentType& content_type,
191  GoogleString* text);
192 
194  void AppendDefaultHeadersWithCanonical(const ContentType& content_type,
195  StringPiece canonical_url,
196  GoogleString* text);
197 
198  void ServeResourceFromManyContexts(const GoogleString& resource_url,
199  const StringPiece& expected_content);
200 
201  void ServeResourceFromManyContextsWithUA(
202  const GoogleString& resource_url,
203  const StringPiece& expected_content,
204  const StringPiece& user_agent);
205 
209  const GoogleString& resource_url,
210  const StringPiece& expected_content);
211 
215  virtual RewriteDriver* html_parse() { return rewrite_driver_; }
216 
218  void DefaultResponseHeaders(const ContentType& content_type, int64 ttl_sec,
219  ResponseHeaders* response_headers);
220 
224  bool FetchResource(const StringPiece& path, const StringPiece& filter_id,
225  const StringPiece& name, const StringPiece& ext,
226  GoogleString* content);
227  bool FetchResource(const StringPiece& path, const StringPiece& filter_id,
228  const StringPiece& name, const StringPiece& ext,
229  GoogleString* content, ResponseHeaders* response);
230 
231  bool FetchResourceUrl(const StringPiece& url, GoogleString* content,
232  ResponseHeaders* response);
233  bool FetchResourceUrl(const StringPiece& url,
234  RequestHeaders* request_headers,
235  GoogleString* content,
236  ResponseHeaders* response_headers);
237  bool FetchResourceUrl(const StringPiece& url, GoogleString* content);
238 
240  bool TryFetchResource(const StringPiece& url);
241 
246  void SetUseManagedRewriteDrivers(bool use_managed_rewrite_drivers);
247 
248  GoogleString CssLinkHref(const StringPiece& url) {
249  return StrCat("<link rel=stylesheet href=", url, ">");
250  }
251 
253  class CssLink {
254  public:
255  CssLink(const StringPiece& url, const StringPiece& content,
256  const StringPiece& media, bool supply_mock);
257 
259  class Vector : public std::vector<CssLink*> {
260  public:
261  ~Vector();
262  void Add(const StringPiece& url, const StringPiece& content,
263  const StringPiece& media, bool supply_mock);
264  };
265 
268  bool DecomposeCombinedUrl(StringPiece base_url, GoogleString* base,
269  StringVector* segments, MessageHandler* handler);
270 
271  GoogleString url_;
272  GoogleString content_;
273  GoogleString media_;
274  bool supply_mock_;
275  };
276 
278  void CollectCssLinks(const StringPiece& id, const StringPiece& html,
279  StringVector* css_links);
280 
282  void CollectCssLinks(const StringPiece& id, const StringPiece& html,
283  CssLink::Vector* css_links);
284 
286  void EncodePathAndLeaf(const StringPiece& filter_id,
287  const StringPiece& hash,
288  const StringVector& name_vector,
289  const StringPiece& ext,
290  ResourceNamer* namer);
291 
292  StringVector MultiUrl(const StringPiece& url1) {
293  StringVector v;
294  v.push_back(url1.as_string());
295  return v;
296  }
297 
298  StringVector MultiUrl(const StringPiece& url1, const StringPiece& url2) {
299  StringVector v;
300  v.push_back(url1.as_string());
301  v.push_back(url2.as_string());
302  return v;
303  }
304 
305  StringVector MultiUrl(const StringPiece& url1, const StringPiece& url2,
306  const StringPiece& url3) {
307  StringVector v;
308  v.push_back(url1.as_string());
309  v.push_back(url2.as_string());
310  v.push_back(url3.as_string());
311  return v;
312  }
313 
314  StringVector MultiUrl(const StringPiece& url1, const StringPiece& url2,
315  const StringPiece& url3, const StringPiece& url4) {
316  StringVector v;
317  v.push_back(url1.as_string());
318  v.push_back(url2.as_string());
319  v.push_back(url3.as_string());
320  v.push_back(url4.as_string());
321  return v;
322  }
323 
326  GoogleString Encode(const StringPiece& path,
327  const StringPiece& filter_id,
328  const StringPiece& hash,
329  const StringPiece& name,
330  const StringPiece& ext) {
331  return Encode(path, filter_id, hash, MultiUrl(name), ext);
332  }
333  GoogleString Encode(const StringPiece& path,
334  const StringPiece& filter_id,
335  const StringPiece& hash,
336  const StringVector& name_vector,
337  const StringPiece& ext);
338 
340  GoogleString EncodeNormal(const StringPiece& path,
341  const StringPiece& filter_id,
342  const StringPiece& hash,
343  const StringPiece& name,
344  const StringPiece& ext) {
345  return EncodeNormal(path, filter_id, hash, MultiUrl(name), ext);
346  }
347  GoogleString EncodeNormal(const StringPiece& path,
348  const StringPiece& filter_id,
349  const StringPiece& hash,
350  const StringVector& name_vector,
351  const StringPiece& ext);
352 
355  GoogleString EncodeWithBase(const StringPiece& base,
356  const StringPiece& path,
357  const StringPiece& filter_id,
358  const StringPiece& hash,
359  const StringPiece& name,
360  const StringPiece& ext) {
361  return EncodeWithBase(base, path, filter_id, hash, MultiUrl(name), ext);
362  }
363  GoogleString EncodeWithBase(const StringPiece& base,
364  const StringPiece& path,
365  const StringPiece& filter_id,
366  const StringPiece& hash,
367  const StringVector& name_vector,
368  const StringPiece& ext);
369 
372  GoogleString EncodeImage(int width, int height,
373  StringPiece filename, StringPiece hash,
374  StringPiece rewritten_ext);
375 
377  GoogleString AddOptionsToEncodedUrl(const StringPiece& url,
378  const StringPiece& options);
379 
384  static GoogleString ChangeSuffix(
385  StringPiece old_url, bool append_new_suffix,
386  StringPiece old_suffix, StringPiece new_suffix);
387 
392  void SetupWaitFetcher();
393  void CallFetcherCallbacks();
394  void OtherCallFetcherCallbacks();
395  RewriteOptions* options() const { return options_; }
396  RewriteOptions* other_options() const { return other_options_; }
397 
399  void SetRewriteOptions(RewriteOptions* opts);
400 
403  bool AddDomain(StringPiece domain);
404 
407  bool AddOriginDomainMapping(StringPiece to_domain, StringPiece from_domain);
408 
411  bool AddRewriteDomainMapping(StringPiece to_domain, StringPiece from_domain);
412 
415  bool AddShard(StringPiece domain, StringPiece shards);
416 
418  void TestServeFiles(const ContentType* content_type,
419  const StringPiece& filter_id,
420  const StringPiece& rewritten_ext,
421  const StringPiece& orig_name,
422  const StringPiece& orig_content,
423  const StringPiece& rewritten_name,
424  const StringPiece& rewritten_content);
425 
428  void ValidateFallbackHeaderSanitization(StringPiece filter_id);
429 
430  TestRewriteDriverFactory* factory() { return factory_.get(); }
431  TestRewriteDriverFactory* other_factory() { return other_factory_.get(); }
432 
433  void UseMd5Hasher() {
434  server_context_->set_hasher(&md5_hasher_);
435  server_context_->http_cache()->set_hasher(&md5_hasher_);
436  other_server_context_->set_hasher(&md5_hasher_);
437  other_server_context_->http_cache()->set_hasher(&md5_hasher_);
438  }
439 
440 
441  void SetDefaultLongCacheHeaders(const ContentType* content_type,
442  ResponseHeaders* header) {
443  server_context_->SetDefaultLongCacheHeaders(
444  content_type, StringPiece(), StringPiece(), header);
445  }
446 
447  void SetFetchResponse(const StringPiece& url,
448  const ResponseHeaders& response_header,
449  const StringPiece& response_body) {
450  mock_url_fetcher()->SetResponse(url, response_header, response_body);
451  }
452 
454  void SetResponseWithDefaultHeaders(const StringPiece& relative_url,
455  const ContentType& content_type,
456  const StringPiece& content,
457  int64 ttl_sec);
458 
461  bool LoadFile(const StringPiece& filename, GoogleString* contents);
462 
464  void AddFileToMockFetcher(const StringPiece& url,
465  const StringPiece& filename,
466  const ContentType& content_type, int64 ttl_sec);
467 
468  void AddToResponse(const StringPiece& url,
469  const StringPiece& name,
470  const StringPiece& value) {
471  mock_url_fetcher()->AddToResponse(url, name, value);
472  }
473 
474  void SetFetchResponse404(const StringPiece& url);
475 
476  void SetFetchFailOnUnexpected(bool fail) {
477  mock_url_fetcher()->set_fail_on_unexpected(fail);
478  }
479  void FetcherUpdateDateHeaders() {
480  mock_url_fetcher()->set_timer(timer());
481  mock_url_fetcher()->set_update_date_headers(true);
482  }
483  void ClearFetcherResponses() { mock_url_fetcher()->Clear(); }
484 
485  virtual void ClearStats();
486 
491  void ClearRewriteDriver();
492 
493  MockUrlFetcher* mock_url_fetcher() {
494  return &mock_url_fetcher_;
495  }
496  TestDistributedFetcher* test_distributed_fetcher() {
497  return &test_distributed_fetcher_;
498  }
499  Hasher* hasher() { return server_context_->hasher(); }
500  DelayCache* delay_cache() { return factory_->delay_cache(); }
501  LRUCache* lru_cache() { return factory_->lru_cache(); }
502  Statistics* statistics() { return factory_->statistics(); }
503  MemFileSystem* file_system() { return factory_->mem_file_system(); }
504  HTTPCache* http_cache() { return server_context_->http_cache(); }
505  PropertyCache* page_property_cache() {
506  return server_context_->page_property_cache();
507  }
508  MockMessageHandler* message_handler() {
509  return factory_->mock_message_handler();
510  }
511 
519  RewriteDriver* rewrite_driver() { return rewrite_driver_; }
520  RewriteDriver* other_rewrite_driver() { return other_rewrite_driver_; }
521 
523  MockScheduler* mock_scheduler() { return factory_->mock_scheduler(); }
524 
525  int64 start_time_ms() const { return factory_->kStartTimeMs; }
526 
527  bool ReadFile(const char* filename, GoogleString* contents) {
528  return file_system()->ReadFile(filename, contents, message_handler());
529  }
530  bool WriteFile(const char* filename, const StringPiece& contents) {
531  return file_system()->WriteFile(filename, contents, message_handler());
532  }
533 
534  ServerContext* server_context() { return server_context_; }
535  ServerContext* other_server_context() { return other_server_context_; }
536  CountingUrlAsyncFetcher* counting_url_async_fetcher() {
537  return factory_->counting_url_async_fetcher();
538  }
539  CountingUrlAsyncFetcher* counting_distributed_fetcher() {
540  return factory_->counting_distributed_async_fetcher();
541  }
542  void SetMockHashValue(const GoogleString& value) {
543  factory_->mock_hasher()->set_hash_value(value);
544  }
545 
546  void SetCacheDelayUs(int64 delay_us);
547 
548  void SetupWriter() override;
549 
554  RewriteDriver* MakeDriver(ServerContext* server_context,
555  RewriteOptions* options);
556 
558  GoogleString AbsolutifyUrl(const StringPiece& in);
559 
564  void TestRetainExtraHeaders(const StringPiece& name,
565  const StringPiece& filter_id,
566  const StringPiece& ext);
567 
571  const UrlSegmentEncoder* FindEncoder(const StringPiece& id) const;
572 
574  void SetUseTestUrlNamer(bool use_test_url_namer);
575 
578  GoogleString EncodeCssName(const StringPiece& name,
579  bool supports_webp,
580  bool can_inline);
581 
585  bool ReadIfCached(const ResourcePtr& resource);
586 
591  void InitiateResourceRead(const ResourcePtr& resource);
592 
596  HTTPCache::FindResult HttpBlockingFind(
597  const GoogleString& key, HTTPCache* http_cache, HTTPValue* value_out,
598  ResponseHeaders* headers);
599 
602  HTTPCache::FindResult HttpBlockingFindStatus(
603  const GoogleString& key, HTTPCache* http_cache);
604 
606  HTTPCache::FindResult HttpBlockingFindWithOptions(
607  const RewriteOptions* options,
608  const GoogleString& key, HTTPCache* http_cache, HTTPValue* value_out,
609  ResponseHeaders* headers);
610 
612  void SetXhtmlMimetype() { SetMimetype("application/xhtml+xml"); }
613 
615  void SetHtmlMimetype() { SetMimetype("text/html"); }
616 
618  void SetMimetype(const StringPiece& mimetype);
619 
623  StringPiece url,
624  StringPiece expected_contents,
625  int64 expected_expiration_ms);
626 
628  const PropertyCache::Cohort* SetupCohort(
629  PropertyCache* cache, const GoogleString& cohort) {
630  return factory()->SetupCohort(cache, cohort);
631  }
632 
635  void SetupSharedCache();
636 
638  MockPropertyPage* NewMockPage(const StringPiece& url,
639  const StringPiece& options_signature_hash,
640  UserAgentMatcher::DeviceType device_type) {
641  return new MockPropertyPage(
642  server_context_->thread_system(),
643  server_context_->page_property_cache(),
644  url,
645  options_signature_hash,
646  UserAgentMatcher::DeviceTypeSuffix(device_type));
647  }
648 
649  MockPropertyPage* NewMockPage(const StringPiece& url) {
650  return NewMockPage(url, "hash", UserAgentMatcher::kDesktop);
651  }
652 
654  void SetMockLogRecord();
655 
657  MockLogRecord* mock_log_record();
658 
660  GoogleString GetLazyloadScriptHtml();
661  GoogleString GetLazyloadPostscriptHtml();
662 
669 
673  StringPiece url, bool ignores_metadata_and_pcache);
674 
678  void EnableCachePurge();
679 
681  void EnableDebug();
682 
686  void DebugWithMessage(StringPiece expected_debug_message) {
687  EnableDebug();
688 
689  expected_debug_message.CopyToString(&debug_message_);
690  }
691 
696  GoogleString DebugMessage(StringPiece url);
697 
700  static const ProcessContext& process_context();
701 
704  void DisableGzip();
705 
707  bool WasGzipped(const ResponseHeaders& response_headers);
708 
709  protected:
712  const HTTPCache::FindResult kNotFoundResult;
713 
714  void Init();
715 
718  virtual RequestContextPtr CreateRequestContext();
719 
723  RewriteDriver* driver);
724 
727  void PopulateDefaultHeaders(const ContentType& content_type,
728  int64 original_content_length,
729  ResponseHeaders* headers);
730 
733  void SetActiveServer(ActiveServerFlag server_to_use);
734 
737  void AdvanceTimeUs(int64 delay_ms);
738  void AdvanceTimeMs(int64 delay_ms) { AdvanceTimeUs(delay_ms * Timer::kMsUs); }
739  void SetTimeUs(int64 time_us);
740  void SetTimeMs(int64 time_ms) { SetTimeUs(time_ms * Timer::kMsUs); }
741 
743  void AdjustTimeUsWithoutWakingAlarms(int64 time_us);
744 
746  const RequestTimingInfo& timing_info();
747  RequestTimingInfo* mutable_timing_info();
748 
754  virtual RequestContextPtr request_context();
755 
760  LoggingInfo* logging_info();
761 
763  const MetadataCacheInfo& metadata_cache_info() {
764  return logging_info()->metadata_cache_info();
765  }
766 
769  GoogleString AppliedRewriterStringFromLog();
770 
773  void VerifyRewriterInfoEntry(AbstractLogRecord* log_record,
774  const GoogleString& id,
775  int url_index,
776  int rewriter_info_index,
777  int rewriter_info_size,
778  int url_list_size,
779  const GoogleString& url);
780 
782  void SetCurrentUserAgent(const StringPiece& user_agent) {
783  current_user_agent_ = user_agent;
784  }
785 
787  void SetupForWebp() {
788  SetCurrentUserAgent("webp");
789  AddRequestAttribute(HttpAttributes::kAccept, "image/webp");
790  }
791 
792  void SetupForWebpLossless() {
793  SetCurrentUserAgent("webp-la");
794  AddRequestAttribute(HttpAttributes::kAccept, "image/webp");
795  }
796 
797  void SetupForWebpAnimated() {
798  SetCurrentUserAgent("webp-animated");
799  AddRequestAttribute(HttpAttributes::kAccept, "image/webp");
800  }
801 
805  void AddRequestAttribute(StringPiece name, StringPiece value);
806 
808  void PopulateRequestHeaders(RequestHeaders* request_headers);
809 
812  virtual void ParseUrl(StringPiece url, StringPiece html_input);
813 
814  GoogleString ExpectedNonce();
815 
818  GoogleString HttpCacheKey(StringPiece url) {
819  return http_cache()->CompositeKey(url, rewrite_driver_->CacheFragment());
820  }
821 
823  int TimedValue(StringPiece name);
824 
828  TestDistributedFetcher test_distributed_fetcher_;
829  scoped_ptr<Statistics> statistics_;
830 
836  scoped_ptr<TestRewriteDriverFactory> factory_;
837  scoped_ptr<TestRewriteDriverFactory> other_factory_;
838  ServerContext* server_context_;
839  RewriteDriver* rewrite_driver_;
840  ServerContext* other_server_context_;
841  RewriteDriver* other_rewrite_driver_;
842  scoped_ptr<HtmlWriterFilter> other_html_writer_filter_;
843  ActiveServerFlag active_server_;
844  bool use_managed_rewrite_drivers_;
845  StringPiece current_user_agent_;
846  StringVector request_attribute_names_;
847  StringVector request_attribute_values_;
848 
849  MD5Hasher md5_hasher_;
850 
853  UrlSegmentEncoder default_encoder_;
854  ResponseHeaders response_headers_;
855  const GoogleString kEtag0;
856  uint64 expected_nonce_;
857 
858  GoogleString debug_message_;
859 
860  private:
861  void ValidateFallbackHeaderSanitizationHelper(
862  StringPiece filter_id, StringPiece origin_content_type, bool expect_load);
863 };
864 
865 }
866 
867 #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:68
void AddFetchOnlyRewriteFilter(RewriteFilter *filter)
virtual RewriteDriver * html_parse()
Definition: rewrite_test_base.h:215
void SetActiveServer(ActiveServerFlag server_to_use)
void SetCurrentUserAgent(const StringPiece &user_agent)
Sets current_user_agent_.
Definition: rewrite_test_base.h:782
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:818
GoogleString EncodeImage(int width, int height, StringPiece filename, StringPiece hash, StringPiece rewritten_ext)
Use the normal data members.
Definition: rewrite_test_base.h:106
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:326
void AdjustTimeUsWithoutWakingAlarms(int64 time_us)
Adjusts time ignoring any scheduler callbacks. Use with caution.
virtual RequestContextPtr request_context()
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:79
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.
RewriteOptions * other_options_
owned by other_rewrite_driver_.
Definition: rewrite_test_base.h:852
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:638
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:686
HTTPCache::FindResult HttpBlockingFindStatus(const GoogleString &key, HTTPCache *http_cache)
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:355
Definition: rewrite_test_base.h:91
void AddOtherRewriteFilter(RewriteFilter *filter)
RewriteDriver * rewrite_driver()
Definition: rewrite_test_base.h:519
static const char kConfiguredBeaconingKey[]
Beaconing key values used when downstream caching is enabled.
Definition: rewrite_test_base.h:96
void SetCacheInvalidationTimestampForUrl(StringPiece url, bool ignores_metadata_and_pcache)
GoogleString CompositeKey(StringPiece key, StringPiece fragment) const
Definition: http_cache.h:354
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)
void AddOtherFilter(RewriteOptions::Filter filter)
Add a single rewrite filter to other_rewrite_driver_.
const UrlSegmentEncoder * FindEncoder(const StringPiece &id) const
void set_fail_on_unexpected(bool x)
Definition: mock_url_fetcher.h:113
void PopulateRequestHeaders(RequestHeaders *request_headers)
Populates a RequestHeaders* object with al.
GoogleString debug_message_
Message used by DebugMessage.
Definition: rewrite_test_base.h:858
MockScheduler * mock_scheduler()
The scheduler used by rewrite_driver.
Definition: rewrite_test_base.h:523
const HTTPCache::FindResult kFoundResult
Common values for HttpBlockingFind* result.
Definition: rewrite_test_base.h:711
RewriteOptions * options_
owned by rewrite_driver_.
Definition: rewrite_test_base.h:851
void SetHtmlMimetype()
Sets the response-headers Content-Type to "text/html".
Definition: rewrite_test_base.h:615
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:787
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:836
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)
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:628
Definition: test_distributed_fetcher.h:37
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)
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:127
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:107
void AddRewriteFilter(RewriteFilter *filter)
Filter
Definition: rewrite_options.h:107
bool WasGzipped(const ResponseHeaders &response_headers)
Determines whether a response was originally gzipped.
Definition: rewrite_driver.h:98
Definition: server_context.h:100
void SetXhtmlMimetype()
Sets the response-headers Content-Type to "application/xhtml+xml".
Definition: rewrite_test_base.h:612
MockUrlFetcher mock_url_fetcher_
Definition: rewrite_test_base.h:827
Definition: process_context.h:35
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:340
const MetadataCacheInfo & metadata_cache_info()
Convenience method to extract read-only metadata_cache_info.
Definition: rewrite_test_base.h:763
virtual TestRewriteDriverFactory * MakeTestFactory()
const RequestTimingInfo & timing_info()
Accessor for TimingInfo.
void SetBaseUrlForFetch(const StringPiece &url)
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
const GoogleString kEtag0
Etag with a 0 hash.
Definition: rewrite_test_base.h:855
Hasher * hasher() const
Definition: server_context.h:177
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:105
static const char kTestData[]
Testdata directory.
Definition: rewrite_test_base.h:93
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)
void AdvanceTimeUs(int64 delay_ms)
Timer * timer()
Definition: rewrite_test_base.h:187
void set_hasher(Hasher *hasher)
Setters should probably only be used in testing.
Definition: server_context.h:322
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)