Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: extensions/renderer/argument_spec_builder.h

Issue 2847843002: [Extensions Bindings] Move signature parsing tests to their own file (Closed)
Patch Set: Builder Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // Allow implicit conversion to ArgumentSpec so callers don't need to use
42 // Build().
43 operator std::unique_ptr<ArgumentSpec>();
Devlin 2017/04/27 20:55:46 This might violate https://google.github.io/styleg
jbroman 2017/04/27 21:24:32 Yeaahhh, I don't feel strongly. Agreed that it has
Devlin 2017/04/28 01:16:44 Well, given we're both on the fence, let's take it
44
45 private:
46 std::unique_ptr<ArgumentSpec> spec_;
47 ArgumentSpec::PropertiesMap properties_;
48
49 DISALLOW_COPY_AND_ASSIGN(ArgumentSpecBuilder);
50 };
51
52 } // namespace extensions
53
54 #endif // EXTENSIONS_RENDERER_ARGUMENT_SPEC_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698