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

Unified Diff: chrome/common/extensions/api/common_extension_api_unittest.cc

Issue 2266113002: [Extensions] Prefix extension apis in the generation step (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lazyboys Created 4 years, 4 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
« no previous file with comments | « no previous file | extensions/common/extension_api.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/api/common_extension_api_unittest.cc
diff --git a/chrome/common/extensions/api/common_extension_api_unittest.cc b/chrome/common/extensions/api/common_extension_api_unittest.cc
index 5249256917d1152f4d8fa1f76ef1482aeb8e05b2..a956ec523dfbdb6993e4c1910ec23c534d4f0b70 100644
--- a/chrome/common/extensions/api/common_extension_api_unittest.cc
+++ b/chrome/common/extensions/api/common_extension_api_unittest.cc
@@ -672,64 +672,93 @@ static void GetDictionaryFromList(const base::DictionaryValue* schema,
EXPECT_TRUE(list->GetDictionary(list_index, out));
}
+static const base::DictionaryValue* GetDictChecked(
+ const base::DictionaryValue* dict,
+ const std::string& key) {
+ const base::DictionaryValue* out = nullptr;
+ CHECK(dict->GetDictionary(key, &out)) << key;
+ return out;
+}
+
+static std::string GetStringChecked(const base::DictionaryValue* dict,
+ const std::string& key) {
+ std::string out;
+ CHECK(dict->GetString(key, &out)) << key;
+ return out;
+}
+
TEST(ExtensionAPITest, TypesHaveNamespace) {
- base::FilePath manifest_path;
- PathService::Get(chrome::DIR_TEST_DATA, &manifest_path);
- manifest_path = manifest_path.AppendASCII("extensions")
- .AppendASCII("extension_api_unittest")
- .AppendASCII("types_have_namespace.json");
-
- std::string manifest_str;
- ASSERT_TRUE(base::ReadFileToString(manifest_path, &manifest_str))
- << "Failed to load: " << manifest_path.value();
-
- TestExtensionAPI api;
- api.add_fake_schema("test.foo");
- api.LoadSchema("test.foo", manifest_str);
-
- const base::DictionaryValue* schema = api.GetSchema("test.foo");
-
- const base::DictionaryValue* dict;
- const base::DictionaryValue* sub_dict;
- std::string type;
-
- GetDictionaryFromList(schema, "types", 0, &dict);
- EXPECT_TRUE(dict->GetString("id", &type));
- EXPECT_EQ("test.foo.TestType", type);
- EXPECT_TRUE(dict->GetString("customBindings", &type));
- EXPECT_EQ("test.foo.TestType", type);
- EXPECT_TRUE(dict->GetDictionary("properties", &sub_dict));
- const base::DictionaryValue* property;
- EXPECT_TRUE(sub_dict->GetDictionary("foo", &property));
- EXPECT_TRUE(property->GetString("$ref", &type));
- EXPECT_EQ("test.foo.OtherType", type);
- EXPECT_TRUE(sub_dict->GetDictionary("bar", &property));
- EXPECT_TRUE(property->GetString("$ref", &type));
- EXPECT_EQ("fully.qualified.Type", type);
-
- GetDictionaryFromList(schema, "functions", 0, &dict);
- GetDictionaryFromList(dict, "parameters", 0, &sub_dict);
- EXPECT_TRUE(sub_dict->GetString("$ref", &type));
- EXPECT_EQ("test.foo.TestType", type);
- EXPECT_TRUE(dict->GetDictionary("returns", &sub_dict));
- EXPECT_TRUE(sub_dict->GetString("$ref", &type));
- EXPECT_EQ("fully.qualified.Type", type);
-
- GetDictionaryFromList(schema, "functions", 1, &dict);
- GetDictionaryFromList(dict, "parameters", 0, &sub_dict);
- EXPECT_TRUE(sub_dict->GetString("$ref", &type));
- EXPECT_EQ("fully.qualified.Type", type);
- EXPECT_TRUE(dict->GetDictionary("returns", &sub_dict));
- EXPECT_TRUE(sub_dict->GetString("$ref", &type));
- EXPECT_EQ("test.foo.TestType", type);
-
- GetDictionaryFromList(schema, "events", 0, &dict);
- GetDictionaryFromList(dict, "parameters", 0, &sub_dict);
- EXPECT_TRUE(sub_dict->GetString("$ref", &type));
- EXPECT_EQ("test.foo.TestType", type);
- GetDictionaryFromList(dict, "parameters", 1, &sub_dict);
- EXPECT_TRUE(sub_dict->GetString("$ref", &type));
- EXPECT_EQ("fully.qualified.Type", type);
+ std::unique_ptr<ExtensionAPI> api(
+ ExtensionAPI::CreateWithDefaultConfiguration());
+
+ // Returns the dictionary that has |key|: |value|.
+ auto get_dict_from_list = [](
+ const base::ListValue* list, const std::string& key,
+ const std::string& value) -> const base::DictionaryValue* {
+ const base::DictionaryValue* ret = nullptr;
+ for (const auto& val : *list) {
+ const base::DictionaryValue* dict = nullptr;
+ if (!val->GetAsDictionary(&dict))
+ continue;
+ std::string str;
+ if (dict->GetString(key, &str) && str == value) {
+ ret = dict;
+ break;
+ }
+ }
+ return ret;
+ };
+
+ const base::DictionaryValue* schema = api->GetSchema("sessions");
+ ASSERT_TRUE(schema);
+
+ const base::ListValue* types = nullptr;
+ ASSERT_TRUE(schema->GetList("types", &types));
+ {
+ const base::DictionaryValue* session_type =
+ get_dict_from_list(types, "id", "sessions.Session");
+ ASSERT_TRUE(session_type);
+ const base::DictionaryValue* props =
+ GetDictChecked(session_type, "properties");
+ const base::DictionaryValue* tab = GetDictChecked(props, "tab");
+ EXPECT_EQ("tabs.Tab", GetStringChecked(tab, "$ref"));
+ const base::DictionaryValue* window = GetDictChecked(props, "window");
+ EXPECT_EQ("windows.Window", GetStringChecked(window, "$ref"));
+ }
+ {
+ const base::DictionaryValue* device_type =
+ get_dict_from_list(types, "id", "sessions.Device");
+ ASSERT_TRUE(device_type);
+ const base::DictionaryValue* props =
+ GetDictChecked(device_type, "properties");
+ const base::DictionaryValue* sessions = GetDictChecked(props, "sessions");
+ const base::DictionaryValue* items = GetDictChecked(sessions, "items");
+ EXPECT_EQ("sessions.Session", GetStringChecked(items, "$ref"));
+ }
+ const base::ListValue* functions = nullptr;
+ ASSERT_TRUE(schema->GetList("functions", &functions));
+ {
+ const base::DictionaryValue* get_recently_closed =
+ get_dict_from_list(functions, "name", "getRecentlyClosed");
+ ASSERT_TRUE(get_recently_closed);
+ const base::ListValue* parameters = nullptr;
+ ASSERT_TRUE(get_recently_closed->GetList("parameters", &parameters));
+ const base::DictionaryValue* filter =
+ get_dict_from_list(parameters, "name", "filter");
+ ASSERT_TRUE(filter);
+ EXPECT_EQ("sessions.Filter", GetStringChecked(filter, "$ref"));
+ }
+
+ schema = api->GetSchema("types");
+ ASSERT_TRUE(schema);
+ ASSERT_TRUE(schema->GetList("types", &types));
+ {
+ const base::DictionaryValue* chrome_setting =
+ get_dict_from_list(types, "id", "types.ChromeSetting");
+ ASSERT_TRUE(chrome_setting);
+ EXPECT_EQ("types.ChromeSetting",
+ GetStringChecked(chrome_setting, "customBindings"));
+ }
}
// Tests API availability with an empty manifest.
« no previous file with comments | « no previous file | extensions/common/extension_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698