OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 EXTENSIONS_RENDERER_ARGUMENT_SPEC_BUILDER_H_ |
| 6 #define EXTENSIONS_RENDERER_ARGUMENT_SPEC_BUILDER_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <set> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "base/strings/string_piece.h" |
| 14 #include "extensions/renderer/argument_spec.h" |
| 15 |
| 16 namespace extensions { |
| 17 |
| 18 // A utility class for helping construct ArgumentSpecs in tests. |
| 19 // NOTE: This is designed to be test-only. It's not worth adding to production |
| 20 // code because it's a) only a bit of syntactic sugar and b) rife with footguns. |
| 21 class ArgumentSpecBuilder { |
| 22 public: |
| 23 explicit ArgumentSpecBuilder(ArgumentType type); |
| 24 ArgumentSpecBuilder(ArgumentType type, base::StringPiece name); |
| 25 |
| 26 ~ArgumentSpecBuilder(); |
| 27 |
| 28 ArgumentSpecBuilder& MakeOptional(); |
| 29 ArgumentSpecBuilder& AddProperty(base::StringPiece property_name, |
| 30 std::unique_ptr<ArgumentSpec> property_spec); |
| 31 ArgumentSpecBuilder& SetMinimum(int minimum); |
| 32 ArgumentSpecBuilder& SetListType(std::unique_ptr<ArgumentSpec> list_type); |
| 33 ArgumentSpecBuilder& SetRef(base::StringPiece ref); |
| 34 ArgumentSpecBuilder& SetChoices( |
| 35 std::vector<std::unique_ptr<ArgumentSpec>> choices); |
| 36 ArgumentSpecBuilder& SetEnums(std::set<std::string> enum_values); |
| 37 ArgumentSpecBuilder& SetAdditionalProperties( |
| 38 std::unique_ptr<ArgumentSpec> additional_properties); |
| 39 std::unique_ptr<ArgumentSpec> Build(); |
| 40 |
| 41 private: |
| 42 std::unique_ptr<ArgumentSpec> spec_; |
| 43 ArgumentSpec::PropertiesMap properties_; |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(ArgumentSpecBuilder); |
| 46 }; |
| 47 |
| 48 } // namespace extensions |
| 49 |
| 50 #endif // EXTENSIONS_RENDERER_ARGUMENT_SPEC_BUILDER_H_ |
OLD | NEW |