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

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

#include "base/check_op.h"
#include "base/containers/span.h"
#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/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/functional/overloaded.h"
#include "base/strings/strcat.h"
#include "base/test/bind.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/gmock_expected_support.h"
#include "base/test/metrics/histogram_tester.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/isolated_web_app_install_command_helper.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_install_source.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_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/isolated_web_app_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_builder.h"
#include "chrome/browser/web_applications/isolated_web_apps/test/test_signed_web_bundle_builder.h"
#include "chrome/browser/web_applications/locks/lock.h"
#include "chrome/browser/web_applications/test/fake_web_app_provider.h"
#include "chrome/browser/web_applications/test/fake_web_contents_manager.h"
#include "chrome/browser/web_applications/test/mock_data_retriever.h"
#include "chrome/browser/web_applications/test/web_app_icon_test_utils.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_command_manager.h"
#include "chrome/browser/web_applications/web_app_command_scheduler.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_icon_manager.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_app_registrar.h"
#include "chrome/common/chrome_features.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/web_bundle_builder.h"
#include "components/webapps/browser/installable/installable_logging.h"
#include "components/webapps/browser/installable/installable_metrics.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 "net/http/http_status_code.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.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 "url/gurl.h"

namespace web_app {
namespace {

BucketsAre;
ErrorIs;
HasValue;
IsNotNullCallback;
RunOnceCallback;
_;
AllOf;
DoAll;
Eq;
Field;
HasSubstr;
IsEmpty;
IsFalse;
IsNull;
IsTrue;
NiceMock;
Not;
NotNull;
Optional;
Pair;
Pointee;
Property;
ResultOf;
UnorderedElementsAre;
VariantWith;
WithArg;

constexpr std::string_view kManifestPath =;
constexpr std::string_view kIconPath =;

IsolatedWebAppUrlInfo CreateRandomIsolatedWebAppUrlInfo() {}

IsolatedWebAppUrlInfo CreateEd25519IsolatedWebAppUrlInfo() {}

IwaSourceProxy CreateDevProxySource() {}

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

GURL CreateDefaultManifestURL(const GURL& application_url) {}

class InstallIsolatedWebAppCommandTest : public WebAppTest {};

TEST_F(InstallIsolatedWebAppCommandTest, PropagateErrorWhenURLLoaderFails) {}

TEST_F(InstallIsolatedWebAppCommandTest,
       PropagateErrorWhenURLLoaderFailsWithDestroyedWebContentsError) {}

TEST_F(InstallIsolatedWebAppCommandTest,
       InstallationSucceedesWhenFinalizerReturnSuccessNewInstall) {}

TEST_F(InstallIsolatedWebAppCommandTest,
       InstallationFailsWhenDevModeIsDisabled) {}

struct ProxyInstallSourceParam {};

class InstallIsolatedWebAppCommandProxyInstallSourceTest
    : public InstallIsolatedWebAppCommandTest,
      public ::testing::WithParamInterface<ProxyInstallSourceParam> {};

TEST_P(InstallIsolatedWebAppCommandProxyInstallSourceTest,
       InstallationFinalizedWithCorrectInstallSurface) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(InstallIsolatedWebAppCommandTest,
       InstallationFailsWhenAppIsNotInstallable) {}

TEST_F(InstallIsolatedWebAppCommandTest, PendingUpdateInfoIsEmpty) {}

TEST_F(InstallIsolatedWebAppCommandTest,
       InstallationFailsWhenAppVersionDoesNotMatchExpectedVersion) {}

TEST_F(InstallIsolatedWebAppCommandTest, CommandLocksOnAppId) {}

TEST_F(InstallIsolatedWebAppCommandTest, LocationSentToFinalizer) {}

TEST_F(InstallIsolatedWebAppCommandTest,
       CreatesStorageParitionDuringInstallation) {}

TEST_F(InstallIsolatedWebAppCommandTest, UsersCanDeleteIsolatedApp) {}

TEST_F(InstallIsolatedWebAppCommandTest,
       CreatesStoragePartitionBeforeUrlLoading) {}

InstallIsolatedWebAppCommandManifestTest;

TEST_F(InstallIsolatedWebAppCommandManifestTest,
       PassesManifestIdToFinalizerWhenManifestIdIsEmpty) {}

TEST_F(InstallIsolatedWebAppCommandManifestTest,
       FailsWhenManifestIdIsNotEmpty) {}

TEST_F(InstallIsolatedWebAppCommandManifestTest,
       InstalledApplicationScopeIsResolvedToRootWhenManifestScopeIsSlash) {}

TEST_F(InstallIsolatedWebAppCommandManifestTest,
       PassesManifestNameAsUntranslatedName) {}

TEST_F(InstallIsolatedWebAppCommandManifestTest,
       UseShortNameAsUntranslatedNameWhenNameIsNotPresent) {}

TEST_F(InstallIsolatedWebAppCommandManifestTest,
       UseShortNameAsTitleWhenManifestNameIsEmpty) {}

InstallIsolatedWebAppCommandManifestIconsTest;

TEST_F(InstallIsolatedWebAppCommandManifestIconsTest,
       ManifestIconIsDownloaded) {}

TEST_F(InstallIsolatedWebAppCommandManifestIconsTest,
       InstallationFailsWhenIconDownloadingFails) {}

TEST_F(InstallIsolatedWebAppCommandTest,
       ReportSuccessWhenFinishedSuccessfully) {}

TEST_F(InstallIsolatedWebAppCommandTest, ReportErrorWhenUrlLoaderFails) {}

TEST_F(InstallIsolatedWebAppCommandTest, ReportFailureWhenAppIsNotInstallable) {}

TEST_F(InstallIsolatedWebAppCommandTest, ReportFailureWhenManifestIsNull) {}

TEST_F(InstallIsolatedWebAppCommandTest,
       ReportFailureWhenManifestIdIsNotEmpty) {}

struct BundleTestInfo {};

class InstallIsolatedWebAppCommandBundleTest
    : public InstallIsolatedWebAppCommandTest,
      public ::testing::WithParamInterface<std::tuple<bool, BundleTestInfo>> {};

TEST_P(InstallIsolatedWebAppCommandBundleTest, InstallsWhenThereIsNoError) {}

INSTANTIATE_TEST_SUITE_P();

struct BundleInstallSourceParam {};

class InstallIsolatedWebAppCommandBundleInstallSourceTest
    : public InstallIsolatedWebAppCommandTest,
      public ::testing::WithParamInterface<BundleInstallSourceParam> {};

TEST_P(InstallIsolatedWebAppCommandBundleInstallSourceTest,
       InstallationFinalizedWithCorrectInstallSurface) {}

INSTANTIATE_TEST_SUITE_P(
    /* no prefix */,
    InstallIsolatedWebAppCommandBundleInstallSourceTest,
    ::testing::Values(
        BundleInstallSourceParam{};

}  // namespace
}  // namespace web_app