OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 "extensions/utility/extension_extractor_filter.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include <memory> | |
10 | |
11 #include "base/files/file_util.h" | |
12 #include "base/files/scoped_temp_dir.h" | |
13 #include "base/macros.h" | |
14 #include "build/build_config.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 #include "testing/platform_test.h" | |
17 | |
18 namespace { | |
19 | |
20 class ExtensionExtractorFilterTest : public PlatformTest { | |
Devlin
2016/09/08 21:10:16
Do we need this instead of just testing::Test?
meacer
2016/09/08 22:40:10
Moved this to unpacker_unittest.cc
| |
21 protected: | |
22 void SetUp() override { | |
23 PlatformTest::SetUp(); | |
24 | |
25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
26 test_dir_ = temp_dir_.path(); | |
27 | |
28 filter_ = new extensions::ExtensionExtractorFilter(); | |
29 } | |
30 | |
31 base::FilePath CreateEmptyTestFile(const base::FilePath& file_path) { | |
32 base::FilePath test_file(test_dir_.Append(file_path)); | |
33 base::FilePath temp_file; | |
34 EXPECT_TRUE(base::CreateTemporaryFileInDir(test_dir_, &temp_file)); | |
35 EXPECT_TRUE(base::Move(temp_file, test_file)); | |
36 return test_file; | |
37 } | |
38 | |
39 scoped_refptr<extensions::ExtensionExtractorFilter> filter_; | |
40 | |
41 base::ScopedTempDir temp_dir_; | |
42 | |
43 base::FilePath test_dir_; | |
44 }; | |
45 | |
46 struct UnaryBooleanTestData { | |
47 const base::FilePath::CharType* input; | |
48 bool expected; | |
49 }; | |
50 | |
51 TEST_F(ExtensionExtractorFilterTest, NormalCases) { | |
52 const struct UnaryBooleanTestData cases[] = { | |
53 {FILE_PATH_LITERAL("foo"), true}, | |
54 {FILE_PATH_LITERAL("foo.nexe"), true}, | |
55 {FILE_PATH_LITERAL("foo.dll"), true}, | |
56 {FILE_PATH_LITERAL("foo.exe"), false}, | |
57 }; | |
58 | |
59 for (size_t i = 0; i < arraysize(cases); ++i) { | |
60 base::FilePath input(cases[i].input); | |
61 base::FilePath test_file(CreateEmptyTestFile(input)); | |
62 bool observed = filter_->ShouldExtractFile(test_file); | |
63 EXPECT_EQ(cases[i].expected, observed) << "i: " << i | |
64 << ", input: " << test_file.value(); | |
65 } | |
66 } | |
67 } // namespace | |
OLD | NEW |