summaryrefslogtreecommitdiff
path: root/chromium/chrome/common/safe_browsing/file_type_policies_test_util.h
blob: 7d6fd54ceb1bb3541321c44f34525eb72c3a1a7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_COMMON_SAFE_BROWSING_FILE_TYPE_POLICIES_TEST_UTIL_H_
#define CHROME_COMMON_SAFE_BROWSING_FILE_TYPE_POLICIES_TEST_UTIL_H_

#include "chrome/common/safe_browsing/file_type_policies.h"

namespace safe_browsing {

// This is a test fixture for modifying the proto with FileTypePolicies.
// While an object of this class is in scope, it will cause callers
// of FileTypePolicies::GetInstance() to see the modified list.
// When it goes out of scope, future callers will get the original list.
//
// Example:
//   FileTypePoliciesTestOverlay overlay_;
//   std::unique_ptr<DownloadFileTypesConfig> cfg =
//       overlay_.DuplicateConfig();
//   cfg.set_sampled_ping_probability(1.0);
//   overlay_.SwapConfig(cfg);
//   ...
class FileTypePoliciesTestOverlay {
 public:
  FileTypePoliciesTestOverlay();
  ~FileTypePoliciesTestOverlay();

  // Swaps the contents bewtween the existing config and |new_config|.
  void SwapConfig(std::unique_ptr<DownloadFileTypeConfig>& new_config) const;

  // Return a new copy of the original config.
  std::unique_ptr<DownloadFileTypeConfig> DuplicateConfig() const;

 private:
  std::unique_ptr<DownloadFileTypeConfig> orig_config_;
};

}  // namespace safe_browsing

#endif  // CHROME_COMMON_SAFE_BROWSING_FILE_TYPE_POLICIES_TEST_UTIL_H_