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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/pattern.h" | 10 #include "base/strings/pattern.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 const char kExpected[] = "Could not decode image: "; | 188 const char kExpected[] = "Could not decode image: "; |
189 SetupUnpacker("bad_image.crx"); | 189 SetupUnpacker("bad_image.crx"); |
190 EXPECT_FALSE(unpacker_->Run()); | 190 EXPECT_FALSE(unpacker_->Run()); |
191 EXPECT_TRUE(base::StartsWith(unpacker_->error_message(), | 191 EXPECT_TRUE(base::StartsWith(unpacker_->error_message(), |
192 ASCIIToUTF16(kExpected), | 192 ASCIIToUTF16(kExpected), |
193 base::CompareCase::INSENSITIVE_ASCII)) | 193 base::CompareCase::INSENSITIVE_ASCII)) |
194 << "Expected prefix: \"" << kExpected << "\", actual error: \"" | 194 << "Expected prefix: \"" << kExpected << "\", actual error: \"" |
195 << unpacker_->error_message() << "\""; | 195 << unpacker_->error_message() << "\""; |
196 } | 196 } |
197 | 197 |
| 198 base::FilePath CreateEmptyTestFile(const base::FilePath& test_dir, |
| 199 const base::FilePath& file_path) { |
| 200 base::FilePath test_file(test_dir.Append(file_path)); |
| 201 base::FilePath temp_file; |
| 202 EXPECT_TRUE(base::CreateTemporaryFileInDir(test_dir, &temp_file)); |
| 203 EXPECT_TRUE(base::Move(temp_file, test_file)); |
| 204 return test_file; |
| 205 } |
| 206 |
| 207 TEST_F(UnpackerTest, BlockedFileTypes) { |
| 208 const struct { |
| 209 const base::FilePath::CharType* input; |
| 210 bool expected; |
| 211 } cases[] = { |
| 212 {FILE_PATH_LITERAL("foo"), true}, |
| 213 {FILE_PATH_LITERAL("foo.nexe"), true}, |
| 214 {FILE_PATH_LITERAL("foo.dll"), true}, |
| 215 {FILE_PATH_LITERAL("foo.jpg.exe"), false}, |
| 216 {FILE_PATH_LITERAL("foo.exe"), false}, |
| 217 }; |
| 218 |
| 219 base::ScopedTempDir temp_dir; |
| 220 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 221 |
| 222 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 223 base::FilePath input(cases[i].input); |
| 224 base::FilePath test_file(CreateEmptyTestFile(temp_dir.path(), input)); |
| 225 bool observed = Unpacker::ShouldExtractFile(test_file); |
| 226 EXPECT_EQ(cases[i].expected, observed) << "i: " << i |
| 227 << ", input: " << test_file.value(); |
| 228 } |
| 229 } |
| 230 |
198 } // namespace extensions | 231 } // namespace extensions |
OLD | NEW |