| 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" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 class ArchivePatchHelperTest : public testing::Test { | 15 class ArchivePatchHelperTest : public testing::Test { |
| 16 protected: | 16 protected: |
| 17 static void SetUpTestCase() { | 17 static void SetUpTestCase() { |
| 18 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); | 18 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); |
| 19 data_dir_ = data_dir_.AppendASCII("installer"); | 19 data_dir_ = data_dir_.AppendASCII("installer"); |
| 20 ASSERT_TRUE(base::PathExists(data_dir_)); | 20 ASSERT_TRUE(base::PathExists(data_dir_)); |
| 21 } | 21 } |
| 22 | 22 |
| 23 static void TearDownTestCase() { | 23 static void TearDownTestCase() { |
| 24 data_dir_.clear(); | 24 data_dir_.clear(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 virtual void SetUp() override { | 27 void SetUp() override { |
| 28 // Create a temp directory for testing. | 28 // Create a temp directory for testing. |
| 29 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 29 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 virtual void TearDown() override { | 32 void TearDown() override { |
| 33 // Clean up test directory manually so we can fail if it leaks. | 33 // Clean up test directory manually so we can fail if it leaks. |
| 34 ASSERT_TRUE(test_dir_.Delete()); | 34 ASSERT_TRUE(test_dir_.Delete()); |
| 35 } | 35 } |
| 36 | 36 |
| 37 // The path to input data used in tests. | 37 // The path to input data used in tests. |
| 38 static base::FilePath data_dir_; | 38 static base::FilePath data_dir_; |
| 39 | 39 |
| 40 // The temporary directory used to contain the test operations. | 40 // The temporary directory used to contain the test operations. |
| 41 base::ScopedTempDir test_dir_; | 41 base::ScopedTempDir test_dir_; |
| 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_.path().AppendASCII("archive2.7z"); |
| 53 installer::ArchivePatchHelper archive_helper(test_dir_.path(), | 53 installer::ArchivePatchHelper archive_helper(test_dir_.path(), |
| 54 base::FilePath(), | 54 base::FilePath(), |
| 55 src, | 55 src, |
| 56 dest); | 56 dest); |
| 57 archive_helper.set_last_uncompressed_file(patch); | 57 archive_helper.set_last_uncompressed_file(patch); |
| 58 EXPECT_TRUE(archive_helper.EnsemblePatch() || archive_helper.BinaryPatch()); | 58 EXPECT_TRUE(archive_helper.EnsemblePatch() || archive_helper.BinaryPatch()); |
| 59 base::FilePath base = data_dir_.AppendASCII("archive2.7z"); | 59 base::FilePath base = data_dir_.AppendASCII("archive2.7z"); |
| 60 EXPECT_TRUE(base::ContentsEqual(dest, base)); | 60 EXPECT_TRUE(base::ContentsEqual(dest, base)); |
| 61 } | 61 } |
| OLD | NEW |