| 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/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.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/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 15 #include "chrome/common/extensions/extension_manifest_constants.h" | 15 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 | 20 |
| 21 using extensions::Extension; | 21 using extensions::Extension; |
| 22 | 22 |
| 23 namespace keys = extension_manifest_keys; | 23 namespace keys = extension_manifest_keys; |
| 24 | 24 |
| 25 #if defined(OS_WIN) |
| 26 // http://crbug.com/106381 |
| 27 #define InstallUninstallGarbageCollect DISABLED_InstallUninstallGarbageCollect |
| 28 #endif |
| 29 TEST(ExtensionFileUtil, InstallUninstallGarbageCollect) { |
| 30 ScopedTempDir temp; |
| 31 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 32 |
| 33 // Create a source extension. |
| 34 std::string extension_id("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| 35 std::string version("1.0"); |
| 36 FilePath src = temp.path().AppendASCII(extension_id); |
| 37 ASSERT_TRUE(file_util::CreateDirectory(src)); |
| 38 |
| 39 // Create a extensions tree. |
| 40 FilePath all_extensions = temp.path().AppendASCII("extensions"); |
| 41 ASSERT_TRUE(file_util::CreateDirectory(all_extensions)); |
| 42 |
| 43 // Install in empty directory. Should create parent directories as needed. |
| 44 FilePath version_1 = extension_file_util::InstallExtension(src, |
| 45 extension_id, |
| 46 version, |
| 47 all_extensions); |
| 48 ASSERT_EQ(version_1.value(), |
| 49 all_extensions.AppendASCII(extension_id).AppendASCII("1.0_0") |
| 50 .value()); |
| 51 ASSERT_TRUE(file_util::DirectoryExists(version_1)); |
| 52 |
| 53 // Should have moved the source. |
| 54 ASSERT_FALSE(file_util::DirectoryExists(src)); |
| 55 |
| 56 // Install again. Should create a new one with different name. |
| 57 ASSERT_TRUE(file_util::CreateDirectory(src)); |
| 58 FilePath version_2 = extension_file_util::InstallExtension(src, |
| 59 extension_id, |
| 60 version, |
| 61 all_extensions); |
| 62 ASSERT_EQ(version_2.value(), |
| 63 all_extensions.AppendASCII(extension_id).AppendASCII("1.0_1") |
| 64 .value()); |
| 65 ASSERT_TRUE(file_util::DirectoryExists(version_2)); |
| 66 |
| 67 // Collect garbage. Should remove first one. |
| 68 std::map<std::string, FilePath> extension_paths; |
| 69 extension_paths[extension_id] = |
| 70 FilePath().AppendASCII(extension_id).Append(version_2.BaseName()); |
| 71 extension_file_util::GarbageCollectExtensions(all_extensions, |
| 72 extension_paths); |
| 73 ASSERT_FALSE(file_util::DirectoryExists(version_1)); |
| 74 ASSERT_TRUE(file_util::DirectoryExists(version_2)); |
| 75 |
| 76 // Uninstall. Should remove entire extension subtree. |
| 77 extension_file_util::UninstallExtension(all_extensions, extension_id); |
| 78 ASSERT_FALSE(file_util::DirectoryExists(version_2.DirName())); |
| 79 ASSERT_TRUE(file_util::DirectoryExists(all_extensions)); |
| 80 } |
| 81 |
| 25 TEST(ExtensionFileUtil, LoadExtensionWithValidLocales) { | 82 TEST(ExtensionFileUtil, LoadExtensionWithValidLocales) { |
| 26 FilePath install_dir; | 83 FilePath install_dir; |
| 27 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 84 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 28 install_dir = install_dir.AppendASCII("extensions") | 85 install_dir = install_dir.AppendASCII("extensions") |
| 29 .AppendASCII("good") | 86 .AppendASCII("good") |
| 30 .AppendASCII("Extensions") | 87 .AppendASCII("Extensions") |
| 31 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 88 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 32 .AppendASCII("1.0.0.0"); | 89 .AppendASCII("1.0.0.0"); |
| 33 | 90 |
| 34 std::string error; | 91 std::string error; |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 Extension::ERROR_ON_PRIVATE_KEY, &error); | 524 Extension::ERROR_ON_PRIVATE_KEY, &error); |
| 468 EXPECT_FALSE(extension.get()); | 525 EXPECT_FALSE(extension.get()); |
| 469 EXPECT_THAT(error, | 526 EXPECT_THAT(error, |
| 470 testing::ContainsRegex( | 527 testing::ContainsRegex( |
| 471 "extension includes the key file.*ext_root.a_key.pem")); | 528 "extension includes the key file.*ext_root.a_key.pem")); |
| 472 } | 529 } |
| 473 | 530 |
| 474 // TODO(aa): More tests as motivation allows. Maybe steal some from | 531 // TODO(aa): More tests as motivation allows. Maybe steal some from |
| 475 // ExtensionService? Many of them could probably be tested here without the | 532 // ExtensionService? Many of them could probably be tested here without the |
| 476 // MessageLoop shenanigans. | 533 // MessageLoop shenanigans. |
| OLD | NEW |