| 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 "third_party/zlib/google/zip_reader.h" | 5 #include "third_party/zlib/google/zip_reader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/files/file.h" | 15 #include "base/files/file.h" |
| 16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 17 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/md5.h" | 20 #include "base/md5.h" |
| 21 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 25 #include "base/test/scoped_task_environment.h" |
| 25 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "testing/platform_test.h" | 29 #include "testing/platform_test.h" |
| 29 #include "third_party/zlib/google/zip_internal.h" | 30 #include "third_party/zlib/google/zip_internal.h" |
| 30 | 31 |
| 31 using ::testing::Return; | 32 using ::testing::Return; |
| 32 using ::testing::_; | 33 using ::testing::_; |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // The path to evil.zip in the test data directory. | 182 // The path to evil.zip in the test data directory. |
| 182 base::FilePath evil_zip_file_; | 183 base::FilePath evil_zip_file_; |
| 183 // The path to evil_via_invalid_utf8.zip in the test data directory. | 184 // The path to evil_via_invalid_utf8.zip in the test data directory. |
| 184 base::FilePath evil_via_invalid_utf8_zip_file_; | 185 base::FilePath evil_via_invalid_utf8_zip_file_; |
| 185 // The path to evil_via_absolute_file_name.zip in the test data directory. | 186 // The path to evil_via_absolute_file_name.zip in the test data directory. |
| 186 base::FilePath evil_via_absolute_file_name_zip_file_; | 187 base::FilePath evil_via_absolute_file_name_zip_file_; |
| 187 std::set<base::FilePath> test_zip_contents_; | 188 std::set<base::FilePath> test_zip_contents_; |
| 188 | 189 |
| 189 base::ScopedTempDir temp_dir_; | 190 base::ScopedTempDir temp_dir_; |
| 190 | 191 |
| 191 base::MessageLoop message_loop_; | 192 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 192 }; | 193 }; |
| 193 | 194 |
| 194 TEST_F(ZipReaderTest, Open_ValidZipFile) { | 195 TEST_F(ZipReaderTest, Open_ValidZipFile) { |
| 195 ZipReader reader; | 196 ZipReader reader; |
| 196 ASSERT_TRUE(reader.Open(test_zip_file_)); | 197 ASSERT_TRUE(reader.Open(test_zip_file_)); |
| 197 } | 198 } |
| 198 | 199 |
| 199 TEST_F(ZipReaderTest, Open_ValidZipPlatformFile) { | 200 TEST_F(ZipReaderTest, Open_ValidZipPlatformFile) { |
| 200 ZipReader reader; | 201 ZipReader reader; |
| 201 FileWrapper zip_fd_wrapper(test_zip_file_, FileWrapper::READ_ONLY); | 202 FileWrapper zip_fd_wrapper(test_zip_file_, FileWrapper::READ_ONLY); |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 ASSERT_TRUE(writer.PrepareOutput()); | 684 ASSERT_TRUE(writer.PrepareOutput()); |
| 684 ASSERT_TRUE(writer.WriteBytes(kSomeData, kSomeDataLen)); | 685 ASSERT_TRUE(writer.WriteBytes(kSomeData, kSomeDataLen)); |
| 685 } | 686 } |
| 686 ASSERT_EQ(kSomeDataLen, file_.GetLength()); | 687 ASSERT_EQ(kSomeDataLen, file_.GetLength()); |
| 687 char buf[kSomeDataLen] = {}; | 688 char buf[kSomeDataLen] = {}; |
| 688 ASSERT_EQ(kSomeDataLen, file_.Read(0LL, buf, kSomeDataLen)); | 689 ASSERT_EQ(kSomeDataLen, file_.Read(0LL, buf, kSomeDataLen)); |
| 689 ASSERT_EQ(std::string(kSomeData), std::string(buf, kSomeDataLen)); | 690 ASSERT_EQ(std::string(kSomeData), std::string(buf, kSomeDataLen)); |
| 690 } | 691 } |
| 691 | 692 |
| 692 } // namespace zip | 693 } // namespace zip |
| OLD | NEW |