| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 12 #include "chrome/common/unzip.h" | 12 #include "chrome/common/unzip.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Make the test a PlatformTest to setup autorelease pools properly on Mac. | 18 // Make the test a PlatformTest to setup autorelease pools properly on Mac. |
| 19 class UnzipTest : public PlatformTest { | 19 class UnzipTest : public PlatformTest { |
| 20 protected: | 20 protected: |
| 21 virtual void SetUp() { | 21 virtual void SetUp() { |
| 22 PlatformTest::SetUp(); | 22 PlatformTest::SetUp(); |
| 23 | 23 |
| 24 ASSERT_TRUE(file_util::CreateNewTempDirectory( | 24 ASSERT_TRUE(file_util::CreateNewTempDirectory( |
| 25 FILE_PATH_LITERAL("unzip_unittest_"), &test_dir_)); | 25 FILE_PATH_LITERAL("unzip_unittest_"), &test_dir_)); |
| 26 | 26 |
| 27 FilePath zip_path(test_dir_.Append(FILE_PATH_LITERAL("test"))); | 27 FilePath zip_path(test_dir_.AppendASCII("test")); |
| 28 zip_contents_.insert(zip_path); | 28 zip_contents_.insert(zip_path); |
| 29 zip_contents_.insert(zip_path.Append(FILE_PATH_LITERAL("foo.txt"))); | 29 zip_contents_.insert(zip_path.AppendASCII("foo.txt")); |
| 30 zip_path = zip_path.Append(FILE_PATH_LITERAL("foo")); | 30 zip_path = zip_path.AppendASCII("foo"); |
| 31 zip_contents_.insert(zip_path); | 31 zip_contents_.insert(zip_path); |
| 32 zip_contents_.insert(zip_path.Append(FILE_PATH_LITERAL("bar.txt"))); | 32 zip_contents_.insert(zip_path.AppendASCII("bar.txt")); |
| 33 zip_path = zip_path.Append(FILE_PATH_LITERAL("bar")); | 33 zip_path = zip_path.AppendASCII("bar"); |
| 34 zip_contents_.insert(zip_path); | 34 zip_contents_.insert(zip_path); |
| 35 zip_contents_.insert(zip_path.Append(FILE_PATH_LITERAL("baz.txt"))); | 35 zip_contents_.insert(zip_path.AppendASCII("baz.txt")); |
| 36 zip_contents_.insert(zip_path.Append(FILE_PATH_LITERAL("quux.txt"))); | 36 zip_contents_.insert(zip_path.AppendASCII("quux.txt")); |
| 37 zip_path = zip_path.Append(FILE_PATH_LITERAL("baz")); | 37 zip_path = zip_path.AppendASCII("baz"); |
| 38 zip_contents_.insert(zip_path); | 38 zip_contents_.insert(zip_path); |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual void TearDown() { | 41 virtual void TearDown() { |
| 42 PlatformTest::TearDown(); | 42 PlatformTest::TearDown(); |
| 43 // Clean up test directory | 43 // Clean up test directory |
| 44 ASSERT_TRUE(file_util::Delete(test_dir_, true)); | 44 ASSERT_TRUE(file_util::Delete(test_dir_, true)); |
| 45 ASSERT_FALSE(file_util::PathExists(test_dir_)); | 45 ASSERT_FALSE(file_util::PathExists(test_dir_)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void TestZipFile(const FilePath::StringType& filename) { | 48 void TestZipFile(const FilePath::StringType& filename) { |
| 49 FilePath test_dir; | 49 FilePath test_dir; |
| 50 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); | 50 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); |
| 51 test_dir = test_dir.Append(FILE_PATH_LITERAL("unzip")); | 51 test_dir = test_dir.AppendASCII("unzip"); |
| 52 FilePath path = test_dir.Append(filename); | 52 FilePath path = test_dir.Append(filename); |
| 53 | 53 |
| 54 ASSERT_TRUE(file_util::PathExists(path)) << "no file " << path.value(); | 54 ASSERT_TRUE(file_util::PathExists(path)) << "no file " << path.value(); |
| 55 std::vector<FilePath> out_files; | 55 std::vector<FilePath> out_files; |
| 56 ASSERT_TRUE(Unzip(path, test_dir_, &out_files)); | 56 ASSERT_TRUE(Unzip(path, test_dir_, &out_files)); |
| 57 | 57 |
| 58 file_util::FileEnumerator files(test_dir_, true, | 58 file_util::FileEnumerator files(test_dir_, true, |
| 59 file_util::FileEnumerator::FILES_AND_DIRECTORIES); | 59 file_util::FileEnumerator::FILES_AND_DIRECTORIES); |
| 60 FilePath next_path = files.Next(); | 60 FilePath next_path = files.Next(); |
| 61 size_t count = 0; | 61 size_t count = 0; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 85 TEST_F(UnzipTest, Unzip) { | 85 TEST_F(UnzipTest, Unzip) { |
| 86 TestZipFile(FILE_PATH_LITERAL("test.zip")); | 86 TestZipFile(FILE_PATH_LITERAL("test.zip")); |
| 87 } | 87 } |
| 88 | 88 |
| 89 TEST_F(UnzipTest, UnzipUncompressed) { | 89 TEST_F(UnzipTest, UnzipUncompressed) { |
| 90 TestZipFile(FILE_PATH_LITERAL("test_nocompress.zip")); | 90 TestZipFile(FILE_PATH_LITERAL("test_nocompress.zip")); |
| 91 } | 91 } |
| 92 | 92 |
| 93 } // namespace | 93 } // namespace |
| 94 | 94 |
| OLD | NEW |