| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "components/zip/zip_reader.h" | 5 #include "third_party/zlib/google/zip_reader.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/md5.h" | 13 #include "base/md5.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "components/zip/zip_internal.h" | |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "testing/platform_test.h" | 19 #include "testing/platform_test.h" |
| 20 #include "third_party/zlib/google/zip_internal.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Wrap PlatformFiles in a class so that we don't leak them in tests. | 24 // Wrap PlatformFiles in a class so that we don't leak them in tests. |
| 25 class PlatformFileWrapper { | 25 class PlatformFileWrapper { |
| 26 public: | 26 public: |
| 27 typedef enum { | 27 typedef enum { |
| 28 READ_ONLY, | 28 READ_ONLY, |
| 29 READ_WRITE | 29 READ_WRITE |
| 30 } AccessMode; | 30 } AccessMode; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // Make the test a PlatformTest to setup autorelease pools properly on Mac. | 68 // Make the test a PlatformTest to setup autorelease pools properly on Mac. |
| 69 class ZipReaderTest : public PlatformTest { | 69 class ZipReaderTest : public PlatformTest { |
| 70 protected: | 70 protected: |
| 71 virtual void SetUp() { | 71 virtual void SetUp() { |
| 72 PlatformTest::SetUp(); | 72 PlatformTest::SetUp(); |
| 73 | 73 |
| 74 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 74 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 75 test_dir_ = temp_dir_.path(); | 75 test_dir_ = temp_dir_.path(); |
| 76 | 76 |
| 77 ASSERT_TRUE(GetTestDataDirectory(&test_data_dir_)); | 77 ASSERT_TRUE(GetTestDataDirectory(&test_data_dir_)); |
| 78 test_data_dir_ = test_data_dir_.AppendASCII("zip"); | |
| 79 | 78 |
| 80 test_zip_file_ = test_data_dir_.AppendASCII("test.zip"); | 79 test_zip_file_ = test_data_dir_.AppendASCII("test.zip"); |
| 81 evil_zip_file_ = test_data_dir_.AppendASCII("evil.zip"); | 80 evil_zip_file_ = test_data_dir_.AppendASCII("evil.zip"); |
| 82 evil_via_invalid_utf8_zip_file_ = test_data_dir_.AppendASCII( | 81 evil_via_invalid_utf8_zip_file_ = test_data_dir_.AppendASCII( |
| 83 "evil_via_invalid_utf8.zip"); | 82 "evil_via_invalid_utf8.zip"); |
| 84 evil_via_absolute_file_name_zip_file_ = test_data_dir_.AppendASCII( | 83 evil_via_absolute_file_name_zip_file_ = test_data_dir_.AppendASCII( |
| 85 "evil_via_absolute_file_name.zip"); | 84 "evil_via_absolute_file_name.zip"); |
| 86 | 85 |
| 87 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo/"))); | 86 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo/"))); |
| 88 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo/bar/"))); | 87 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo/bar/"))); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 99 | 98 |
| 100 virtual void TearDown() { | 99 virtual void TearDown() { |
| 101 PlatformTest::TearDown(); | 100 PlatformTest::TearDown(); |
| 102 } | 101 } |
| 103 | 102 |
| 104 bool GetTestDataDirectory(base::FilePath* path) { | 103 bool GetTestDataDirectory(base::FilePath* path) { |
| 105 bool success = PathService::Get(base::DIR_SOURCE_ROOT, path); | 104 bool success = PathService::Get(base::DIR_SOURCE_ROOT, path); |
| 106 EXPECT_TRUE(success); | 105 EXPECT_TRUE(success); |
| 107 if (!success) | 106 if (!success) |
| 108 return false; | 107 return false; |
| 109 *path = path->AppendASCII("components"); | 108 *path = path->AppendASCII("third_party"); |
| 109 *path = path->AppendASCII("zlib"); |
| 110 *path = path->AppendASCII("google"); |
| 110 *path = path->AppendASCII("test"); | 111 *path = path->AppendASCII("test"); |
| 111 *path = path->AppendASCII("data"); | 112 *path = path->AppendASCII("data"); |
| 112 return true; | 113 return true; |
| 113 } | 114 } |
| 114 | 115 |
| 115 // The path to temporary directory used to contain the test operations. | 116 // The path to temporary directory used to contain the test operations. |
| 116 base::FilePath test_dir_; | 117 base::FilePath test_dir_; |
| 117 // The path to the test data directory where test.zip etc. are located. | 118 // The path to the test data directory where test.zip etc. are located. |
| 118 base::FilePath test_data_dir_; | 119 base::FilePath test_data_dir_; |
| 119 // The path to test.zip in the test data directory. | 120 // The path to test.zip in the test data directory. |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath( | 422 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath( |
| 422 test_dir_.AppendASCII("test.txt"))); | 423 test_dir_.AppendASCII("test.txt"))); |
| 423 | 424 |
| 424 std::string actual; | 425 std::string actual; |
| 425 ASSERT_TRUE(file_util::ReadFileToString( | 426 ASSERT_TRUE(file_util::ReadFileToString( |
| 426 test_dir_.AppendASCII("test.txt"), &actual)); | 427 test_dir_.AppendASCII("test.txt"), &actual)); |
| 427 EXPECT_EQ(std::string("This is a test.\n"), actual); | 428 EXPECT_EQ(std::string("This is a test.\n"), actual); |
| 428 } | 429 } |
| 429 | 430 |
| 430 } // namespace zip | 431 } // namespace zip |
| OLD | NEW |