Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1017)

Unified Diff: extensions/utility/extension_extractor_filter_unittest.cc

Issue 2321823002: Exclude exe files while unzipping CRXes (Closed)
Patch Set: Fix build Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/utility/extension_extractor_filter_unittest.cc
diff --git a/extensions/utility/extension_extractor_filter_unittest.cc b/extensions/utility/extension_extractor_filter_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5bf1177ff213b57a7807cedee26e61a034a6f98f
--- /dev/null
+++ b/extensions/utility/extension_extractor_filter_unittest.cc
@@ -0,0 +1,67 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/utility/extension_extractor_filter.h"
+
+#include <stddef.h>
+
+#include <memory>
+
+#include "base/files/file_util.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/macros.h"
+#include "build/build_config.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+namespace {
+
+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
+ protected:
+ void SetUp() override {
+ PlatformTest::SetUp();
+
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ test_dir_ = temp_dir_.path();
+
+ filter_ = new extensions::ExtensionExtractorFilter();
+ }
+
+ base::FilePath CreateEmptyTestFile(const base::FilePath& file_path) {
+ base::FilePath test_file(test_dir_.Append(file_path));
+ base::FilePath temp_file;
+ EXPECT_TRUE(base::CreateTemporaryFileInDir(test_dir_, &temp_file));
+ EXPECT_TRUE(base::Move(temp_file, test_file));
+ return test_file;
+ }
+
+ scoped_refptr<extensions::ExtensionExtractorFilter> filter_;
+
+ base::ScopedTempDir temp_dir_;
+
+ base::FilePath test_dir_;
+};
+
+struct UnaryBooleanTestData {
+ const base::FilePath::CharType* input;
+ bool expected;
+};
+
+TEST_F(ExtensionExtractorFilterTest, NormalCases) {
+ const struct UnaryBooleanTestData cases[] = {
+ {FILE_PATH_LITERAL("foo"), true},
+ {FILE_PATH_LITERAL("foo.nexe"), true},
+ {FILE_PATH_LITERAL("foo.dll"), true},
+ {FILE_PATH_LITERAL("foo.exe"), false},
+ };
+
+ for (size_t i = 0; i < arraysize(cases); ++i) {
+ base::FilePath input(cases[i].input);
+ base::FilePath test_file(CreateEmptyTestFile(input));
+ bool observed = filter_->ShouldExtractFile(test_file);
+ EXPECT_EQ(cases[i].expected, observed) << "i: " << i
+ << ", input: " << test_file.value();
+ }
+}
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698