Page Speed Optimization Libraries
1.3.25.1
|
00001 /* 00002 * Copyright 2012 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 00020 00021 #ifndef NET_INSTAWEB_UTIL_PUBLIC_MOCK_PROPERTY_PAGE_H_ 00022 #define NET_INSTAWEB_UTIL_PUBLIC_MOCK_PROPERTY_PAGE_H_ 00023 00024 #include "net/instaweb/http/public/log_record.h" 00025 #include "net/instaweb/http/public/request_context.h" 00026 #include "net/instaweb/util/public/basictypes.h" 00027 #include "net/instaweb/util/public/property_cache.h" 00028 #include "net/instaweb/util/public/thread_system.h" 00029 #include "net/instaweb/util/public/string_util.h" 00030 00031 namespace net_instaweb { 00032 00033 class MockPropertyPage : public PropertyPage { 00034 public: 00036 static const int kMockCacheType = 1; 00037 00039 static const int kMockDeviceType = 2; 00040 00041 MockPropertyPage(ThreadSystem* thread_system, 00042 const PropertyCache& property_cache, 00043 const StringPiece& key) 00044 : PropertyPage(thread_system->NewMutex(), property_cache, key, 00045 RequestContext::NewTestRequestContext(thread_system)), 00046 called_(false), 00047 valid_(false), 00048 time_ms_(-1) {} 00049 virtual ~MockPropertyPage(); 00050 virtual bool IsCacheValid(int64 write_timestamp_ms) const { 00051 return time_ms_ == -1 || write_timestamp_ms > time_ms_; 00052 } 00053 virtual void Done(bool valid) { 00054 called_ = true; 00055 valid_ = valid; 00056 } 00057 00061 virtual void LogPageCohortInfo(LogRecord* log_record, int cohort_index) { 00062 log_record->SetDeviceAndCacheTypeForCohortInfo( 00063 cohort_index, kMockDeviceType, kMockCacheType); 00064 } 00065 00066 bool called() const { return called_; } 00067 bool valid() const { return valid_; } 00068 void set_time_ms(int64 time_ms) { 00069 time_ms_ = time_ms; 00070 } 00071 00072 private: 00073 bool called_; 00074 bool valid_; 00075 int64 time_ms_; 00076 00077 DISALLOW_COPY_AND_ASSIGN(MockPropertyPage); 00078 }; 00079 } 00080 00081 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_MOCK_PROPERTY_PAGE_H_