| 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 12 #include "chrome/common/extensions/extension_manifest_constants.h" | 12 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 13 #include "chrome/common/extensions/extension_unpacker.h" | 13 #include "chrome/common/extensions/unpacker.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 | 16 |
| 17 namespace errors = extension_manifest_errors; | 17 namespace errors = extension_manifest_errors; |
| 18 namespace keys = extension_manifest_keys; | 18 namespace keys = extension_manifest_keys; |
| 19 | 19 |
| 20 class ExtensionUnpackerTest : public testing::Test { | 20 namespace extensions { |
| 21 |
| 22 class UnpackerTest : public testing::Test { |
| 21 public: | 23 public: |
| 22 ~ExtensionUnpackerTest() { | 24 ~UnpackerTest() { |
| 23 LOG(WARNING) << "Deleting temp dir: " | 25 LOG(WARNING) << "Deleting temp dir: " |
| 24 << temp_dir_.path().LossyDisplayName(); | 26 << temp_dir_.path().LossyDisplayName(); |
| 25 LOG(WARNING) << temp_dir_.Delete(); | 27 LOG(WARNING) << temp_dir_.Delete(); |
| 26 } | 28 } |
| 27 | 29 |
| 28 void SetupUnpacker(const std::string& crx_name) { | 30 void SetupUnpacker(const std::string& crx_name) { |
| 29 FilePath original_path; | 31 FilePath original_path; |
| 30 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); | 32 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); |
| 31 original_path = original_path.AppendASCII("extensions") | 33 original_path = original_path.AppendASCII("extensions") |
| 32 .AppendASCII("unpacker") | 34 .AppendASCII("unpacker") |
| 33 .AppendASCII(crx_name); | 35 .AppendASCII(crx_name); |
| 34 ASSERT_TRUE(file_util::PathExists(original_path)) << original_path.value(); | 36 ASSERT_TRUE(file_util::PathExists(original_path)) << original_path.value(); |
| 35 | 37 |
| 36 // Try bots won't let us write into DIR_TEST_DATA, so we have to create | 38 // Try bots won't let us write into DIR_TEST_DATA, so we have to create |
| 37 // a temp folder to play in. | 39 // a temp folder to play in. |
| 38 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 39 | 41 |
| 40 FilePath crx_path = temp_dir_.path().AppendASCII(crx_name); | 42 FilePath crx_path = temp_dir_.path().AppendASCII(crx_name); |
| 41 ASSERT_TRUE(file_util::CopyFile(original_path, crx_path)) << | 43 ASSERT_TRUE(file_util::CopyFile(original_path, crx_path)) << |
| 42 "Original path " << original_path.value() << | 44 "Original path " << original_path.value() << |
| 43 ", Crx path " << crx_path.value(); | 45 ", Crx path " << crx_path.value(); |
| 44 | 46 |
| 45 unpacker_.reset( | 47 unpacker_.reset(new Unpacker(crx_path, |
| 46 new ExtensionUnpacker(crx_path, | 48 std::string(), |
| 47 std::string(), | 49 Extension::INTERNAL, |
| 48 extensions::Extension::INTERNAL, | 50 Extension::NO_FLAGS)); |
| 49 extensions::Extension::NO_FLAGS)); | |
| 50 } | 51 } |
| 51 | 52 |
| 52 protected: | 53 protected: |
| 53 ScopedTempDir temp_dir_; | 54 ScopedTempDir temp_dir_; |
| 54 scoped_ptr<ExtensionUnpacker> unpacker_; | 55 scoped_ptr<Unpacker> unpacker_; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 // Crashes intermittently on Windows, see http://crbug.com/109238 | 58 // Crashes intermittently on Windows, see http://crbug.com/109238 |
| 58 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
| 59 #define MAYBE_EmptyDefaultLocale DISABLED_EmptyDefaultLocale | 60 #define MAYBE_EmptyDefaultLocale DISABLED_EmptyDefaultLocale |
| 60 #else | 61 #else |
| 61 #define MAYBE_EmptyDefaultLocale EmptyDefaultLocale | 62 #define MAYBE_EmptyDefaultLocale EmptyDefaultLocale |
| 62 #endif | 63 #endif |
| 63 TEST_F(ExtensionUnpackerTest, MAYBE_EmptyDefaultLocale) { | 64 TEST_F(UnpackerTest, MAYBE_EmptyDefaultLocale) { |
| 64 SetupUnpacker("empty_default_locale.crx"); | 65 SetupUnpacker("empty_default_locale.crx"); |
| 65 EXPECT_FALSE(unpacker_->Run()); | 66 EXPECT_FALSE(unpacker_->Run()); |
| 66 EXPECT_EQ(ASCIIToUTF16(errors::kInvalidDefaultLocale), | 67 EXPECT_EQ(ASCIIToUTF16(errors::kInvalidDefaultLocale), |
| 67 unpacker_->error_message()); | 68 unpacker_->error_message()); |
| 68 } | 69 } |
| 69 | 70 |
| 70 // Crashes intermittently on Vista, see http://crbug.com/109385 | 71 // Crashes intermittently on Vista, see http://crbug.com/109385 |
| 71 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
| 72 #define MAYBE_HasDefaultLocaleMissingLocalesFolder \ | 73 #define MAYBE_HasDefaultLocaleMissingLocalesFolder \ |
| 73 DISABLED_HasDefaultLocaleMissingLocalesFolder | 74 DISABLED_HasDefaultLocaleMissingLocalesFolder |
| 74 #else | 75 #else |
| 75 #define MAYBE_HasDefaultLocaleMissingLocalesFolder \ | 76 #define MAYBE_HasDefaultLocaleMissingLocalesFolder \ |
| 76 HasDefaultLocaleMissingLocalesFolder | 77 HasDefaultLocaleMissingLocalesFolder |
| 77 #endif | 78 #endif |
| 78 TEST_F(ExtensionUnpackerTest, MAYBE_HasDefaultLocaleMissingLocalesFolder) { | 79 TEST_F(UnpackerTest, MAYBE_HasDefaultLocaleMissingLocalesFolder) { |
| 79 SetupUnpacker("has_default_missing_locales.crx"); | 80 SetupUnpacker("has_default_missing_locales.crx"); |
| 80 EXPECT_FALSE(unpacker_->Run()); | 81 EXPECT_FALSE(unpacker_->Run()); |
| 81 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesTreeMissing), | 82 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesTreeMissing), |
| 82 unpacker_->error_message()); | 83 unpacker_->error_message()); |
| 83 } | 84 } |
| 84 | 85 |
| 85 // Crashes intermittently on Windows, see http://crbug.com/109238 | 86 // Crashes intermittently on Windows, see http://crbug.com/109238 |
| 86 #if defined(OS_WIN) | 87 #if defined(OS_WIN) |
| 87 #define MAYBE_InvalidDefaultLocale DISABLED_InvalidDefaultLocale | 88 #define MAYBE_InvalidDefaultLocale DISABLED_InvalidDefaultLocale |
| 88 #else | 89 #else |
| 89 #define MAYBE_InvalidDefaultLocale InvalidDefaultLocale | 90 #define MAYBE_InvalidDefaultLocale InvalidDefaultLocale |
| 90 #endif | 91 #endif |
| 91 TEST_F(ExtensionUnpackerTest, MAYBE_InvalidDefaultLocale) { | 92 TEST_F(UnpackerTest, MAYBE_InvalidDefaultLocale) { |
| 92 SetupUnpacker("invalid_default_locale.crx"); | 93 SetupUnpacker("invalid_default_locale.crx"); |
| 93 EXPECT_FALSE(unpacker_->Run()); | 94 EXPECT_FALSE(unpacker_->Run()); |
| 94 EXPECT_EQ(ASCIIToUTF16(errors::kInvalidDefaultLocale), | 95 EXPECT_EQ(ASCIIToUTF16(errors::kInvalidDefaultLocale), |
| 95 unpacker_->error_message()); | 96 unpacker_->error_message()); |
| 96 } | 97 } |
| 97 | 98 |
| 98 // Crashes intermittently on Windows, see http://crbug.com/109738 | 99 // Crashes intermittently on Windows, see http://crbug.com/109738 |
| 99 #if defined(OS_WIN) | 100 #if defined(OS_WIN) |
| 100 #define MAYBE_InvalidMessagesFile DISABLED_InvalidMessagesFile | 101 #define MAYBE_InvalidMessagesFile DISABLED_InvalidMessagesFile |
| 101 #else | 102 #else |
| 102 #define MAYBE_InvalidMessagesFile InvalidMessagesFile | 103 #define MAYBE_InvalidMessagesFile InvalidMessagesFile |
| 103 #endif | 104 #endif |
| 104 TEST_F(ExtensionUnpackerTest, MAYBE_InvalidMessagesFile) { | 105 TEST_F(UnpackerTest, MAYBE_InvalidMessagesFile) { |
| 105 SetupUnpacker("invalid_messages_file.crx"); | 106 SetupUnpacker("invalid_messages_file.crx"); |
| 106 EXPECT_FALSE(unpacker_->Run()); | 107 EXPECT_FALSE(unpacker_->Run()); |
| 107 EXPECT_TRUE(MatchPattern(unpacker_->error_message(), | 108 EXPECT_TRUE(MatchPattern(unpacker_->error_message(), |
| 108 ASCIIToUTF16("*_locales?en_US?messages.json: Line: 2, column: 11," | 109 ASCIIToUTF16("*_locales?en_US?messages.json: Line: 2, column: 11," |
| 109 " Syntax error."))) << unpacker_->error_message(); | 110 " Syntax error."))) << unpacker_->error_message(); |
| 110 } | 111 } |
| 111 | 112 |
| 112 // Crashes intermittently on Vista, see http://crbug.com/109238 | 113 // Crashes intermittently on Vista, see http://crbug.com/109238 |
| 113 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
| 114 #define MAYBE_MissingDefaultData DISABLED_MissingDefaultData | 115 #define MAYBE_MissingDefaultData DISABLED_MissingDefaultData |
| 115 #else | 116 #else |
| 116 #define MAYBE_MissingDefaultData MissingDefaultData | 117 #define MAYBE_MissingDefaultData MissingDefaultData |
| 117 #endif | 118 #endif |
| 118 TEST_F(ExtensionUnpackerTest, MAYBE_MissingDefaultData) { | 119 TEST_F(UnpackerTest, MAYBE_MissingDefaultData) { |
| 119 SetupUnpacker("missing_default_data.crx"); | 120 SetupUnpacker("missing_default_data.crx"); |
| 120 EXPECT_FALSE(unpacker_->Run()); | 121 EXPECT_FALSE(unpacker_->Run()); |
| 121 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), | 122 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), |
| 122 unpacker_->error_message()); | 123 unpacker_->error_message()); |
| 123 } | 124 } |
| 124 | 125 |
| 125 // Crashes intermittently on Vista, see http://crbug.com/109238 | 126 // Crashes intermittently on Vista, see http://crbug.com/109238 |
| 126 #if defined(OS_WIN) | 127 #if defined(OS_WIN) |
| 127 #define MAYBE_MissingDefaultLocaleHasLocalesFolder \ | 128 #define MAYBE_MissingDefaultLocaleHasLocalesFolder \ |
| 128 DISABLED_MissingDefaultLocaleHasLocalesFolder | 129 DISABLED_MissingDefaultLocaleHasLocalesFolder |
| 129 #else | 130 #else |
| 130 #define MAYBE_MissingDefaultLocaleHasLocalesFolder \ | 131 #define MAYBE_MissingDefaultLocaleHasLocalesFolder \ |
| 131 MissingDefaultLocaleHasLocalesFolder | 132 MissingDefaultLocaleHasLocalesFolder |
| 132 #endif | 133 #endif |
| 133 TEST_F(ExtensionUnpackerTest, MAYBE_MissingDefaultLocaleHasLocalesFolder) { | 134 TEST_F(UnpackerTest, MAYBE_MissingDefaultLocaleHasLocalesFolder) { |
| 134 SetupUnpacker("missing_default_has_locales.crx"); | 135 SetupUnpacker("missing_default_has_locales.crx"); |
| 135 EXPECT_FALSE(unpacker_->Run()); | 136 EXPECT_FALSE(unpacker_->Run()); |
| 136 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultLocaleSpecified), | 137 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultLocaleSpecified), |
| 137 unpacker_->error_message()); | 138 unpacker_->error_message()); |
| 138 } | 139 } |
| 139 | 140 |
| 140 // Crashes intermittently on Vista, see http://crbug.com/109238 | 141 // Crashes intermittently on Vista, see http://crbug.com/109238 |
| 141 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
| 142 #define MAYBE_MissingMessagesFile DISABLED_MissingMessagesFile | 143 #define MAYBE_MissingMessagesFile DISABLED_MissingMessagesFile |
| 143 #else | 144 #else |
| 144 #define MAYBE_MissingMessagesFile MissingMessagesFile | 145 #define MAYBE_MissingMessagesFile MissingMessagesFile |
| 145 #endif | 146 #endif |
| 146 TEST_F(ExtensionUnpackerTest, MAYBE_MissingMessagesFile) { | 147 TEST_F(UnpackerTest, MAYBE_MissingMessagesFile) { |
| 147 SetupUnpacker("missing_messages_file.crx"); | 148 SetupUnpacker("missing_messages_file.crx"); |
| 148 EXPECT_FALSE(unpacker_->Run()); | 149 EXPECT_FALSE(unpacker_->Run()); |
| 149 EXPECT_TRUE(MatchPattern(unpacker_->error_message(), | 150 EXPECT_TRUE(MatchPattern(unpacker_->error_message(), |
| 150 ASCIIToUTF16(errors::kLocalesMessagesFileMissing) + | 151 ASCIIToUTF16(errors::kLocalesMessagesFileMissing) + |
| 151 ASCIIToUTF16("*_locales?en_US?messages.json"))); | 152 ASCIIToUTF16("*_locales?en_US?messages.json"))); |
| 152 } | 153 } |
| 153 | 154 |
| 154 // Crashes intermittently on Vista, see http://crbug.com/109238 | 155 // Crashes intermittently on Vista, see http://crbug.com/109238 |
| 155 #if defined(OS_WIN) | 156 #if defined(OS_WIN) |
| 156 #define MAYBE_NoLocaleData DISABLED_NoLocaleData | 157 #define MAYBE_NoLocaleData DISABLED_NoLocaleData |
| 157 #else | 158 #else |
| 158 #define MAYBE_NoLocaleData NoLocaleData | 159 #define MAYBE_NoLocaleData NoLocaleData |
| 159 #endif | 160 #endif |
| 160 TEST_F(ExtensionUnpackerTest, MAYBE_NoLocaleData) { | 161 TEST_F(UnpackerTest, MAYBE_NoLocaleData) { |
| 161 SetupUnpacker("no_locale_data.crx"); | 162 SetupUnpacker("no_locale_data.crx"); |
| 162 EXPECT_FALSE(unpacker_->Run()); | 163 EXPECT_FALSE(unpacker_->Run()); |
| 163 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), | 164 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), |
| 164 unpacker_->error_message()); | 165 unpacker_->error_message()); |
| 165 } | 166 } |
| 166 | 167 |
| 167 // Crashes intermittently on Vista, see http://crbug.com/109238 | 168 // Crashes intermittently on Vista, see http://crbug.com/109238 |
| 168 #if defined(OS_WIN) | 169 #if defined(OS_WIN) |
| 169 #define MAYBE_GoodL10n DISABLED_GoodL10n | 170 #define MAYBE_GoodL10n DISABLED_GoodL10n |
| 170 #else | 171 #else |
| 171 #define MAYBE_GoodL10n GoodL10n | 172 #define MAYBE_GoodL10n GoodL10n |
| 172 #endif | 173 #endif |
| 173 TEST_F(ExtensionUnpackerTest, MAYBE_GoodL10n) { | 174 TEST_F(UnpackerTest, MAYBE_GoodL10n) { |
| 174 SetupUnpacker("good_l10n.crx"); | 175 SetupUnpacker("good_l10n.crx"); |
| 175 EXPECT_TRUE(unpacker_->Run()); | 176 EXPECT_TRUE(unpacker_->Run()); |
| 176 EXPECT_TRUE(unpacker_->error_message().empty()); | 177 EXPECT_TRUE(unpacker_->error_message().empty()); |
| 177 ASSERT_EQ(2U, unpacker_->parsed_catalogs()->size()); | 178 ASSERT_EQ(2U, unpacker_->parsed_catalogs()->size()); |
| 178 } | 179 } |
| 179 | 180 |
| 180 // Crashes intermittently on Vista, see http://crbug.com/109238 | 181 // Crashes intermittently on Vista, see http://crbug.com/109238 |
| 181 #if defined(OS_WIN) | 182 #if defined(OS_WIN) |
| 182 #define MAYBE_NoL10n DISABLED_NoL10n | 183 #define MAYBE_NoL10n DISABLED_NoL10n |
| 183 #else | 184 #else |
| 184 #define MAYBE_NoL10n NoL10n | 185 #define MAYBE_NoL10n NoL10n |
| 185 #endif | 186 #endif |
| 186 TEST_F(ExtensionUnpackerTest, MAYBE_NoL10n) { | 187 TEST_F(UnpackerTest, MAYBE_NoL10n) { |
| 187 SetupUnpacker("no_l10n.crx"); | 188 SetupUnpacker("no_l10n.crx"); |
| 188 EXPECT_TRUE(unpacker_->Run()); | 189 EXPECT_TRUE(unpacker_->Run()); |
| 189 EXPECT_TRUE(unpacker_->error_message().empty()); | 190 EXPECT_TRUE(unpacker_->error_message().empty()); |
| 190 EXPECT_EQ(0U, unpacker_->parsed_catalogs()->size()); | 191 EXPECT_EQ(0U, unpacker_->parsed_catalogs()->size()); |
| 191 } | 192 } |
| 193 |
| 194 } // namespace extensions |
| OLD | NEW |