chromium/chrome/browser/ui/web_applications/create_shortcut_browsertest.cc

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

#include <initializer_list>
#include <map>
#include <optional>
#include <string>
#include <utility>

#include "base/check.h"
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shortcuts/shortcut_icon_generator.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/ui/web_applications/web_app_browsertest_base.h"
#include "chrome/browser/ui/web_applications/web_app_dialogs.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom-shared.h"
#include "chrome/browser/web_applications/test/web_app_test_observers.h"
#include "chrome/browser/web_applications/test/web_app_test_utils.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_command_manager.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_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_sync_bridge.h"
#include "chrome/common/chrome_paths.h"
#include "components/webapps/browser/features.h"
#include "components/webapps/browser/installable/installable_metrics.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/common/extension.h"
#include "net/test/embedded_test_server/embedded_test_server.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 "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/skia_util.h"
#include "url/gurl.h"

#if !BUILDFLAG(IS_CHROMEOS)
#include "chrome/common/chrome_features.h"
#endif  // !BUILDFLAG(IS_CHROMEOS)

namespace {

std::string LoadExtension(Profile* profile, const base::FilePath& path) {}

}  // namespace

namespace web_app {

// TODO(crbug.com/344912771): Remove once ShortcutsNotApps launches to 100%
// Stable.
class CreateShortcutBrowserTest : public WebAppBrowserTestBase {};

IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest,
                       CreateShortcutForInstallableSite) {}

// TODO(crbug.com/40269598): flaky on Mac11 Tests builder.
#if BUILDFLAG(IS_MAC)
#define MAYBE_InstallSourceRecorded
#else
#define MAYBE_InstallSourceRecorded
#endif
IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest, MAYBE_InstallSourceRecorded) {}

IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest,
                       CanInstallOverTabShortcutApp) {}

IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest,
                       CannotInstallOverWindowShortcutApp) {}

// Check that toolbar is not shown for shortcut apps within extensions pages.
// This simulates a case where the user has manually navigated to a page hosted
// within an extension, then added it as a shortcut app.
// Regression test for https://crbug.com/828233.
//
// TODO(crbug.com/40793595): Remove chrome-extension scheme for web apps.
IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest,
                       ShouldShowCustomTabBarForExtensionPage) {}

// Tests that Create Shortcut doesn't timeout on a page that has a delayed
// iframe load. Context: crbug.com/1046883
IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest, WorksAfterDelayedIFrameLoad) {}

// Tests that Create Shortcut on non-promotable sites still uses available
// manifest data.
IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest,
                       UseNonPromotableManifestData) {}

// Tests that Create Shortcut won't use manifest data that's invalid.
IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest, IgnoreInvalidManifestData) {}

// TODO(crbug.com/40883914): Un-flake and re-enable this test.
IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest,
                       DISABLED_CreateShortcutAgainOverwriteUserDisplayMode) {}

// TODO(crbug.com/40908616): Re-enable this test
IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest,
                       DISABLED_OpenShortcutWindowOnlyOnce) {}

// Tests that Create Shortcut on sites where the title is a url generates a
// letter icon correctly and does not use the "H" letter from the "https"
// scheme.
IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest, UseHostWhenTitleIsUrl) {}

IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest,
                       InstallableSiteDifferentStartUrl) {}

IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest, InstallOverTabShortcutApp) {}

}  // namespace web_app