chromium/third_party/zlib/google/zip_reader_unittest.cc

// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/zlib/google/zip_reader.h"

#include <stddef.h>
#include <stdint.h>
#include <string.h>

#include <iterator>
#include <string>
#include <string_view>
#include <vector>

#include "base/check.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/hash/md5.h"
#include "base/i18n/time_formatting.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
#include "third_party/zlib/google/zip_internal.h"

_;
ElementsAre;
ElementsAreArray;
Return;
SizeIs;

namespace {

const static std::string kQuuxExpectedMD5 =;

class FileWrapper {};

// A mock that provides methods that can be used as callbacks in asynchronous
// unzip functions.  Tracks the number of calls and number of bytes reported.
// Assumes that progress callbacks will be executed in-order.
class MockUnzipListener final {};

class MockWriterDelegate : public zip::WriterDelegate {};

bool ExtractCurrentEntryToFilePath(zip::ZipReader* reader,
                                   base::FilePath path) {}

const zip::ZipReader::Entry* LocateAndOpenEntry(
    zip::ZipReader* const reader,
    const base::FilePath& path_in_zip) {}

Paths;

}  // namespace

namespace zip {

// Make the test a PlatformTest to setup autorelease pools properly on Mac.
class ZipReaderTest : public PlatformTest {};

TEST_F(ZipReaderTest, Open_ValidZipFile) {}

TEST_F(ZipReaderTest, Open_ValidZipPlatformFile) {}

TEST_F(ZipReaderTest, Open_NonExistentFile) {}

TEST_F(ZipReaderTest, Open_ExistentButNonZipFile) {}

TEST_F(ZipReaderTest, Open_EmptyFile) {}

// Iterate through the contents in the test ZIP archive, and compare that the
// contents collected from the ZipReader matches the expected contents.
TEST_F(ZipReaderTest, Iteration) {}

// Open the test ZIP archive from a file descriptor, iterate through its
// contents, and compare that they match the expected contents.
TEST_F(ZipReaderTest, PlatformFileIteration) {}

TEST_F(ZipReaderTest, RegularFile) {}

TEST_F(ZipReaderTest, DotDotFile) {}

TEST_F(ZipReaderTest, InvalidUTF8File) {}

// By default, file paths in ZIPs are interpreted as UTF-8. But in this test,
// the ZIP archive contains file paths that are actually encoded in Shift JIS.
// The SJIS-encoded paths are thus wrongly interpreted as UTF-8, resulting in
// garbled paths. Invalid UTF-8 sequences are safely converted to the
// replacement character �.
TEST_F(ZipReaderTest, EncodingSjisAsUtf8) {}

// In this test, SJIS-encoded paths are interpreted as Code Page 1252. This
// results in garbled paths. Note the presence of C1 control codes U+0090 and
// U+0081 in the garbled paths.
TEST_F(ZipReaderTest, EncodingSjisAs1252) {}

// In this test, SJIS-encoded paths are interpreted as Code Page 866. This
// results in garbled paths.
TEST_F(ZipReaderTest, EncodingSjisAsIbm866) {}

// Tests that SJIS-encoded paths are correctly converted to Unicode.
TEST_F(ZipReaderTest, EncodingSjis) {}

TEST_F(ZipReaderTest, AbsoluteFile) {}

TEST_F(ZipReaderTest, Directory) {}

TEST_F(ZipReaderTest, EncryptedFile_WrongPassword) {}

TEST_F(ZipReaderTest, EncryptedFile_RightPassword) {}

// Verifies that the ZipReader class can extract a file from a zip archive
// stored in memory. This test opens a zip archive in a std::string object,
// extracts its content, and verifies the content is the same as the expected
// text.
TEST_F(ZipReaderTest, OpenFromString) {}

// Verifies that the asynchronous extraction to a file works.
TEST_F(ZipReaderTest, ExtractToFileAsync_RegularFile) {}

TEST_F(ZipReaderTest, ExtractToFileAsync_Encrypted_NoPassword) {}

TEST_F(ZipReaderTest, ExtractToFileAsync_Encrypted_RightPassword) {}

TEST_F(ZipReaderTest, ExtractToFileAsync_WrongCrc) {}

// Verifies that the asynchronous extraction to a file works.
TEST_F(ZipReaderTest, ExtractToFileAsync_Directory) {}

TEST_F(ZipReaderTest, ExtractCurrentEntryToString) {}

TEST_F(ZipReaderTest, ExtractPartOfCurrentEntry) {}

TEST_F(ZipReaderTest, ExtractPosixPermissions) {}

// This test exposes http://crbug.com/430959, at least on OS X
TEST_F(ZipReaderTest, DISABLED_LeakDetectionTest) {}

// Test that when WriterDelegate::PrepareMock returns false, no other methods on
// the delegate are called and the extraction fails.
TEST_F(ZipReaderTest, ExtractCurrentEntryPrepareFailure) {}

// Test that when WriterDelegate::WriteBytes returns false, only the OnError
// method on the delegate is called and the extraction fails.
TEST_F(ZipReaderTest, ExtractCurrentEntryWriteBytesFailure) {}

// Test that extraction succeeds when the writer delegate reports all is well.
TEST_F(ZipReaderTest, ExtractCurrentEntrySuccess) {}

TEST_F(ZipReaderTest, WrongCrc) {}

class FileWriterDelegateTest : public ::testing::Test {};

TEST_F(FileWriterDelegateTest, WriteToEnd) {}

TEST_F(FileWriterDelegateTest, EmptyOnError) {}

}  // namespace zip