Commit c92e571e authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions Binding] Update ArgumentSpec to support dictionary enums

The enum definitions in our schemas can either be in the form of a list
value with string entries (e.g. "enum": ["foo", "bar", "baz"]) or in the
form of a dictionary with a name entry (e.g. "enum": [{"name": "foo"}]).

Adjust ArgumentSpec to account for the latter, and add tests.

BUG=653596

Review-Url: https://chromiumcodereview.appspot.com/2439263003
Cr-Commit-Position: refs/heads/master@{#426999}
parent 8d505b43
......@@ -93,7 +93,13 @@ void ArgumentSpec::InitializeType(const base::DictionaryValue* dict) {
CHECK_GT(size, 0u);
for (size_t i = 0; i < size; ++i) {
std::string enum_value;
CHECK(enums->GetString(i, &enum_value));
// Enum entries come in two versions: a list of possible strings, and
// a dictionary with a field 'name'.
if (!enums->GetString(i, &enum_value)) {
const base::DictionaryValue* enum_value_dictionary = nullptr;
CHECK(enums->GetDictionary(i, &enum_value_dictionary));
CHECK(enum_value_dictionary->GetString("name", &enum_value));
}
enum_values_.insert(std::move(enum_value));
}
}
......
......@@ -129,6 +129,18 @@ TEST_F(ArgumentSpecUnitTest, Test) {
ExpectFailure(spec, "''");
}
{
ArgumentSpec spec(*ValueFromString(
"{'type': 'string', 'enum': [{'name': 'foo'}, {'name': 'bar'}]}"));
ExpectSuccess(spec, "'foo'", "'foo'");
ExpectSuccess(spec, "'bar'", "'bar'");
ExpectFailure(spec, "['foo']");
ExpectFailure(spec, "'fo'");
ExpectFailure(spec, "'foobar'");
ExpectFailure(spec, "'baz'");
ExpectFailure(spec, "''");
}
{
ArgumentSpec spec(*ValueFromString("{'type': 'boolean'}"));
ExpectSuccess(spec, "true", "true");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment