| 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 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/common/extensions/api/commands/commands_handler.h" | 16 #include "chrome/common/extensions/api/commands/commands_handler.h" |
| 17 #include "chrome/common/extensions/api/content_scripts/content_scripts_handler.h
" |
| 17 #include "chrome/common/extensions/api/extension_action/action_info.h" | 18 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 18 #include "chrome/common/extensions/command.h" | 19 #include "chrome/common/extensions/command.h" |
| 19 #include "chrome/common/extensions/extension_file_util.h" | 20 #include "chrome/common/extensions/extension_file_util.h" |
| 20 #include "chrome/common/extensions/extension_manifest_constants.h" | 21 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 21 #include "chrome/common/extensions/extension_resource.h" | 22 #include "chrome/common/extensions/extension_resource.h" |
| 22 #include "chrome/common/extensions/features/feature.h" | 23 #include "chrome/common/extensions/features/feature.h" |
| 23 #include "chrome/common/extensions/manifest_handler.h" | 24 #include "chrome/common/extensions/manifest_handler.h" |
| 24 #include "chrome/common/extensions/permissions/api_permission.h" | 25 #include "chrome/common/extensions/permissions/api_permission.h" |
| 25 #include "chrome/common/extensions/permissions/permission_set.h" | 26 #include "chrome/common/extensions/permissions/permission_set.h" |
| 26 #include "chrome/common/extensions/permissions/socket_permission.h" | 27 #include "chrome/common/extensions/permissions/socket_permission.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 manifest, Extension::INTERNAL, Extension::NO_FLAGS, &error); | 118 manifest, Extension::INTERNAL, Extension::NO_FLAGS, &error); |
| 118 EXPECT_FALSE(extension); | 119 EXPECT_FALSE(extension); |
| 119 EXPECT_EQ(expected_error, error); | 120 EXPECT_EQ(expected_error, error); |
| 120 } | 121 } |
| 121 | 122 |
| 122 } | 123 } |
| 123 | 124 |
| 124 class ExtensionTest : public testing::Test { | 125 class ExtensionTest : public testing::Test { |
| 125 protected: | 126 protected: |
| 126 virtual void SetUp() OVERRIDE { | 127 virtual void SetUp() OVERRIDE { |
| 128 testing::Test::SetUp(); |
| 129 ManifestHandler::Register(extension_manifest_keys::kContentScripts, |
| 130 new ContentScriptsHandler); |
| 127 ManifestHandler::Register(extension_manifest_keys::kCommands, | 131 ManifestHandler::Register(extension_manifest_keys::kCommands, |
| 128 new CommandsHandler); | 132 new CommandsHandler); |
| 129 } | 133 } |
| 130 }; | 134 }; |
| 131 | 135 |
| 132 // We persist location values in the preferences, so this is a sanity test that | 136 // We persist location values in the preferences, so this is a sanity test that |
| 133 // someone doesn't accidentally change them. | 137 // someone doesn't accidentally change them. |
| 134 TEST_F(ExtensionTest, LocationValuesTest) { | 138 TEST_F(ExtensionTest, LocationValuesTest) { |
| 135 ASSERT_EQ(0, Extension::INVALID); | 139 ASSERT_EQ(0, Extension::INVALID); |
| 136 ASSERT_EQ(1, Extension::INTERNAL); | 140 ASSERT_EQ(1, Extension::INTERNAL); |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 extension = LoadManifest("permissions", "permissions_http_scheme.json", | 703 extension = LoadManifest("permissions", "permissions_http_scheme.json", |
| 700 Extension::ALLOW_FILE_ACCESS); | 704 Extension::ALLOW_FILE_ACCESS); |
| 701 EXPECT_FALSE(extension->wants_file_access()); | 705 EXPECT_FALSE(extension->wants_file_access()); |
| 702 EXPECT_FALSE(extension->CanExecuteScriptOnPage( | 706 EXPECT_FALSE(extension->CanExecuteScriptOnPage( |
| 703 file_url, file_url, -1, NULL, NULL)); | 707 file_url, file_url, -1, NULL, NULL)); |
| 704 | 708 |
| 705 // <all_urls> content script match | 709 // <all_urls> content script match |
| 706 extension = LoadManifest("permissions", "content_script_all_urls.json"); | 710 extension = LoadManifest("permissions", "content_script_all_urls.json"); |
| 707 EXPECT_TRUE(extension->wants_file_access()); | 711 EXPECT_TRUE(extension->wants_file_access()); |
| 708 EXPECT_FALSE(extension->CanExecuteScriptOnPage( | 712 EXPECT_FALSE(extension->CanExecuteScriptOnPage( |
| 709 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); | 713 file_url, |
| 714 file_url, |
| 715 -1, |
| 716 &ContentScriptsInfo::GetContentScripts(extension)[0], |
| 717 NULL)); |
| 710 extension = LoadManifest("permissions", "content_script_all_urls.json", | 718 extension = LoadManifest("permissions", "content_script_all_urls.json", |
| 711 Extension::ALLOW_FILE_ACCESS); | 719 Extension::ALLOW_FILE_ACCESS); |
| 712 EXPECT_TRUE(extension->wants_file_access()); | 720 EXPECT_TRUE(extension->wants_file_access()); |
| 713 EXPECT_TRUE(extension->CanExecuteScriptOnPage( | 721 EXPECT_TRUE(extension->CanExecuteScriptOnPage( |
| 714 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); | 722 file_url, |
| 723 file_url, |
| 724 -1, |
| 725 &ContentScriptsInfo::GetContentScripts(extension)[0], |
| 726 NULL)); |
| 715 | 727 |
| 716 // file:///* content script match | 728 // file:///* content script match |
| 717 extension = LoadManifest("permissions", "content_script_file_scheme.json"); | 729 extension = LoadManifest("permissions", "content_script_file_scheme.json"); |
| 718 EXPECT_TRUE(extension->wants_file_access()); | 730 EXPECT_TRUE(extension->wants_file_access()); |
| 719 EXPECT_FALSE(extension->CanExecuteScriptOnPage( | 731 EXPECT_FALSE(extension->CanExecuteScriptOnPage( |
| 720 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); | 732 file_url, |
| 733 file_url, |
| 734 -1, |
| 735 &ContentScriptsInfo::GetContentScripts(extension)[0], |
| 736 NULL)); |
| 721 extension = LoadManifest("permissions", "content_script_file_scheme.json", | 737 extension = LoadManifest("permissions", "content_script_file_scheme.json", |
| 722 Extension::ALLOW_FILE_ACCESS); | 738 Extension::ALLOW_FILE_ACCESS); |
| 723 EXPECT_TRUE(extension->wants_file_access()); | 739 EXPECT_TRUE(extension->wants_file_access()); |
| 724 EXPECT_TRUE(extension->CanExecuteScriptOnPage( | 740 EXPECT_TRUE(extension->CanExecuteScriptOnPage( |
| 725 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); | 741 file_url, |
| 742 file_url, |
| 743 -1, |
| 744 &ContentScriptsInfo::GetContentScripts(extension)[0], |
| 745 NULL)); |
| 726 | 746 |
| 727 // http://* content script match | 747 // http://* content script match |
| 728 extension = LoadManifest("permissions", "content_script_http_scheme.json"); | 748 extension = LoadManifest("permissions", "content_script_http_scheme.json"); |
| 729 EXPECT_FALSE(extension->wants_file_access()); | 749 EXPECT_FALSE(extension->wants_file_access()); |
| 730 EXPECT_FALSE(extension->CanExecuteScriptOnPage( | 750 EXPECT_FALSE(extension->CanExecuteScriptOnPage( |
| 731 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); | 751 file_url, |
| 752 file_url, |
| 753 -1, |
| 754 &ContentScriptsInfo::GetContentScripts(extension)[0], |
| 755 NULL)); |
| 732 extension = LoadManifest("permissions", "content_script_http_scheme.json", | 756 extension = LoadManifest("permissions", "content_script_http_scheme.json", |
| 733 Extension::ALLOW_FILE_ACCESS); | 757 Extension::ALLOW_FILE_ACCESS); |
| 734 EXPECT_FALSE(extension->wants_file_access()); | 758 EXPECT_FALSE(extension->wants_file_access()); |
| 735 EXPECT_FALSE(extension->CanExecuteScriptOnPage( | 759 EXPECT_FALSE(extension->CanExecuteScriptOnPage( |
| 736 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); | 760 file_url, |
| 761 file_url, |
| 762 -1, |
| 763 &ContentScriptsInfo::GetContentScripts(extension)[0], |
| 764 NULL)); |
| 737 } | 765 } |
| 738 | 766 |
| 739 TEST_F(ExtensionTest, ExtraFlags) { | 767 TEST_F(ExtensionTest, ExtraFlags) { |
| 740 scoped_refptr<Extension> extension; | 768 scoped_refptr<Extension> extension; |
| 741 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE); | 769 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE); |
| 742 EXPECT_TRUE(extension->from_webstore()); | 770 EXPECT_TRUE(extension->from_webstore()); |
| 743 | 771 |
| 744 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK); | 772 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK); |
| 745 EXPECT_TRUE(extension->from_bookmark()); | 773 EXPECT_TRUE(extension->from_bookmark()); |
| 746 | 774 |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 scoped_refptr<Extension> extension( | 1318 scoped_refptr<Extension> extension( |
| 1291 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1319 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
| 1292 Extension::INTERNAL, 2, FilePath(), | 1320 Extension::INTERNAL, 2, FilePath(), |
| 1293 Extension::NO_FLAGS)); | 1321 Extension::NO_FLAGS)); |
| 1294 if (extension) | 1322 if (extension) |
| 1295 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1323 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1296 } | 1324 } |
| 1297 #endif // !defined(OS_CHROMEOS) | 1325 #endif // !defined(OS_CHROMEOS) |
| 1298 | 1326 |
| 1299 } // namespace extensions | 1327 } // namespace extensions |
| OLD | NEW |