chromium/chrome/browser/web_applications/isolated_web_apps/isolated_web_app_url_loader_factory_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_url_loader_factory.h"

#include <memory>
#include <optional>
#include <string>

#include "base/feature_list.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/memory/raw_ptr.h"
#include "base/strings/strcat.h"
#include "base/test/gmock_expected_support.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ui/web_applications/test/isolated_web_app_test_utils.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_source.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_storage_location.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_url_info.h"
#include "chrome/browser/web_applications/isolated_web_apps/pending_install_info.h"
#include "chrome/browser/web_applications/isolated_web_apps/test/isolated_web_app_builder.h"
#include "chrome/browser/web_applications/proto/web_app_install_state.pb.h"
#include "chrome/browser/web_applications/test/fake_web_app_database_factory.h"
#include "chrome/browser/web_applications/test/fake_web_app_provider.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/browser/web_applications/test/web_app_test.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/url_constants.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/test_support/signed_web_bundles/web_bundle_signer.h"
#include "components/web_package/web_bundle_builder.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/storage_partition_config.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/test/simple_url_loader_test_helper.h"
#include "content/public/test/url_loader_interceptor.h"
#include "net/base/net_errors.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/network/public/cpp/parsed_headers.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/content_security_policy.mojom.h"
#include "services/network/public/mojom/fetch_api.mojom.h"
#include "services/network/public/mojom/parsed_headers.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"
#include "url/url_constants.h"

namespace web_app {
namespace {

_;
Eq;
HasSubstr;
IsFalse;
IsNull;
IsTrue;
NotNull;

inline constexpr uint8_t kTestPublicKey[] =;

inline constexpr uint8_t kTestPrivateKey[] =;

// Derived from `kTestPublicKey`.
inline constexpr std::string_view kTestEd25519WebBundleId =;

MATCHER_P(IsNetError, err, net::ErrorToString(err)) {}

MATCHER_P(IsHttpStatusCode, err, net::GetHttpReasonPhrase(err)) {}

std::unique_ptr<WebApp> CreateWebApp(const GURL& start_url) {}

std::unique_ptr<WebApp> CreateIsolatedWebApp(
    const GURL& start_url,
    WebApp::IsolationData isolation_data) {}

class ScopedUrlHandler {};

}  // namespace

class IsolatedWebAppURLLoaderFactoryTestBase : public WebAppTest {};

class IsolatedWebAppURLLoaderFactoryTest
    : public IsolatedWebAppURLLoaderFactoryTestBase {};

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       RequestFailsWithErrFailedIfAppNotInstalled) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       RequestFailsWithErrFailedIfInstalledAppNotIwa) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       RequestFailsWithErrFailedIfAppNotLocallyInstalled) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest, GetRequestsSucceed) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest, HeadRequestsSucceed) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       PostRequestsReturnMethodNotSupportedWhenAppIsInstalled) {}

TEST_F(
    IsolatedWebAppURLLoaderFactoryTest,
    PostRequestsReturnMethodNotSupportedWhenAppIsInstalledAndThereIsPendingInstall) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       RequestWithUnsupportedHttpMethodFailWithErrFailedIfAppNotInstalled) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       RequestFailsWithErrFailedIfStoragePartitionDoesNotExist) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       RequestUsesNonDefaultStoragePartition) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       RequestSucceedsIfProxyUrlHasTrailingSlash) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       RequestSucceedsIfProxyUrlDoesNotHaveTrailingSlash) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest, ProxyUrlInheritsQuery) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest, ProxyUrlDoesNotHaveUrlFragment) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest, ProxyUrlKeepsOriginUrlPath) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest, ProxyUrlRemovesOriginalRequestData) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest, ProxyRequestCopiesAcceptHeader) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest, ProxyRequestDisablesCaching) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest, ProxyRequestDefaultsToAcceptingAll) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       DoNotReturnGeneratedPageWhenNotInstallingApplication) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       ReturnGeneratedPageWhenInstallingApplication) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       RequestsRedirectedToPendingInstallIsolationDataWhenAppIsInstalled) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       RequestsRedirectedToPendingInstallIsolationDataWhenAppIsNotInstalled) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       GeneratedInstallPageIsNotReturnedForNonInstallingApp) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       CannotRequestResourceFromDifferentIwa) {}

TEST_F(IsolatedWebAppURLLoaderFactoryTest,
       BrowserCanRequestIwaResourceFromNonApp) {}

IsolatedWebAppURLLoaderFactoryWebAppProviderReadyTest;

TEST_F(IsolatedWebAppURLLoaderFactoryWebAppProviderReadyTest, Waits) {}

IsolatedWebAppURLLoaderFactoryForServiceWorkerTest;

TEST_F(IsolatedWebAppURLLoaderFactoryForServiceWorkerTest, GetRequestsSucceed) {}

class IsolatedWebAppURLLoaderFactorySignedWebBundleTestBase
    : public IsolatedWebAppURLLoaderFactoryTest {};

class IsolatedWebAppURLLoaderFactorySignedWebBundleTest
    : public IsolatedWebAppURLLoaderFactorySignedWebBundleTestBase,
      public ::testing::WithParamInterface<
          std::tuple</*is_dev_mode_bundle=*/bool,
                     /*relative_urls=*/bool>> {};

TEST_P(IsolatedWebAppURLLoaderFactorySignedWebBundleTest, RequestIndex) {}

TEST_P(IsolatedWebAppURLLoaderFactorySignedWebBundleTest,
       RequestIndexWithoutTrustedPublicKey) {}

TEST_P(IsolatedWebAppURLLoaderFactorySignedWebBundleTest,
       RequestResourceWithNon200StatusCode) {}

TEST_P(IsolatedWebAppURLLoaderFactorySignedWebBundleTest,
       RequestNonExistingResource) {}

TEST_P(IsolatedWebAppURLLoaderFactorySignedWebBundleTest,
       SuccessfulRequestHasCorrectLengthFields) {}

TEST_P(IsolatedWebAppURLLoaderFactorySignedWebBundleTest,
       NonExistingRequestHasCorrectLengthFields) {}

TEST_P(IsolatedWebAppURLLoaderFactorySignedWebBundleTest,
       ExistingCoiOverridden) {}

TEST_P(IsolatedWebAppURLLoaderFactorySignedWebBundleTest, ExistingCspKept) {}

INSTANTIATE_TEST_SUITE_P();

class IsolatedWebAppURLLoaderFactoryFeatureFlagDisabledTest
    : public IsolatedWebAppURLLoaderFactorySignedWebBundleTest {};

TEST_P(IsolatedWebAppURLLoaderFactoryFeatureFlagDisabledTest,
       RequestFailsWhenFeatureIsDisabled) {}

INSTANTIATE_TEST_SUITE_P();

class IsolatedWebAppURLLoaderFactoryDevModeDisabledTest
    : public IsolatedWebAppURLLoaderFactorySignedWebBundleTest {};

TEST_P(IsolatedWebAppURLLoaderFactoryDevModeDisabledTest,
       DevModeBundleRequestFailsWhenDevModeIsDisabled) {}

INSTANTIATE_TEST_SUITE_P();

class IsolatedWebAppURLLoaderFactoryHeaderTest
    : public IsolatedWebAppURLLoaderFactorySignedWebBundleTestBase,
      public ::testing::WithParamInterface</*is_bundle=*/bool> {};

TEST_P(IsolatedWebAppURLLoaderFactoryHeaderTest, CoiInjected) {}

TEST_P(IsolatedWebAppURLLoaderFactoryHeaderTest, CspInjected) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace web_app