| 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/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.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/api/i18n/default_locale_handler.h" | |
| 13 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
| 15 #include "chrome/common/extensions/extension_manifest_constants.h" | 14 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 16 #include "chrome/common/extensions/manifest_handler.h" | |
| 17 #include "chrome/common/extensions/manifest_handlers/theme_handler.h" | |
| 18 #include "chrome/common/extensions/unpacker.h" | 15 #include "chrome/common/extensions/unpacker.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 21 | 18 |
| 22 namespace errors = extension_manifest_errors; | 19 namespace errors = extension_manifest_errors; |
| 23 namespace filenames = extension_filenames; | 20 namespace filenames = extension_filenames; |
| 24 namespace keys = extension_manifest_keys; | 21 namespace keys = extension_manifest_keys; |
| 25 | 22 |
| 26 namespace extensions { | 23 namespace extensions { |
| 27 | 24 |
| 28 class UnpackerTest : public testing::Test { | 25 class UnpackerTest : public testing::Test { |
| 29 public: | 26 public: |
| 30 virtual ~UnpackerTest() { | 27 virtual ~UnpackerTest() { |
| 31 LOG(WARNING) << "Deleting temp dir: " | 28 LOG(WARNING) << "Deleting temp dir: " |
| 32 << temp_dir_.path().LossyDisplayName(); | 29 << temp_dir_.path().LossyDisplayName(); |
| 33 LOG(WARNING) << temp_dir_.Delete(); | 30 LOG(WARNING) << temp_dir_.Delete(); |
| 34 } | 31 } |
| 35 | 32 |
| 36 virtual void SetUp() OVERRIDE { | |
| 37 testing::Test::SetUp(); | |
| 38 (new DefaultLocaleHandler)->Register(); | |
| 39 (new ThemeHandler)->Register(); | |
| 40 } | |
| 41 | |
| 42 virtual void TearDown() OVERRIDE { | |
| 43 ManifestHandler::ClearRegistryForTesting(); | |
| 44 } | |
| 45 | |
| 46 void SetupUnpacker(const std::string& crx_name) { | 33 void SetupUnpacker(const std::string& crx_name) { |
| 47 base::FilePath original_path; | 34 base::FilePath original_path; |
| 48 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); | 35 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); |
| 49 original_path = original_path.AppendASCII("extensions") | 36 original_path = original_path.AppendASCII("extensions") |
| 50 .AppendASCII("unpacker") | 37 .AppendASCII("unpacker") |
| 51 .AppendASCII(crx_name); | 38 .AppendASCII(crx_name); |
| 52 ASSERT_TRUE(file_util::PathExists(original_path)) << original_path.value(); | 39 ASSERT_TRUE(file_util::PathExists(original_path)) << original_path.value(); |
| 53 | 40 |
| 54 // Try bots won't let us write into DIR_TEST_DATA, so we have to create | 41 // Try bots won't let us write into DIR_TEST_DATA, so we have to create |
| 55 // a temp folder to play in. | 42 // a temp folder to play in. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 SetupUnpacker("bad_image.crx"); | 168 SetupUnpacker("bad_image.crx"); |
| 182 EXPECT_FALSE(unpacker_->Run()); | 169 EXPECT_FALSE(unpacker_->Run()); |
| 183 EXPECT_TRUE(StartsWith(unpacker_->error_message(), | 170 EXPECT_TRUE(StartsWith(unpacker_->error_message(), |
| 184 ASCIIToUTF16(kExpected), | 171 ASCIIToUTF16(kExpected), |
| 185 false)) << "Expected prefix: \"" << kExpected | 172 false)) << "Expected prefix: \"" << kExpected |
| 186 << "\", actual error: \"" << unpacker_->error_message() | 173 << "\", actual error: \"" << unpacker_->error_message() |
| 187 << "\""; | 174 << "\""; |
| 188 } | 175 } |
| 189 | 176 |
| 190 } // namespace extensions | 177 } // namespace extensions |
| OLD | NEW |