1 // Copyright (c) 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_EVENT_LOG_MANAGER_UNITTEST_HELPERS_H_ 6 #define CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_EVENT_LOG_MANAGER_UNITTEST_HELPERS_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include "base/files/file_path.h" 12 #include "build/build_config.h" 13 #include "chrome/browser/media/webrtc/webrtc_event_log_manager_common.h" 14 15 namespace webrtc_event_logging { 16 17 // Which type of compression, if any, LogFileWriterTest should use. 18 enum class WebRtcEventLogCompression { 19 NONE, 20 GZIP_NULL_ESTIMATION, 21 GZIP_PERFECT_ESTIMATION 22 }; 23 24 // Produce a LogFileWriter::Factory object. 25 std::unique_ptr<LogFileWriter::Factory> CreateLogFileWriterFactory( 26 WebRtcEventLogCompression compression); 27 28 #if defined(OS_POSIX) 29 void RemoveWritePermissions(const base::FilePath& path); 30 #endif // defined(OS_POSIX) 31 32 // Always estimates strings to be compressed to zero bytes. 33 class NullEstimator : public CompressedSizeEstimator { 34 public: 35 class Factory : public CompressedSizeEstimator::Factory { 36 public: 37 ~Factory() override = default; 38 39 std::unique_ptr<CompressedSizeEstimator> Create() const override; 40 }; 41 42 ~NullEstimator() override = default; 43 44 size_t EstimateCompressedSize(const std::string& input) const override; 45 }; 46 47 // Provides a perfect estimation of the compressed size by cheating - performing 48 // actual compression, then reporting the resulting size. 49 // This class is stateful; the number, nature and order of calls to 50 // EstimateCompressedSize() is important. 51 class PerfectGzipEstimator : public CompressedSizeEstimator { 52 public: 53 class Factory : public CompressedSizeEstimator::Factory { 54 public: 55 ~Factory() override = default; 56 57 std::unique_ptr<CompressedSizeEstimator> Create() const override; 58 }; 59 60 PerfectGzipEstimator(); 61 62 ~PerfectGzipEstimator() override; 63 64 size_t EstimateCompressedSize(const std::string& input) const override; 65 66 private: 67 // This compressor allows EstimateCompressedSize to return an exact estimate. 68 // EstimateCompressedSize is normally const, but here we fake it, so we set 69 // it as mutable. 70 mutable std::unique_ptr<LogCompressor> compressor_; 71 }; 72 73 // Check the gzipped size of |uncompressed|, including header and footer, 74 // assuming it were gzipped on its own. 75 size_t GzippedSize(const std::string& uncompressed); 76 77 // Same as other version, but with elements compressed in sequence. 78 size_t GzippedSize(const std::vector<std::string>& uncompressed); 79 80 } // namespace webrtc_event_logging 81 82 #endif // CHROME_BROWSER_MEDIA_WEBRTC_WEBRTC_EVENT_LOG_MANAGER_UNITTEST_HELPERS_H_ 83