| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "chrome/common/chrome_paths.h" | 9 #include "chrome/common/chrome_paths.h" |
| 10 #include "chrome/installer/setup/archive_patch_helper.h" | 10 #include "chrome/installer/setup/archive_patch_helper.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 base::FilePath ArchivePatchHelperTest::data_dir_; | 44 base::FilePath ArchivePatchHelperTest::data_dir_; |
| 45 | 45 |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| 48 // Test that patching works. | 48 // Test that patching works. |
| 49 TEST_F(ArchivePatchHelperTest, Patching) { | 49 TEST_F(ArchivePatchHelperTest, Patching) { |
| 50 base::FilePath src = data_dir_.AppendASCII("archive1.7z"); | 50 base::FilePath src = data_dir_.AppendASCII("archive1.7z"); |
| 51 base::FilePath patch = data_dir_.AppendASCII("archive.diff"); | 51 base::FilePath patch = data_dir_.AppendASCII("archive.diff"); |
| 52 base::FilePath dest = test_dir_.path().AppendASCII("archive2.7z"); | 52 base::FilePath dest = test_dir_.GetPath().AppendASCII("archive2.7z"); |
| 53 installer::ArchivePatchHelper archive_helper(test_dir_.path(), | 53 installer::ArchivePatchHelper archive_helper(test_dir_.GetPath(), |
| 54 base::FilePath(), | 54 base::FilePath(), src, dest); |
| 55 src, | |
| 56 dest); | |
| 57 archive_helper.set_last_uncompressed_file(patch); | 55 archive_helper.set_last_uncompressed_file(patch); |
| 58 EXPECT_TRUE(archive_helper.EnsemblePatch() || archive_helper.BinaryPatch()); | 56 EXPECT_TRUE(archive_helper.EnsemblePatch() || archive_helper.BinaryPatch()); |
| 59 base::FilePath base = data_dir_.AppendASCII("archive2.7z"); | 57 base::FilePath base = data_dir_.AppendASCII("archive2.7z"); |
| 60 EXPECT_TRUE(base::ContentsEqual(dest, base)); | 58 EXPECT_TRUE(base::ContentsEqual(dest, base)); |
| 61 } | 59 } |
| 62 | 60 |
| 63 TEST_F(ArchivePatchHelperTest, InvalidDiff_MisalignedCblen) { | 61 TEST_F(ArchivePatchHelperTest, InvalidDiff_MisalignedCblen) { |
| 64 base::FilePath src = data_dir_.AppendASCII("bin.old"); | 62 base::FilePath src = data_dir_.AppendASCII("bin.old"); |
| 65 base::FilePath patch = data_dir_.AppendASCII("misaligned_cblen.diff"); | 63 base::FilePath patch = data_dir_.AppendASCII("misaligned_cblen.diff"); |
| 66 base::FilePath dest = test_dir_.path().AppendASCII("bin.new"); | 64 base::FilePath dest = test_dir_.GetPath().AppendASCII("bin.new"); |
| 67 installer::ArchivePatchHelper archive_helper(test_dir_.path(), | 65 installer::ArchivePatchHelper archive_helper(test_dir_.GetPath(), |
| 68 base::FilePath(), | 66 base::FilePath(), src, dest); |
| 69 src, | |
| 70 dest); | |
| 71 archive_helper.set_last_uncompressed_file(patch); | 67 archive_helper.set_last_uncompressed_file(patch); |
| 72 // Should fail, but not crash. | 68 // Should fail, but not crash. |
| 73 EXPECT_FALSE(archive_helper.BinaryPatch()); | 69 EXPECT_FALSE(archive_helper.BinaryPatch()); |
| 74 } | 70 } |
| 75 | 71 |
| 76 TEST_F(ArchivePatchHelperTest, InvalidDiff_NegativeSeek) { | 72 TEST_F(ArchivePatchHelperTest, InvalidDiff_NegativeSeek) { |
| 77 base::FilePath src = data_dir_.AppendASCII("bin.old"); | 73 base::FilePath src = data_dir_.AppendASCII("bin.old"); |
| 78 base::FilePath patch = data_dir_.AppendASCII("negative_seek.diff"); | 74 base::FilePath patch = data_dir_.AppendASCII("negative_seek.diff"); |
| 79 base::FilePath dest = test_dir_.path().AppendASCII("bin.new"); | 75 base::FilePath dest = test_dir_.GetPath().AppendASCII("bin.new"); |
| 80 installer::ArchivePatchHelper archive_helper(test_dir_.path(), | 76 installer::ArchivePatchHelper archive_helper(test_dir_.GetPath(), |
| 81 base::FilePath(), | 77 base::FilePath(), src, dest); |
| 82 src, | |
| 83 dest); | |
| 84 archive_helper.set_last_uncompressed_file(patch); | 78 archive_helper.set_last_uncompressed_file(patch); |
| 85 // Should fail, but not crash. | 79 // Should fail, but not crash. |
| 86 EXPECT_FALSE(archive_helper.BinaryPatch()); | 80 EXPECT_FALSE(archive_helper.BinaryPatch()); |
| 87 } | 81 } |
| OLD | NEW |