Page Speed Optimization Libraries  1.2.24.1
net/instaweb/rewriter/public/test_rewrite_driver_factory.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_
00021 
00022 #include <vector>
00023 
00024 #include "net/instaweb/rewriter/public/rewrite_driver_factory.h"
00025 #include "net/instaweb/util/public/basictypes.h"
00026 #include "net/instaweb/util/public/scoped_ptr.h"
00027 #include "net/instaweb/util/public/simple_stats.h"
00028 #include "net/instaweb/util/public/string.h"
00029 #include "net/instaweb/util/public/string_util.h"
00030 
00031 namespace net_instaweb {
00032 
00033 class CountingUrlAsyncFetcher;
00034 class DelayCache;
00035 class FakeUrlAsyncFetcher;
00036 class FileSystem;
00037 class Hasher;
00038 class HtmlFilter;
00039 class LRUCache;
00040 class MemFileSystem;
00041 class MessageHandler;
00042 class MockHasher;
00043 class MockMessageHandler;
00044 class MockScheduler;
00045 class MockTimer;
00046 class MockTimeCache;
00047 class MockUrlFetcher;
00048 class ServerContext;
00049 class RewriteDriver;
00050 class RewriteFilter;
00051 class RewriteOptions;
00052 class Scheduler;
00053 class ThreadsafeCache;
00054 class Timer;
00055 class UrlAsyncFetcher;
00056 class UrlFetcher;
00057 class UrlNamer;
00058 class WaitUrlAsyncFetcher;
00059 
00062 class TestRewriteDriverFactory : public RewriteDriverFactory {
00063  public:
00064   static const int64 kStartTimeMs; 
00065   static const char kUrlNamerScheme[]; 
00066 
00067   class CreateFilterCallback {
00068    public:
00069     CreateFilterCallback() {}
00070     virtual ~CreateFilterCallback();
00071     virtual HtmlFilter* Done(RewriteDriver* driver) = 0;
00072 
00073    private:
00074     DISALLOW_COPY_AND_ASSIGN(CreateFilterCallback);
00075   };
00076 
00077   class CreateRewriterCallback {
00078    public:
00079     CreateRewriterCallback() {}
00080     virtual ~CreateRewriterCallback();
00081     virtual RewriteFilter* Done(RewriteDriver* driver) = 0;
00082 
00083    private:
00084     DISALLOW_COPY_AND_ASSIGN(CreateRewriterCallback);
00085   };
00086 
00087   class PlatformSpecificConfigurationCallback {
00088    public:
00089     PlatformSpecificConfigurationCallback() {}
00090     virtual ~PlatformSpecificConfigurationCallback();
00091     virtual void Done(RewriteDriver* driver) = 0;
00092 
00093    private:
00094     DISALLOW_COPY_AND_ASSIGN(PlatformSpecificConfigurationCallback);
00095   };
00096 
00097   TestRewriteDriverFactory(const StringPiece& temp_dir,
00098                            MockUrlFetcher* mock_fetcher);
00099   virtual ~TestRewriteDriverFactory();
00100 
00101   DelayCache* delay_cache() { return delay_cache_; }
00102   LRUCache* lru_cache() { return lru_cache_; }
00103   MockTimer* mock_timer() { return mock_timer_; }
00104   MockHasher* mock_hasher() { return mock_hasher_; }
00105   MemFileSystem* mem_file_system() { return mem_file_system_; }
00106   FakeUrlAsyncFetcher* mock_url_async_fetcher() {
00107     return mock_url_async_fetcher_.get();
00108   }
00109   WaitUrlAsyncFetcher* wait_url_async_fetcher() {
00110     return wait_url_async_fetcher_.get();
00111   }
00112   CountingUrlAsyncFetcher* counting_url_async_fetcher() {
00113     return counting_url_async_fetcher_;
00114   }
00115   MockTimeCache* mock_time_cache() { return mock_time_cache_.get(); }
00116 
00117   void SetupWaitFetcher();
00118   void CallFetcherCallbacksForDriver(RewriteDriver* driver);
00119   MockMessageHandler* mock_message_handler() { return mock_message_handler_; }
00120   MockScheduler* mock_scheduler() { return mock_scheduler_; }
00121   bool use_test_url_namer() const { return use_test_url_namer_; }
00122   void SetUseTestUrlNamer(bool x);
00123 
00125   void AddCreateFilterCallback(CreateFilterCallback* callback) {
00126     filter_callback_vector_.push_back(callback);
00127   }
00128 
00129   void ClearFilterCallbackVector() {
00130     filter_callback_vector_.clear();
00131   }
00132 
00134   void AddCreateRewriterCallback(CreateRewriterCallback* callback) {
00135     rewriter_callback_vector_.push_back(callback);
00136   }
00137 
00138   void ClearRewriterCallbackVector() {
00139     rewriter_callback_vector_.clear();
00140   }
00141 
00143   void AddPlatformSpecificConfigurationCallback(
00144       PlatformSpecificConfigurationCallback* callback) {
00145     platform_config_vector_.push_back(callback);
00146   }
00147 
00148   void ClearPlatformSpecificConfigurationCallback() {
00149     platform_config_vector_.clear();
00150   }
00151 
00153   virtual RewriteOptions* NewRewriteOptions();
00154 
00155   virtual bool IsDebugClient(const GoogleString& ip) const {
00156     return ip == "127.0.0.1";
00157   }
00158 
00161   void set_add_platform_specific_decoding_passes(bool value) {
00162     add_platform_specific_decoding_passes_ = value;
00163   }
00164 
00165   bool add_platform_specific_decoding_passes() const {
00166     return add_platform_specific_decoding_passes_;
00167   }
00168 
00170   void AdvanceTimeMs(int64 delta_ms);
00171 
00172  protected:
00173   virtual Hasher* NewHasher();
00174   virtual MessageHandler* DefaultHtmlParseMessageHandler();
00175   virtual MessageHandler* DefaultMessageHandler();
00176   virtual UrlFetcher* DefaultUrlFetcher();
00177   virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher();
00178   virtual FileSystem* DefaultFileSystem();
00179   virtual Timer* DefaultTimer();
00180   virtual void SetupCaches(ServerContext* resource_manager);
00181   virtual UrlNamer* DefaultUrlNamer();
00182   virtual Scheduler* CreateScheduler();
00183   virtual void AddPlatformSpecificDecodingPasses(RewriteDriver* driver);
00184   virtual void AddPlatformSpecificRewritePasses(RewriteDriver* driver);
00185   virtual void ApplyPlatformSpecificConfiguration(RewriteDriver* driver);
00186 
00187  private:
00188   MockTimer* mock_timer_; 
00189   MockScheduler* mock_scheduler_; 
00190   DelayCache* delay_cache_;
00191   scoped_ptr<ThreadsafeCache> threadsafe_cache_;
00192   LRUCache* lru_cache_;
00193   UrlFetcher* proxy_url_fetcher_;
00194   MockUrlFetcher* mock_url_fetcher_;
00195   scoped_ptr<FakeUrlAsyncFetcher> mock_url_async_fetcher_;
00196   CountingUrlAsyncFetcher* counting_url_async_fetcher_;
00197   scoped_ptr<WaitUrlAsyncFetcher> wait_url_async_fetcher_;
00198   scoped_ptr<MockTimeCache> mock_time_cache_;
00199   MemFileSystem* mem_file_system_; 
00200   MockHasher* mock_hasher_;
00201   SimpleStats simple_stats_;
00202   MockMessageHandler* mock_message_handler_;
00203   MockMessageHandler* mock_html_message_handler_;
00204   bool use_test_url_namer_;
00205   bool add_platform_specific_decoding_passes_;
00206   std::vector<CreateFilterCallback*> filter_callback_vector_;
00207   std::vector<CreateRewriterCallback*> rewriter_callback_vector_;
00208   std::vector<PlatformSpecificConfigurationCallback*> platform_config_vector_;
00209 };
00210 
00211 }  
00212 
00213 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines