1 // Copyright 2016 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 COMPONENTS_SAFE_BROWSING_CORE_FILE_TYPE_POLICIES_TEST_UTIL_H_
6 #define COMPONENTS_SAFE_BROWSING_CORE_FILE_TYPE_POLICIES_TEST_UTIL_H_
7 
8 #include "components/safe_browsing/core/file_type_policies.h"
9 
10 namespace safe_browsing {
11 
12 // This is a test fixture for modifying the proto with FileTypePolicies.
13 // While an object of this class is in scope, it will cause callers
14 // of FileTypePolicies::GetInstance() to see the modified list.
15 // When it goes out of scope, future callers will get the original list.
16 //
17 // Example:
18 //   FileTypePoliciesTestOverlay overlay_;
19 //   std::unique_ptr<DownloadFileTypesConfig> cfg =
20 //       overlay_.DuplicateConfig();
21 //   cfg.set_sampled_ping_probability(1.0);
22 //   overlay_.SwapConfig(cfg);
23 //   ...
24 class FileTypePoliciesTestOverlay {
25  public:
26   FileTypePoliciesTestOverlay();
27   ~FileTypePoliciesTestOverlay();
28 
29   // Swaps the contents bewtween the existing config and |new_config|.
30   void SwapConfig(std::unique_ptr<DownloadFileTypeConfig>& new_config) const;
31 
32   // Return a new copy of the original config.
33   std::unique_ptr<DownloadFileTypeConfig> DuplicateConfig() const;
34 
35  private:
36   std::unique_ptr<DownloadFileTypeConfig> orig_config_;
37 };
38 
39 }  // namespace safe_browsing
40 
41 #endif  // COMPONENTS_SAFE_BROWSING_CORE_FILE_TYPE_POLICIES_TEST_UTIL_H_
42