| Index: third_party/zlib/google/zip_reader_unittest.cc
|
| diff --git a/third_party/zlib/google/zip_reader_unittest.cc b/third_party/zlib/google/zip_reader_unittest.cc
|
| index 2033f9fa002c2db2de3510d39a81c5bd39ea27c5..f9e921abb7611a1d76983728387e3848901606df 100644
|
| --- a/third_party/zlib/google/zip_reader_unittest.cc
|
| +++ b/third_party/zlib/google/zip_reader_unittest.cc
|
| @@ -12,9 +12,11 @@
|
| #include "base/files/scoped_temp_dir.h"
|
| #include "base/logging.h"
|
| #include "base/md5.h"
|
| +#include "base/memory/ref_counted_memory.h"
|
| #include "base/path_service.h"
|
| #include "base/platform_file.h"
|
| #include "base/run_loop.h"
|
| +#include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/time/time.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -70,7 +72,7 @@ class PlatformFileWrapper {
|
| // Assumes that progress callbacks will be executed in-order.
|
| class MockUnzipListener : public base::SupportsWeakPtr<MockUnzipListener> {
|
| public:
|
| - MockUnzipListener()
|
| + MockUnzipListener()
|
| : success_calls_(0),
|
| failure_calls_(0),
|
| progress_calls_(0),
|
| @@ -553,4 +555,45 @@ TEST_F(ZipReaderTest, ExtractToFileAsync_Directory) {
|
| ASSERT_TRUE(base::DirectoryExists(target_file));
|
| }
|
|
|
| +TEST_F(ZipReaderTest, ExtractCurrentEntryToRefCountedMemory) {
|
| + // test_mismatch_size.zip contains files with names from 0.txt to 7.txt with
|
| + // sizes from 0 to 7 bytes respectively, but the metadata in the zip file says
|
| + // the uncompressed size is 3 bytes. The ZipReader code needs to be clever
|
| + // enough to get all the data out.
|
| + base::FilePath test_zip_file =
|
| + test_data_dir_.AppendASCII("test_mismatch_size.zip");
|
| +
|
| + ZipReader reader;
|
| + scoped_refptr<base::RefCountedMemory> contents;
|
| + ASSERT_TRUE(reader.Open(test_zip_file));
|
| +
|
| + for (size_t k = 0; k < 8; k++) {
|
| + SCOPED_TRACE(base::StringPrintf("<loop:%d>", static_cast<int>(k)));
|
| +
|
| + base::FilePath file_name = base::FilePath(
|
| + base::StringPrintf(FILE_PATH_LITERAL("%d.txt"), static_cast<int>(k)));
|
| + ASSERT_TRUE(reader.LocateAndOpenEntry(file_name));
|
| + EXPECT_EQ(3, reader.current_entry_info()->original_size());
|
| +
|
| + if (k > 1) {
|
| + // Off by one byte read limit: must fail.
|
| + EXPECT_FALSE(reader.ExtractCurrentEntryToRefCountedMemory(
|
| + k - 1, &contents));
|
| + }
|
| +
|
| + if (k > 0) {
|
| + // Exact byte read limit: must pass.
|
| + EXPECT_TRUE(reader.ExtractCurrentEntryToRefCountedMemory(k, &contents));
|
| + EXPECT_EQ(k, contents->size());
|
| + EXPECT_EQ(0, memcmp(contents->front(), "0123456", k));
|
| + }
|
| +
|
| + // More than necessary byte read limit: must pass.
|
| + EXPECT_TRUE(reader.ExtractCurrentEntryToRefCountedMemory(16, &contents));
|
| + EXPECT_EQ(k, contents->size());
|
| + EXPECT_EQ(0, memcmp(contents->front(), "0123456", k));
|
| + }
|
| + reader.Close();
|
| +}
|
| +
|
| } // namespace zip
|
|
|