#include "extensions/browser/content_verifier/test_utils.h"
#include "base/base64url.h"
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/json/json_writer.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/values.h"
#include "content/public/browser/browser_thread.h"
#include "crypto/sha2.h"
#include "crypto/signature_creator.h"
#include "extensions/browser/extension_file_task_runner.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/file_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/zlib/google/zip.h"
namespace extensions {
TestContentVerifySingleJobObserver::TestContentVerifySingleJobObserver(
const ExtensionId& extension_id,
const base::FilePath& relative_path)
: … { … }
TestContentVerifySingleJobObserver::~TestContentVerifySingleJobObserver() { … }
ContentVerifyJob::FailureReason
TestContentVerifySingleJobObserver::WaitForJobFinished() { … }
ContentHashReader::InitStatus
TestContentVerifySingleJobObserver::WaitForOnHashesReady() { … }
TestContentVerifySingleJobObserver::ObserverClient::ObserverClient(
const ExtensionId& extension_id,
const base::FilePath& relative_path)
: … { … }
TestContentVerifySingleJobObserver::ObserverClient::~ObserverClient() = default;
void TestContentVerifySingleJobObserver::ObserverClient::JobFinished(
const ExtensionId& extension_id,
const base::FilePath& relative_path,
ContentVerifyJob::FailureReason reason) { … }
void TestContentVerifySingleJobObserver::ObserverClient::OnHashesReady(
const ExtensionId& extension_id,
const base::FilePath& relative_path,
const ContentHashReader& hash_reader) { … }
void TestContentVerifySingleJobObserver::ObserverClient::
OnHashesReadyOnCreationThread(const ExtensionId& extension_id,
const base::FilePath& relative_path,
ContentHashReader::InitStatus hashes_status) { … }
ContentVerifyJob::FailureReason
TestContentVerifySingleJobObserver::ObserverClient::WaitForJobFinished() { … }
ContentHashReader::InitStatus
TestContentVerifySingleJobObserver::ObserverClient::WaitForOnHashesReady() { … }
TestContentVerifyJobObserver::TestContentVerifyJobObserver()
: … { … }
TestContentVerifyJobObserver::~TestContentVerifyJobObserver() { … }
void TestContentVerifyJobObserver::ExpectJobResult(
const ExtensionId& extension_id,
const base::FilePath& relative_path,
Result expected_result) { … }
bool TestContentVerifyJobObserver::WaitForExpectedJobs() { … }
TestContentVerifyJobObserver::ObserverClient::ObserverClient() { … }
TestContentVerifyJobObserver::ObserverClient::~ObserverClient() = default;
void TestContentVerifyJobObserver::ObserverClient::JobFinished(
const ExtensionId& extension_id,
const base::FilePath& relative_path,
ContentVerifyJob::FailureReason failure_reason) { … }
void TestContentVerifyJobObserver::ObserverClient::ExpectJobResult(
const ExtensionId& extension_id,
const base::FilePath& relative_path,
Result expected_result) { … }
bool TestContentVerifyJobObserver::ObserverClient::WaitForExpectedJobs() { … }
MockContentVerifierDelegate::MockContentVerifierDelegate()
: … { … }
MockContentVerifierDelegate::~MockContentVerifierDelegate() = default;
ContentVerifierDelegate::VerifierSourceType
MockContentVerifierDelegate::GetVerifierSourceType(const Extension& extension) { … }
ContentVerifierKey MockContentVerifierDelegate::GetPublicKey() { … }
GURL MockContentVerifierDelegate::GetSignatureFetchUrl(
const ExtensionId& extension_id,
const base::Version& version) { … }
std::set<base::FilePath> MockContentVerifierDelegate::GetBrowserImagePaths(
const extensions::Extension* extension) { … }
void MockContentVerifierDelegate::VerifyFailed(
const ExtensionId& extension_id,
ContentVerifyJob::FailureReason reason) { … }
void MockContentVerifierDelegate::Shutdown() { … }
void MockContentVerifierDelegate::SetVerifierSourceType(
VerifierSourceType type) { … }
void MockContentVerifierDelegate::SetVerifierKey(std::vector<uint8_t> key) { … }
VerifierObserver::VerifierObserver() { … }
VerifierObserver::~VerifierObserver() { … }
void VerifierObserver::EnsureFetchCompleted(const ExtensionId& extension_id) { … }
void VerifierObserver::OnFetchComplete(
const scoped_refptr<const ContentHash>& content_hash,
bool did_hash_mismatch) { … }
ContentHashResult::ContentHashResult(
const ExtensionId& extension_id,
bool success,
bool was_cancelled,
const std::set<base::FilePath> mismatch_paths)
: … { … }
ContentHashResult::~ContentHashResult() = default;
ContentHashWaiter::ContentHashWaiter()
: … { … }
ContentHashWaiter::~ContentHashWaiter() = default;
std::unique_ptr<ContentHashResult> ContentHashWaiter::CreateAndWaitForCallback(
ContentHash::FetchKey key,
ContentVerifierDelegate::VerifierSourceType source_type) { … }
void ContentHashWaiter::CreatedCallback(scoped_refptr<ContentHash> content_hash,
bool was_cancelled) { … }
void ContentHashWaiter::CreateContentHash(
ContentHash::FetchKey key,
ContentVerifierDelegate::VerifierSourceType source_type) { … }
namespace content_verifier_test_utils {
TestExtensionBuilder::TestExtensionBuilder()
: … { … }
TestExtensionBuilder::TestExtensionBuilder(const ExtensionId& extension_id)
: … { … }
TestExtensionBuilder::~TestExtensionBuilder() = default;
void TestExtensionBuilder::WriteManifest() { … }
void TestExtensionBuilder::WriteResource(
base::FilePath::StringType relative_path,
std::string contents) { … }
void TestExtensionBuilder::AddResource(base::FilePath::StringType relative_path,
std::string contents) { … }
void TestExtensionBuilder::WriteComputedHashes() { … }
std::string TestExtensionBuilder::CreateVerifiedContents() const { … }
void TestExtensionBuilder::WriteVerifiedContents() { … }
std::vector<uint8_t> TestExtensionBuilder::GetTestContentVerifierPublicKey()
const { … }
std::unique_ptr<base::Value>
TestExtensionBuilder::CreateVerifiedContentsPayload() const { … }
scoped_refptr<Extension> UnzipToDirAndLoadExtension(
const base::FilePath& extension_zip,
const base::FilePath& unzip_dir) { … }
}
}