Chromium Code Reviews| 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 11 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "testing/platform_test.h" | 18 #include "testing/platform_test.h" |
| 18 #include "third_party/zlib/google/zip.h" | 19 #include "third_party/zlib/google/zip.h" |
| 19 #include "third_party/zlib/google/zip_reader.h" | 20 #include "third_party/zlib/google/zip_reader.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Make the test a PlatformTest to setup autorelease pools properly on Mac. | 24 // Make the test a PlatformTest to setup autorelease pools properly on Mac. |
| 24 class ZipTest : public PlatformTest { | 25 class ZipTest : public PlatformTest { |
| 25 protected: | 26 protected: |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 EXPECT_EQ(zip_file_list_.size(), static_cast<size_t>(reader.num_entries())); | 296 EXPECT_EQ(zip_file_list_.size(), static_cast<size_t>(reader.num_entries())); |
| 296 for (size_t i = 0; i < zip_file_list_.size(); ++i) { | 297 for (size_t i = 0; i < zip_file_list_.size(); ++i) { |
| 297 EXPECT_TRUE(reader.LocateAndOpenEntry(zip_file_list_[i])); | 298 EXPECT_TRUE(reader.LocateAndOpenEntry(zip_file_list_[i])); |
| 298 // Check the path in the entry just in case. | 299 // Check the path in the entry just in case. |
| 299 const zip::ZipReader::EntryInfo* entry_info = reader.current_entry_info(); | 300 const zip::ZipReader::EntryInfo* entry_info = reader.current_entry_info(); |
| 300 EXPECT_EQ(entry_info->file_path(), zip_file_list_[i]); | 301 EXPECT_EQ(entry_info->file_path(), zip_file_list_[i]); |
| 301 } | 302 } |
| 302 } | 303 } |
| 303 #endif // defined(OS_POSIX) | 304 #endif // defined(OS_POSIX) |
| 304 | 305 |
| 306 TEST_F(ZipTest, UnzipFilesWithIncorrectSize) { | |
| 307 base::FilePath test_data_folder; | |
| 308 ASSERT_TRUE(GetTestDataDirectory(&test_data_folder)); | |
| 309 | |
| 310 // test_mismatch_size.zip contains files with names from 0.txt to 7.txt with | |
| 311 // sizes from 0 to 7 bytes respectively, but the metadata in the zip file says | |
| 312 // the uncompressed size is 3 bytes. The ZipReader and minizip code needs to | |
| 313 // be clever enough to get all the data out. | |
| 314 base::FilePath test_zip_file = | |
| 315 test_data_folder.AppendASCII("test_mismatch_size.zip"); | |
| 316 | |
| 317 base::ScopedTempDir scoped_temp_dir; | |
| 318 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | |
| 319 const base::FilePath& temp_dir = scoped_temp_dir.path(); | |
|
gavinp
2014/05/07 14:01:01
This freaks me out. However, it is safe. But it fr
João Eiras
2014/05/07 15:31:20
Why ? The folder needs to be used somehow.
| |
| 320 | |
| 321 ASSERT_TRUE(zip::Unzip(test_zip_file, temp_dir)); | |
| 322 | |
|
gavinp
2014/05/07 14:01:01
nit: lose this blank line.
| |
| 323 EXPECT_TRUE(base::DirectoryExists(temp_dir.AppendASCII("d"))); | |
| 324 | |
| 325 for (int i = 0; i < 8; i++) { | |
| 326 SCOPED_TRACE(base::StringPrintf("Processing %d.txt", i)); | |
| 327 base::FilePath file_path = temp_dir.AppendASCII( | |
| 328 base::StringPrintf("%d.txt", i)); | |
| 329 int64 file_size = -1; | |
| 330 EXPECT_TRUE(base::GetFileSize(file_path, &file_size)); | |
| 331 EXPECT_EQ(static_cast<int64>(i), file_size); | |
| 332 } | |
| 333 } | |
| 334 | |
| 305 } // namespace | 335 } // namespace |
| OLD | NEW |