| 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" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
| 19 #include "chrome/common/extensions/features/simple_feature.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace extensions { | 22 namespace extensions { |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 class TestFeatureProvider : public FeatureProvider { | 25 class TestFeatureProvider : public FeatureProvider { |
| 25 public: | 26 public: |
| 26 explicit TestFeatureProvider(Feature::Context context) | 27 explicit TestFeatureProvider(Feature::Context context) |
| 27 : context_(context) { | 28 : context_(context) { |
| 28 } | 29 } |
| 29 | 30 |
| 30 virtual Feature* GetFeature(const std::string& name) OVERRIDE { | 31 virtual Feature* GetFeature(const std::string& name) OVERRIDE { |
| 31 Feature* result = new Feature(); | 32 SimpleFeature* result = new SimpleFeature(); |
| 32 result->set_name(name); | 33 result->set_name(name); |
| 33 result->extension_types()->insert(Extension::TYPE_EXTENSION); | 34 result->extension_types()->insert(Extension::TYPE_EXTENSION); |
| 34 result->contexts()->insert(context_); | 35 result->contexts()->insert(context_); |
| 35 to_destroy_.push_back(make_linked_ptr(result)); | 36 to_destroy_.push_back(make_linked_ptr(result)); |
| 36 return result; | 37 return result; |
| 37 } | 38 } |
| 38 | 39 |
| 39 private: | 40 private: |
| 40 std::vector<linked_ptr<Feature> > to_destroy_; | 41 std::vector<linked_ptr<Feature> > to_destroy_; |
| 41 Feature::Context context_; | 42 Feature::Context context_; |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 std::string api_name = api->GetAPINameFromFullName(test_data[i].input, | 346 std::string api_name = api->GetAPINameFromFullName(test_data[i].input, |
| 346 &child_name); | 347 &child_name); |
| 347 EXPECT_EQ(test_data[i].api_name, api_name) << test_data[i].input; | 348 EXPECT_EQ(test_data[i].api_name, api_name) << test_data[i].input; |
| 348 EXPECT_EQ(test_data[i].child_name, child_name) << test_data[i].input; | 349 EXPECT_EQ(test_data[i].child_name, child_name) << test_data[i].input; |
| 349 } | 350 } |
| 350 } | 351 } |
| 351 | 352 |
| 352 TEST(ExtensionAPI, DefaultConfigurationFeatures) { | 353 TEST(ExtensionAPI, DefaultConfigurationFeatures) { |
| 353 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); | 354 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); |
| 354 | 355 |
| 355 Feature* bookmarks = api->GetFeature("bookmarks"); | 356 SimpleFeature* bookmarks = |
| 356 Feature* bookmarks_create = api->GetFeature("bookmarks.create"); | 357 static_cast<SimpleFeature*>(api->GetFeature("bookmarks")); |
| 358 SimpleFeature* bookmarks_create = |
| 359 static_cast<SimpleFeature*>(api->GetFeature("bookmarks.create")); |
| 357 | 360 |
| 358 struct { | 361 struct { |
| 359 Feature* feature; | 362 SimpleFeature* feature; |
| 360 // TODO(aa): More stuff to test over time. | 363 // TODO(aa): More stuff to test over time. |
| 361 } test_data[] = { | 364 } test_data[] = { |
| 362 { bookmarks }, | 365 { bookmarks }, |
| 363 { bookmarks_create } | 366 { bookmarks_create } |
| 364 }; | 367 }; |
| 365 | 368 |
| 366 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 369 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 367 Feature* feature = test_data[i].feature; | 370 SimpleFeature* feature = test_data[i].feature; |
| 368 ASSERT_TRUE(feature) << i; | 371 ASSERT_TRUE(feature) << i; |
| 369 | 372 |
| 370 EXPECT_TRUE(feature->whitelist()->empty()); | 373 EXPECT_TRUE(feature->whitelist()->empty()); |
| 371 EXPECT_TRUE(feature->extension_types()->empty()); | 374 EXPECT_TRUE(feature->extension_types()->empty()); |
| 372 | 375 |
| 373 EXPECT_EQ(1u, feature->contexts()->size()); | 376 EXPECT_EQ(1u, feature->contexts()->size()); |
| 374 EXPECT_TRUE(feature->contexts()->count( | 377 EXPECT_TRUE(feature->contexts()->count( |
| 375 Feature::BLESSED_EXTENSION_CONTEXT)); | 378 Feature::BLESSED_EXTENSION_CONTEXT)); |
| 376 | 379 |
| 377 EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location()); | 380 EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location()); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); | 482 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); |
| 480 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | 483 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); |
| 481 EXPECT_EQ("test.foo.TestType", type); | 484 EXPECT_EQ("test.foo.TestType", type); |
| 482 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); | 485 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); |
| 483 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | 486 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); |
| 484 EXPECT_EQ("fully.qualified.Type", type); | 487 EXPECT_EQ("fully.qualified.Type", type); |
| 485 } | 488 } |
| 486 | 489 |
| 487 } // namespace | 490 } // namespace |
| 488 } // namespace extensions | 491 } // namespace extensions |
| OLD | NEW |