| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "base/memory/scoped_temp_dir.h" |
| 9 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
| 10 #include "chrome/common/extensions/extension_constants.h" | 11 #include "chrome/common/extensions/extension_constants.h" |
| 11 #include "chrome/common/extensions/extension_unpacker.h" | 12 #include "chrome/common/extensions/extension_unpacker.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 | 15 |
| 15 namespace errors = extension_manifest_errors; | 16 namespace errors = extension_manifest_errors; |
| 16 namespace keys = extension_manifest_keys; | 17 namespace keys = extension_manifest_keys; |
| 17 | 18 |
| 18 class ExtensionUnpackerTest : public testing::Test { | 19 class ExtensionUnpackerTest : public testing::Test { |
| 19 public: | 20 public: |
| 20 void SetupUnpacker(const std::string& crx_name) { | 21 void SetupUnpacker(const std::string& crx_name) { |
| 21 FilePath original_path; | 22 FilePath original_path; |
| 22 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); | 23 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); |
| 23 original_path = original_path.AppendASCII("extensions") | 24 original_path = original_path.AppendASCII("extensions") |
| 24 .AppendASCII("unpacker") | 25 .AppendASCII("unpacker") |
| 25 .AppendASCII(crx_name); | 26 .AppendASCII(crx_name); |
| 26 ASSERT_TRUE(file_util::PathExists(original_path)) << original_path.value(); | 27 ASSERT_TRUE(file_util::PathExists(original_path)) << original_path.value(); |
| 27 | 28 |
| 28 // Try bots won't let us write into DIR_TEST_DATA, so we have to create | 29 // Try bots won't let us write into DIR_TEST_DATA, so we have to create |
| 29 // a temp folder to play in. | 30 // a temp folder to play in. |
| 30 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &install_dir_)); | 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 31 install_dir_ = install_dir_.AppendASCII("extension_unpacker_test"); | |
| 32 file_util::Delete(install_dir_, true); | |
| 33 file_util::CreateDirectory(install_dir_); | |
| 34 | 32 |
| 35 FilePath crx_path = install_dir_.AppendASCII(crx_name); | 33 FilePath crx_path = temp_dir_.path().AppendASCII(crx_name); |
| 36 ASSERT_TRUE(file_util::CopyFile(original_path, crx_path)) << | 34 ASSERT_TRUE(file_util::CopyFile(original_path, crx_path)) << |
| 37 "Original path " << original_path.value() << | 35 "Original path " << original_path.value() << |
| 38 ", Crx path " << crx_path.value(); | 36 ", Crx path " << crx_path.value(); |
| 39 | 37 |
| 40 unpacker_.reset(new ExtensionUnpacker(crx_path)); | 38 unpacker_.reset(new ExtensionUnpacker(crx_path)); |
| 41 } | 39 } |
| 42 | 40 |
| 43 virtual void TearDown() { | |
| 44 ASSERT_TRUE(file_util::Delete(install_dir_, true)) << | |
| 45 install_dir_.value(); | |
| 46 } | |
| 47 | |
| 48 protected: | 41 protected: |
| 49 FilePath install_dir_; | 42 ScopedTempDir temp_dir_; |
| 50 scoped_ptr<ExtensionUnpacker> unpacker_; | 43 scoped_ptr<ExtensionUnpacker> unpacker_; |
| 51 }; | 44 }; |
| 52 | 45 |
| 53 TEST_F(ExtensionUnpackerTest, EmptyDefaultLocale) { | 46 TEST_F(ExtensionUnpackerTest, EmptyDefaultLocale) { |
| 54 SetupUnpacker("empty_default_locale.crx"); | 47 SetupUnpacker("empty_default_locale.crx"); |
| 55 EXPECT_FALSE(unpacker_->Run()); | 48 EXPECT_FALSE(unpacker_->Run()); |
| 56 EXPECT_EQ(errors::kInvalidDefaultLocale, unpacker_->error_message()); | 49 EXPECT_EQ(errors::kInvalidDefaultLocale, unpacker_->error_message()); |
| 57 } | 50 } |
| 58 | 51 |
| 59 TEST_F(ExtensionUnpackerTest, HasDefaultLocaleMissingLocalesFolder) { | 52 TEST_F(ExtensionUnpackerTest, HasDefaultLocaleMissingLocalesFolder) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 EXPECT_TRUE(unpacker_->error_message().empty()); | 102 EXPECT_TRUE(unpacker_->error_message().empty()); |
| 110 ASSERT_EQ(2U, unpacker_->parsed_catalogs()->size()); | 103 ASSERT_EQ(2U, unpacker_->parsed_catalogs()->size()); |
| 111 } | 104 } |
| 112 | 105 |
| 113 TEST_F(ExtensionUnpackerTest, NoL10n) { | 106 TEST_F(ExtensionUnpackerTest, NoL10n) { |
| 114 SetupUnpacker("no_l10n.crx"); | 107 SetupUnpacker("no_l10n.crx"); |
| 115 EXPECT_TRUE(unpacker_->Run()); | 108 EXPECT_TRUE(unpacker_->Run()); |
| 116 EXPECT_TRUE(unpacker_->error_message().empty()); | 109 EXPECT_TRUE(unpacker_->error_message().empty()); |
| 117 EXPECT_EQ(0U, unpacker_->parsed_catalogs()->size()); | 110 EXPECT_EQ(0U, unpacker_->parsed_catalogs()->size()); |
| 118 } | 111 } |
| OLD | NEW |