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 "extensions/common/extension_api.h" | 5 #include "extensions/common/extension_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 scoped_refptr<Extension> CreateExtensionWithPermissions( | 318 scoped_refptr<Extension> CreateExtensionWithPermissions( |
319 const std::set<std::string>& permissions) { | 319 const std::set<std::string>& permissions) { |
320 base::DictionaryValue manifest; | 320 base::DictionaryValue manifest; |
321 manifest.SetString("name", "extension"); | 321 manifest.SetString("name", "extension"); |
322 manifest.SetString("version", "1.0"); | 322 manifest.SetString("version", "1.0"); |
323 manifest.SetInteger("manifest_version", 2); | 323 manifest.SetInteger("manifest_version", 2); |
324 { | 324 { |
325 std::unique_ptr<base::ListValue> permissions_list(new base::ListValue()); | 325 std::unique_ptr<base::ListValue> permissions_list(new base::ListValue()); |
326 for (std::set<std::string>::const_iterator i = permissions.begin(); | 326 for (std::set<std::string>::const_iterator i = permissions.begin(); |
327 i != permissions.end(); ++i) { | 327 i != permissions.end(); ++i) { |
328 permissions_list->Append(new base::StringValue(*i)); | 328 permissions_list->AppendString(*i); |
329 } | 329 } |
330 manifest.Set("permissions", permissions_list.release()); | 330 manifest.Set("permissions", permissions_list.release()); |
331 } | 331 } |
332 | 332 |
333 std::string error; | 333 std::string error; |
334 scoped_refptr<Extension> extension(Extension::Create( | 334 scoped_refptr<Extension> extension(Extension::Create( |
335 base::FilePath(), Manifest::UNPACKED, | 335 base::FilePath(), Manifest::UNPACKED, |
336 manifest, Extension::NO_FLAGS, &error)); | 336 manifest, Extension::NO_FLAGS, &error)); |
337 CHECK(extension.get()); | 337 CHECK(extension.get()); |
338 CHECK(error.empty()); | 338 CHECK(error.empty()); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 const std::set<std::string>& permissions) { | 437 const std::set<std::string>& permissions) { |
438 base::DictionaryValue values; | 438 base::DictionaryValue values; |
439 values.SetString(manifest_keys::kName, "test"); | 439 values.SetString(manifest_keys::kName, "test"); |
440 values.SetString(manifest_keys::kVersion, "0.1"); | 440 values.SetString(manifest_keys::kVersion, "0.1"); |
441 values.SetString(manifest_keys::kPlatformAppBackground, | 441 values.SetString(manifest_keys::kPlatformAppBackground, |
442 "http://www.example.com"); | 442 "http://www.example.com"); |
443 | 443 |
444 base::DictionaryValue* app = new base::DictionaryValue(); | 444 base::DictionaryValue* app = new base::DictionaryValue(); |
445 base::DictionaryValue* background = new base::DictionaryValue(); | 445 base::DictionaryValue* background = new base::DictionaryValue(); |
446 base::ListValue* scripts = new base::ListValue(); | 446 base::ListValue* scripts = new base::ListValue(); |
447 scripts->Append(new base::StringValue("test.js")); | 447 scripts->AppendString("test.js"); |
448 background->Set("scripts", scripts); | 448 background->Set("scripts", scripts); |
449 app->Set("background", background); | 449 app->Set("background", background); |
450 values.Set(manifest_keys::kApp, app); | 450 values.Set(manifest_keys::kApp, app); |
451 { | 451 { |
452 std::unique_ptr<base::ListValue> permissions_list(new base::ListValue()); | 452 std::unique_ptr<base::ListValue> permissions_list(new base::ListValue()); |
453 for (std::set<std::string>::const_iterator i = permissions.begin(); | 453 for (std::set<std::string>::const_iterator i = permissions.begin(); |
454 i != permissions.end(); ++i) { | 454 i != permissions.end(); ++i) { |
455 permissions_list->Append(new base::StringValue(*i)); | 455 permissions_list->AppendString(*i); |
456 } | 456 } |
457 values.Set("permissions", permissions_list.release()); | 457 values.Set("permissions", permissions_list.release()); |
458 } | 458 } |
459 | 459 |
460 std::string error; | 460 std::string error; |
461 scoped_refptr<Extension> extension(Extension::Create( | 461 scoped_refptr<Extension> extension(Extension::Create( |
462 base::FilePath(), Manifest::INTERNAL, values, Extension::NO_FLAGS, | 462 base::FilePath(), Manifest::INTERNAL, values, Extension::NO_FLAGS, |
463 &error)); | 463 &error)); |
464 CHECK(extension.get()) << error; | 464 CHECK(extension.get()) << error; |
465 return extension; | 465 return extension; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 | 678 |
679 TEST(ExtensionAPITest, FeaturesRequireContexts) { | 679 TEST(ExtensionAPITest, FeaturesRequireContexts) { |
680 // TODO(cduvall): Make this check API featues. | 680 // TODO(cduvall): Make this check API featues. |
681 std::unique_ptr<base::DictionaryValue> api_features1( | 681 std::unique_ptr<base::DictionaryValue> api_features1( |
682 new base::DictionaryValue()); | 682 new base::DictionaryValue()); |
683 std::unique_ptr<base::DictionaryValue> api_features2( | 683 std::unique_ptr<base::DictionaryValue> api_features2( |
684 new base::DictionaryValue()); | 684 new base::DictionaryValue()); |
685 base::DictionaryValue* test1 = new base::DictionaryValue(); | 685 base::DictionaryValue* test1 = new base::DictionaryValue(); |
686 base::DictionaryValue* test2 = new base::DictionaryValue(); | 686 base::DictionaryValue* test2 = new base::DictionaryValue(); |
687 base::ListValue* contexts = new base::ListValue(); | 687 base::ListValue* contexts = new base::ListValue(); |
688 contexts->Append(new base::StringValue("content_script")); | 688 contexts->AppendString("content_script"); |
689 test1->Set("contexts", contexts); | 689 test1->Set("contexts", contexts); |
690 test1->SetString("channel", "stable"); | 690 test1->SetString("channel", "stable"); |
691 test2->SetString("channel", "stable"); | 691 test2->SetString("channel", "stable"); |
692 api_features1->Set("test", test1); | 692 api_features1->Set("test", test1); |
693 api_features2->Set("test", test2); | 693 api_features2->Set("test", test2); |
694 | 694 |
695 struct { | 695 struct { |
696 base::DictionaryValue* api_features; | 696 base::DictionaryValue* api_features; |
697 bool expect_success; | 697 bool expect_success; |
698 } test_data[] = { | 698 } test_data[] = { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 extension.get(), | 855 extension.get(), |
856 Feature::BLESSED_EXTENSION_CONTEXT, | 856 Feature::BLESSED_EXTENSION_CONTEXT, |
857 GURL()).is_available()); | 857 GURL()).is_available()); |
858 EXPECT_FALSE(extension_api->IsAvailable("pageAction", | 858 EXPECT_FALSE(extension_api->IsAvailable("pageAction", |
859 extension.get(), | 859 extension.get(), |
860 Feature::BLESSED_EXTENSION_CONTEXT, | 860 Feature::BLESSED_EXTENSION_CONTEXT, |
861 GURL()).is_available()); | 861 GURL()).is_available()); |
862 } | 862 } |
863 | 863 |
864 } // namespace extensions | 864 } // namespace extensions |
OLD | NEW |