| 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/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #if defined(TOOLKIT_GTK) | 7 #if defined(TOOLKIT_GTK) |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 | 568 |
| 569 // Forbid options page with non-(http|https) scheme in hosted app. | 569 // Forbid options page with non-(http|https) scheme in hosted app. |
| 570 LoadAndExpectError("hosted_app_file_options.json", | 570 LoadAndExpectError("hosted_app_file_options.json", |
| 571 errors::kInvalidOptionsPageInHostedApp); | 571 errors::kInvalidOptionsPageInHostedApp); |
| 572 | 572 |
| 573 // Forbid absolute URL for options page in packaged apps. | 573 // Forbid absolute URL for options page in packaged apps. |
| 574 LoadAndExpectError("packaged_app_absolute_options.json", | 574 LoadAndExpectError("packaged_app_absolute_options.json", |
| 575 errors::kInvalidOptionsPageExpectUrlInPackage); | 575 errors::kInvalidOptionsPageExpectUrlInPackage); |
| 576 } | 576 } |
| 577 | 577 |
| 578 TEST_F(ExtensionManifestTest, HostedAppPermissions) { | |
| 579 std::string error; | |
| 580 scoped_ptr<DictionaryValue> manifest( | |
| 581 LoadManifestFile("hosted_app_absolute_options.json", &error)); | |
| 582 ASSERT_TRUE(manifest.get()); | |
| 583 ListValue* permissions = NULL; | |
| 584 ASSERT_TRUE(manifest->GetList("permissions", &permissions)); | |
| 585 | |
| 586 int platform_app = ExtensionAPIPermission::kTypePlatformApp; | |
| 587 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); | |
| 588 ExtensionAPIPermissionSet api_perms = info->GetAll(); | |
| 589 for (ExtensionAPIPermissionSet::iterator i = api_perms.begin(); | |
| 590 i != api_perms.end(); ++i) { | |
| 591 if (*i == ExtensionAPIPermission::kExperimental) | |
| 592 continue; | |
| 593 | |
| 594 ExtensionAPIPermission* permission = info->GetByID(*i); | |
| 595 const char* name = permission->name(); | |
| 596 StringValue* p = new StringValue(name); | |
| 597 permissions->Clear(); | |
| 598 permissions->Append(p); | |
| 599 | |
| 600 // Some permissions are only available to component hosted apps. | |
| 601 if (permission->is_component_only()) { | |
| 602 LoadAndExpectError(Manifest(manifest.get(), name), | |
| 603 errors::kPermissionNotAllowed, | |
| 604 Extension::INTERNAL); | |
| 605 scoped_refptr<Extension> extension( | |
| 606 LoadAndExpectSuccess(Manifest(manifest.get(), name), | |
| 607 Extension::COMPONENT)); | |
| 608 EXPECT_TRUE(extension->GetActivePermissions()->HasAPIPermission( | |
| 609 permission->id())); | |
| 610 | |
| 611 } else if (permission->type_restrictions() == platform_app) { | |
| 612 LoadAndExpectError(Manifest(manifest.get(), name), | |
| 613 errors::kPermissionNotAllowed, | |
| 614 Extension::INTERNAL, | |
| 615 Extension::STRICT_ERROR_CHECKS); | |
| 616 } else if (!permission->supports_hosted_apps()) { | |
| 617 // Most normal extension permissions also aren't available to hosted apps. | |
| 618 // For these, the error is only reported in strict mode for legacy | |
| 619 // reasons: crbug.com/101993. | |
| 620 LoadAndExpectError(Manifest(manifest.get(), name), | |
| 621 errors::kPermissionNotAllowed, | |
| 622 Extension::INTERNAL, | |
| 623 Extension::STRICT_ERROR_CHECKS); | |
| 624 scoped_refptr<Extension> extension( | |
| 625 LoadAndExpectSuccess(Manifest(manifest.get(), name), | |
| 626 Extension::INTERNAL)); | |
| 627 EXPECT_FALSE(extension->GetActivePermissions()->HasAPIPermission( | |
| 628 permission->id())); | |
| 629 | |
| 630 // These permissions are also allowed for component hosted apps. | |
| 631 extension = LoadAndExpectSuccess(Manifest(manifest.get(), name), | |
| 632 Extension::COMPONENT); | |
| 633 EXPECT_TRUE(extension->GetActivePermissions()->HasAPIPermission( | |
| 634 permission->id())); | |
| 635 | |
| 636 } else { | |
| 637 scoped_refptr<Extension> extension( | |
| 638 LoadAndExpectSuccess(Manifest(manifest.get(), name))); | |
| 639 EXPECT_TRUE(extension->GetActivePermissions()->HasAPIPermission( | |
| 640 permission->id())); | |
| 641 } | |
| 642 } | |
| 643 } | |
| 644 | |
| 645 TEST_F(ExtensionManifestTest, ComponentOnlyPermission) { | |
| 646 std::string error; | |
| 647 scoped_ptr<DictionaryValue> manifest( | |
| 648 LoadManifestFile("init_valid_minimal.json", &error)); | |
| 649 ASSERT_TRUE(manifest.get()); | |
| 650 ListValue* permissions = new ListValue(); | |
| 651 manifest->Set("permissions", permissions); | |
| 652 | |
| 653 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); | |
| 654 ExtensionAPIPermissionSet api_perms = info->GetAll(); | |
| 655 for (ExtensionAPIPermissionSet::iterator i = api_perms.begin(); | |
| 656 i != api_perms.end(); ++i) { | |
| 657 if (*i == ExtensionAPIPermission::kExperimental) | |
| 658 continue; | |
| 659 | |
| 660 ExtensionAPIPermission* permission = info->GetByID(*i); | |
| 661 const char* name = permission->name(); | |
| 662 StringValue* p = new StringValue(name); | |
| 663 permissions->Clear(); | |
| 664 permissions->Append(p); | |
| 665 | |
| 666 if (!permission->is_component_only()) | |
| 667 continue; | |
| 668 | |
| 669 // Component-only extensions should only be enabled for component | |
| 670 // extensions. | |
| 671 LoadAndExpectError(Manifest(manifest.get(), name), | |
| 672 errors::kPermissionNotAllowed); | |
| 673 LoadAndExpectSuccess(Manifest(manifest.get(), name), | |
| 674 Extension::COMPONENT); | |
| 675 } | |
| 676 } | |
| 677 | |
| 678 TEST_F(ExtensionManifestTest, AllowUnrecognizedPermissions) { | 578 TEST_F(ExtensionManifestTest, AllowUnrecognizedPermissions) { |
| 679 std::string error; | 579 std::string error; |
| 680 scoped_ptr<DictionaryValue> manifest( | 580 scoped_ptr<DictionaryValue> manifest( |
| 681 LoadManifestFile("valid_app.json", &error)); | 581 LoadManifestFile("valid_app.json", &error)); |
| 682 ListValue* permissions = NULL; | 582 ListValue* permissions = NULL; |
| 683 ASSERT_TRUE(manifest->GetList("permissions", &permissions)); | 583 ASSERT_TRUE(manifest->GetList("permissions", &permissions)); |
| 684 permissions->Append(new StringValue("not-a-valid-permission")); | 584 permissions->Append(new StringValue("not-a-valid-permission")); |
| 685 LoadAndExpectSuccess(Manifest(manifest.get(), "")); | 585 LoadAndExpectSuccess(Manifest(manifest.get(), "")); |
| 686 } | 586 } |
| 687 | 587 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 EXPECT_EQ("", extension->page_action()->id()); | 958 EXPECT_EQ("", extension->page_action()->id()); |
| 1059 EXPECT_EQ(0u, extension->page_action()->icon_paths()->size()); | 959 EXPECT_EQ(0u, extension->page_action()->icon_paths()->size()); |
| 1060 EXPECT_EQ("", extension->page_action()->GetTitle( | 960 EXPECT_EQ("", extension->page_action()->GetTitle( |
| 1061 ExtensionAction::kDefaultTabId)); | 961 ExtensionAction::kDefaultTabId)); |
| 1062 EXPECT_FALSE(extension->page_action()->HasPopup( | 962 EXPECT_FALSE(extension->page_action()->HasPopup( |
| 1063 ExtensionAction::kDefaultTabId)); | 963 ExtensionAction::kDefaultTabId)); |
| 1064 | 964 |
| 1065 LoadAndExpectError("page_action_manifest_version_2b.json", | 965 LoadAndExpectError("page_action_manifest_version_2b.json", |
| 1066 errors::kInvalidPageActionPopup); | 966 errors::kInvalidPageActionPopup); |
| 1067 } | 967 } |
| OLD | NEW |