| 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/extension_action/action_info.h" | 17 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 18 #include "chrome/common/extensions/command.h" | 18 #include "chrome/common/extensions/command.h" |
| 19 #include "chrome/common/extensions/extension_file_util.h" | 19 #include "chrome/common/extensions/extension_file_util.h" |
| 20 #include "chrome/common/extensions/extension_manifest_constants.h" | 20 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 21 #include "chrome/common/extensions/extension_resource.h" | 21 #include "chrome/common/extensions/extension_resource.h" |
| 22 #include "chrome/common/extensions/features/feature.h" | 22 #include "chrome/common/extensions/features/feature.h" |
| 23 #include "chrome/common/extensions/manifest.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" |
| 27 #include "chrome/common/extensions/permissions/usb_device_permission.h" | 28 #include "chrome/common/extensions/permissions/usb_device_permission.h" |
| 28 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 29 #include "extensions/common/error_utils.h" | 30 #include "extensions/common/error_utils.h" |
| 30 #include "googleurl/src/gurl.h" | 31 #include "googleurl/src/gurl.h" |
| 31 #include "net/base/mime_sniffer.h" | 32 #include "net/base/mime_sniffer.h" |
| 32 #include "net/base/mock_host_resolver.h" | 33 #include "net/base/mock_host_resolver.h" |
| 33 #include "skia/ext/image_operations.h" | 34 #include "skia/ext/image_operations.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "third_party/skia/include/core/SkBitmap.h" | 36 #include "third_party/skia/include/core/SkBitmap.h" |
| 36 #include "ui/gfx/codec/png_codec.h" | 37 #include "ui/gfx/codec/png_codec.h" |
| 37 | 38 |
| 38 using content::SocketPermissionRequest; | 39 using content::SocketPermissionRequest; |
| 39 | 40 |
| 40 namespace keys = extension_manifest_keys; | 41 namespace keys = extension_manifest_keys; |
| 41 namespace values = extension_manifest_values; | 42 namespace values = extension_manifest_values; |
| 42 namespace errors = extension_manifest_errors; | 43 namespace errors = extension_manifest_errors; |
| 43 | 44 |
| 44 namespace extensions { | 45 namespace extensions { |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 scoped_refptr<Extension> LoadManifestUnchecked( | 48 scoped_refptr<Extension> LoadManifestUnchecked( |
| 48 const std::string& dir, | 49 const std::string& dir, |
| 49 const std::string& test_file, | 50 const std::string& test_file, |
| 50 Extension::Location location, | 51 Manifest::Location location, |
| 51 int extra_flags, | 52 int extra_flags, |
| 52 std::string* error) { | 53 std::string* error) { |
| 53 FilePath path; | 54 FilePath path; |
| 54 PathService::Get(chrome::DIR_TEST_DATA, &path); | 55 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 55 path = path.AppendASCII("extensions") | 56 path = path.AppendASCII("extensions") |
| 56 .AppendASCII(dir) | 57 .AppendASCII(dir) |
| 57 .AppendASCII(test_file); | 58 .AppendASCII(test_file); |
| 58 | 59 |
| 59 JSONFileValueSerializer serializer(path); | 60 JSONFileValueSerializer serializer(path); |
| 60 scoped_ptr<Value> result(serializer.Deserialize(NULL, error)); | 61 scoped_ptr<Value> result(serializer.Deserialize(NULL, error)); |
| 61 if (!result.get()) | 62 if (!result.get()) |
| 62 return NULL; | 63 return NULL; |
| 63 | 64 |
| 64 scoped_refptr<Extension> extension = Extension::Create( | 65 scoped_refptr<Extension> extension = Extension::Create( |
| 65 path.DirName(), location, *static_cast<DictionaryValue*>(result.get()), | 66 path.DirName(), location, *static_cast<DictionaryValue*>(result.get()), |
| 66 extra_flags, error); | 67 extra_flags, error); |
| 67 return extension; | 68 return extension; |
| 68 } | 69 } |
| 69 | 70 |
| 70 static scoped_refptr<Extension> LoadManifest(const std::string& dir, | 71 static scoped_refptr<Extension> LoadManifest(const std::string& dir, |
| 71 const std::string& test_file, | 72 const std::string& test_file, |
| 72 Extension::Location location, | 73 Manifest::Location location, |
| 73 int extra_flags) { | 74 int extra_flags) { |
| 74 std::string error; | 75 std::string error; |
| 75 scoped_refptr<Extension> extension = LoadManifestUnchecked(dir, test_file, | 76 scoped_refptr<Extension> extension = LoadManifestUnchecked(dir, test_file, |
| 76 location, extra_flags, &error); | 77 location, extra_flags, &error); |
| 77 | 78 |
| 78 EXPECT_TRUE(extension) << test_file << ":" << error; | 79 EXPECT_TRUE(extension) << test_file << ":" << error; |
| 79 return extension; | 80 return extension; |
| 80 } | 81 } |
| 81 | 82 |
| 82 static scoped_refptr<Extension> LoadManifest(const std::string& dir, | 83 static scoped_refptr<Extension> LoadManifest(const std::string& dir, |
| 83 const std::string& test_file, | 84 const std::string& test_file, |
| 84 int extra_flags) { | 85 int extra_flags) { |
| 85 return LoadManifest(dir, test_file, Extension::INVALID, extra_flags); | 86 return LoadManifest(dir, test_file, Manifest::INVALID_LOCATION, extra_flags); |
| 86 } | 87 } |
| 87 | 88 |
| 88 static scoped_refptr<Extension> LoadManifest(const std::string& dir, | 89 static scoped_refptr<Extension> LoadManifest(const std::string& dir, |
| 89 const std::string& test_file) { | 90 const std::string& test_file) { |
| 90 return LoadManifest(dir, test_file, Extension::NO_FLAGS); | 91 return LoadManifest(dir, test_file, Extension::NO_FLAGS); |
| 91 } | 92 } |
| 92 | 93 |
| 93 static scoped_refptr<Extension> LoadManifestStrict( | 94 static scoped_refptr<Extension> LoadManifestStrict( |
| 94 const std::string& dir, | 95 const std::string& dir, |
| 95 const std::string& test_file) { | 96 const std::string& test_file) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 107 } | 108 } |
| 108 ADD_FAILURE() << "Expected manifest in " << manifest | 109 ADD_FAILURE() << "Expected manifest in " << manifest |
| 109 << " to include a page_action section."; | 110 << " to include a page_action section."; |
| 110 return scoped_ptr<ActionInfo>(); | 111 return scoped_ptr<ActionInfo>(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 static void LoadActionAndExpectError(const std::string& manifest, | 114 static void LoadActionAndExpectError(const std::string& manifest, |
| 114 const std::string& expected_error) { | 115 const std::string& expected_error) { |
| 115 std::string error; | 116 std::string error; |
| 116 scoped_refptr<Extension> extension = LoadManifestUnchecked("page_action", | 117 scoped_refptr<Extension> extension = LoadManifestUnchecked("page_action", |
| 117 manifest, Extension::INTERNAL, Extension::NO_FLAGS, &error); | 118 manifest, Manifest::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 { |
| 127 ManifestHandler::Register(extension_manifest_keys::kCommands, | 128 ManifestHandler::Register(extension_manifest_keys::kCommands, |
| 128 new CommandsHandler); | 129 new CommandsHandler); |
| 129 } | 130 } |
| 130 }; | 131 }; |
| 131 | 132 |
| 132 // We persist location values in the preferences, so this is a sanity test that | 133 // We persist location values in the preferences, so this is a sanity test that |
| 133 // someone doesn't accidentally change them. | 134 // someone doesn't accidentally change them. |
| 134 TEST_F(ExtensionTest, LocationValuesTest) { | 135 TEST_F(ExtensionTest, LocationValuesTest) { |
| 135 ASSERT_EQ(0, Extension::INVALID); | 136 ASSERT_EQ(0, Manifest::INVALID_LOCATION); |
| 136 ASSERT_EQ(1, Extension::INTERNAL); | 137 ASSERT_EQ(1, Manifest::INTERNAL); |
| 137 ASSERT_EQ(2, Extension::EXTERNAL_PREF); | 138 ASSERT_EQ(2, Manifest::EXTERNAL_PREF); |
| 138 ASSERT_EQ(3, Extension::EXTERNAL_REGISTRY); | 139 ASSERT_EQ(3, Manifest::EXTERNAL_REGISTRY); |
| 139 ASSERT_EQ(4, Extension::LOAD); | 140 ASSERT_EQ(4, Manifest::LOAD); |
| 140 ASSERT_EQ(5, Extension::COMPONENT); | 141 ASSERT_EQ(5, Manifest::COMPONENT); |
| 141 ASSERT_EQ(6, Extension::EXTERNAL_PREF_DOWNLOAD); | 142 ASSERT_EQ(6, Manifest::EXTERNAL_PREF_DOWNLOAD); |
| 142 ASSERT_EQ(7, Extension::EXTERNAL_POLICY_DOWNLOAD); | 143 ASSERT_EQ(7, Manifest::EXTERNAL_POLICY_DOWNLOAD); |
| 143 } | 144 } |
| 144 | 145 |
| 145 TEST_F(ExtensionTest, LocationPriorityTest) { | 146 TEST_F(ExtensionTest, LocationPriorityTest) { |
| 146 for (int i = 0; i < Extension::NUM_LOCATIONS; i++) { | 147 for (int i = 0; i < Manifest::NUM_LOCATIONS; i++) { |
| 147 Extension::Location loc = static_cast<Extension::Location>(i); | 148 Manifest::Location loc = static_cast<Manifest::Location>(i); |
| 148 | 149 |
| 149 // INVALID is not a valid location. | 150 // INVALID is not a valid location. |
| 150 if (loc == Extension::INVALID) | 151 if (loc == Manifest::INVALID_LOCATION) |
| 151 continue; | 152 continue; |
| 152 | 153 |
| 153 // Comparing a location that has no rank will hit a CHECK. Do a | 154 // Comparing a location that has no rank will hit a CHECK. Do a |
| 154 // compare with every valid location, to be sure each one is covered. | 155 // compare with every valid location, to be sure each one is covered. |
| 155 | 156 |
| 156 // Check that no install source can override a componenet extension. | 157 // Check that no install source can override a componenet extension. |
| 157 ASSERT_EQ(Extension::COMPONENT, | 158 ASSERT_EQ(Manifest::COMPONENT, |
| 158 Extension::GetHigherPriorityLocation(Extension::COMPONENT, loc)); | 159 Manifest::GetHigherPriorityLocation(Manifest::COMPONENT, loc)); |
| 159 ASSERT_EQ(Extension::COMPONENT, | 160 ASSERT_EQ(Manifest::COMPONENT, |
| 160 Extension::GetHigherPriorityLocation(loc, Extension::COMPONENT)); | 161 Manifest::GetHigherPriorityLocation(loc, Manifest::COMPONENT)); |
| 161 | 162 |
| 162 // Check that any source can override a user install. This might change | 163 // Check that any source can override a user install. This might change |
| 163 // in the future, in which case this test should be updated. | 164 // in the future, in which case this test should be updated. |
| 164 ASSERT_EQ(loc, | 165 ASSERT_EQ(loc, |
| 165 Extension::GetHigherPriorityLocation(Extension::INTERNAL, loc)); | 166 Manifest::GetHigherPriorityLocation(Manifest::INTERNAL, loc)); |
| 166 ASSERT_EQ(loc, | 167 ASSERT_EQ(loc, |
| 167 Extension::GetHigherPriorityLocation(loc, Extension::INTERNAL)); | 168 Manifest::GetHigherPriorityLocation(loc, Manifest::INTERNAL)); |
| 168 } | 169 } |
| 169 | 170 |
| 170 // Check a few interesting cases that we know can happen: | 171 // Check a few interesting cases that we know can happen: |
| 171 ASSERT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, | 172 ASSERT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 172 Extension::GetHigherPriorityLocation( | 173 Manifest::GetHigherPriorityLocation( |
| 173 Extension::EXTERNAL_POLICY_DOWNLOAD, | 174 Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 174 Extension::EXTERNAL_PREF)); | 175 Manifest::EXTERNAL_PREF)); |
| 175 | 176 |
| 176 ASSERT_EQ(Extension::EXTERNAL_PREF, | 177 ASSERT_EQ(Manifest::EXTERNAL_PREF, |
| 177 Extension::GetHigherPriorityLocation( | 178 Manifest::GetHigherPriorityLocation( |
| 178 Extension::INTERNAL, | 179 Manifest::INTERNAL, |
| 179 Extension::EXTERNAL_PREF)); | 180 Manifest::EXTERNAL_PREF)); |
| 180 } | 181 } |
| 181 | 182 |
| 182 TEST_F(ExtensionTest, GetResourceURLAndPath) { | 183 TEST_F(ExtensionTest, GetResourceURLAndPath) { |
| 183 scoped_refptr<Extension> extension = LoadManifestStrict("empty_manifest", | 184 scoped_refptr<Extension> extension = LoadManifestStrict("empty_manifest", |
| 184 "empty.json"); | 185 "empty.json"); |
| 185 EXPECT_TRUE(extension.get()); | 186 EXPECT_TRUE(extension.get()); |
| 186 | 187 |
| 187 EXPECT_EQ(extension->url().spec() + "bar/baz.js", | 188 EXPECT_EQ(extension->url().spec() + "bar/baz.js", |
| 188 Extension::GetResourceURL(extension->url(), "bar/baz.js").spec()); | 189 Extension::GetResourceURL(extension->url(), "bar/baz.js").spec()); |
| 189 EXPECT_EQ(extension->url().spec() + "baz.js", | 190 EXPECT_EQ(extension->url().spec() + "baz.js", |
| 190 Extension::GetResourceURL(extension->url(), | 191 Extension::GetResourceURL(extension->url(), |
| 191 "bar/../baz.js").spec()); | 192 "bar/../baz.js").spec()); |
| 192 EXPECT_EQ(extension->url().spec() + "baz.js", | 193 EXPECT_EQ(extension->url().spec() + "baz.js", |
| 193 Extension::GetResourceURL(extension->url(), "../baz.js").spec()); | 194 Extension::GetResourceURL(extension->url(), "../baz.js").spec()); |
| 194 | 195 |
| 195 // Test that absolute-looking paths ("/"-prefixed) are pasted correctly. | 196 // Test that absolute-looking paths ("/"-prefixed) are pasted correctly. |
| 196 EXPECT_EQ(extension->url().spec() + "test.html", | 197 EXPECT_EQ(extension->url().spec() + "test.html", |
| 197 extension->GetResourceURL("/test.html").spec()); | 198 extension->GetResourceURL("/test.html").spec()); |
| 198 } | 199 } |
| 199 | 200 |
| 200 TEST_F(ExtensionTest, GetAbsolutePathNoError) { | 201 TEST_F(ExtensionTest, GetAbsolutePathNoError) { |
| 201 scoped_refptr<Extension> extension = LoadManifestStrict("absolute_path", | 202 scoped_refptr<Extension> extension = LoadManifestStrict("absolute_path", |
| 202 "absolute.json"); | 203 "absolute.json"); |
| 203 EXPECT_TRUE(extension.get()); | 204 EXPECT_TRUE(extension.get()); |
| 204 std::string err; | 205 std::string err; |
| 205 Extension::InstallWarningVector warnings; | 206 InstallWarning::Vector warnings; |
| 206 EXPECT_TRUE(extension_file_util::ValidateExtension(extension.get(), | 207 EXPECT_TRUE(extension_file_util::ValidateExtension(extension.get(), |
| 207 &err, &warnings)); | 208 &err, &warnings)); |
| 208 EXPECT_EQ(0U, warnings.size()); | 209 EXPECT_EQ(0U, warnings.size()); |
| 209 | 210 |
| 210 EXPECT_EQ(extension->path().AppendASCII("test.html").value(), | 211 EXPECT_EQ(extension->path().AppendASCII("test.html").value(), |
| 211 extension->GetResource("test.html").GetFilePath().value()); | 212 extension->GetResource("test.html").GetFilePath().value()); |
| 212 EXPECT_EQ(extension->path().AppendASCII("test.js").value(), | 213 EXPECT_EQ(extension->path().AppendASCII("test.js").value(), |
| 213 extension->GetResource("test.js").GetFilePath().value()); | 214 extension->GetResource("test.js").GetFilePath().value()); |
| 214 } | 215 } |
| 215 | 216 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 chrome::VersionInfo::CHANNEL_DEV); | 467 chrome::VersionInfo::CHANNEL_DEV); |
| 467 scoped_refptr<Extension> extension; | 468 scoped_refptr<Extension> extension; |
| 468 std::string error; | 469 std::string error; |
| 469 | 470 |
| 470 extension = LoadManifest("socket_permissions", "empty.json"); | 471 extension = LoadManifest("socket_permissions", "empty.json"); |
| 471 EXPECT_FALSE(CheckSocketPermission(extension, | 472 EXPECT_FALSE(CheckSocketPermission(extension, |
| 472 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); | 473 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); |
| 473 | 474 |
| 474 extension = LoadManifestUnchecked("socket_permissions", | 475 extension = LoadManifestUnchecked("socket_permissions", |
| 475 "socket1.json", | 476 "socket1.json", |
| 476 Extension::INTERNAL, Extension::NO_FLAGS, | 477 Manifest::INTERNAL, Extension::NO_FLAGS, |
| 477 &error); | 478 &error); |
| 478 EXPECT_TRUE(extension == NULL); | 479 EXPECT_TRUE(extension == NULL); |
| 479 ASSERT_EQ(ErrorUtils::FormatErrorMessage( | 480 ASSERT_EQ(ErrorUtils::FormatErrorMessage( |
| 480 errors::kInvalidPermission, "socket"), error); | 481 errors::kInvalidPermission, "socket"), error); |
| 481 | 482 |
| 482 extension = LoadManifest("socket_permissions", "socket2.json"); | 483 extension = LoadManifest("socket_permissions", "socket2.json"); |
| 483 EXPECT_TRUE(CheckSocketPermission(extension, | 484 EXPECT_TRUE(CheckSocketPermission(extension, |
| 484 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); | 485 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); |
| 485 EXPECT_FALSE(CheckSocketPermission( | 486 EXPECT_FALSE(CheckSocketPermission( |
| 486 extension, SocketPermissionRequest::UDP_BIND, "", 80)); | 487 extension, SocketPermissionRequest::UDP_BIND, "", 80)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 511 FilePath path; | 512 FilePath path; |
| 512 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); | 513 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 513 path = path.AppendASCII("extensions"); | 514 path = path.AppendASCII("extensions"); |
| 514 | 515 |
| 515 // Initialize the Extension. | 516 // Initialize the Extension. |
| 516 std::string errors; | 517 std::string errors; |
| 517 DictionaryValue values; | 518 DictionaryValue values; |
| 518 values.SetString(keys::kName, "test"); | 519 values.SetString(keys::kName, "test"); |
| 519 values.SetString(keys::kVersion, "0.1"); | 520 values.SetString(keys::kVersion, "0.1"); |
| 520 scoped_refptr<Extension> extension(Extension::Create( | 521 scoped_refptr<Extension> extension(Extension::Create( |
| 521 path, Extension::INVALID, values, Extension::NO_FLAGS, &errors)); | 522 path, Manifest::INVALID_LOCATION, values, Extension::NO_FLAGS, &errors)); |
| 522 ASSERT_TRUE(extension.get()); | 523 ASSERT_TRUE(extension.get()); |
| 523 | 524 |
| 524 // Create an ExtensionResource pointing at an icon. | 525 // Create an ExtensionResource pointing at an icon. |
| 525 FilePath icon_relative_path(FILE_PATH_LITERAL("icon3.png")); | 526 FilePath icon_relative_path(FILE_PATH_LITERAL("icon3.png")); |
| 526 ExtensionResource resource(extension->id(), | 527 ExtensionResource resource(extension->id(), |
| 527 extension->path(), | 528 extension->path(), |
| 528 icon_relative_path); | 529 icon_relative_path); |
| 529 | 530 |
| 530 // Read in the icon file. | 531 // Read in the icon file. |
| 531 FilePath icon_absolute_path = extension->path().Append(icon_relative_path); | 532 FilePath icon_absolute_path = extension->path().Append(icon_relative_path); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 EXPECT_TRUE(Blocked(extension, favicon_url)); | 898 EXPECT_TRUE(Blocked(extension, favicon_url)); |
| 898 extension = LoadManifest("script_and_capture", | 899 extension = LoadManifest("script_and_capture", |
| 899 "extension_wildcard_settings.json"); | 900 "extension_wildcard_settings.json"); |
| 900 EXPECT_TRUE(Blocked(extension, settings_url)); | 901 EXPECT_TRUE(Blocked(extension, settings_url)); |
| 901 | 902 |
| 902 // Having chrome://*/ should not work for regular extensions. Note that | 903 // Having chrome://*/ should not work for regular extensions. Note that |
| 903 // for favicon access, we require the explicit pattern chrome://favicon/*. | 904 // for favicon access, we require the explicit pattern chrome://favicon/*. |
| 904 std::string error; | 905 std::string error; |
| 905 extension = LoadManifestUnchecked("script_and_capture", | 906 extension = LoadManifestUnchecked("script_and_capture", |
| 906 "extension_wildcard_chrome.json", | 907 "extension_wildcard_chrome.json", |
| 907 Extension::INTERNAL, Extension::NO_FLAGS, | 908 Manifest::INTERNAL, Extension::NO_FLAGS, |
| 908 &error); | 909 &error); |
| 909 EXPECT_TRUE(extension == NULL); | 910 EXPECT_TRUE(extension == NULL); |
| 910 EXPECT_EQ(ErrorUtils::FormatErrorMessage( | 911 EXPECT_EQ(ErrorUtils::FormatErrorMessage( |
| 911 errors::kInvalidPermissionScheme, "chrome://*/"), error); | 912 errors::kInvalidPermissionScheme, "chrome://*/"), error); |
| 912 | 913 |
| 913 // Having chrome://favicon/* should not give you chrome://* | 914 // Having chrome://favicon/* should not give you chrome://* |
| 914 extension = LoadManifestStrict("script_and_capture", | 915 extension = LoadManifestStrict("script_and_capture", |
| 915 "extension_chrome_favicon_wildcard.json"); | 916 "extension_chrome_favicon_wildcard.json"); |
| 916 EXPECT_TRUE(Blocked(extension, settings_url)); | 917 EXPECT_TRUE(Blocked(extension, settings_url)); |
| 917 EXPECT_TRUE(CaptureOnly(extension, favicon_url)); | 918 EXPECT_TRUE(CaptureOnly(extension, favicon_url)); |
| 918 EXPECT_TRUE(Blocked(extension, about_url)); | 919 EXPECT_TRUE(Blocked(extension, about_url)); |
| 919 EXPECT_TRUE(extension->HasHostPermission(favicon_url)); | 920 EXPECT_TRUE(extension->HasHostPermission(favicon_url)); |
| 920 | 921 |
| 921 // Having http://favicon should not give you chrome://favicon | 922 // Having http://favicon should not give you chrome://favicon |
| 922 extension = LoadManifestStrict("script_and_capture", | 923 extension = LoadManifestStrict("script_and_capture", |
| 923 "extension_http_favicon.json"); | 924 "extension_http_favicon.json"); |
| 924 EXPECT_TRUE(Blocked(extension, settings_url)); | 925 EXPECT_TRUE(Blocked(extension, settings_url)); |
| 925 EXPECT_TRUE(Blocked(extension, favicon_url)); | 926 EXPECT_TRUE(Blocked(extension, favicon_url)); |
| 926 | 927 |
| 927 // Component extensions with <all_urls> should get everything. | 928 // Component extensions with <all_urls> should get everything. |
| 928 extension = LoadManifest("script_and_capture", "extension_component_all.json", | 929 extension = LoadManifest("script_and_capture", "extension_component_all.json", |
| 929 Extension::COMPONENT, Extension::NO_FLAGS); | 930 Manifest::COMPONENT, Extension::NO_FLAGS); |
| 930 EXPECT_TRUE(Allowed(extension, http_url)); | 931 EXPECT_TRUE(Allowed(extension, http_url)); |
| 931 EXPECT_TRUE(Allowed(extension, https_url)); | 932 EXPECT_TRUE(Allowed(extension, https_url)); |
| 932 EXPECT_TRUE(Allowed(extension, settings_url)); | 933 EXPECT_TRUE(Allowed(extension, settings_url)); |
| 933 EXPECT_TRUE(Allowed(extension, about_url)); | 934 EXPECT_TRUE(Allowed(extension, about_url)); |
| 934 EXPECT_TRUE(Allowed(extension, favicon_url)); | 935 EXPECT_TRUE(Allowed(extension, favicon_url)); |
| 935 EXPECT_TRUE(extension->HasHostPermission(favicon_url)); | 936 EXPECT_TRUE(extension->HasHostPermission(favicon_url)); |
| 936 | 937 |
| 937 // Component extensions should only get access to what they ask for. | 938 // Component extensions should only get access to what they ask for. |
| 938 extension = LoadManifest("script_and_capture", | 939 extension = LoadManifest("script_and_capture", |
| 939 "extension_component_google.json", Extension::COMPONENT, | 940 "extension_component_google.json", Manifest::COMPONENT, |
| 940 Extension::NO_FLAGS); | 941 Extension::NO_FLAGS); |
| 941 EXPECT_TRUE(Allowed(extension, http_url)); | 942 EXPECT_TRUE(Allowed(extension, http_url)); |
| 942 EXPECT_TRUE(Blocked(extension, https_url)); | 943 EXPECT_TRUE(Blocked(extension, https_url)); |
| 943 EXPECT_TRUE(Blocked(extension, file_url)); | 944 EXPECT_TRUE(Blocked(extension, file_url)); |
| 944 EXPECT_TRUE(Blocked(extension, settings_url)); | 945 EXPECT_TRUE(Blocked(extension, settings_url)); |
| 945 EXPECT_TRUE(Blocked(extension, favicon_url)); | 946 EXPECT_TRUE(Blocked(extension, favicon_url)); |
| 946 EXPECT_TRUE(Blocked(extension, about_url)); | 947 EXPECT_TRUE(Blocked(extension, about_url)); |
| 947 EXPECT_TRUE(Blocked(extension, extension_url)); | 948 EXPECT_TRUE(Blocked(extension, extension_url)); |
| 948 EXPECT_FALSE(extension->HasHostPermission(settings_url)); | 949 EXPECT_FALSE(extension->HasHostPermission(settings_url)); |
| 949 } | 950 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 EXTENSION, | 1052 EXTENSION, |
| 1052 APP, | 1053 APP, |
| 1053 USER_SCRIPT, | 1054 USER_SCRIPT, |
| 1054 THEME | 1055 THEME |
| 1055 }; | 1056 }; |
| 1056 | 1057 |
| 1057 static scoped_refptr<Extension> MakeSyncTestExtension( | 1058 static scoped_refptr<Extension> MakeSyncTestExtension( |
| 1058 SyncTestExtensionType type, | 1059 SyncTestExtensionType type, |
| 1059 const GURL& update_url, | 1060 const GURL& update_url, |
| 1060 const GURL& launch_url, | 1061 const GURL& launch_url, |
| 1061 Extension::Location location, | 1062 Manifest::Location location, |
| 1062 int num_plugins, | 1063 int num_plugins, |
| 1063 const FilePath& extension_path, | 1064 const FilePath& extension_path, |
| 1064 int creation_flags) { | 1065 int creation_flags) { |
| 1065 DictionaryValue source; | 1066 DictionaryValue source; |
| 1066 source.SetString(extension_manifest_keys::kName, | 1067 source.SetString(extension_manifest_keys::kName, |
| 1067 "PossiblySyncableExtension"); | 1068 "PossiblySyncableExtension"); |
| 1068 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); | 1069 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); |
| 1069 if (type == APP) | 1070 if (type == APP) |
| 1070 source.SetString(extension_manifest_keys::kApp, "true"); | 1071 source.SetString(extension_manifest_keys::kApp, "true"); |
| 1071 if (type == THEME) | 1072 if (type == THEME) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1100 | 1101 |
| 1101 static const char kValidUpdateUrl1[] = | 1102 static const char kValidUpdateUrl1[] = |
| 1102 "http://clients2.google.com/service/update2/crx"; | 1103 "http://clients2.google.com/service/update2/crx"; |
| 1103 static const char kValidUpdateUrl2[] = | 1104 static const char kValidUpdateUrl2[] = |
| 1104 "https://clients2.google.com/service/update2/crx"; | 1105 "https://clients2.google.com/service/update2/crx"; |
| 1105 } | 1106 } |
| 1106 | 1107 |
| 1107 TEST_F(ExtensionTest, GetSyncTypeNormalExtensionNoUpdateUrl) { | 1108 TEST_F(ExtensionTest, GetSyncTypeNormalExtensionNoUpdateUrl) { |
| 1108 scoped_refptr<Extension> extension( | 1109 scoped_refptr<Extension> extension( |
| 1109 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1110 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
| 1110 Extension::INTERNAL, 0, FilePath(), | 1111 Manifest::INTERNAL, 0, FilePath(), |
| 1111 Extension::NO_FLAGS)); | 1112 Extension::NO_FLAGS)); |
| 1112 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1113 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1113 } | 1114 } |
| 1114 | 1115 |
| 1115 TEST_F(ExtensionTest, GetSyncTypeUserScriptValidUpdateUrl) { | 1116 TEST_F(ExtensionTest, GetSyncTypeUserScriptValidUpdateUrl) { |
| 1116 scoped_refptr<Extension> extension( | 1117 scoped_refptr<Extension> extension( |
| 1117 MakeSyncTestExtension(USER_SCRIPT, GURL(kValidUpdateUrl1), GURL(), | 1118 MakeSyncTestExtension(USER_SCRIPT, GURL(kValidUpdateUrl1), GURL(), |
| 1118 Extension::INTERNAL, 0, FilePath(), | 1119 Manifest::INTERNAL, 0, FilePath(), |
| 1119 Extension::NO_FLAGS)); | 1120 Extension::NO_FLAGS)); |
| 1120 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1121 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1121 } | 1122 } |
| 1122 | 1123 |
| 1123 TEST_F(ExtensionTest, GetSyncTypeUserScriptNoUpdateUrl) { | 1124 TEST_F(ExtensionTest, GetSyncTypeUserScriptNoUpdateUrl) { |
| 1124 scoped_refptr<Extension> extension( | 1125 scoped_refptr<Extension> extension( |
| 1125 MakeSyncTestExtension(USER_SCRIPT, GURL(), GURL(), | 1126 MakeSyncTestExtension(USER_SCRIPT, GURL(), GURL(), |
| 1126 Extension::INTERNAL, 0, FilePath(), | 1127 Manifest::INTERNAL, 0, FilePath(), |
| 1127 Extension::NO_FLAGS)); | 1128 Extension::NO_FLAGS)); |
| 1128 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1129 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1129 } | 1130 } |
| 1130 | 1131 |
| 1131 TEST_F(ExtensionTest, GetSyncTypeThemeNoUpdateUrl) { | 1132 TEST_F(ExtensionTest, GetSyncTypeThemeNoUpdateUrl) { |
| 1132 scoped_refptr<Extension> extension( | 1133 scoped_refptr<Extension> extension( |
| 1133 MakeSyncTestExtension(THEME, GURL(), GURL(), | 1134 MakeSyncTestExtension(THEME, GURL(), GURL(), |
| 1134 Extension::INTERNAL, 0, FilePath(), | 1135 Manifest::INTERNAL, 0, FilePath(), |
| 1135 Extension::NO_FLAGS)); | 1136 Extension::NO_FLAGS)); |
| 1136 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1137 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1137 } | 1138 } |
| 1138 | 1139 |
| 1139 TEST_F(ExtensionTest, GetSyncTypeExtensionWithLaunchUrl) { | 1140 TEST_F(ExtensionTest, GetSyncTypeExtensionWithLaunchUrl) { |
| 1140 scoped_refptr<Extension> extension( | 1141 scoped_refptr<Extension> extension( |
| 1141 MakeSyncTestExtension(EXTENSION, GURL(), GURL("http://www.google.com"), | 1142 MakeSyncTestExtension(EXTENSION, GURL(), GURL("http://www.google.com"), |
| 1142 Extension::INTERNAL, 0, FilePath(), | 1143 Manifest::INTERNAL, 0, FilePath(), |
| 1143 Extension::NO_FLAGS)); | 1144 Extension::NO_FLAGS)); |
| 1144 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1145 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1145 } | 1146 } |
| 1146 | 1147 |
| 1147 TEST_F(ExtensionTest, GetSyncTypeExtensionExternal) { | 1148 TEST_F(ExtensionTest, GetSyncTypeExtensionExternal) { |
| 1148 scoped_refptr<Extension> extension( | 1149 scoped_refptr<Extension> extension( |
| 1149 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1150 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
| 1150 Extension::EXTERNAL_PREF, 0, FilePath(), | 1151 Manifest::EXTERNAL_PREF, 0, FilePath(), |
| 1151 Extension::NO_FLAGS)); | 1152 Extension::NO_FLAGS)); |
| 1152 | 1153 |
| 1153 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1154 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1154 } | 1155 } |
| 1155 | 1156 |
| 1156 TEST_F(ExtensionTest, GetSyncTypeUserScriptThirdPartyUpdateUrl) { | 1157 TEST_F(ExtensionTest, GetSyncTypeUserScriptThirdPartyUpdateUrl) { |
| 1157 scoped_refptr<Extension> extension( | 1158 scoped_refptr<Extension> extension( |
| 1158 MakeSyncTestExtension( | 1159 MakeSyncTestExtension( |
| 1159 USER_SCRIPT, GURL("http://third-party.update_url.com"), GURL(), | 1160 USER_SCRIPT, GURL("http://third-party.update_url.com"), GURL(), |
| 1160 Extension::INTERNAL, 0, FilePath(), Extension::NO_FLAGS)); | 1161 Manifest::INTERNAL, 0, FilePath(), Extension::NO_FLAGS)); |
| 1161 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1162 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1162 } | 1163 } |
| 1163 | 1164 |
| 1164 TEST_F(ExtensionTest, OnlyDisplayAppsInLauncher) { | 1165 TEST_F(ExtensionTest, OnlyDisplayAppsInLauncher) { |
| 1165 scoped_refptr<Extension> extension( | 1166 scoped_refptr<Extension> extension( |
| 1166 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1167 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
| 1167 Extension::INTERNAL, 0, FilePath(), | 1168 Manifest::INTERNAL, 0, FilePath(), |
| 1168 Extension::NO_FLAGS)); | 1169 Extension::NO_FLAGS)); |
| 1169 | 1170 |
| 1170 EXPECT_FALSE(extension->ShouldDisplayInAppLauncher()); | 1171 EXPECT_FALSE(extension->ShouldDisplayInAppLauncher()); |
| 1171 EXPECT_FALSE(extension->ShouldDisplayInNewTabPage()); | 1172 EXPECT_FALSE(extension->ShouldDisplayInNewTabPage()); |
| 1172 | 1173 |
| 1173 scoped_refptr<Extension> app( | 1174 scoped_refptr<Extension> app( |
| 1174 MakeSyncTestExtension(APP, GURL(), GURL("http://www.google.com"), | 1175 MakeSyncTestExtension(APP, GURL(), GURL("http://www.google.com"), |
| 1175 Extension::INTERNAL, 0, FilePath(), | 1176 Manifest::INTERNAL, 0, FilePath(), |
| 1176 Extension::NO_FLAGS)); | 1177 Extension::NO_FLAGS)); |
| 1177 EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); | 1178 EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); |
| 1178 EXPECT_TRUE(app->ShouldDisplayInNewTabPage()); | 1179 EXPECT_TRUE(app->ShouldDisplayInNewTabPage()); |
| 1179 } | 1180 } |
| 1180 | 1181 |
| 1181 TEST_F(ExtensionTest, DisplayInXManifestProperties) { | 1182 TEST_F(ExtensionTest, DisplayInXManifestProperties) { |
| 1182 DictionaryValue manifest; | 1183 DictionaryValue manifest; |
| 1183 manifest.SetString(keys::kName, "TestComponentApp"); | 1184 manifest.SetString(keys::kName, "TestComponentApp"); |
| 1184 manifest.SetString(keys::kVersion, "0.0.0.0"); | 1185 manifest.SetString(keys::kVersion, "0.0.0.0"); |
| 1185 manifest.SetString(keys::kApp, "true"); | 1186 manifest.SetString(keys::kApp, "true"); |
| 1186 manifest.SetString(keys::kPlatformAppBackgroundPage, ""); | 1187 manifest.SetString(keys::kPlatformAppBackgroundPage, ""); |
| 1187 | 1188 |
| 1188 std::string error; | 1189 std::string error; |
| 1189 scoped_refptr<Extension> app; | 1190 scoped_refptr<Extension> app; |
| 1190 | 1191 |
| 1191 // Default to true. | 1192 // Default to true. |
| 1192 app = Extension::Create( | 1193 app = Extension::Create( |
| 1193 FilePath(), Extension::COMPONENT, manifest, 0, &error); | 1194 FilePath(), Manifest::COMPONENT, manifest, 0, &error); |
| 1194 EXPECT_EQ(error, std::string()); | 1195 EXPECT_EQ(error, std::string()); |
| 1195 EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); | 1196 EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); |
| 1196 EXPECT_TRUE(app->ShouldDisplayInNewTabPage()); | 1197 EXPECT_TRUE(app->ShouldDisplayInNewTabPage()); |
| 1197 | 1198 |
| 1198 // Value display_in_NTP defaults to display_in_launcher. | 1199 // Value display_in_NTP defaults to display_in_launcher. |
| 1199 manifest.SetBoolean(keys::kDisplayInLauncher, false); | 1200 manifest.SetBoolean(keys::kDisplayInLauncher, false); |
| 1200 app = Extension::Create( | 1201 app = Extension::Create( |
| 1201 FilePath(), Extension::COMPONENT, manifest, 0, &error); | 1202 FilePath(), Manifest::COMPONENT, manifest, 0, &error); |
| 1202 EXPECT_EQ(error, std::string()); | 1203 EXPECT_EQ(error, std::string()); |
| 1203 EXPECT_FALSE(app->ShouldDisplayInAppLauncher()); | 1204 EXPECT_FALSE(app->ShouldDisplayInAppLauncher()); |
| 1204 EXPECT_FALSE(app->ShouldDisplayInNewTabPage()); | 1205 EXPECT_FALSE(app->ShouldDisplayInNewTabPage()); |
| 1205 | 1206 |
| 1206 // Value display_in_NTP = true overriding display_in_launcher = false. | 1207 // Value display_in_NTP = true overriding display_in_launcher = false. |
| 1207 manifest.SetBoolean(keys::kDisplayInNewTabPage, true); | 1208 manifest.SetBoolean(keys::kDisplayInNewTabPage, true); |
| 1208 app = Extension::Create( | 1209 app = Extension::Create( |
| 1209 FilePath(), Extension::COMPONENT, manifest, 0, &error); | 1210 FilePath(), Manifest::COMPONENT, manifest, 0, &error); |
| 1210 EXPECT_EQ(error, std::string()); | 1211 EXPECT_EQ(error, std::string()); |
| 1211 EXPECT_FALSE(app->ShouldDisplayInAppLauncher()); | 1212 EXPECT_FALSE(app->ShouldDisplayInAppLauncher()); |
| 1212 EXPECT_TRUE(app->ShouldDisplayInNewTabPage()); | 1213 EXPECT_TRUE(app->ShouldDisplayInNewTabPage()); |
| 1213 | 1214 |
| 1214 // Value display_in_NTP = false only, overrides default = true. | 1215 // Value display_in_NTP = false only, overrides default = true. |
| 1215 manifest.Remove(keys::kDisplayInLauncher, NULL); | 1216 manifest.Remove(keys::kDisplayInLauncher, NULL); |
| 1216 manifest.SetBoolean(keys::kDisplayInNewTabPage, false); | 1217 manifest.SetBoolean(keys::kDisplayInNewTabPage, false); |
| 1217 app = Extension::Create( | 1218 app = Extension::Create( |
| 1218 FilePath(), Extension::COMPONENT, manifest, 0, &error); | 1219 FilePath(), Manifest::COMPONENT, manifest, 0, &error); |
| 1219 EXPECT_EQ(error, std::string()); | 1220 EXPECT_EQ(error, std::string()); |
| 1220 EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); | 1221 EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); |
| 1221 EXPECT_FALSE(app->ShouldDisplayInNewTabPage()); | 1222 EXPECT_FALSE(app->ShouldDisplayInNewTabPage()); |
| 1222 | 1223 |
| 1223 // Error checking. | 1224 // Error checking. |
| 1224 manifest.SetString(keys::kDisplayInNewTabPage, "invalid"); | 1225 manifest.SetString(keys::kDisplayInNewTabPage, "invalid"); |
| 1225 app = Extension::Create( | 1226 app = Extension::Create( |
| 1226 FilePath(), Extension::COMPONENT, manifest, 0, &error); | 1227 FilePath(), Manifest::COMPONENT, manifest, 0, &error); |
| 1227 EXPECT_EQ(error, std::string(errors::kInvalidDisplayInNewTabPage)); | 1228 EXPECT_EQ(error, std::string(errors::kInvalidDisplayInNewTabPage)); |
| 1228 } | 1229 } |
| 1229 | 1230 |
| 1230 TEST_F(ExtensionTest, OnlySyncInternal) { | 1231 TEST_F(ExtensionTest, OnlySyncInternal) { |
| 1231 scoped_refptr<Extension> extension_internal( | 1232 scoped_refptr<Extension> extension_internal( |
| 1232 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1233 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
| 1233 Extension::INTERNAL, 0, FilePath(), | 1234 Manifest::INTERNAL, 0, FilePath(), |
| 1234 Extension::NO_FLAGS)); | 1235 Extension::NO_FLAGS)); |
| 1235 EXPECT_TRUE(extension_internal->IsSyncable()); | 1236 EXPECT_TRUE(extension_internal->IsSyncable()); |
| 1236 | 1237 |
| 1237 scoped_refptr<Extension> extension_noninternal( | 1238 scoped_refptr<Extension> extension_noninternal( |
| 1238 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1239 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
| 1239 Extension::COMPONENT, 0, FilePath(), | 1240 Manifest::COMPONENT, 0, FilePath(), |
| 1240 Extension::NO_FLAGS)); | 1241 Extension::NO_FLAGS)); |
| 1241 EXPECT_FALSE(extension_noninternal->IsSyncable()); | 1242 EXPECT_FALSE(extension_noninternal->IsSyncable()); |
| 1242 } | 1243 } |
| 1243 | 1244 |
| 1244 TEST_F(ExtensionTest, DontSyncDefault) { | 1245 TEST_F(ExtensionTest, DontSyncDefault) { |
| 1245 scoped_refptr<Extension> extension_default( | 1246 scoped_refptr<Extension> extension_default( |
| 1246 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1247 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
| 1247 Extension::INTERNAL, 0, FilePath(), | 1248 Manifest::INTERNAL, 0, FilePath(), |
| 1248 Extension::WAS_INSTALLED_BY_DEFAULT)); | 1249 Extension::WAS_INSTALLED_BY_DEFAULT)); |
| 1249 EXPECT_FALSE(extension_default->IsSyncable()); | 1250 EXPECT_FALSE(extension_default->IsSyncable()); |
| 1250 } | 1251 } |
| 1251 | 1252 |
| 1252 TEST_F(ExtensionTest, OptionalOnlyPermission) { | 1253 TEST_F(ExtensionTest, OptionalOnlyPermission) { |
| 1253 // Set feature current channel to dev because the only permission that must | 1254 // Set feature current channel to dev because the only permission that must |
| 1254 // be optional (usbDevices) is only available on dev channel. | 1255 // be optional (usbDevices) is only available on dev channel. |
| 1255 Feature::ScopedCurrentChannel scoped_channel( | 1256 Feature::ScopedCurrentChannel scoped_channel( |
| 1256 chrome::VersionInfo::CHANNEL_DEV); | 1257 chrome::VersionInfo::CHANNEL_DEV); |
| 1257 | 1258 |
| 1258 scoped_refptr<Extension> extension; | 1259 scoped_refptr<Extension> extension; |
| 1259 std::string error; | 1260 std::string error; |
| 1260 extension = LoadManifestUnchecked("optional_only_permission", | 1261 extension = LoadManifestUnchecked("optional_only_permission", |
| 1261 "manifest1.json", | 1262 "manifest1.json", |
| 1262 Extension::INTERNAL, Extension::NO_FLAGS, | 1263 Manifest::INTERNAL, Extension::NO_FLAGS, |
| 1263 &error); | 1264 &error); |
| 1264 EXPECT_TRUE(extension == NULL); | 1265 EXPECT_TRUE(extension == NULL); |
| 1265 ASSERT_EQ(ErrorUtils::FormatErrorMessage( | 1266 ASSERT_EQ(ErrorUtils::FormatErrorMessage( |
| 1266 errors::kPermissionMustBeOptional, "usbDevices"), error); | 1267 errors::kPermissionMustBeOptional, "usbDevices"), error); |
| 1267 | 1268 |
| 1268 error.clear(); | 1269 error.clear(); |
| 1269 extension = LoadManifestUnchecked("optional_only_permission", | 1270 extension = LoadManifestUnchecked("optional_only_permission", |
| 1270 "manifest2.json", | 1271 "manifest2.json", |
| 1271 Extension::INTERNAL, Extension::NO_FLAGS, | 1272 Manifest::INTERNAL, Extension::NO_FLAGS, |
| 1272 &error); | 1273 &error); |
| 1273 EXPECT_TRUE(extension != NULL); | 1274 EXPECT_TRUE(extension != NULL); |
| 1274 EXPECT_TRUE(error.empty()); | 1275 EXPECT_TRUE(error.empty()); |
| 1275 } | 1276 } |
| 1276 | 1277 |
| 1277 // These last 2 tests don't make sense on Chrome OS, where extension plugins | 1278 // These last 2 tests don't make sense on Chrome OS, where extension plugins |
| 1278 // are not allowed. | 1279 // are not allowed. |
| 1279 #if !defined(OS_CHROMEOS) | 1280 #if !defined(OS_CHROMEOS) |
| 1280 TEST_F(ExtensionTest, GetSyncTypeExtensionWithPlugin) { | 1281 TEST_F(ExtensionTest, GetSyncTypeExtensionWithPlugin) { |
| 1281 scoped_refptr<Extension> extension( | 1282 scoped_refptr<Extension> extension( |
| 1282 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1283 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
| 1283 Extension::INTERNAL, 1, FilePath(), | 1284 Manifest::INTERNAL, 1, FilePath(), |
| 1284 Extension::NO_FLAGS)); | 1285 Extension::NO_FLAGS)); |
| 1285 if (extension) | 1286 if (extension) |
| 1286 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1287 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1287 } | 1288 } |
| 1288 | 1289 |
| 1289 TEST_F(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { | 1290 TEST_F(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { |
| 1290 scoped_refptr<Extension> extension( | 1291 scoped_refptr<Extension> extension( |
| 1291 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1292 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
| 1292 Extension::INTERNAL, 2, FilePath(), | 1293 Manifest::INTERNAL, 2, FilePath(), |
| 1293 Extension::NO_FLAGS)); | 1294 Extension::NO_FLAGS)); |
| 1294 if (extension) | 1295 if (extension) |
| 1295 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1296 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1296 } | 1297 } |
| 1297 #endif // !defined(OS_CHROMEOS) | 1298 #endif // !defined(OS_CHROMEOS) |
| 1298 | 1299 |
| 1299 } // namespace extensions | 1300 } // namespace extensions |
| OLD | NEW |