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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/argument_spec_builder.h
diff --git a/extensions/renderer/argument_spec_builder.h b/extensions/renderer/argument_spec_builder.h
new file mode 100644
index 0000000000000000000000000000000000000000..3173aeb46a569fe2203db56a01c2d4faf531357f
--- /dev/null
+++ b/extensions/renderer/argument_spec_builder.h
@@ -0,0 +1,54 @@
+// Copyright 2017 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 EXTENSIONS_RENDERER_ARGUMENT_SPEC_BUILDER_H_
+#define EXTENSIONS_RENDERER_ARGUMENT_SPEC_BUILDER_H_
+
+#include <memory>
+#include <set>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/strings/string_piece.h"
+#include "extensions/renderer/argument_spec.h"
+
+namespace extensions {
+
+// A utility class for helping construct ArgumentSpecs in tests.
+// NOTE: This is designed to be test-only. It's not worth adding to production
+// code because it's a) only a bit of syntactic sugar and b) rife with footguns.
+class ArgumentSpecBuilder {
+ public:
+ explicit ArgumentSpecBuilder(ArgumentType type);
+ ArgumentSpecBuilder(ArgumentType type, base::StringPiece name);
+
+ ~ArgumentSpecBuilder();
+
+ ArgumentSpecBuilder& MakeOptional();
+ ArgumentSpecBuilder& AddProperty(base::StringPiece property_name,
+ std::unique_ptr<ArgumentSpec> property_spec);
+ ArgumentSpecBuilder& SetMinimum(int minimum);
+ ArgumentSpecBuilder& SetListType(std::unique_ptr<ArgumentSpec> list_type);
+ ArgumentSpecBuilder& SetRef(base::StringPiece ref);
+ ArgumentSpecBuilder& SetChoices(
+ std::vector<std::unique_ptr<ArgumentSpec>> choices);
+ ArgumentSpecBuilder& SetEnums(std::set<std::string> enum_values);
+ ArgumentSpecBuilder& SetAdditionalProperties(
+ std::unique_ptr<ArgumentSpec> additional_properties);
+ std::unique_ptr<ArgumentSpec> Build();
+
+ // Allow implicit conversion to ArgumentSpec so callers don't need to use
+ // Build().
+ 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
+
+ private:
+ std::unique_ptr<ArgumentSpec> spec_;
+ ArgumentSpec::PropertiesMap properties_;
+
+ DISALLOW_COPY_AND_ASSIGN(ArgumentSpecBuilder);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_RENDERER_ARGUMENT_SPEC_BUILDER_H_

Powered by Google App Engine
This is Rietveld 408576698