Chromium Code Reviews| Index: chrome/common/safe_browsing/file_type_policies_test_util.h |
| diff --git a/chrome/common/safe_browsing/file_type_policies_test_util.h b/chrome/common/safe_browsing/file_type_policies_test_util.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f4f728001353463a6955ec3835d39b972c86560e |
| --- /dev/null |
| +++ b/chrome/common/safe_browsing/file_type_policies_test_util.h |
| @@ -0,0 +1,43 @@ |
| +// 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 unmodified |
| +// global list. |
| +// |
| +// Example: |
| +// FileTypePoliciesTestOverlay policies_overlay_; |
| +// auto pb = policies_overlay_.GetConfig(); // DownloadFileTypes |
| +// pb.set_sampled_ping_probability(1.0); |
| +// policies_overlay_.SetConfig(pb) |
| +// ... |
| +class FileTypePoliciesTestOverlay { |
| + public: |
| + FileTypePoliciesTestOverlay(); |
| + ~FileTypePoliciesTestOverlay(); |
| + |
| + DownloadFileTypeConfig GetConfig() const { |
| + return policies_->GetConfigForTesting(); |
| + } |
| + |
| + void SetConfig(const DownloadFileTypeConfig& new_config) { |
| + policies_->SetConfigForTesting(new_config); |
|
asanka
2016/06/20 18:15:46
Can we have something like a SwapConfigForTesting
Nathan Parker
2016/06/20 22:47:31
Sure, SGTM. Done.
|
| + } |
| + |
| + private: |
| + std::unique_ptr<FileTypePolicies> policies_; |
| +}; |
| + |
| +} // namespace safe_browsing |
| + |
| +#endif // CHROME_COMMON_SAFE_BROWSING_FILE_TYPE_POLICIES_TEST_UTIL_H_ |