chromium/chrome/browser/web_applications/web_app_install_utils_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chrome/browser/web_applications/web_app_install_utils.h"

#include <stddef.h>

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

#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/feature_list.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "chrome/browser/web_applications/os_integration/os_integration_manager.h"
#include "chrome/browser/web_applications/os_integration/web_app_file_handler_manager.h"
#include "chrome/browser/web_applications/test/web_app_icon_test_utils.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_icon_generator.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "components/services/app_service/public/cpp/icon_info.h"
#include "components/services/app_service/public/cpp/protocol_handler_info.h"
#include "components/services/app_service/public/cpp/share_target.h"
#include "components/services/app_service/public/cpp/url_handler_info.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/manifest/manifest.h"
#include "third_party/blink/public/common/permissions_policy/origin_with_possible_wildcards.h"
#include "third_party/blink/public/common/permissions_policy/permissions_policy.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom-shared.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-shared.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-shared.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "ui/gfx/skia_util.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace web_app {

Purpose;

namespace {

const char16_t kAppTestShortName[] =;
const char16_t kAppTestTitle[] =;
const char16_t kAlternativeAppTestTitle[] =;
const char16_t kShortcutItemTestName[] =;

constexpr SquareSizePx kIconSize =;

// This value is greater than kMaxIcons in web_app_install_utils.cc.
constexpr unsigned int kNumTestIcons =;

IconPurpose IconInfoPurposeToManifestPurpose(
    apps::IconInfo::Purpose icon_info_purpose) {}

GURL StartUrl() {}

// Returns a stack-allocated WebAppInstallInfo with `StartUrl()` as the
// start_url and manifest_id. Needed to migrate existing tests from the default
// constructor. Prefer to instead use
// WebAppInstallInfo::CreateWithStartUrlForTesting when adding new tests.
WebAppInstallInfo CreateWebAppInstallInfo() {}

// Returns a stack-allocated WebAppInstallInfo. Needed to migrate existing tests
// from the default constructor. Prefer to instead use
// WebAppInstallInfo::CreateWithStartUrlForTesting when adding new tests.
WebAppInstallInfo CreateWebAppInstallInfoFromStartUrl(const GURL& start_url) {}

}  // namespace

TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifest) {}

TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifest_EmptyName) {}

// Test that maskable icons are parsed as separate manifest_icons from the
// manifest.
TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifest_MaskableIcon) {}

TEST(WebAppInstallUtils,
     UpdateWebAppInfoFromManifest_MaskableIconOnly_UsesManifestIcons) {}

TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifest_ShareTarget) {}

// Tests that WebAppInfo is correctly updated when Manifest contains Shortcuts.
TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifestWithShortcuts) {}

// Tests that we limit the number of shortcut menu items.
TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifestTooManyShortcuts) {}

// Tests that we limit the number of icons declared by a site.
TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifestTooManyIcons) {}

// Tests that we limit the number of shortcut icons, verifying that at most 20
// shortcut icons are stored per web app.
//
// The test previously created 30 shortcuts, each with 1 icon. Due to the new
// limit of 10 shortcuts per web app, we now create 5 shortcuts, with 6 icons
// each.
TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifestTooManyShortcutIcons) {}

// Tests that we limit the size of icons declared by a site.
TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifestIconsTooLarge) {}

// Tests that we limit the size of shortcut icons declared by a site.
TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifestShortcutIconsTooLarge) {}

TEST(WebAppInstallUtils,
     UpdateWebAppInfoFromManifest_CrossOriginUrls_DropsFields) {}

TEST(WebAppInstallUtils,
     UpdateWebAppInfoFromManifest_WithoutLockscreenFlag_DropsField) {}

// Tests that SkBitmaps associated with shortcut item icons are populated in
// their own map in web_app_info.
TEST(WebAppInstallUtils, PopulateShortcutItemIcons) {}

// Tests that when PopulateOtherItemIcons is called with no shortcut icon
// urls specified, no data is written to shortcuts_menu_item_infos.
TEST(WebAppInstallUtils, PopulateShortcutItemIconsNoShortcutIcons) {}

// Tests that when PopulateProductIcons is called with maskable
// icons available, web_app_info.icon_bitmaps_{any,maskable} are correctly
// populated.
TEST(WebAppInstallUtils, PopulateProductIcons_MaskableIcons) {}

// Tests that when PopulateProductIcons is called with maskable
// icons only, web_app_info.icon_bitmaps_any is correctly populated.
TEST(WebAppInstallUtils, PopulateProductIcons_MaskableIconsOnly) {}

TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifest_InvalidManifestUrl) {}

// Tests that when PopulateProductIcons is called with no
// app icon or shortcut icon data in web_app_info, and kDesktopPWAShortcutsMenu
// feature enabled, web_app_info.icon_bitmaps_any is correctly populated.
TEST(WebAppInstallUtils, PopulateProductIconsNoWebAppIconData_WithShortcuts) {}

TEST(WebAppInstallUtils, PopulateProductIcons_IsGeneratedIcon) {}

TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifest_Translations) {}

TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifest_TabStrip) {}

// All home tab icons are saved from the manifest except for icons that
// exceed the maximum allowed size.
TEST(WebAppInstallUtils, UpdateWebAppInfoFromManifestHomeTabIcons_TabStrip) {}

// Tests that when PopulateOtherItemIcons is called with no home tab icon
// urls specified, no data is written to other_icon_bitmaps.
TEST(WebAppInstallUtils, PopulateHomeTabIconsNoHomeTabIcons_TabStrip) {}

// Tests that SkBitmaps associated with home tab icons are populated in
// their own map in web_app_info.
TEST(WebAppInstallUtils, PopulateHomeTabIcons_TabStrip) {}

// Tests proper parsing of ManifestImageResource icons from the manifest into
// |icons_with_size_any| based on the absence of a size parameter.
TEST(WebAppInstallUtils, PopulateAnyIconsCorrectlyManifestParsingSVGOnly) {}

class FileHandlersFromManifestTest : public ::testing::TestWithParam<bool> {};

TEST_P(FileHandlersFromManifestTest, Basic) {}

TEST_P(FileHandlersFromManifestTest, PopulateFileHandlerIcons) {}

// Tests both file handlers and home tab icons as they use the same variable to
// store their bitmaps.
TEST_P(FileHandlersFromManifestTest, PopulateFileHandlingAndHomeTabIcons) {}

// Test duplicate icon download urls that from the manifest.
TEST(WebAppInstallUtils, DuplicateIconDownloadURLs) {}

INSTANTIATE_TEST_SUITE_P();

TEST(WebAppInstallUtils, SetWebAppManifestFields_Summary) {}

TEST(WebAppInstallUtils, SetWebAppManifestFields_ShareTarget) {}

}  // namespace web_app