Chromium Code Reviews| Index: chrome/browser/safe_browsing/disk_image_type_sniffer_mac_unittest.cc |
| diff --git a/chrome/browser/safe_browsing/disk_image_type_sniffer_mac_unittest.cc b/chrome/browser/safe_browsing/disk_image_type_sniffer_mac_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..30d527c04af40e5a3f5152763cd468f95a55c768 |
| --- /dev/null |
| +++ b/chrome/browser/safe_browsing/disk_image_type_sniffer_mac_unittest.cc |
| @@ -0,0 +1,104 @@ |
| +// 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/disk_image_type_sniffer_mac.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 DiskImageTypeSnifferMacTest |
| + : 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(DiskImageTypeSnifferMacTest, SniffDiskImage) { |
| + LOG(ERROR) << "start of test"; |
|
vakh (use Gerrit instead)
2017/06/14 00:53:07
Remove LOG.
Better yet define the << operator for
mortonm
2017/06/14 17:13:15
Done.
|
| + const ArchiveTestCase& test_case = GetParam(); |
| + |
| + base::FilePath path; |
| + ASSERT_NO_FATAL_FAILURE(path = GetFilePath(test_case.file_name)); |
| + bool result = DiskImageTypeSnifferMac::IsAppleDiskImage(path); |
|
vakh (use Gerrit instead)
2017/06/14 00:53:07
ASSERT_EQ(test_case.expected_results, DiskImageTyp
mortonm
2017/06/14 17:13:15
Done.
|
| + |
| + if (test_case.expected_results) |
| + 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. |
| + {"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(DiskImageTypeSnifferMacTestInstantiation, |
| + DiskImageTypeSnifferMacTest, |
| + testing::ValuesIn(cases)); |
| + |
| +} // namespace |
| +} // namespace safe_browsing |