OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/extensions/api/extension_api.h" | 5 #include "chrome/common/extensions/api/extension_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 409 |
410 ExtensionAPI api; | 410 ExtensionAPI api; |
411 api.RegisterSchema("test", base::StringPiece(schema_source)); | 411 api.RegisterSchema("test", base::StringPiece(schema_source)); |
412 api.LoadAllSchemas(); | 412 api.LoadAllSchemas(); |
413 | 413 |
414 Feature* feature = api.GetFeature("test"); | 414 Feature* feature = api.GetFeature("test"); |
415 EXPECT_EQ(test_data[i].expect_success, feature != NULL) << i; | 415 EXPECT_EQ(test_data[i].expect_success, feature != NULL) << i; |
416 } | 416 } |
417 } | 417 } |
418 | 418 |
419 static void GetDictionaryFromList(const DictionaryValue* schema, | |
420 const std::string& list_name, | |
421 const int list_index, | |
422 DictionaryValue** out) { | |
423 ListValue* list; | |
424 EXPECT_TRUE(schema->GetList(list_name, &list)); | |
425 EXPECT_TRUE(list->GetDictionary(list_index, out)); | |
426 } | |
427 | |
428 TEST(ExtensionAPI, TypesHaveNamespace) { | |
429 FilePath manifest_path; | |
430 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path); | |
431 manifest_path = manifest_path.AppendASCII("extensions") | |
432 .AppendASCII("extension_api_unittest") | |
433 .AppendASCII("types_have_namespace.json"); | |
434 | |
435 std::string manifest_str; | |
436 ASSERT_TRUE(file_util::ReadFileToString(manifest_path, &manifest_str)) | |
437 << "Failed to load: " << manifest_path.value(); | |
438 | |
439 ExtensionAPI api; | |
440 api.RegisterSchema("test.foo", manifest_str); | |
441 api.LoadAllSchemas(); | |
442 | |
443 const DictionaryValue* schema = api.GetSchema("test.foo"); | |
444 | |
445 DictionaryValue* dict; | |
446 DictionaryValue* sub_dict; | |
447 std::string type; | |
448 | |
449 GetDictionaryFromList(schema, "types", 0, &dict); | |
450 EXPECT_TRUE(dict->GetString("id", &type)); | |
451 EXPECT_EQ("test.foo.TestType", type); | |
452 EXPECT_TRUE(dict->GetString("customBindings", &type)); | |
453 EXPECT_EQ("test.foo.TestType", type); | |
454 EXPECT_TRUE(dict->GetDictionary("properties", &sub_dict)); | |
455 DictionaryValue* property; | |
456 EXPECT_TRUE(sub_dict->GetDictionary("foo", &property)); | |
457 EXPECT_TRUE(property->GetString("$ref", &type)); | |
458 EXPECT_EQ("test.foo.OtherType", type); | |
459 EXPECT_TRUE(sub_dict->GetDictionary("bar", &property)); | |
460 EXPECT_TRUE(property->GetString("$ref", &type)); | |
461 EXPECT_EQ("fully.qualified.Type", type); | |
462 | |
463 GetDictionaryFromList(schema, "functions", 0, &dict); | |
464 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); | |
465 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | |
466 EXPECT_EQ("test.foo.TestType", type); | |
467 EXPECT_TRUE(dict->GetDictionary("returns", &sub_dict)); | |
468 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | |
469 EXPECT_EQ("fully.qualified.Type", type); | |
470 | |
471 GetDictionaryFromList(schema, "functions", 1, &dict); | |
472 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); | |
473 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | |
474 EXPECT_EQ("fully.qualified.Type", type); | |
475 EXPECT_TRUE(dict->GetDictionary("returns", &sub_dict)); | |
476 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | |
477 EXPECT_EQ("test.foo.TestType", type); | |
478 | |
479 GetDictionaryFromList(schema, "events", 0, &dict); | |
480 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); | |
481 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | |
482 EXPECT_EQ("test.foo.TestType", type); | |
483 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); | |
484 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | |
485 EXPECT_EQ("fully.qualified.Type", type); | |
486 } | |
487 | |
488 } // namespace | 419 } // namespace |
489 } // namespace extensions | 420 } // namespace extensions |
OLD | NEW |