| 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/extension_action/browser_action_handler.h
" | 14 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h
" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/extension_manifest_constants.h" | 16 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 17 #include "chrome/common/extensions/manifest.h" |
| 17 #include "chrome/common/extensions/manifest_handler.h" | 18 #include "chrome/common/extensions/manifest_handler.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 | 23 |
| 23 using extensions::Extension; | 24 using extensions::Extension; |
| 25 using extensions::Manifest; |
| 24 | 26 |
| 25 namespace keys = extension_manifest_keys; | 27 namespace keys = extension_manifest_keys; |
| 26 | 28 |
| 27 class ExtensionFileUtilTest : public testing::Test { | 29 class ExtensionFileUtilTest : public testing::Test { |
| 28 protected: | 30 protected: |
| 29 virtual void SetUp() OVERRIDE { | 31 virtual void SetUp() OVERRIDE { |
| 30 testing::Test::SetUp(); | 32 testing::Test::SetUp(); |
| 31 extensions::ManifestHandler::Register( | 33 extensions::ManifestHandler::Register( |
| 32 extension_manifest_keys::kBrowserAction, | 34 extension_manifest_keys::kBrowserAction, |
| 33 new extensions::BrowserActionHandler); | 35 new extensions::BrowserActionHandler); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 FilePath install_dir; | 115 FilePath install_dir; |
| 114 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 116 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 115 install_dir = install_dir.AppendASCII("extensions") | 117 install_dir = install_dir.AppendASCII("extensions") |
| 116 .AppendASCII("good") | 118 .AppendASCII("good") |
| 117 .AppendASCII("Extensions") | 119 .AppendASCII("Extensions") |
| 118 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 120 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 119 .AppendASCII("1.0.0.0"); | 121 .AppendASCII("1.0.0.0"); |
| 120 | 122 |
| 121 std::string error; | 123 std::string error; |
| 122 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 124 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 123 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 125 install_dir, Manifest::LOAD, Extension::NO_FLAGS, &error)); |
| 124 ASSERT_TRUE(extension != NULL); | 126 ASSERT_TRUE(extension != NULL); |
| 125 EXPECT_EQ("The first extension that I made.", extension->description()); | 127 EXPECT_EQ("The first extension that I made.", extension->description()); |
| 126 } | 128 } |
| 127 | 129 |
| 128 TEST_F(ExtensionFileUtilTest, LoadExtensionWithoutLocalesFolder) { | 130 TEST_F(ExtensionFileUtilTest, LoadExtensionWithoutLocalesFolder) { |
| 129 FilePath install_dir; | 131 FilePath install_dir; |
| 130 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 132 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 131 install_dir = install_dir.AppendASCII("extensions") | 133 install_dir = install_dir.AppendASCII("extensions") |
| 132 .AppendASCII("good") | 134 .AppendASCII("good") |
| 133 .AppendASCII("Extensions") | 135 .AppendASCII("Extensions") |
| 134 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") | 136 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") |
| 135 .AppendASCII("1.0"); | 137 .AppendASCII("1.0"); |
| 136 | 138 |
| 137 std::string error; | 139 std::string error; |
| 138 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 140 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 139 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 141 install_dir, Manifest::LOAD, Extension::NO_FLAGS, &error)); |
| 140 ASSERT_FALSE(extension == NULL); | 142 ASSERT_FALSE(extension == NULL); |
| 141 EXPECT_TRUE(error.empty()); | 143 EXPECT_TRUE(error.empty()); |
| 142 } | 144 } |
| 143 | 145 |
| 144 #if defined(OS_WIN) | 146 #if defined(OS_WIN) |
| 145 // http://crbug.com/106381 | 147 // http://crbug.com/106381 |
| 146 #define CheckIllegalFilenamesNoUnderscores \ | 148 #define CheckIllegalFilenamesNoUnderscores \ |
| 147 DISABLED_CheckIllegalFilenamesNoUnderscores | 149 DISABLED_CheckIllegalFilenamesNoUnderscores |
| 148 #endif | 150 #endif |
| 149 TEST_F(ExtensionFileUtilTest, CheckIllegalFilenamesNoUnderscores) { | 151 TEST_F(ExtensionFileUtilTest, CheckIllegalFilenamesNoUnderscores) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 FilePath install_dir; | 205 FilePath install_dir; |
| 204 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 206 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 205 install_dir = install_dir.AppendASCII("extensions") | 207 install_dir = install_dir.AppendASCII("extensions") |
| 206 .AppendASCII("bad") | 208 .AppendASCII("bad") |
| 207 .AppendASCII("Extensions") | 209 .AppendASCII("Extensions") |
| 208 .AppendASCII("dddddddddddddddddddddddddddddddd") | 210 .AppendASCII("dddddddddddddddddddddddddddddddd") |
| 209 .AppendASCII("1.0"); | 211 .AppendASCII("1.0"); |
| 210 | 212 |
| 211 std::string error; | 213 std::string error; |
| 212 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 214 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 213 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 215 install_dir, Manifest::LOAD, Extension::NO_FLAGS, &error)); |
| 214 ASSERT_TRUE(extension == NULL); | 216 ASSERT_TRUE(extension == NULL); |
| 215 ASSERT_FALSE(error.empty()); | 217 ASSERT_FALSE(error.empty()); |
| 216 ASSERT_STREQ("Manifest file is missing or unreadable.", error.c_str()); | 218 ASSERT_STREQ("Manifest file is missing or unreadable.", error.c_str()); |
| 217 } | 219 } |
| 218 | 220 |
| 219 TEST_F(ExtensionFileUtilTest, LoadExtensionGivesHelpfullErrorOnBadManifest) { | 221 TEST_F(ExtensionFileUtilTest, LoadExtensionGivesHelpfullErrorOnBadManifest) { |
| 220 FilePath install_dir; | 222 FilePath install_dir; |
| 221 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 223 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 222 install_dir = install_dir.AppendASCII("extensions") | 224 install_dir = install_dir.AppendASCII("extensions") |
| 223 .AppendASCII("bad") | 225 .AppendASCII("bad") |
| 224 .AppendASCII("Extensions") | 226 .AppendASCII("Extensions") |
| 225 .AppendASCII("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") | 227 .AppendASCII("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") |
| 226 .AppendASCII("1.0"); | 228 .AppendASCII("1.0"); |
| 227 | 229 |
| 228 std::string error; | 230 std::string error; |
| 229 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 231 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 230 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 232 install_dir, Manifest::LOAD, Extension::NO_FLAGS, &error)); |
| 231 ASSERT_TRUE(extension == NULL); | 233 ASSERT_TRUE(extension == NULL); |
| 232 ASSERT_FALSE(error.empty()); | 234 ASSERT_FALSE(error.empty()); |
| 233 ASSERT_STREQ("Manifest is not valid JSON. " | 235 ASSERT_STREQ("Manifest is not valid JSON. " |
| 234 "Line: 2, column: 16, Syntax error.", error.c_str()); | 236 "Line: 2, column: 16, Syntax error.", error.c_str()); |
| 235 } | 237 } |
| 236 | 238 |
| 237 TEST_F(ExtensionFileUtilTest, FailLoadingNonUTF8Scripts) { | 239 TEST_F(ExtensionFileUtilTest, FailLoadingNonUTF8Scripts) { |
| 238 FilePath install_dir; | 240 FilePath install_dir; |
| 239 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 241 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 240 install_dir = install_dir.AppendASCII("extensions") | 242 install_dir = install_dir.AppendASCII("extensions") |
| 241 .AppendASCII("bad") | 243 .AppendASCII("bad") |
| 242 .AppendASCII("bad_encoding"); | 244 .AppendASCII("bad_encoding"); |
| 243 | 245 |
| 244 std::string error; | 246 std::string error; |
| 245 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 247 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 246 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 248 install_dir, Manifest::LOAD, Extension::NO_FLAGS, &error)); |
| 247 ASSERT_TRUE(extension == NULL); | 249 ASSERT_TRUE(extension == NULL); |
| 248 ASSERT_STREQ("Could not load file 'bad_encoding.js' for content script. " | 250 ASSERT_STREQ("Could not load file 'bad_encoding.js' for content script. " |
| 249 "It isn't UTF-8 encoded.", error.c_str()); | 251 "It isn't UTF-8 encoded.", error.c_str()); |
| 250 } | 252 } |
| 251 | 253 |
| 252 TEST_F(ExtensionFileUtilTest, ExtensionURLToRelativeFilePath) { | 254 TEST_F(ExtensionFileUtilTest, ExtensionURLToRelativeFilePath) { |
| 253 #define URL_PREFIX "chrome-extension://extension-id/" | 255 #define URL_PREFIX "chrome-extension://extension-id/" |
| 254 struct TestCase { | 256 struct TestCase { |
| 255 const char* url; | 257 const char* url; |
| 256 const char* expected_relative_path; | 258 const char* expected_relative_path; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 EXPECT_EQ(expected_path.value(), actual_path.value()) << | 359 EXPECT_EQ(expected_path.value(), actual_path.value()) << |
| 358 " For the path " << url; | 360 " For the path " << url; |
| 359 } | 361 } |
| 360 // Remove temp files. | 362 // Remove temp files. |
| 361 ASSERT_TRUE(file_util::Delete(root_path, true)); | 363 ASSERT_TRUE(file_util::Delete(root_path, true)); |
| 362 } | 364 } |
| 363 | 365 |
| 364 static scoped_refptr<Extension> LoadExtensionManifest( | 366 static scoped_refptr<Extension> LoadExtensionManifest( |
| 365 DictionaryValue* manifest, | 367 DictionaryValue* manifest, |
| 366 const FilePath& manifest_dir, | 368 const FilePath& manifest_dir, |
| 367 Extension::Location location, | 369 Manifest::Location location, |
| 368 int extra_flags, | 370 int extra_flags, |
| 369 std::string* error) { | 371 std::string* error) { |
| 370 scoped_refptr<Extension> extension = Extension::Create( | 372 scoped_refptr<Extension> extension = Extension::Create( |
| 371 manifest_dir, location, *manifest, extra_flags, error); | 373 manifest_dir, location, *manifest, extra_flags, error); |
| 372 return extension; | 374 return extension; |
| 373 } | 375 } |
| 374 | 376 |
| 375 static scoped_refptr<Extension> LoadExtensionManifest( | 377 static scoped_refptr<Extension> LoadExtensionManifest( |
| 376 const std::string& manifest_value, | 378 const std::string& manifest_value, |
| 377 const FilePath& manifest_dir, | 379 const FilePath& manifest_dir, |
| 378 Extension::Location location, | 380 Manifest::Location location, |
| 379 int extra_flags, | 381 int extra_flags, |
| 380 std::string* error) { | 382 std::string* error) { |
| 381 JSONStringValueSerializer serializer(manifest_value); | 383 JSONStringValueSerializer serializer(manifest_value); |
| 382 scoped_ptr<Value> result(serializer.Deserialize(NULL, error)); | 384 scoped_ptr<Value> result(serializer.Deserialize(NULL, error)); |
| 383 if (!result.get()) | 385 if (!result.get()) |
| 384 return NULL; | 386 return NULL; |
| 385 CHECK_EQ(Value::TYPE_DICTIONARY, result->GetType()); | 387 CHECK_EQ(Value::TYPE_DICTIONARY, result->GetType()); |
| 386 return LoadExtensionManifest(static_cast<DictionaryValue*>(result.get()), | 388 return LoadExtensionManifest(static_cast<DictionaryValue*>(result.get()), |
| 387 manifest_dir, | 389 manifest_dir, |
| 388 location, | 390 location, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 404 non_ascii_file)); | 406 non_ascii_file)); |
| 405 file_util::WriteFile(non_ascii_path, "", 0); | 407 file_util::WriteFile(non_ascii_path, "", 0); |
| 406 | 408 |
| 407 std::string kManifest = | 409 std::string kManifest = |
| 408 base::StringPrintf( | 410 base::StringPrintf( |
| 409 "{ \"name\": \"Test\", \"version\": \"1.0\", " | 411 "{ \"name\": \"Test\", \"version\": \"1.0\", " |
| 410 " \"theme\": { \"images\": { \"theme_frame\": \"%s\" } }" | 412 " \"theme\": { \"images\": { \"theme_frame\": \"%s\" } }" |
| 411 "}", non_ascii_file.c_str()); | 413 "}", non_ascii_file.c_str()); |
| 412 std::string error; | 414 std::string error; |
| 413 scoped_refptr<Extension> extension = LoadExtensionManifest( | 415 scoped_refptr<Extension> extension = LoadExtensionManifest( |
| 414 kManifest, temp.path(), Extension::LOAD, 0, &error); | 416 kManifest, temp.path(), Manifest::LOAD, 0, &error); |
| 415 ASSERT_TRUE(extension.get()) << error; | 417 ASSERT_TRUE(extension.get()) << error; |
| 416 | 418 |
| 417 Extension::InstallWarningVector warnings; | 419 extensions::InstallWarning::Vector warnings; |
| 418 EXPECT_TRUE(extension_file_util::ValidateExtension(extension, | 420 EXPECT_TRUE(extension_file_util::ValidateExtension(extension, |
| 419 &error, &warnings)) << | 421 &error, &warnings)) << |
| 420 error; | 422 error; |
| 421 EXPECT_EQ(0U, warnings.size()); | 423 EXPECT_EQ(0U, warnings.size()); |
| 422 } | 424 } |
| 423 | 425 |
| 424 #if defined(OS_WIN) | 426 #if defined(OS_WIN) |
| 425 // This test hangs on Windows sometimes. http://crbug.com/110279 | 427 // This test hangs on Windows sometimes. http://crbug.com/110279 |
| 426 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist | 428 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist |
| 427 #else | 429 #else |
| 428 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist | 430 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist |
| 429 #endif | 431 #endif |
| 430 TEST_F(ExtensionFileUtilTest, MAYBE_BackgroundScriptsMustExist) { | 432 TEST_F(ExtensionFileUtilTest, MAYBE_BackgroundScriptsMustExist) { |
| 431 base::ScopedTempDir temp; | 433 base::ScopedTempDir temp; |
| 432 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 434 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 433 | 435 |
| 434 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | 436 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
| 435 value->SetString("name", "test"); | 437 value->SetString("name", "test"); |
| 436 value->SetString("version", "1"); | 438 value->SetString("version", "1"); |
| 437 value->SetInteger("manifest_version", 1); | 439 value->SetInteger("manifest_version", 1); |
| 438 | 440 |
| 439 ListValue* scripts = new ListValue(); | 441 ListValue* scripts = new ListValue(); |
| 440 scripts->Append(Value::CreateStringValue("foo.js")); | 442 scripts->Append(Value::CreateStringValue("foo.js")); |
| 441 value->Set("background.scripts", scripts); | 443 value->Set("background.scripts", scripts); |
| 442 | 444 |
| 443 std::string error; | 445 std::string error; |
| 444 Extension::InstallWarningVector warnings; | 446 extensions::InstallWarning::Vector warnings; |
| 445 scoped_refptr<Extension> extension = LoadExtensionManifest( | 447 scoped_refptr<Extension> extension = LoadExtensionManifest( |
| 446 value.get(), temp.path(), Extension::LOAD, 0, &error); | 448 value.get(), temp.path(), Manifest::LOAD, 0, &error); |
| 447 ASSERT_TRUE(extension.get()) << error; | 449 ASSERT_TRUE(extension.get()) << error; |
| 448 | 450 |
| 449 EXPECT_FALSE(extension_file_util::ValidateExtension(extension, | 451 EXPECT_FALSE(extension_file_util::ValidateExtension(extension, |
| 450 &error, &warnings)); | 452 &error, &warnings)); |
| 451 EXPECT_EQ(l10n_util::GetStringFUTF8( | 453 EXPECT_EQ(l10n_util::GetStringFUTF8( |
| 452 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, ASCIIToUTF16("foo.js")), | 454 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, ASCIIToUTF16("foo.js")), |
| 453 error); | 455 error); |
| 454 EXPECT_EQ(0U, warnings.size()); | 456 EXPECT_EQ(0U, warnings.size()); |
| 455 | 457 |
| 456 scripts->Clear(); | 458 scripts->Clear(); |
| 457 scripts->Append(Value::CreateStringValue("http://google.com/foo.js")); | 459 scripts->Append(Value::CreateStringValue("http://google.com/foo.js")); |
| 458 | 460 |
| 459 extension = LoadExtensionManifest(value.get(), temp.path(), Extension::LOAD, | 461 extension = LoadExtensionManifest(value.get(), temp.path(), Manifest::LOAD, |
| 460 0, &error); | 462 0, &error); |
| 461 ASSERT_TRUE(extension.get()) << error; | 463 ASSERT_TRUE(extension.get()) << error; |
| 462 | 464 |
| 463 warnings.clear(); | 465 warnings.clear(); |
| 464 EXPECT_FALSE(extension_file_util::ValidateExtension(extension, | 466 EXPECT_FALSE(extension_file_util::ValidateExtension(extension, |
| 465 &error, &warnings)); | 467 &error, &warnings)); |
| 466 EXPECT_EQ(l10n_util::GetStringFUTF8( | 468 EXPECT_EQ(l10n_util::GetStringFUTF8( |
| 467 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, | 469 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, |
| 468 ASCIIToUTF16("http://google.com/foo.js")), | 470 ASCIIToUTF16("http://google.com/foo.js")), |
| 469 error); | 471 error); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 " \"manifest_version\": 2,\n" | 532 " \"manifest_version\": 2,\n" |
| 531 " \"description\": \"The first extension that I made.\"\n" | 533 " \"description\": \"The first extension that I made.\"\n" |
| 532 "}\n"; | 534 "}\n"; |
| 533 ASSERT_TRUE(file_util::WriteFile(ext_path.AppendASCII("manifest.json"), | 535 ASSERT_TRUE(file_util::WriteFile(ext_path.AppendASCII("manifest.json"), |
| 534 manifest, strlen(manifest))); | 536 manifest, strlen(manifest))); |
| 535 ASSERT_TRUE(file_util::WriteFile(ext_path.AppendASCII("a_key.pem"), | 537 ASSERT_TRUE(file_util::WriteFile(ext_path.AppendASCII("a_key.pem"), |
| 536 private_key, strlen(private_key))); | 538 private_key, strlen(private_key))); |
| 537 | 539 |
| 538 std::string error; | 540 std::string error; |
| 539 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 541 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 540 ext_path, "the_id", Extension::EXTERNAL_PREF, | 542 ext_path, "the_id", Manifest::EXTERNAL_PREF, |
| 541 Extension::NO_FLAGS, &error)); | 543 Extension::NO_FLAGS, &error)); |
| 542 ASSERT_TRUE(extension.get()) << error; | 544 ASSERT_TRUE(extension.get()) << error; |
| 543 ASSERT_EQ(1u, extension->install_warnings().size()); | 545 ASSERT_EQ(1u, extension->install_warnings().size()); |
| 544 EXPECT_THAT( | 546 EXPECT_THAT( |
| 545 extension->install_warnings(), | 547 extension->install_warnings(), |
| 546 testing::ElementsAre( | 548 testing::ElementsAre( |
| 547 testing::Field( | 549 testing::Field( |
| 548 &Extension::InstallWarning::message, | 550 &extensions::InstallWarning::message, |
| 549 testing::ContainsRegex( | 551 testing::ContainsRegex( |
| 550 "extension includes the key file.*ext_root.a_key.pem")))); | 552 "extension includes the key file.*ext_root.a_key.pem")))); |
| 551 | 553 |
| 552 // Turn the warning into an error with ERROR_ON_PRIVATE_KEY. | 554 // Turn the warning into an error with ERROR_ON_PRIVATE_KEY. |
| 553 extension = extension_file_util::LoadExtension( | 555 extension = extension_file_util::LoadExtension( |
| 554 ext_path, "the_id", Extension::EXTERNAL_PREF, | 556 ext_path, "the_id", Manifest::EXTERNAL_PREF, |
| 555 Extension::ERROR_ON_PRIVATE_KEY, &error); | 557 Extension::ERROR_ON_PRIVATE_KEY, &error); |
| 556 EXPECT_FALSE(extension.get()); | 558 EXPECT_FALSE(extension.get()); |
| 557 EXPECT_THAT(error, | 559 EXPECT_THAT(error, |
| 558 testing::ContainsRegex( | 560 testing::ContainsRegex( |
| 559 "extension includes the key file.*ext_root.a_key.pem")); | 561 "extension includes the key file.*ext_root.a_key.pem")); |
| 560 } | 562 } |
| 561 | 563 |
| 562 TEST_F(ExtensionFileUtilTest, CheckZeroLengthImageFile) { | 564 TEST_F(ExtensionFileUtilTest, CheckZeroLengthImageFile) { |
| 563 FilePath install_dir; | 565 FilePath install_dir; |
| 564 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 566 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 565 | 567 |
| 566 // Try to install an extension with a zero-length icon file. | 568 // Try to install an extension with a zero-length icon file. |
| 567 FilePath ext_dir = install_dir.AppendASCII("extensions") | 569 FilePath ext_dir = install_dir.AppendASCII("extensions") |
| 568 .AppendASCII("bad") | 570 .AppendASCII("bad") |
| 569 .AppendASCII("Extensions") | 571 .AppendASCII("Extensions") |
| 570 .AppendASCII("ffffffffffffffffffffffffffffffff"); | 572 .AppendASCII("ffffffffffffffffffffffffffffffff"); |
| 571 | 573 |
| 572 std::string error; | 574 std::string error; |
| 573 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 575 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 574 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 576 ext_dir, Manifest::LOAD, Extension::NO_FLAGS, &error)); |
| 575 ASSERT_TRUE(extension == NULL); | 577 ASSERT_TRUE(extension == NULL); |
| 576 ASSERT_STREQ("Could not load extension icon 'icon.png'.", | 578 ASSERT_STREQ("Could not load extension icon 'icon.png'.", |
| 577 error.c_str()); | 579 error.c_str()); |
| 578 | 580 |
| 579 // Try to install an extension with a zero-length browser action icon file. | 581 // Try to install an extension with a zero-length browser action icon file. |
| 580 ext_dir = install_dir.AppendASCII("extensions") | 582 ext_dir = install_dir.AppendASCII("extensions") |
| 581 .AppendASCII("bad") | 583 .AppendASCII("bad") |
| 582 .AppendASCII("Extensions") | 584 .AppendASCII("Extensions") |
| 583 .AppendASCII("gggggggggggggggggggggggggggggggg"); | 585 .AppendASCII("gggggggggggggggggggggggggggggggg"); |
| 584 | 586 |
| 585 scoped_refptr<Extension> extension2(extension_file_util::LoadExtension( | 587 scoped_refptr<Extension> extension2(extension_file_util::LoadExtension( |
| 586 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 588 ext_dir, Manifest::LOAD, Extension::NO_FLAGS, &error)); |
| 587 ASSERT_TRUE(extension2 == NULL); | 589 ASSERT_TRUE(extension2 == NULL); |
| 588 ASSERT_STREQ("Could not load icon 'icon.png' for browser action.", | 590 ASSERT_STREQ("Could not load icon 'icon.png' for browser action.", |
| 589 error.c_str()); | 591 error.c_str()); |
| 590 | 592 |
| 591 // Try to install an extension with a zero-length page action icon file. | 593 // Try to install an extension with a zero-length page action icon file. |
| 592 ext_dir = install_dir.AppendASCII("extensions") | 594 ext_dir = install_dir.AppendASCII("extensions") |
| 593 .AppendASCII("bad") | 595 .AppendASCII("bad") |
| 594 .AppendASCII("Extensions") | 596 .AppendASCII("Extensions") |
| 595 .AppendASCII("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"); | 597 .AppendASCII("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"); |
| 596 | 598 |
| 597 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( | 599 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( |
| 598 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); | 600 ext_dir, Manifest::LOAD, Extension::NO_FLAGS, &error)); |
| 599 ASSERT_TRUE(extension3 == NULL); | 601 ASSERT_TRUE(extension3 == NULL); |
| 600 ASSERT_STREQ("Could not load icon 'icon.png' for page action.", | 602 ASSERT_STREQ("Could not load icon 'icon.png' for page action.", |
| 601 error.c_str()); | 603 error.c_str()); |
| 602 } | 604 } |
| 603 | 605 |
| 604 // TODO(aa): More tests as motivation allows. Maybe steal some from | 606 // TODO(aa): More tests as motivation allows. Maybe steal some from |
| 605 // ExtensionService? Many of them could probably be tested here without the | 607 // ExtensionService? Many of them could probably be tested here without the |
| 606 // MessageLoop shenanigans. | 608 // MessageLoop shenanigans. |
| OLD | NEW |