Chromium Code Reviews| Index: chrome/browser/safe_browsing/mac_archive_type_sniffer_unittest.cc |
| diff --git a/chrome/browser/safe_browsing/mac_archive_type_sniffer_unittest.cc b/chrome/browser/safe_browsing/mac_archive_type_sniffer_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..aa9a4e40ba79dfc309b52295ee9df5383698c014 |
| --- /dev/null |
| +++ b/chrome/browser/safe_browsing/mac_archive_type_sniffer_unittest.cc |
| @@ -0,0 +1,105 @@ |
| +// Copyright 2017 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 "chrome/browser/safe_browsing/mac_archive_type_sniffer.h" |
| + |
| +#include "base/files/file_path.h" |
| +#include "base/macros.h" |
| +#include "base/path_service.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "chrome/common/chrome_paths.h" |
| +#include "content/public/test/test_browser_thread_bundle.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace safe_browsing { |
| +namespace { |
| + |
| +struct ArchiveTestCase { |
| + // The disk image file to open. |
| + const char* file_name; |
| + |
| + // Expectation regarding the file being recognized as a DMG. As the UDIFParser |
| + // class currently only supports certain UDIF features, this is used to |
| + // properly test expectations. |
| + bool expected_results; |
| +}; |
| + |
| +class MacArchiveTypeSnifferTest |
| + : public testing::TestWithParam<ArchiveTestCase> { |
| + protected: |
| + base::FilePath GetFilePath(const char* file_name) { |
| + base::FilePath test_data; |
| + EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &test_data)); |
| + return test_data.AppendASCII("chrome") |
| + .AppendASCII("safe_browsing_dmg") |
| + .AppendASCII(file_name); |
| + } |
| + |
| + private: |
| + content::TestBrowserThreadBundle thread_bundle_; |
| +}; |
| + |
| +TEST_P(MacArchiveTypeSnifferTest, SniffArchive) { |
| + const ArchiveTestCase& test_case = GetParam(); |
| + |
| + base::FilePath path; |
| + ASSERT_NO_FATAL_FAILURE(path = GetFilePath(test_case.file_name)); |
| + bool result = MacArchiveTypeSniffer::FileIsArchiveType(path); |
| + |
| + if (test_case.expected_results) { |
|
Jialiu Lin
2017/06/09 18:48:49
nit: no need {} around single line statement
mortonm
2017/06/09 19:47:20
Done.
|
| + ASSERT_TRUE(result); |
| + } else { |
| + ASSERT_FALSE(result); |
| + } |
| +} |
| + |
| +const ArchiveTestCase cases[] = { |
| + {"dmg_UDBZ_GPTSPUD.dmg", true}, |
| + {"dmg_UDBZ_NONE.dmg", true}, |
| + {"dmg_UDBZ_SPUD.dmg", true}, |
| + {"dmg_UDCO_GPTSPUD.dmg", true}, |
| + {"dmg_UDCO_NONE.dmg", true}, |
| + {"dmg_UDCO_SPUD.dmg", true}, |
| + {"dmg_UDRO_GPTSPUD.dmg", true}, |
| + {"dmg_UDRO_NONE.dmg", true}, |
| + {"dmg_UDRO_SPUD.dmg", true}, |
| + // UDRW not supported. |
| + {"dmg_UDRW_GPTSPUD.dmg", false}, |
| + // UDRW not supported. |
| + {"dmg_UDRW_NONE.dmg", false}, |
| + // UDRW not supported. |
| + {"dmg_UDRW_SPUD.dmg", false}, |
| + // Sparse images not supported. |
| + {"dmg_UDSP_GPTSPUD.sparseimage", false}, |
| + // UDRW not supported. |
| + {"dmg_UDSP_NONE.sparseimage", false}, |
| + // Sparse images not supported. |
| + {"dmg_UDSP_SPUD.sparseimage", false}, |
| + // CD/DVD format not supported. |
| + {"dmg_UDTO_GPTSPUD.cdr", false}, |
| + // CD/DVD format not supported. |
| + {"dmg_UDTO_NONE.cdr", false}, |
| + // CD/DVD format not supported. |
| + {"dmg_UDTO_SPUD.cdr", false}, |
| + {"dmg_UDZO_GPTSPUD.dmg", true}, |
| + {"dmg_UDZO_SPUD.dmg", true}, |
| + {"dmg_UFBI_GPTSPUD.dmg", true}, |
| + {"dmg_UFBI_SPUD.dmg", true}, |
| + {"mach_o_in_dmg.dmg", true}, |
| + // Absence of 'koly' signature will cause parsing to fail - even if file has |
| + // .dmg extension. Note that DownloadProtectionService does not check for |
|
Jialiu Lin
2017/06/09 18:48:49
You probably don't need to mention DownloadProtect
mortonm
2017/06/09 19:47:20
Done.
|
| + // 'koly' signature when file has .dmg extension. |
| + {"mach_o_in_dmg_no_koly_signature.dmg", false}, |
| + // Type sniffer should realize DMG type even without extension. |
| + {"mach_o_in_dmg.txt", true} |
| + |
| +}; |
| + |
| +INSTANTIATE_TEST_CASE_P(MacArchiveTypeSnifferTestInstantiation, |
| + MacArchiveTypeSnifferTest, |
| + testing::ValuesIn(cases)); |
| + |
| +} // namespace |
| +} // namespace safe_browsing |