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

// Copyright 2023 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_install_command_helper.h"

#include <map>
#include <memory>
#include <optional>
#include <sstream>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>

#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/test/bind.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/gmock_expected_support.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "base/types/expected.h"
#include "chrome/browser/ui/web_applications/test/isolated_web_app_test_utils.h"
#include "chrome/browser/web_applications/isolated_web_apps/error/unusable_swbn_file_error.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_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_url_info.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_validator.h"
#include "chrome/browser/web_applications/isolated_web_apps/iwa_identity_validator.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_fake_response_reader_factory.h"
#include "chrome/browser/web_applications/isolated_web_apps/test/test_signed_web_bundle_builder.h"
#include "chrome/browser/web_applications/test/mock_data_retriever.h"
#include "chrome/browser/web_applications/test/test_web_app_url_loader.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_install_info.h"
#include "chrome/browser/web_applications/web_app_install_utils.h"
#include "chrome/browser/web_applications/web_contents/web_app_data_retriever.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/testing_profile.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/webapps/browser/web_contents/web_app_url_loader.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_task_environment.h"
#include "net/http/http_status_code.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-shared.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "url/gurl.h"

namespace web_app {
namespace {

ErrorIs;
HasValue;
IsNotNullCallback;
RunOnceCallback;
ValueIs;
_;
DoAll;
Each;
Eq;
Field;
HasSubstr;
IsEmpty;
IsFalse;
IsNull;
IsTrue;
NiceMock;
Not;
NotNull;
Optional;
Pair;
ResultOf;
UnorderedElementsAre;
VariantWith;
WithArg;

IsolatedWebAppUrlInfo CreateRandomIsolatedWebAppUrlInfo() {}

IsolatedWebAppUrlInfo CreateEd25519IsolatedWebAppUrlInfo() {}

IwaSourceWithMode CreateDevProxySource(
    std::string_view dev_mode_proxy_url = "http://default-proxy-url.org/") {}

GURL CreateDefaultManifestURL(const GURL& application_url) {}

blink::mojom::ManifestPtr CreateDefaultManifest(const GURL& application_url) {}

auto ReturnManifest(const blink::mojom::ManifestPtr& manifest,
                    webapps::InstallableStatusCode error_code =
                        webapps::InstallableStatusCode::NO_ERROR_DETECTED) {}

std::unique_ptr<MockDataRetriever> CreateDefaultDataRetriever(
    const GURL& application_url) {}

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

IsolatedWebAppInstallCommandHelperTrustAndSignaturesTest;

TEST_F(IsolatedWebAppInstallCommandHelperTrustAndSignaturesTest,
       DevProxySucceeds) {}

TEST_F(IsolatedWebAppInstallCommandHelperTrustAndSignaturesTest,
       DevProxyFailsWhenDevModeIsDisabled) {}

class IsolatedWebAppInstallCommandHelperTrustAndSignaturesBundleTest
    : public IsolatedWebAppInstallCommandHelperTrustAndSignaturesTest,
      public ::testing::WithParamInterface<bool> {};

TEST_P(IsolatedWebAppInstallCommandHelperTrustAndSignaturesBundleTest,
       SucceedsWhenThereIsNoError) {}

TEST_P(IsolatedWebAppInstallCommandHelperTrustAndSignaturesBundleTest,
       ErrorsOnBundleError) {}

TEST_P(IsolatedWebAppInstallCommandHelperTrustAndSignaturesBundleTest,
       DoesNotInstallDevModeBundleWhenDevModeIsDisabled) {}

INSTANTIATE_TEST_SUITE_P();

IsolatedWebAppInstallCommandHelperStoragePartitionTest;

TEST_F(IsolatedWebAppInstallCommandHelperStoragePartitionTest,
       CreateIfNotPresent) {}

TEST_F(IsolatedWebAppInstallCommandHelperStoragePartitionTest,
       CreateIfPresent) {}

IsolatedWebAppInstallCommandHelperLoadUrlTest;

TEST_F(IsolatedWebAppInstallCommandHelperLoadUrlTest,
       URLLoaderIsCalledWithUrlGivenToTheInstallCommand) {}

TEST_F(IsolatedWebAppInstallCommandHelperLoadUrlTest,
       SetDevModeLocationBeforeUrlLoading) {}

TEST_F(IsolatedWebAppInstallCommandHelperLoadUrlTest,
       SetInstalledBundleLocationBeforeUrlLoading) {}

TEST_F(IsolatedWebAppInstallCommandHelperLoadUrlTest, HandlesFailure) {}

IsolatedWebAppInstallCommandHelperRetrieveManifestTest;

TEST_F(IsolatedWebAppInstallCommandHelperRetrieveManifestTest,
       ServiceWorkerIsNotRequired) {}

TEST_F(IsolatedWebAppInstallCommandHelperRetrieveManifestTest,
       FailsWhenAppIsNotInstallable) {}

TEST_F(IsolatedWebAppInstallCommandHelperRetrieveManifestTest,
       FailsWhenAppIsInstallableButManifestIsNull) {}

struct InvalidVersionParam {};

IsolatedWebAppInstallCommandHelperValidateManifestTest;

class InstallIsolatedWebAppCommandHelperInvalidVersionTest
    : public IsolatedWebAppInstallCommandHelperValidateManifestTest,
      public ::testing::WithParamInterface<InvalidVersionParam> {};

TEST_P(InstallIsolatedWebAppCommandHelperInvalidVersionTest,
       InstallationFails) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(IsolatedWebAppInstallCommandHelperValidateManifestTest,
       FailsWhenAppVersionDoesNotMatchExpectedVersion) {}

TEST_F(IsolatedWebAppInstallCommandHelperValidateManifestTest,
       SucceedsWhenManifestIdIsEmpty) {}

TEST_F(IsolatedWebAppInstallCommandHelperValidateManifestTest,
       FailsWhenManifestIdIsNotEmpty) {}

TEST_F(IsolatedWebAppInstallCommandHelperValidateManifestTest,
       FailsWhenManifestScopeIsNotSlash) {}

TEST_F(IsolatedWebAppInstallCommandHelperValidateManifestTest,
       ScopeIsResolvedToRootWhenManifestScopeIsSlash) {}

TEST_F(IsolatedWebAppInstallCommandHelperValidateManifestTest,
       UntranslatedNameIsEmptyWhenNameAndShortNameAreNotPresent) {}

class InstallIsolatedWebAppCommandHelperManifestIconsTest
    : public IsolatedWebAppInstallCommandHelperTest {};

TEST_F(InstallIsolatedWebAppCommandHelperManifestIconsTest,
       ManifestIconIsDownloaded) {}

TEST_F(InstallIsolatedWebAppCommandHelperManifestIconsTest,
       InstallationFailsWhenIconDownloadingFails) {}

struct VerifyRelocationVisitor {};

struct VerifyCleanupVisitor {};

class InstallIsolatedWebAppCommandHelperRelocationTest
    : public ::testing::TestWithParam<IwaSourceBundleModeAndFileOp> {};

TEST_P(InstallIsolatedWebAppCommandHelperRelocationTest, NormalFlow) {}

INSTANTIATE_TEST_SUITE_P();

TEST(InstallIsolatedWebAppCommandHelperCleanupTest, CleanupNotOwned) {}

}  // namespace
}  // namespace web_app