Chromium Code Reviews| 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 "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 using extensions::Feature; | |
|
not at google - send to devlin
2012/12/12 17:42:41
this file is in the extensions namespace, this sho
justinlin
2012/12/14 12:26:26
Done.
| |
| 22 | |
| 21 namespace extensions { | 23 namespace extensions { |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 class TestFeatureProvider : public FeatureProvider { | 26 class TestFeatureProvider : public FeatureProvider { |
| 25 public: | 27 public: |
| 26 explicit TestFeatureProvider(Feature::Context context) | 28 explicit TestFeatureProvider(Feature::Context context) |
| 27 : context_(context) { | 29 : context_(context) { |
| 28 } | 30 } |
| 29 | 31 |
| 30 virtual Feature* GetFeature(const std::string& name) OVERRIDE { | 32 virtual SimpleFeature* GetFeature(const std::string& name) OVERRIDE { |
|
not at google - send to devlin
2012/12/12 17:42:41
Feature etc
justinlin
2012/12/14 12:26:26
I changed the method signature, but I think the ot
| |
| 31 Feature* result = new Feature(); | 33 SimpleFeature* result = new SimpleFeature(); |
| 32 result->set_name(name); | 34 result->set_name(name); |
| 33 result->extension_types()->insert(Extension::TYPE_EXTENSION); | 35 result->extension_types()->insert(Extension::TYPE_EXTENSION); |
| 34 result->contexts()->insert(context_); | 36 result->contexts()->insert(context_); |
| 35 to_destroy_.push_back(make_linked_ptr(result)); | 37 to_destroy_.push_back(make_linked_ptr(result)); |
| 36 return result; | 38 return result; |
| 37 } | 39 } |
| 38 | 40 |
| 39 private: | 41 private: |
| 40 std::vector<linked_ptr<Feature> > to_destroy_; | 42 std::vector<linked_ptr<Feature> > to_destroy_; |
| 41 Feature::Context context_; | 43 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, | 347 std::string api_name = api->GetAPINameFromFullName(test_data[i].input, |
| 346 &child_name); | 348 &child_name); |
| 347 EXPECT_EQ(test_data[i].api_name, api_name) << test_data[i].input; | 349 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; | 350 EXPECT_EQ(test_data[i].child_name, child_name) << test_data[i].input; |
| 349 } | 351 } |
| 350 } | 352 } |
| 351 | 353 |
| 352 TEST(ExtensionAPI, DefaultConfigurationFeatures) { | 354 TEST(ExtensionAPI, DefaultConfigurationFeatures) { |
| 353 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); | 355 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); |
| 354 | 356 |
| 355 Feature* bookmarks = api->GetFeature("bookmarks"); | 357 SimpleFeature* bookmarks = api->GetFeature("bookmarks"); |
| 356 Feature* bookmarks_create = api->GetFeature("bookmarks.create"); | 358 SimpleFeature* bookmarks_create = api->GetFeature("bookmarks.create"); |
| 357 | 359 |
| 358 struct { | 360 struct { |
| 359 Feature* feature; | 361 SimpleFeature* feature; |
| 360 // TODO(aa): More stuff to test over time. | 362 // TODO(aa): More stuff to test over time. |
| 361 } test_data[] = { | 363 } test_data[] = { |
| 362 { bookmarks }, | 364 { bookmarks }, |
| 363 { bookmarks_create } | 365 { bookmarks_create } |
| 364 }; | 366 }; |
| 365 | 367 |
| 366 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 368 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 367 Feature* feature = test_data[i].feature; | 369 SimpleFeature* feature = test_data[i].feature; |
| 368 ASSERT_TRUE(feature) << i; | 370 ASSERT_TRUE(feature) << i; |
| 369 | 371 |
| 370 EXPECT_TRUE(feature->whitelist()->empty()); | 372 EXPECT_TRUE(feature->whitelist()->empty()); |
| 371 EXPECT_TRUE(feature->extension_types()->empty()); | 373 EXPECT_TRUE(feature->extension_types()->empty()); |
| 372 | 374 |
| 373 EXPECT_EQ(1u, feature->contexts()->size()); | 375 EXPECT_EQ(1u, feature->contexts()->size()); |
| 374 EXPECT_TRUE(feature->contexts()->count( | 376 EXPECT_TRUE(feature->contexts()->count( |
| 375 Feature::BLESSED_EXTENSION_CONTEXT)); | 377 Feature::BLESSED_EXTENSION_CONTEXT)); |
| 376 | 378 |
| 377 EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location()); | 379 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); | 481 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); |
| 480 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | 482 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); |
| 481 EXPECT_EQ("test.foo.TestType", type); | 483 EXPECT_EQ("test.foo.TestType", type); |
| 482 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); | 484 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); |
| 483 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | 485 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); |
| 484 EXPECT_EQ("fully.qualified.Type", type); | 486 EXPECT_EQ("fully.qualified.Type", type); |
| 485 } | 487 } |
| 486 | 488 |
| 487 } // namespace | 489 } // namespace |
| 488 } // namespace extensions | 490 } // namespace extensions |
| OLD | NEW |