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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, | 419 static void GetDictionaryFromList(const DictionaryValue* schema, |
420 const std::string& list_name, | 420 const std::string& list_name, |
421 const int list_index, | 421 const int list_index, |
422 DictionaryValue** out) { | 422 const DictionaryValue** out) { |
423 const ListValue* list; | 423 const ListValue* list; |
424 EXPECT_TRUE(schema->GetList(list_name, &list)); | 424 EXPECT_TRUE(schema->GetList(list_name, &list)); |
425 EXPECT_TRUE(list->GetDictionary(list_index, out)); | 425 EXPECT_TRUE(list->GetDictionary(list_index, out)); |
426 } | 426 } |
427 | 427 |
428 TEST(ExtensionAPI, TypesHaveNamespace) { | 428 TEST(ExtensionAPI, TypesHaveNamespace) { |
429 FilePath manifest_path; | 429 FilePath manifest_path; |
430 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path); | 430 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path); |
431 manifest_path = manifest_path.AppendASCII("extensions") | 431 manifest_path = manifest_path.AppendASCII("extensions") |
432 .AppendASCII("extension_api_unittest") | 432 .AppendASCII("extension_api_unittest") |
433 .AppendASCII("types_have_namespace.json"); | 433 .AppendASCII("types_have_namespace.json"); |
434 | 434 |
435 std::string manifest_str; | 435 std::string manifest_str; |
436 ASSERT_TRUE(file_util::ReadFileToString(manifest_path, &manifest_str)) | 436 ASSERT_TRUE(file_util::ReadFileToString(manifest_path, &manifest_str)) |
437 << "Failed to load: " << manifest_path.value(); | 437 << "Failed to load: " << manifest_path.value(); |
438 | 438 |
439 ExtensionAPI api; | 439 ExtensionAPI api; |
440 api.RegisterSchema("test.foo", manifest_str); | 440 api.RegisterSchema("test.foo", manifest_str); |
441 api.LoadAllSchemas(); | 441 api.LoadAllSchemas(); |
442 | 442 |
443 const DictionaryValue* schema = api.GetSchema("test.foo"); | 443 const DictionaryValue* schema = api.GetSchema("test.foo"); |
444 | 444 |
445 DictionaryValue* dict; | 445 const DictionaryValue* dict; |
446 DictionaryValue* sub_dict; | 446 const DictionaryValue* sub_dict; |
447 std::string type; | 447 std::string type; |
448 | 448 |
449 GetDictionaryFromList(schema, "types", 0, &dict); | 449 GetDictionaryFromList(schema, "types", 0, &dict); |
450 EXPECT_TRUE(dict->GetString("id", &type)); | 450 EXPECT_TRUE(dict->GetString("id", &type)); |
451 EXPECT_EQ("test.foo.TestType", type); | 451 EXPECT_EQ("test.foo.TestType", type); |
452 EXPECT_TRUE(dict->GetString("customBindings", &type)); | 452 EXPECT_TRUE(dict->GetString("customBindings", &type)); |
453 EXPECT_EQ("test.foo.TestType", type); | 453 EXPECT_EQ("test.foo.TestType", type); |
454 EXPECT_TRUE(dict->GetDictionary("properties", &sub_dict)); | 454 EXPECT_TRUE(dict->GetDictionary("properties", &sub_dict)); |
455 DictionaryValue* property; | 455 const DictionaryValue* property; |
456 EXPECT_TRUE(sub_dict->GetDictionary("foo", &property)); | 456 EXPECT_TRUE(sub_dict->GetDictionary("foo", &property)); |
457 EXPECT_TRUE(property->GetString("$ref", &type)); | 457 EXPECT_TRUE(property->GetString("$ref", &type)); |
458 EXPECT_EQ("test.foo.OtherType", type); | 458 EXPECT_EQ("test.foo.OtherType", type); |
459 EXPECT_TRUE(sub_dict->GetDictionary("bar", &property)); | 459 EXPECT_TRUE(sub_dict->GetDictionary("bar", &property)); |
460 EXPECT_TRUE(property->GetString("$ref", &type)); | 460 EXPECT_TRUE(property->GetString("$ref", &type)); |
461 EXPECT_EQ("fully.qualified.Type", type); | 461 EXPECT_EQ("fully.qualified.Type", type); |
462 | 462 |
463 GetDictionaryFromList(schema, "functions", 0, &dict); | 463 GetDictionaryFromList(schema, "functions", 0, &dict); |
464 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); | 464 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); |
465 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | 465 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); |
(...skipping 14 matching lines...) Expand all Loading... |
480 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); | 480 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); |
481 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | 481 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); |
482 EXPECT_EQ("test.foo.TestType", type); | 482 EXPECT_EQ("test.foo.TestType", type); |
483 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); | 483 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); |
484 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | 484 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); |
485 EXPECT_EQ("fully.qualified.Type", type); | 485 EXPECT_EQ("fully.qualified.Type", type); |
486 } | 486 } |
487 | 487 |
488 } // namespace | 488 } // namespace |
489 } // namespace extensions | 489 } // namespace extensions |
OLD | NEW |