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