Chromium Code Reviews| 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_file_util.h" | 5 #include "chrome/common/extensions/extension_file_util.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" | |
| 14 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 15 #include "chrome/common/extensions/extension_manifest_constants.h" | 16 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 17 #include "chrome/common/extensions/manifest_handler.h" | |
| 16 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 20 | 22 |
| 21 using extensions::Extension; | 23 using extensions::Extension; |
| 22 | 24 |
| 23 namespace keys = extension_manifest_keys; | 25 namespace keys = extension_manifest_keys; |
| 24 | 26 |
| 27 class ExtensionFileUtil : public testing::Test { | |
| 28 virtual void SetUp() OVERRIDE { | |
| 29 extensions::ManifestHandler::Register(keys::kDefaultLocale, | |
|
Devlin
2013/01/18 21:08:46
Call the super's SetUp function as well (even if i
Joe Thomas
2013/01/18 22:16:57
Done.
| |
| 30 new extensions::DefaultLocaleHandler); | |
| 31 } | |
| 32 }; | |
| 33 | |
| 25 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
| 26 // http://crbug.com/106381 | 35 // http://crbug.com/106381 |
| 27 #define InstallUninstallGarbageCollect DISABLED_InstallUninstallGarbageCollect | 36 #define InstallUninstallGarbageCollect DISABLED_InstallUninstallGarbageCollect |
| 28 #endif | 37 #endif |
| 29 TEST(ExtensionFileUtil, InstallUninstallGarbageCollect) { | 38 TEST_F(ExtensionFileUtil, InstallUninstallGarbageCollect) { |
| 30 base::ScopedTempDir temp; | 39 base::ScopedTempDir temp; |
| 31 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 40 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 32 | 41 |
| 33 // Create a source extension. | 42 // Create a source extension. |
| 34 std::string extension_id("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); | 43 std::string extension_id("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| 35 std::string version("1.0"); | 44 std::string version("1.0"); |
| 36 FilePath src = temp.path().AppendASCII(extension_id); | 45 FilePath src = temp.path().AppendASCII(extension_id); |
| 37 ASSERT_TRUE(file_util::CreateDirectory(src)); | 46 ASSERT_TRUE(file_util::CreateDirectory(src)); |
| 38 | 47 |
| 39 // Create a extensions tree. | 48 // Create a extensions tree. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 ASSERT_TRUE(file_util::DirectoryExists(version_2)); | 99 ASSERT_TRUE(file_util::DirectoryExists(version_2)); |
| 91 ASSERT_TRUE(file_util::DirectoryExists(version_3)); | 100 ASSERT_TRUE(file_util::DirectoryExists(version_3)); |
| 92 | 101 |
| 93 // Uninstall. Should remove entire extension subtree. | 102 // Uninstall. Should remove entire extension subtree. |
| 94 extension_file_util::UninstallExtension(all_extensions, extension_id); | 103 extension_file_util::UninstallExtension(all_extensions, extension_id); |
| 95 ASSERT_FALSE(file_util::DirectoryExists(version_2.DirName())); | 104 ASSERT_FALSE(file_util::DirectoryExists(version_2.DirName())); |
| 96 ASSERT_FALSE(file_util::DirectoryExists(version_3.DirName())); | 105 ASSERT_FALSE(file_util::DirectoryExists(version_3.DirName())); |
| 97 ASSERT_TRUE(file_util::DirectoryExists(all_extensions)); | 106 ASSERT_TRUE(file_util::DirectoryExists(all_extensions)); |
| 98 } | 107 } |
| 99 | 108 |
| 100 TEST(ExtensionFileUtil, LoadExtensionWithValidLocales) { | 109 TEST_F(ExtensionFileUtil, LoadExtensionWithValidLocales) { |
| 101 FilePath install_dir; | 110 FilePath install_dir; |
| 102 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 111 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 103 install_dir = install_dir.AppendASCII("extensions") | 112 install_dir = install_dir.AppendASCII("extensions") |
| 104 .AppendASCII("good") | 113 .AppendASCII("good") |
| 105 .AppendASCII("Extensions") | 114 .AppendASCII("Extensions") |
| 106 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 115 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 107 .AppendASCII("1.0.0.0"); | 116 .AppendASCII("1.0.0.0"); |
| 108 | 117 |
| 109 std::string error; | 118 std::string error; |
| 110 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 119 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 111 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 120 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); |
| 112 ASSERT_TRUE(extension != NULL); | 121 ASSERT_TRUE(extension != NULL); |
| 113 EXPECT_EQ("The first extension that I made.", extension->description()); | 122 EXPECT_EQ("The first extension that I made.", extension->description()); |
| 114 } | 123 } |
| 115 | 124 |
| 116 TEST(ExtensionFileUtil, LoadExtensionWithoutLocalesFolder) { | 125 TEST_F(ExtensionFileUtil, LoadExtensionWithoutLocalesFolder) { |
| 117 FilePath install_dir; | 126 FilePath install_dir; |
| 118 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 127 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 119 install_dir = install_dir.AppendASCII("extensions") | 128 install_dir = install_dir.AppendASCII("extensions") |
| 120 .AppendASCII("good") | 129 .AppendASCII("good") |
| 121 .AppendASCII("Extensions") | 130 .AppendASCII("Extensions") |
| 122 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") | 131 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") |
| 123 .AppendASCII("1.0"); | 132 .AppendASCII("1.0"); |
| 124 | 133 |
| 125 std::string error; | 134 std::string error; |
| 126 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 135 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 127 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 136 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); |
| 128 ASSERT_FALSE(extension == NULL); | 137 ASSERT_FALSE(extension == NULL); |
| 129 EXPECT_TRUE(error.empty()); | 138 EXPECT_TRUE(error.empty()); |
| 130 } | 139 } |
| 131 | 140 |
| 132 #if defined(OS_WIN) | 141 #if defined(OS_WIN) |
| 133 // http://crbug.com/106381 | 142 // http://crbug.com/106381 |
| 134 #define CheckIllegalFilenamesNoUnderscores \ | 143 #define CheckIllegalFilenamesNoUnderscores \ |
| 135 DISABLED_CheckIllegalFilenamesNoUnderscores | 144 DISABLED_CheckIllegalFilenamesNoUnderscores |
| 136 #endif | 145 #endif |
| 137 TEST(ExtensionFileUtil, CheckIllegalFilenamesNoUnderscores) { | 146 TEST_F(ExtensionFileUtil, CheckIllegalFilenamesNoUnderscores) { |
| 138 base::ScopedTempDir temp; | 147 base::ScopedTempDir temp; |
| 139 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 148 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 140 | 149 |
| 141 FilePath src_path = temp.path().AppendASCII("some_dir"); | 150 FilePath src_path = temp.path().AppendASCII("some_dir"); |
| 142 ASSERT_TRUE(file_util::CreateDirectory(src_path)); | 151 ASSERT_TRUE(file_util::CreateDirectory(src_path)); |
| 143 | 152 |
| 144 std::string data = "{ \"name\": { \"message\": \"foobar\" } }"; | 153 std::string data = "{ \"name\": { \"message\": \"foobar\" } }"; |
| 145 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("some_file.txt"), | 154 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("some_file.txt"), |
| 146 data.c_str(), data.length())); | 155 data.c_str(), data.length())); |
| 147 std::string error; | 156 std::string error; |
| 148 EXPECT_TRUE(extension_file_util::CheckForIllegalFilenames(temp.path(), | 157 EXPECT_TRUE(extension_file_util::CheckForIllegalFilenames(temp.path(), |
| 149 &error)); | 158 &error)); |
| 150 } | 159 } |
| 151 | 160 |
| 152 #if defined(OS_WIN) | 161 #if defined(OS_WIN) |
| 153 // http://crbug.com/106381 | 162 // http://crbug.com/106381 |
| 154 #define CheckIllegalFilenamesOnlyReserved \ | 163 #define CheckIllegalFilenamesOnlyReserved \ |
| 155 DISABLED_CheckIllegalFilenamesOnlyReserved | 164 DISABLED_CheckIllegalFilenamesOnlyReserved |
| 156 #endif | 165 #endif |
| 157 TEST(ExtensionFileUtil, CheckIllegalFilenamesOnlyReserved) { | 166 TEST_F(ExtensionFileUtil, CheckIllegalFilenamesOnlyReserved) { |
| 158 base::ScopedTempDir temp; | 167 base::ScopedTempDir temp; |
| 159 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 168 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 160 | 169 |
| 161 FilePath src_path = temp.path().Append(Extension::kLocaleFolder); | 170 FilePath src_path = temp.path().Append(Extension::kLocaleFolder); |
| 162 ASSERT_TRUE(file_util::CreateDirectory(src_path)); | 171 ASSERT_TRUE(file_util::CreateDirectory(src_path)); |
| 163 | 172 |
| 164 std::string error; | 173 std::string error; |
| 165 EXPECT_TRUE(extension_file_util::CheckForIllegalFilenames(temp.path(), | 174 EXPECT_TRUE(extension_file_util::CheckForIllegalFilenames(temp.path(), |
| 166 &error)); | 175 &error)); |
| 167 } | 176 } |
| 168 | 177 |
| 169 #if defined(OS_WIN) | 178 #if defined(OS_WIN) |
| 170 // http://crbug.com/106381 | 179 // http://crbug.com/106381 |
| 171 #define CheckIllegalFilenamesReservedAndIllegal \ | 180 #define CheckIllegalFilenamesReservedAndIllegal \ |
| 172 DISABLED_CheckIllegalFilenamesReservedAndIllegal | 181 DISABLED_CheckIllegalFilenamesReservedAndIllegal |
| 173 #endif | 182 #endif |
| 174 TEST(ExtensionFileUtil, CheckIllegalFilenamesReservedAndIllegal) { | 183 TEST_F(ExtensionFileUtil, CheckIllegalFilenamesReservedAndIllegal) { |
| 175 base::ScopedTempDir temp; | 184 base::ScopedTempDir temp; |
| 176 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 185 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 177 | 186 |
| 178 FilePath src_path = temp.path().Append(Extension::kLocaleFolder); | 187 FilePath src_path = temp.path().Append(Extension::kLocaleFolder); |
| 179 ASSERT_TRUE(file_util::CreateDirectory(src_path)); | 188 ASSERT_TRUE(file_util::CreateDirectory(src_path)); |
| 180 | 189 |
| 181 src_path = temp.path().AppendASCII("_some_dir"); | 190 src_path = temp.path().AppendASCII("_some_dir"); |
| 182 ASSERT_TRUE(file_util::CreateDirectory(src_path)); | 191 ASSERT_TRUE(file_util::CreateDirectory(src_path)); |
| 183 | 192 |
| 184 std::string error; | 193 std::string error; |
| 185 EXPECT_FALSE(extension_file_util::CheckForIllegalFilenames(temp.path(), | 194 EXPECT_FALSE(extension_file_util::CheckForIllegalFilenames(temp.path(), |
| 186 &error)); | 195 &error)); |
| 187 } | 196 } |
| 188 | 197 |
| 189 TEST(ExtensionFileUtil, LoadExtensionGivesHelpfullErrorOnMissingManifest) { | 198 TEST_F(ExtensionFileUtil, LoadExtensionGivesHelpfullErrorOnMissingManifest) { |
| 190 FilePath install_dir; | 199 FilePath install_dir; |
| 191 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 200 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 192 install_dir = install_dir.AppendASCII("extensions") | 201 install_dir = install_dir.AppendASCII("extensions") |
| 193 .AppendASCII("bad") | 202 .AppendASCII("bad") |
| 194 .AppendASCII("Extensions") | 203 .AppendASCII("Extensions") |
| 195 .AppendASCII("dddddddddddddddddddddddddddddddd") | 204 .AppendASCII("dddddddddddddddddddddddddddddddd") |
| 196 .AppendASCII("1.0"); | 205 .AppendASCII("1.0"); |
| 197 | 206 |
| 198 std::string error; | 207 std::string error; |
| 199 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 208 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 200 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 209 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); |
| 201 ASSERT_TRUE(extension == NULL); | 210 ASSERT_TRUE(extension == NULL); |
| 202 ASSERT_FALSE(error.empty()); | 211 ASSERT_FALSE(error.empty()); |
| 203 ASSERT_STREQ("Manifest file is missing or unreadable.", error.c_str()); | 212 ASSERT_STREQ("Manifest file is missing or unreadable.", error.c_str()); |
| 204 } | 213 } |
| 205 | 214 |
| 206 TEST(ExtensionFileUtil, LoadExtensionGivesHelpfullErrorOnBadManifest) { | 215 TEST_F(ExtensionFileUtil, LoadExtensionGivesHelpfullErrorOnBadManifest) { |
| 207 FilePath install_dir; | 216 FilePath install_dir; |
| 208 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 217 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 209 install_dir = install_dir.AppendASCII("extensions") | 218 install_dir = install_dir.AppendASCII("extensions") |
| 210 .AppendASCII("bad") | 219 .AppendASCII("bad") |
| 211 .AppendASCII("Extensions") | 220 .AppendASCII("Extensions") |
| 212 .AppendASCII("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") | 221 .AppendASCII("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") |
| 213 .AppendASCII("1.0"); | 222 .AppendASCII("1.0"); |
| 214 | 223 |
| 215 std::string error; | 224 std::string error; |
| 216 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 225 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 217 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 226 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); |
| 218 ASSERT_TRUE(extension == NULL); | 227 ASSERT_TRUE(extension == NULL); |
| 219 ASSERT_FALSE(error.empty()); | 228 ASSERT_FALSE(error.empty()); |
| 220 ASSERT_STREQ("Manifest is not valid JSON. " | 229 ASSERT_STREQ("Manifest is not valid JSON. " |
| 221 "Line: 2, column: 16, Syntax error.", error.c_str()); | 230 "Line: 2, column: 16, Syntax error.", error.c_str()); |
| 222 } | 231 } |
| 223 | 232 |
| 224 TEST(ExtensionFileUtil, FailLoadingNonUTF8Scripts) { | 233 TEST_F(ExtensionFileUtil, FailLoadingNonUTF8Scripts) { |
| 225 FilePath install_dir; | 234 FilePath install_dir; |
| 226 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 235 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 227 install_dir = install_dir.AppendASCII("extensions") | 236 install_dir = install_dir.AppendASCII("extensions") |
| 228 .AppendASCII("bad") | 237 .AppendASCII("bad") |
| 229 .AppendASCII("bad_encoding"); | 238 .AppendASCII("bad_encoding"); |
| 230 | 239 |
| 231 std::string error; | 240 std::string error; |
| 232 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 241 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 233 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 242 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); |
| 234 ASSERT_TRUE(extension == NULL); | 243 ASSERT_TRUE(extension == NULL); |
| 235 ASSERT_STREQ("Could not load file 'bad_encoding.js' for content script. " | 244 ASSERT_STREQ("Could not load file 'bad_encoding.js' for content script. " |
| 236 "It isn't UTF-8 encoded.", error.c_str()); | 245 "It isn't UTF-8 encoded.", error.c_str()); |
| 237 } | 246 } |
| 238 | 247 |
| 239 TEST(ExtensionFileUtil, ExtensionURLToRelativeFilePath) { | 248 TEST_F(ExtensionFileUtil, ExtensionURLToRelativeFilePath) { |
| 240 #define URL_PREFIX "chrome-extension://extension-id/" | 249 #define URL_PREFIX "chrome-extension://extension-id/" |
| 241 struct TestCase { | 250 struct TestCase { |
| 242 const char* url; | 251 const char* url; |
| 243 const char* expected_relative_path; | 252 const char* expected_relative_path; |
| 244 } test_cases[] = { | 253 } test_cases[] = { |
| 245 { URL_PREFIX "simple.html", | 254 { URL_PREFIX "simple.html", |
| 246 "simple.html" }, | 255 "simple.html" }, |
| 247 { URL_PREFIX "directory/to/file.html", | 256 { URL_PREFIX "directory/to/file.html", |
| 248 "directory/to/file.html" }, | 257 "directory/to/file.html" }, |
| 249 { URL_PREFIX "escape%20spaces.html", | 258 { URL_PREFIX "escape%20spaces.html", |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 275 | 284 |
| 276 FilePath actual_path = | 285 FilePath actual_path = |
| 277 extension_file_util::ExtensionURLToRelativeFilePath(url); | 286 extension_file_util::ExtensionURLToRelativeFilePath(url); |
| 278 EXPECT_FALSE(actual_path.IsAbsolute()) << | 287 EXPECT_FALSE(actual_path.IsAbsolute()) << |
| 279 " For the path " << actual_path.value(); | 288 " For the path " << actual_path.value(); |
| 280 EXPECT_EQ(expected_path.value(), actual_path.value()) << | 289 EXPECT_EQ(expected_path.value(), actual_path.value()) << |
| 281 " For the path " << url; | 290 " For the path " << url; |
| 282 } | 291 } |
| 283 } | 292 } |
| 284 | 293 |
| 285 TEST(ExtensionFileUtil, ExtensionResourceURLToFilePath) { | 294 TEST_F(ExtensionFileUtil, ExtensionResourceURLToFilePath) { |
| 286 // Setup filesystem for testing. | 295 // Setup filesystem for testing. |
| 287 FilePath root_path; | 296 FilePath root_path; |
| 288 ASSERT_TRUE(file_util::CreateNewTempDirectory( | 297 ASSERT_TRUE(file_util::CreateNewTempDirectory( |
| 289 FILE_PATH_LITERAL(""), &root_path)); | 298 FILE_PATH_LITERAL(""), &root_path)); |
| 290 ASSERT_TRUE(file_util::AbsolutePath(&root_path)); | 299 ASSERT_TRUE(file_util::AbsolutePath(&root_path)); |
| 291 | 300 |
| 292 FilePath api_path = root_path.Append(FILE_PATH_LITERAL("apiname")); | 301 FilePath api_path = root_path.Append(FILE_PATH_LITERAL("apiname")); |
| 293 ASSERT_TRUE(file_util::CreateDirectory(api_path)); | 302 ASSERT_TRUE(file_util::CreateDirectory(api_path)); |
| 294 | 303 |
| 295 const char data[] = "Test Data"; | 304 const char data[] = "Test Data"; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 manifest_dir, | 383 manifest_dir, |
| 375 location, | 384 location, |
| 376 extra_flags, | 385 extra_flags, |
| 377 error); | 386 error); |
| 378 } | 387 } |
| 379 | 388 |
| 380 #if defined(OS_WIN) | 389 #if defined(OS_WIN) |
| 381 // http://crbug.com/108279 | 390 // http://crbug.com/108279 |
| 382 #define ValidateThemeUTF8 DISABLED_ValidateThemeUTF8 | 391 #define ValidateThemeUTF8 DISABLED_ValidateThemeUTF8 |
| 383 #endif | 392 #endif |
| 384 TEST(ExtensionFileUtil, ValidateThemeUTF8) { | 393 TEST_F(ExtensionFileUtil, ValidateThemeUTF8) { |
| 385 base::ScopedTempDir temp; | 394 base::ScopedTempDir temp; |
| 386 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 395 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 387 | 396 |
| 388 // "aeo" with accents. Use http://0xcc.net/jsescape/ to decode them. | 397 // "aeo" with accents. Use http://0xcc.net/jsescape/ to decode them. |
| 389 std::string non_ascii_file = "\xC3\xA0\xC3\xA8\xC3\xB2.png"; | 398 std::string non_ascii_file = "\xC3\xA0\xC3\xA8\xC3\xB2.png"; |
| 390 FilePath non_ascii_path = temp.path().Append(FilePath::FromUTF8Unsafe( | 399 FilePath non_ascii_path = temp.path().Append(FilePath::FromUTF8Unsafe( |
| 391 non_ascii_file)); | 400 non_ascii_file)); |
| 392 file_util::WriteFile(non_ascii_path, "", 0); | 401 file_util::WriteFile(non_ascii_path, "", 0); |
| 393 | 402 |
| 394 std::string kManifest = | 403 std::string kManifest = |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 407 error; | 416 error; |
| 408 EXPECT_EQ(0U, warnings.size()); | 417 EXPECT_EQ(0U, warnings.size()); |
| 409 } | 418 } |
| 410 | 419 |
| 411 #if defined(OS_WIN) | 420 #if defined(OS_WIN) |
| 412 // This test hangs on Windows sometimes. http://crbug.com/110279 | 421 // This test hangs on Windows sometimes. http://crbug.com/110279 |
| 413 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist | 422 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist |
| 414 #else | 423 #else |
| 415 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist | 424 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist |
| 416 #endif | 425 #endif |
| 417 TEST(ExtensionFileUtil, MAYBE_BackgroundScriptsMustExist) { | 426 TEST_F(ExtensionFileUtil, MAYBE_BackgroundScriptsMustExist) { |
| 418 base::ScopedTempDir temp; | 427 base::ScopedTempDir temp; |
| 419 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 428 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 420 | 429 |
| 421 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | 430 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
| 422 value->SetString("name", "test"); | 431 value->SetString("name", "test"); |
| 423 value->SetString("version", "1"); | 432 value->SetString("version", "1"); |
| 424 value->SetInteger("manifest_version", 1); | 433 value->SetInteger("manifest_version", 1); |
| 425 | 434 |
| 426 ListValue* scripts = new ListValue(); | 435 ListValue* scripts = new ListValue(); |
| 427 scripts->Append(Value::CreateStringValue("foo.js")); | 436 scripts->Append(Value::CreateStringValue("foo.js")); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 "4GAAeWonDdkQJBANNb8wrqNWFn7DqyQTfELzcRTRnqQ/r1pdeJo6obzbnwGnlqe3t\n" | 479 "4GAAeWonDdkQJBANNb8wrqNWFn7DqyQTfELzcRTRnqQ/r1pdeJo6obzbnwGnlqe3t\n" |
| 471 "KhLjtJNIGrQg5iC0OVLWFuvPJs0t3z62A1ckCQQDPq2JZuwTwu5Pl4DJ0r9O1FdqN\n" | 480 "KhLjtJNIGrQg5iC0OVLWFuvPJs0t3z62A1ckCQQDPq2JZuwTwu5Pl4DJ0r9O1FdqN\n" |
| 472 "JgqPZyMptokCDQ3khLLGakIu+TqB9YtrzI69rJMSG2Egb+6McaDX+dh3XmR/AkB9t\n" | 481 "JgqPZyMptokCDQ3khLLGakIu+TqB9YtrzI69rJMSG2Egb+6McaDX+dh3XmR/AkB9t\n" |
| 473 "xJf6qDnmA2td/tMtTc0NOk8Qdg/fD8xbZ/YfYMnVoYYs9pQoilBaWRePDRNURMLYZ\n" | 482 "xJf6qDnmA2td/tMtTc0NOk8Qdg/fD8xbZ/YfYMnVoYYs9pQoilBaWRePDRNURMLYZ\n" |
| 474 "vHAI0Llmw7tj7jv17pAkEAz44uXRpjRKtllUIvi5pUENAHwDz+HvdpGH68jpU3hmb\n" | 483 "vHAI0Llmw7tj7jv17pAkEAz44uXRpjRKtllUIvi5pUENAHwDz+HvdpGH68jpU3hmb\n" |
| 475 "uOwrmnQYxaMReFV68Z2w9DcLZn07f7/R9Wn72z89CxwJAFsDoNaDes4h48bX7plct\n" | 484 "uOwrmnQYxaMReFV68Z2w9DcLZn07f7/R9Wn72z89CxwJAFsDoNaDes4h48bX7plct\n" |
| 476 "s9ACjmTwcCigZjN2K7AGv7ntCLF3DnV5dK0dTHNaAdD3SbY3jl29Rk2CwiURSX6Ee\n" | 485 "s9ACjmTwcCigZjN2K7AGv7ntCLF3DnV5dK0dTHNaAdD3SbY3jl29Rk2CwiURSX6Ee\n" |
| 477 "g==\n" | 486 "g==\n" |
| 478 "-----END PRIVATE KEY-----\n"; | 487 "-----END PRIVATE KEY-----\n"; |
| 479 | 488 |
| 480 TEST(ExtensionFileUtil, FindPrivateKeyFiles) { | 489 TEST_F(ExtensionFileUtil, FindPrivateKeyFiles) { |
| 481 base::ScopedTempDir temp; | 490 base::ScopedTempDir temp; |
| 482 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 491 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 483 | 492 |
| 484 FilePath src_path = temp.path().AppendASCII("some_dir"); | 493 FilePath src_path = temp.path().AppendASCII("some_dir"); |
| 485 ASSERT_TRUE(file_util::CreateDirectory(src_path)); | 494 ASSERT_TRUE(file_util::CreateDirectory(src_path)); |
| 486 | 495 |
| 487 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("a_key.pem"), | 496 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("a_key.pem"), |
| 488 private_key, arraysize(private_key))); | 497 private_key, arraysize(private_key))); |
| 489 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("second_key.pem"), | 498 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("second_key.pem"), |
| 490 private_key, arraysize(private_key))); | 499 private_key, arraysize(private_key))); |
| 491 // Shouldn't find a key with a different extension. | 500 // Shouldn't find a key with a different extension. |
| 492 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("key.diff_ext"), | 501 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("key.diff_ext"), |
| 493 private_key, arraysize(private_key))); | 502 private_key, arraysize(private_key))); |
| 494 // Shouldn't find a key that isn't parsable. | 503 // Shouldn't find a key that isn't parsable. |
| 495 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("unparsable_key.pem"), | 504 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("unparsable_key.pem"), |
| 496 private_key, arraysize(private_key) - 30)); | 505 private_key, arraysize(private_key) - 30)); |
| 497 std::vector<FilePath> private_keys = | 506 std::vector<FilePath> private_keys = |
| 498 extension_file_util::FindPrivateKeyFiles(temp.path()); | 507 extension_file_util::FindPrivateKeyFiles(temp.path()); |
| 499 EXPECT_EQ(2U, private_keys.size()); | 508 EXPECT_EQ(2U, private_keys.size()); |
| 500 EXPECT_THAT(private_keys, | 509 EXPECT_THAT(private_keys, |
| 501 testing::Contains(src_path.AppendASCII("a_key.pem"))); | 510 testing::Contains(src_path.AppendASCII("a_key.pem"))); |
| 502 EXPECT_THAT(private_keys, | 511 EXPECT_THAT(private_keys, |
| 503 testing::Contains(src_path.AppendASCII("second_key.pem"))); | 512 testing::Contains(src_path.AppendASCII("second_key.pem"))); |
| 504 } | 513 } |
| 505 | 514 |
| 506 TEST(ExtensionFileUtil, WarnOnPrivateKey) { | 515 TEST_F(ExtensionFileUtil, WarnOnPrivateKey) { |
| 507 base::ScopedTempDir temp; | 516 base::ScopedTempDir temp; |
| 508 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 517 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 509 | 518 |
| 510 FilePath ext_path = temp.path().AppendASCII("ext_root"); | 519 FilePath ext_path = temp.path().AppendASCII("ext_root"); |
| 511 ASSERT_TRUE(file_util::CreateDirectory(ext_path)); | 520 ASSERT_TRUE(file_util::CreateDirectory(ext_path)); |
| 512 | 521 |
| 513 const char manifest[] = | 522 const char manifest[] = |
| 514 "{\n" | 523 "{\n" |
| 515 " \"name\": \"Test Extension\",\n" | 524 " \"name\": \"Test Extension\",\n" |
| 516 " \"version\": \"1.0\",\n" | 525 " \"version\": \"1.0\",\n" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 539 // Turn the warning into an error with ERROR_ON_PRIVATE_KEY. | 548 // Turn the warning into an error with ERROR_ON_PRIVATE_KEY. |
| 540 extension = extension_file_util::LoadExtension( | 549 extension = extension_file_util::LoadExtension( |
| 541 ext_path, "the_id", Extension::EXTERNAL_PREF, | 550 ext_path, "the_id", Extension::EXTERNAL_PREF, |
| 542 Extension::ERROR_ON_PRIVATE_KEY, &error); | 551 Extension::ERROR_ON_PRIVATE_KEY, &error); |
| 543 EXPECT_FALSE(extension.get()); | 552 EXPECT_FALSE(extension.get()); |
| 544 EXPECT_THAT(error, | 553 EXPECT_THAT(error, |
| 545 testing::ContainsRegex( | 554 testing::ContainsRegex( |
| 546 "extension includes the key file.*ext_root.a_key.pem")); | 555 "extension includes the key file.*ext_root.a_key.pem")); |
| 547 } | 556 } |
| 548 | 557 |
| 549 TEST(ExtensionFileUtil, CheckZeroLengthImageFile) { | 558 TEST_F(ExtensionFileUtil, CheckZeroLengthImageFile) { |
| 550 FilePath install_dir; | 559 FilePath install_dir; |
| 551 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 560 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 552 | 561 |
| 553 // Try to install an extension with a zero-length icon file. | 562 // Try to install an extension with a zero-length icon file. |
| 554 FilePath ext_dir = install_dir.AppendASCII("extensions") | 563 FilePath ext_dir = install_dir.AppendASCII("extensions") |
| 555 .AppendASCII("bad") | 564 .AppendASCII("bad") |
| 556 .AppendASCII("Extensions") | 565 .AppendASCII("Extensions") |
| 557 .AppendASCII("ffffffffffffffffffffffffffffffff"); | 566 .AppendASCII("ffffffffffffffffffffffffffffffff"); |
| 558 | 567 |
| 559 std::string error; | 568 std::string error; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 584 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( | 593 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( |
| 585 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 594 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); |
| 586 ASSERT_TRUE(extension3 == NULL); | 595 ASSERT_TRUE(extension3 == NULL); |
| 587 ASSERT_STREQ("Could not load icon 'icon.png' for page action.", | 596 ASSERT_STREQ("Could not load icon 'icon.png' for page action.", |
| 588 error.c_str()); | 597 error.c_str()); |
| 589 } | 598 } |
| 590 | 599 |
| 591 // TODO(aa): More tests as motivation allows. Maybe steal some from | 600 // TODO(aa): More tests as motivation allows. Maybe steal some from |
| 592 // ExtensionService? Many of them could probably be tested here without the | 601 // ExtensionService? Many of them could probably be tested here without the |
| 593 // MessageLoop shenanigans. | 602 // MessageLoop shenanigans. |
| OLD | NEW |