chromium/chrome/browser/web_applications/isolated_web_apps/isolated_web_app_reader_registry_unittest.cc

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

#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_reader_registry.h"

#include <memory>
#include <optional>

#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/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/bind.h"
#include "base/test/gmock_expected_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/repeating_test_future.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/types/expected.h"
#include "chrome/browser/web_applications/isolated_web_apps/error/uma_logging.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_response_reader.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_response_reader_factory.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_trust_checker.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_validator.h"
#include "chrome/browser/web_applications/test/signed_web_bundle_utils.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/testing_profile.h"
#include "components/web_package/mojom/web_bundle_parser.mojom.h"
#include "components/web_package/signed_web_bundles/ed25519_public_key.h"
#include "components/web_package/signed_web_bundles/signed_web_bundle_id.h"
#include "components/web_package/signed_web_bundles/signed_web_bundle_integrity_block.h"
#include "components/web_package/signed_web_bundles/signed_web_bundle_signature_verifier.h"
#include "components/web_package/test_support/mock_web_bundle_parser_factory.h"
#include "components/web_package/test_support/signed_web_bundles/signature_verifier_test_utils.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_task_environment.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/network/public/cpp/resource_request.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/url_constants.h"

namespace web_app {

namespace {

ErrorIs;
HasValue;
ElementsAre;
Field;
HasSubstr;

ReadResponseError;
VerifierError;

constexpr uint8_t kEd25519PublicKey[32] =;

constexpr uint8_t kEd25519Signature[64] =;

class FakeIsolatedWebAppValidator : public IsolatedWebAppValidator {};

}  // namespace

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

ReadResult;

TEST_F(IsolatedWebAppReaderRegistryTest, TestSingleRequest) {}

TEST_F(IsolatedWebAppReaderRegistryTest,
       ReadResponseWhenBundleIsNoLongerTrusted) {}

TEST_F(IsolatedWebAppReaderRegistryTest,
       TestSingleRequestWithQueryAndFragment) {}

TEST_F(IsolatedWebAppReaderRegistryTest, TestMixedDevModeAndProdModeRequests) {}

TEST_F(IsolatedWebAppReaderRegistryTest,
       TestReadingResponseAfterSignedWebBundleReaderIsDeleted) {}

TEST_F(IsolatedWebAppReaderRegistryTest, TestRequestToNonExistingResponse) {}

TEST_F(IsolatedWebAppReaderRegistryTest, TestSignedWebBundleReaderLifetime) {}

class IsolatedWebAppReaderRegistryIntegrityBlockParserErrorTest
    : public IsolatedWebAppReaderRegistryTest,
      public ::testing::WithParamInterface<
          std::pair<web_package::mojom::BundleParseErrorType,
                    UnusableSwbnFileError::Error>> {};

TEST_P(IsolatedWebAppReaderRegistryIntegrityBlockParserErrorTest,
       TestIntegrityBlockParserError) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(IsolatedWebAppReaderRegistryTest, TestInvalidIntegrityBlockContents) {}

class IsolatedWebAppReaderRegistrySignatureVerificationErrorTest
    : public IsolatedWebAppReaderRegistryTest,
      public ::testing::WithParamInterface<VerifierError> {};

TEST_P(IsolatedWebAppReaderRegistrySignatureVerificationErrorTest,
       SignatureVerificationError) {}

INSTANTIATE_TEST_SUITE_P();

class IsolatedWebAppReaderRegistryMetadataParserErrorTest
    : public IsolatedWebAppReaderRegistryTest,
      public ::testing::WithParamInterface<
          std::pair<web_package::mojom::BundleParseErrorType,
                    UnusableSwbnFileError::Error>> {};

TEST_P(IsolatedWebAppReaderRegistryMetadataParserErrorTest,
       TestMetadataParserError) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(IsolatedWebAppReaderRegistryTest, TestInvalidMetadataPrimaryUrl) {}

TEST_F(IsolatedWebAppReaderRegistryTest, TestInvalidMetadataInvalidExchange) {}

class IsolatedWebAppReaderRegistryResponseHeadParserErrorTest
    : public IsolatedWebAppReaderRegistryTest,
      public ::testing::WithParamInterface<
          std::pair<web_package::mojom::BundleParseErrorType,
                    IsolatedWebAppReaderRegistry::ReadResponseHeadError>> {};

TEST_P(IsolatedWebAppReaderRegistryResponseHeadParserErrorTest,
       TestResponseHeadParserError) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(IsolatedWebAppReaderRegistryTest, TestConcurrentRequests) {}

// Check that we can close the cached reader that keeps
// the signed web bundle file opened.
TEST_F(IsolatedWebAppReaderRegistryTest, Close) {}

// Check the case when the close request is coming while the reader
// is being created.
TEST_F(IsolatedWebAppReaderRegistryTest, CloseOnArrival) {}

// Closing unopened signed web bundle should not cause problems.
TEST_F(IsolatedWebAppReaderRegistryTest, CloseEmpty) {}

// Reopen of the closed file should work.
TEST_F(IsolatedWebAppReaderRegistryTest, OpenCloseOpen) {}

// TODO(crbug.com/40239531): Add a test that checks the behavior when
// `SignedWebBundleReader`s for two different Web Bundle IDs are requested
// concurrently. Testing this is currently not possible, since running two
// `MockWebBundleParser`s at the same time is not yet possible.

}  // namespace web_app