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 "chrome/common/extensions/features/simple_feature.h" |
| 20 #include "chrome/common/extensions/manifest.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 namespace extensions { | 23 namespace extensions { |
23 namespace { | 24 namespace { |
24 | 25 |
25 class TestFeatureProvider : public FeatureProvider { | 26 class TestFeatureProvider : public FeatureProvider { |
26 public: | 27 public: |
27 explicit TestFeatureProvider(Feature::Context context) | 28 explicit TestFeatureProvider(Feature::Context context) |
28 : context_(context) { | 29 : context_(context) { |
29 } | 30 } |
30 | 31 |
31 virtual Feature* GetFeature(const std::string& name) OVERRIDE { | 32 virtual Feature* GetFeature(const std::string& name) OVERRIDE { |
32 SimpleFeature* result = new SimpleFeature(); | 33 SimpleFeature* result = new SimpleFeature(); |
33 result->set_name(name); | 34 result->set_name(name); |
34 result->extension_types()->insert(Extension::TYPE_EXTENSION); | 35 result->extension_types()->insert(Manifest::TYPE_EXTENSION); |
35 result->GetContexts()->insert(context_); | 36 result->GetContexts()->insert(context_); |
36 to_destroy_.push_back(make_linked_ptr(result)); | 37 to_destroy_.push_back(make_linked_ptr(result)); |
37 return result; | 38 return result; |
38 } | 39 } |
39 | 40 |
40 private: | 41 private: |
41 std::vector<linked_ptr<Feature> > to_destroy_; | 42 std::vector<linked_ptr<Feature> > to_destroy_; |
42 Feature::Context context_; | 43 Feature::Context context_; |
43 }; | 44 }; |
44 | 45 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 scoped_ptr<ListValue> permissions_list(new ListValue()); | 201 scoped_ptr<ListValue> permissions_list(new ListValue()); |
201 for (std::set<std::string>::const_iterator i = permissions.begin(); | 202 for (std::set<std::string>::const_iterator i = permissions.begin(); |
202 i != permissions.end(); ++i) { | 203 i != permissions.end(); ++i) { |
203 permissions_list->Append(Value::CreateStringValue(*i)); | 204 permissions_list->Append(Value::CreateStringValue(*i)); |
204 } | 205 } |
205 manifest.Set("permissions", permissions_list.release()); | 206 manifest.Set("permissions", permissions_list.release()); |
206 } | 207 } |
207 | 208 |
208 std::string error; | 209 std::string error; |
209 scoped_refptr<Extension> extension(Extension::Create( | 210 scoped_refptr<Extension> extension(Extension::Create( |
210 FilePath(), Extension::LOAD, manifest, Extension::NO_FLAGS, &error)); | 211 FilePath(), Manifest::LOAD, manifest, Extension::NO_FLAGS, &error)); |
211 CHECK(extension.get()); | 212 CHECK(extension.get()); |
212 CHECK(error.empty()); | 213 CHECK(error.empty()); |
213 | 214 |
214 return extension; | 215 return extension; |
215 } | 216 } |
216 | 217 |
217 scoped_refptr<Extension> CreateExtensionWithPermission( | 218 scoped_refptr<Extension> CreateExtensionWithPermission( |
218 const std::string& permission) { | 219 const std::string& permission) { |
219 std::set<std::string> permissions; | 220 std::set<std::string> permissions; |
220 permissions.insert(permission); | 221 permissions.insert(permission); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); | 483 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); |
483 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | 484 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); |
484 EXPECT_EQ("test.foo.TestType", type); | 485 EXPECT_EQ("test.foo.TestType", type); |
485 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); | 486 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); |
486 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); | 487 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); |
487 EXPECT_EQ("fully.qualified.Type", type); | 488 EXPECT_EQ("fully.qualified.Type", type); |
488 } | 489 } |
489 | 490 |
490 } // namespace | 491 } // namespace |
491 } // namespace extensions | 492 } // namespace extensions |
OLD | NEW |