chromium/chrome/browser/web_applications/commands/external_app_resolution_command_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/commands/external_app_resolution_command.h"

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

#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/containers/to_vector.h"
#include "base/functional/callback_helpers.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/test_future.h"
#include "chrome/browser/web_applications/commands/internal/callback_command.h"
#include "chrome/browser/web_applications/external_install_options.h"
#include "chrome/browser/web_applications/locks/app_lock.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/proto/web_app_install_state.pb.h"
#include "chrome/browser/web_applications/test/fake_data_retriever.h"
#include "chrome/browser/web_applications/test/fake_os_integration_manager.h"
#include "chrome/browser/web_applications/test/fake_web_app_provider.h"
#include "chrome/browser/web_applications/test/fake_web_app_ui_manager.h"
#include "chrome/browser/web_applications/test/fake_web_contents_manager.h"
#include "chrome/browser/web_applications/test/test_file_utils.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_constants.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_icon_generator.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/browser/web_applications/web_contents/web_app_data_retriever.h"
#include "chrome/browser/web_applications/web_contents/web_contents_manager.h"
#include "components/services/app_service/public/cpp/icon_info.h"
#include "components/webapps/browser/install_result_code.h"
#include "components/webapps/browser/installable/installable_logging.h"
#include "components/webapps/browser/web_contents/web_app_url_loader.h"
#include "components/webapps/common/web_app_id.h"
#include "components/webapps/common/web_page_metadata.mojom.h"
#include "net/http/http_status_code.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/size.h"

BucketsAre;
_;
Return;

namespace web_app {
namespace {

struct PageStateOptions {};

class MockWebAppUiManager : public web_app::FakeWebAppUiManager {};

class ExternalAppResolutionCommandTest : public WebAppTest {};

TEST_F(ExternalAppResolutionCommandTest, SuccessInternalDefault) {}

TEST_F(ExternalAppResolutionCommandTest, SuccessAppFromPolicy) {}

TEST_F(ExternalAppResolutionCommandTest, InstallFails) {}

TEST_F(ExternalAppResolutionCommandTest, SuccessInstallPlaceholder) {}

TEST_F(ExternalAppResolutionCommandTest, InstallPlaceholderTwice) {}

TEST_F(ExternalAppResolutionCommandTest, ReinstallPlaceholderSucceeds) {}

TEST_F(ExternalAppResolutionCommandTest,
       ReinstallPlaceholderSucceedsWithAppRelaunch) {}

TEST_F(ExternalAppResolutionCommandTest,
       ReinstallPlaceholderAppRelaunchNoWindow) {}

// With go/external_app_refactoring the placeholder is updated in-place and not
// uninstalled anymore.
TEST_F(ExternalAppResolutionCommandTest,
       ReinstallPlaceholderMigrationSucceedsWithFailingFileDeletion) {}

#if BUILDFLAG(IS_CHROMEOS)
TEST_F(ExternalAppResolutionCommandTest, InstallPlaceholderCustomName) {
  const GURL kWebAppUrl("https://foo.example");
  const std::string kCustomName("Custom äpp näme");
  ExternalInstallOptions options(kWebAppUrl,
                                 mojom::UserDisplayMode::kStandalone,
                                 ExternalInstallSource::kExternalPolicy);
  options.install_placeholder = true;
  options.override_name = kCustomName;
  SetPageState(options,
               {.url_load_result =
                    webapps::WebAppUrlLoaderResult::kRedirectedUrlLoaded});

  auto result = InstallAndWait(options);

  EXPECT_EQ(webapps::InstallResultCode::kSuccessNewInstall, result.code);
  ASSERT_TRUE(result.app_id.has_value());

  EXPECT_EQ(registrar().GetAppShortName(result.app_id.value()), kCustomName);
}
#endif  // BUILDFLAG(IS_CHROMEOS)

TEST_F(ExternalAppResolutionCommandTest, UninstallAndReplace) {}

TEST_F(ExternalAppResolutionCommandTest, InstallURLLoadFailed) {}

TEST_F(ExternalAppResolutionCommandTest, InstallWithWebAppInfoSucceeds) {}

TEST_F(ExternalAppResolutionCommandTest, InstallWithWebAppInfoFails) {}

TEST_F(ExternalAppResolutionCommandTest, SucessInstallForcedContainerWindow) {}

TEST_F(ExternalAppResolutionCommandTest, GetWebAppInstallInfoFailed) {}

TEST_F(ExternalAppResolutionCommandTest, UpgradeLock) {}

TEST_F(ExternalAppResolutionCommandTest,
       IconDownloadSuccessOverwriteNoIconsBefore) {}

TEST_F(ExternalAppResolutionCommandTest, IconDownloadSuccessOverwriteOldIcons) {}

TEST_F(ExternalAppResolutionCommandTest,
       IconDownloadFailDoesNotOverwriteOldIcons) {}

#if !BUILDFLAG(IS_CHROMEOS_LACROS)
TEST_F(ExternalAppResolutionCommandTest, SuccessWithUninstallAndReplace) {}
#endif  // !BUILDFLAG(IS_CHROMEOS_LACROS)

TEST_F(ExternalAppResolutionCommandTest, WriteDataToDiskFailed) {}

}  // namespace
}  // namespace web_app