Page Speed Optimization Libraries  1.9.32.2
 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 
28 #include "net/instaweb/http/public/logging_proto.h"
29 #include "net/instaweb/http/public/logging_proto_impl.h"
31 #include "net/instaweb/http/public/request_context.h"
39 #include "net/instaweb/util/public/mock_property_page.h"
40 #include "net/instaweb/util/public/property_cache.h"
41 #include "pagespeed/kernel/base/basictypes.h"
42 #include "pagespeed/kernel/base/md5_hasher.h"
43 #include "pagespeed/kernel/base/mem_file_system.h"
44 #include "pagespeed/kernel/base/mock_hasher.h"
45 #include "pagespeed/kernel/base/mock_message_handler.h"
47 #include "pagespeed/kernel/base/mock_timer.h"
48 #include "pagespeed/kernel/base/scoped_ptr.h"
49 #include "pagespeed/kernel/base/string.h"
50 #include "pagespeed/kernel/base/string_util.h"
51 #include "pagespeed/kernel/base/timer.h"
52 #include "pagespeed/kernel/html/html_parse_test_base.h"
53 #include "pagespeed/kernel/http/content_type.h"
54 #include "pagespeed/kernel/http/response_headers.h"
55 #include "pagespeed/kernel/http/user_agent_matcher.h"
56 #include "pagespeed/kernel/util/url_segment_encoder.h"
57 
58 
59 namespace net_instaweb {
60 
61 class AbstractLogRecord;
62 class CountingUrlAsyncFetcher;
63 class DelayCache;
64 class HTTPValue;
65 class Hasher;
66 class HtmlWriterFilter;
67 class LRUCache;
68 class MessageHandler;
69 class MockLogRecord;
70 class MockScheduler;
71 class ProcessContext;
72 class RequestHeaders;
73 class RequestTimingInfo;
74 class ResourceNamer;
75 class RewriteFilter;
76 class Statistics;
77 class WaitUrlAsyncFetcher;
78 
79 class RewriteOptionsTestBase : public HtmlParseTestBaseNoAlloc {
80  protected:
81  RewriteOptionsTestBase() {
83  }
84  ~RewriteOptionsTestBase() {
85  RewriteOptions::Terminate();
86  }
87 };
88 
90  public:
91  static const char kTestData[];
92 
94  static const char kConfiguredBeaconingKey[];
95  static const char kWrongBeaconingKey[];
96 
106  };
107 
108  RewriteTestBase();
109  explicit RewriteTestBase(Statistics* statistics);
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 
166  void SetDummyRequestHeaders();
167 
171  StringPiece downstream_cache_purge_method,
172  StringPiece downstream_cache_purge_location_prefix,
173  StringPiece rebeaconing_key);
174 
176  void SetShouldBeaconHeader(StringPiece rebeaconing_key);
177 
178  ResourcePtr CreateResource(const StringPiece& base, const StringPiece& url);
179 
184  Timer* timer() { return factory()->mock_timer(); }
185 
187  void AppendDefaultHeaders(const ContentType& content_type,
188  GoogleString* text);
189 
192  void AppendDefaultHeaders(const ContentType& content_type,
193  int64 original_content_length,
194  GoogleString* text);
195 
196  void ServeResourceFromManyContexts(const GoogleString& resource_url,
197  const StringPiece& expected_content);
198 
199  void ServeResourceFromManyContextsWithUA(
200  const GoogleString& resource_url,
201  const StringPiece& expected_content,
202  const StringPiece& user_agent);
203 
207  const GoogleString& resource_url,
208  const StringPiece& expected_content);
209 
213  virtual RewriteDriver* html_parse() { return rewrite_driver_; }
214 
216  void DefaultResponseHeaders(const ContentType& content_type, int64 ttl_sec,
217  ResponseHeaders* response_headers);
218 
222  bool FetchResource(const StringPiece& path, const StringPiece& filter_id,
223  const StringPiece& name, const StringPiece& ext,
224  GoogleString* content);
225  bool FetchResource(const StringPiece& path, const StringPiece& filter_id,
226  const StringPiece& name, const StringPiece& ext,
227  GoogleString* content, ResponseHeaders* response);
228 
229  bool FetchResourceUrl(const StringPiece& url, GoogleString* content,
230  ResponseHeaders* response);
231  bool FetchResourceUrl(const StringPiece& url,
232  RequestHeaders* request_headers,
233  GoogleString* content,
234  ResponseHeaders* response_headers);
235  bool FetchResourceUrl(const StringPiece& url, GoogleString* content);
236 
238  bool TryFetchResource(const StringPiece& url);
239 
244  void SetUseManagedRewriteDrivers(bool use_managed_rewrite_drivers);
245 
246  GoogleString CssLinkHref(const StringPiece& url) {
247  return StrCat("<link rel=stylesheet href=", url, ">");
248  }
249 
251  class CssLink {
252  public:
253  CssLink(const StringPiece& url, const StringPiece& content,
254  const StringPiece& media, bool supply_mock);
255 
257  class Vector : public std::vector<CssLink*> {
258  public:
259  ~Vector();
260  void Add(const StringPiece& url, const StringPiece& content,
261  const StringPiece& media, bool supply_mock);
262  };
263 
266  bool DecomposeCombinedUrl(StringPiece base_url, GoogleString* base,
267  StringVector* segments, MessageHandler* handler);
268 
269  GoogleString url_;
270  GoogleString content_;
271  GoogleString media_;
272  bool supply_mock_;
273  };
274 
276  void CollectCssLinks(const StringPiece& id, const StringPiece& html,
277  StringVector* css_links);
278 
280  void CollectCssLinks(const StringPiece& id, const StringPiece& html,
281  CssLink::Vector* css_links);
282 
284  void EncodePathAndLeaf(const StringPiece& filter_id,
285  const StringPiece& hash,
286  const StringVector& name_vector,
287  const StringPiece& ext,
288  ResourceNamer* namer);
289 
290  StringVector MultiUrl(const StringPiece& url1) {
291  StringVector v;
292  v.push_back(url1.as_string());
293  return v;
294  }
295 
296  StringVector MultiUrl(const StringPiece& url1, const StringPiece& url2) {
297  StringVector v;
298  v.push_back(url1.as_string());
299  v.push_back(url2.as_string());
300  return v;
301  }
302 
303  StringVector MultiUrl(const StringPiece& url1, const StringPiece& url2,
304  const StringPiece& url3) {
305  StringVector v;
306  v.push_back(url1.as_string());
307  v.push_back(url2.as_string());
308  v.push_back(url3.as_string());
309  return v;
310  }
311 
312  StringVector MultiUrl(const StringPiece& url1, const StringPiece& url2,
313  const StringPiece& url3, const StringPiece& url4) {
314  StringVector v;
315  v.push_back(url1.as_string());
316  v.push_back(url2.as_string());
317  v.push_back(url3.as_string());
318  v.push_back(url4.as_string());
319  return v;
320  }
321 
324  GoogleString Encode(const StringPiece& path,
325  const StringPiece& filter_id,
326  const StringPiece& hash,
327  const StringPiece& name,
328  const StringPiece& ext) {
329  return Encode(path, filter_id, hash, MultiUrl(name), ext);
330  }
331  GoogleString Encode(const StringPiece& path,
332  const StringPiece& filter_id,
333  const StringPiece& hash,
334  const StringVector& name_vector,
335  const StringPiece& ext);
336 
338  GoogleString EncodeNormal(const StringPiece& path,
339  const StringPiece& filter_id,
340  const StringPiece& hash,
341  const StringPiece& name,
342  const StringPiece& ext) {
343  return EncodeNormal(path, filter_id, hash, MultiUrl(name), ext);
344  }
345  GoogleString EncodeNormal(const StringPiece& path,
346  const StringPiece& filter_id,
347  const StringPiece& hash,
348  const StringVector& name_vector,
349  const StringPiece& ext);
350 
353  GoogleString EncodeWithBase(const StringPiece& base,
354  const StringPiece& path,
355  const StringPiece& filter_id,
356  const StringPiece& hash,
357  const StringPiece& name,
358  const StringPiece& ext) {
359  return EncodeWithBase(base, path, filter_id, hash, MultiUrl(name), ext);
360  }
361  GoogleString EncodeWithBase(const StringPiece& base,
362  const StringPiece& path,
363  const StringPiece& filter_id,
364  const StringPiece& hash,
365  const StringVector& name_vector,
366  const StringPiece& ext);
367 
369  GoogleString AddOptionsToEncodedUrl(const StringPiece& url,
370  const StringPiece& options);
371 
376  static GoogleString ChangeSuffix(
377  StringPiece old_url, bool append_new_suffix,
378  StringPiece old_suffix, StringPiece new_suffix);
379 
384  void SetupWaitFetcher();
385  void CallFetcherCallbacks();
386  void OtherCallFetcherCallbacks();
387  RewriteOptions* options() { return options_; }
388  RewriteOptions* other_options() { return other_options_; }
389 
391  void SetRewriteOptions(RewriteOptions* opts);
392 
395  bool AddDomain(StringPiece domain);
396 
399  bool AddOriginDomainMapping(StringPiece to_domain, StringPiece from_domain);
400 
403  bool AddRewriteDomainMapping(StringPiece to_domain, StringPiece from_domain);
404 
407  bool AddShard(StringPiece domain, StringPiece shards);
408 
410  void TestServeFiles(const ContentType* content_type,
411  const StringPiece& filter_id,
412  const StringPiece& rewritten_ext,
413  const StringPiece& orig_name,
414  const StringPiece& orig_content,
415  const StringPiece& rewritten_name,
416  const StringPiece& rewritten_content);
417 
418  TestRewriteDriverFactory* factory() { return factory_.get(); }
419  TestRewriteDriverFactory* other_factory() { return other_factory_.get(); }
420 
421  void UseMd5Hasher() {
422  server_context_->set_hasher(&md5_hasher_);
423  server_context_->http_cache()->set_hasher(&md5_hasher_);
424  other_server_context_->set_hasher(&md5_hasher_);
425  other_server_context_->http_cache()->set_hasher(&md5_hasher_);
426  }
427 
428 
429  void SetDefaultLongCacheHeaders(const ContentType* content_type,
430  ResponseHeaders* header) {
431  server_context_->SetDefaultLongCacheHeaders(
432  content_type, StringPiece(), StringPiece(), header);
433  }
434 
435  void SetFetchResponse(const StringPiece& url,
436  const ResponseHeaders& response_header,
437  const StringPiece& response_body) {
438  mock_url_fetcher()->SetResponse(url, response_header, response_body);
439  }
440 
442  void SetResponseWithDefaultHeaders(const StringPiece& relative_url,
443  const ContentType& content_type,
444  const StringPiece& content,
445  int64 ttl_sec);
446 
449  bool LoadFile(const StringPiece& filename, GoogleString* contents);
450 
452  void AddFileToMockFetcher(const StringPiece& url,
453  const StringPiece& filename,
454  const ContentType& content_type, int64 ttl_sec);
455 
456  void AddToResponse(const StringPiece& url,
457  const StringPiece& name,
458  const StringPiece& value) {
459  mock_url_fetcher()->AddToResponse(url, name, value);
460  }
461 
462  void SetFetchResponse404(const StringPiece& url);
463 
464  void SetFetchFailOnUnexpected(bool fail) {
465  mock_url_fetcher()->set_fail_on_unexpected(fail);
466  }
467  void FetcherUpdateDateHeaders() {
468  mock_url_fetcher()->set_timer(timer());
469  mock_url_fetcher()->set_update_date_headers(true);
470  }
471  void ClearFetcherResponses() { mock_url_fetcher()->Clear(); }
472 
473  virtual void ClearStats();
474 
477  void ClearRewriteDriver();
478 
479  MockUrlFetcher* mock_url_fetcher() {
480  return &mock_url_fetcher_;
481  }
482  TestDistributedFetcher* test_distributed_fetcher() {
483  return &test_distributed_fetcher_;
484  }
485  Hasher* hasher() { return server_context_->hasher(); }
486  DelayCache* delay_cache() { return factory_->delay_cache(); }
487  LRUCache* lru_cache() { return factory_->lru_cache(); }
488  Statistics* statistics() { return factory_->statistics(); }
489  MemFileSystem* file_system() { return factory_->mem_file_system(); }
490  HTTPCache* http_cache() { return server_context_->http_cache(); }
491  PropertyCache* page_property_cache() {
492  return server_context_->page_property_cache();
493  }
494  MockMessageHandler* message_handler() {
495  return factory_->mock_message_handler();
496  }
497 
505  RewriteDriver* rewrite_driver() { return rewrite_driver_; }
506  RewriteDriver* other_rewrite_driver() { return other_rewrite_driver_; }
507 
509  MockScheduler* mock_scheduler() { return factory_->mock_scheduler(); }
510 
511  int64 start_time_ms() const { return factory_->kStartTimeMs; }
512 
513  bool ReadFile(const char* filename, GoogleString* contents) {
514  return file_system()->ReadFile(filename, contents, message_handler());
515  }
516  bool WriteFile(const char* filename, const StringPiece& contents) {
517  return file_system()->WriteFile(filename, contents, message_handler());
518  }
519 
520  ServerContext* server_context() { return server_context_; }
521  ServerContext* other_server_context() { return other_server_context_; }
522  CountingUrlAsyncFetcher* counting_url_async_fetcher() {
523  return factory_->counting_url_async_fetcher();
524  }
525  CountingUrlAsyncFetcher* counting_distributed_fetcher() {
526  return factory_->counting_distributed_async_fetcher();
527  }
528  void SetMockHashValue(const GoogleString& value) {
529  factory_->mock_hasher()->set_hash_value(value);
530  }
531 
532  void SetCacheDelayUs(int64 delay_us);
533 
538  RewriteDriver* MakeDriver(ServerContext* server_context,
539  RewriteOptions* options);
540 
542  GoogleString AbsolutifyUrl(const StringPiece& in);
543 
548  void TestRetainExtraHeaders(const StringPiece& name,
549  const StringPiece& filter_id,
550  const StringPiece& ext);
551 
555  const UrlSegmentEncoder* FindEncoder(const StringPiece& id) const;
556 
558  void SetUseTestUrlNamer(bool use_test_url_namer);
559 
562  GoogleString EncodeCssName(const StringPiece& name,
563  bool supports_webp,
564  bool can_inline);
565 
569  bool ReadIfCached(const ResourcePtr& resource);
570 
575  void InitiateResourceRead(const ResourcePtr& resource);
576 
581  const GoogleString& key, HTTPCache* http_cache, HTTPValue* value_out,
582  ResponseHeaders* headers);
583 
587  const GoogleString& key, HTTPCache* http_cache);
588 
591  const RewriteOptions* options,
592  const GoogleString& key, HTTPCache* http_cache, HTTPValue* value_out,
593  ResponseHeaders* headers);
594 
596  void SetXhtmlMimetype() { SetMimetype("application/xhtml+xml"); }
597 
599  void SetHtmlMimetype() { SetMimetype("text/html"); }
600 
602  void SetMimetype(const StringPiece& mimetype);
603 
607  StringPiece url,
608  StringPiece expected_contents,
609  int64 expected_expiration_ms);
610 
612  const PropertyCache::Cohort* SetupCohort(
613  PropertyCache* cache, const GoogleString& cohort) {
614  return factory()->SetupCohort(cache, cohort);
615  }
616 
619  void SetupSharedCache();
620 
622  MockPropertyPage* NewMockPage(const StringPiece& url,
623  const StringPiece& options_signature_hash,
624  UserAgentMatcher::DeviceType device_type) {
625  return new MockPropertyPage(
626  server_context_->thread_system(),
627  server_context_->page_property_cache(),
628  url,
629  options_signature_hash,
630  UserAgentMatcher::DeviceTypeSuffix(device_type));
631  }
632 
633  MockPropertyPage* NewMockPage(const StringPiece& url) {
634  return NewMockPage(url, "hash", UserAgentMatcher::kDesktop);
635  }
636 
638  void SetMockLogRecord();
639 
641  MockLogRecord* mock_log_record();
642 
644  GoogleString GetLazyloadScriptHtml();
645  GoogleString GetLazyloadPostscriptHtml();
646 
653 
657  StringPiece url, bool ignores_metadata_and_pcache);
658 
662  void EnableCachePurge();
663 
665  void EnableDebug();
666 
670  void DebugWithMessage(StringPiece expected_debug_message) {
671  EnableDebug();
672 
673  expected_debug_message.CopyToString(&debug_message_);
674  }
675 
680  GoogleString DebugMessage(StringPiece url);
681 
684  static const ProcessContext& process_context();
685 
686  protected:
687  void Init();
688 
691  virtual RequestContextPtr CreateRequestContext();
692 
696  RewriteDriver* driver);
697 
700  void PopulateDefaultHeaders(const ContentType& content_type,
701  int64 original_content_length,
702  ResponseHeaders* headers);
703 
706  void SetActiveServer(ActiveServerFlag server_to_use);
707 
710  void AdvanceTimeUs(int64 delay_ms);
711  void AdvanceTimeMs(int64 delay_ms) { AdvanceTimeUs(delay_ms * Timer::kMsUs); }
712  void SetTimeUs(int64 time_us);
713  void SetTimeMs(int64 time_ms) { SetTimeUs(time_ms * Timer::kMsUs); }
714 
716  void AdjustTimeUsWithoutWakingAlarms(int64 time_us);
717 
719  const RequestTimingInfo& timing_info();
720  RequestTimingInfo* mutable_timing_info();
721 
726  LoggingInfo* logging_info();
727 
729  const MetadataCacheInfo& metadata_cache_info() {
730  return logging_info()->metadata_cache_info();
731  }
732 
735  GoogleString AppliedRewriterStringFromLog();
736 
739  void VerifyRewriterInfoEntry(AbstractLogRecord* log_record,
740  const GoogleString& id,
741  int url_index,
742  int rewriter_info_index,
743  int rewriter_info_size,
744  int url_list_size,
745  const GoogleString& url);
746 
748  void SetCurrentUserAgent(const StringPiece& user_agent) {
749  current_user_agent_ = user_agent;
750  }
751 
752  GoogleString ExpectedNonce();
753 
756  GoogleString HttpCacheKey(StringPiece url) {
757  return HTTPCache::CompositeKey(url, rewrite_driver_->CacheFragment());
758  }
759 
761  int TimedValue(StringPiece name);
762 
766  TestDistributedFetcher test_distributed_fetcher_;
767  scoped_ptr<Statistics> statistics_;
768 
774  scoped_ptr<TestRewriteDriverFactory> factory_;
775  scoped_ptr<TestRewriteDriverFactory> other_factory_;
776  ServerContext* server_context_;
777  RewriteDriver* rewrite_driver_;
778  ServerContext* other_server_context_;
779  RewriteDriver* other_rewrite_driver_;
780  scoped_ptr<HtmlWriterFilter> other_html_writer_filter_;
781  ActiveServerFlag active_server_;
782  bool use_managed_rewrite_drivers_;
783  StringPiece current_user_agent_;
784  MD5Hasher md5_hasher_;
785 
788  UrlSegmentEncoder default_encoder_;
789  ResponseHeaders response_headers_;
790  const GoogleString kEtag0;
791  uint64 expected_nonce_;
792 
793  GoogleString debug_message_;
794 };
795 
796 }
797 
798 #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:213
void SetActiveServer(ActiveServerFlag server_to_use)
void SetCurrentUserAgent(const StringPiece &user_agent)
Sets current_user_agent_.
Definition: rewrite_test_base.h:748
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:756
Use the normal data members.
Definition: rewrite_test_base.h:104
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:324
void AdjustTimeUsWithoutWakingAlarms(int64 time_us)
Adjusts time ignoring any scheduler callbacks. Use with caution.
int TimedValue(StringPiece name)
Returns the value of a TimedVariable, specified by name.
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:787
void ServeResourceFromNewContext(const GoogleString &resource_url, const StringPiece &expected_content)
void SetDummyRequestHeaders()
Setup dummy empty RequestHeaders object for the driver.
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:622
void DebugWithMessage(StringPiece expected_debug_message)
Definition: rewrite_test_base.h:670
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)
FindResult
When a lookup is done in the HTTP Cache, it returns one of these values.
Definition: http_cache.h:71
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:353
Definition: rewrite_test_base.h:89
void AddOtherRewriteFilter(RewriteFilter *filter)
RewriteDriver * rewrite_driver()
Definition: rewrite_test_base.h:505
static const char kConfiguredBeaconingKey[]
Beaconing key values used when downstream caching is enabled.
Definition: rewrite_test_base.h:94
void SetCacheInvalidationTimestampForUrl(StringPiece url, bool ignores_metadata_and_pcache)
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
GoogleString debug_message_
Message used by DebugMessage.
Definition: rewrite_test_base.h:793
MockScheduler * mock_scheduler()
The scheduler used by rewrite_driver.
Definition: rewrite_test_base.h:509
RewriteOptions * options_
owned by rewrite_driver_.
Definition: rewrite_test_base.h:786
void SetHtmlMimetype()
Sets the response-headers Content-Type to "text/html".
Definition: rewrite_test_base.h:599
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 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:774
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:612
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:37
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:105
void AddRewriteFilter(RewriteFilter *filter)
Filter
Definition: rewrite_options.h:106
Definition: rewrite_driver.h:98
Definition: server_context.h:101
void SetXhtmlMimetype()
Sets the response-headers Content-Type to "application/xhtml+xml".
Definition: rewrite_test_base.h:596
MockUrlFetcher mock_url_fetcher_
Definition: rewrite_test_base.h:765
Definition: process_context.h:35
MockLogRecord * mock_log_record()
Returns the MockLogRecord in the driver.
Definition: wait_url_async_fetcher.h:37
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:338
const MetadataCacheInfo & metadata_cache_info()
Convenience method to extract read-only metadata_cache_info.
Definition: rewrite_test_base.h:729
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:790
Hasher * hasher() const
Definition: server_context.h:178
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:103
static const char kTestData[]
Testdata directory.
Definition: rewrite_test_base.h:91
void TestRetainExtraHeaders(const StringPiece &name, const StringPiece &filter_id, const StringPiece &ext)
RewriteDriver * MakeDriver(ServerContext *server_context, RewriteOptions *options)
Definition: rewrite_options.h:83
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:184
void set_hasher(Hasher *hasher)
Setters should probably only be used in testing.
Definition: server_context.h:340
void SetUseManagedRewriteDrivers(bool use_managed_rewrite_drivers)
static GoogleString CompositeKey(StringPiece key, StringPiece fragment)
Definition: http_cache.h:365
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)