| 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 <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 #endif | 273 #endif |
| 274 | 274 |
| 275 TEST_F(ZipReaderTest, ExtractCurrentEntryToFilePath_Directory) { | 275 TEST_F(ZipReaderTest, ExtractCurrentEntryToFilePath_Directory) { |
| 276 ZipReader reader; | 276 ZipReader reader; |
| 277 ASSERT_TRUE(reader.Open(test_zip_file_)); | 277 ASSERT_TRUE(reader.Open(test_zip_file_)); |
| 278 base::FilePath target_path(FILE_PATH_LITERAL("foo/")); | 278 base::FilePath target_path(FILE_PATH_LITERAL("foo/")); |
| 279 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path)); | 279 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path)); |
| 280 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath( | 280 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath( |
| 281 test_dir_.AppendASCII("foo"))); | 281 test_dir_.AppendASCII("foo"))); |
| 282 // The directory should be created. | 282 // The directory should be created. |
| 283 ASSERT_TRUE(file_util::DirectoryExists(test_dir_.AppendASCII("foo"))); | 283 ASSERT_TRUE(base::DirectoryExists(test_dir_.AppendASCII("foo"))); |
| 284 } | 284 } |
| 285 | 285 |
| 286 TEST_F(ZipReaderTest, ExtractCurrentEntryIntoDirectory_RegularFile) { | 286 TEST_F(ZipReaderTest, ExtractCurrentEntryIntoDirectory_RegularFile) { |
| 287 ZipReader reader; | 287 ZipReader reader; |
| 288 ASSERT_TRUE(reader.Open(test_zip_file_)); | 288 ASSERT_TRUE(reader.Open(test_zip_file_)); |
| 289 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt")); | 289 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt")); |
| 290 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path)); | 290 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path)); |
| 291 ASSERT_TRUE(reader.ExtractCurrentEntryIntoDirectory(test_dir_)); | 291 ASSERT_TRUE(reader.ExtractCurrentEntryIntoDirectory(test_dir_)); |
| 292 // Sub directories should be created. | 292 // Sub directories should be created. |
| 293 ASSERT_TRUE(file_util::DirectoryExists(test_dir_.AppendASCII("foo/bar"))); | 293 ASSERT_TRUE(base::DirectoryExists(test_dir_.AppendASCII("foo/bar"))); |
| 294 // And the file should be created. | 294 // And the file should be created. |
| 295 std::string output; | 295 std::string output; |
| 296 ASSERT_TRUE(file_util::ReadFileToString( | 296 ASSERT_TRUE(file_util::ReadFileToString( |
| 297 test_dir_.AppendASCII("foo/bar/quux.txt"), &output)); | 297 test_dir_.AppendASCII("foo/bar/quux.txt"), &output)); |
| 298 const std::string md5 = base::MD5String(output); | 298 const std::string md5 = base::MD5String(output); |
| 299 const std::string kExpectedMD5 = "d1ae4ac8a17a0e09317113ab284b57a6"; | 299 const std::string kExpectedMD5 = "d1ae4ac8a17a0e09317113ab284b57a6"; |
| 300 EXPECT_EQ(kExpectedMD5, md5); | 300 EXPECT_EQ(kExpectedMD5, md5); |
| 301 } | 301 } |
| 302 | 302 |
| 303 TEST_F(ZipReaderTest, current_entry_info_RegularFile) { | 303 TEST_F(ZipReaderTest, current_entry_info_RegularFile) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath( | 422 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath( |
| 423 test_dir_.AppendASCII("test.txt"))); | 423 test_dir_.AppendASCII("test.txt"))); |
| 424 | 424 |
| 425 std::string actual; | 425 std::string actual; |
| 426 ASSERT_TRUE(file_util::ReadFileToString( | 426 ASSERT_TRUE(file_util::ReadFileToString( |
| 427 test_dir_.AppendASCII("test.txt"), &actual)); | 427 test_dir_.AppendASCII("test.txt"), &actual)); |
| 428 EXPECT_EQ(std::string("This is a test.\n"), actual); | 428 EXPECT_EQ(std::string("This is a test.\n"), actual); |
| 429 } | 429 } |
| 430 | 430 |
| 431 } // namespace zip | 431 } // namespace zip |
| OLD | NEW |