From 84a88977d2f6ad38f1adde9aee3df6c4571653d2 Mon Sep 17 00:00:00 2001 From: Glen Robertson Date: Mon, 13 May 2024 07:21:44 +0000 Subject: [PATCH] webapps: Delete dead code in bookmark_app_util Util functions were never called outside of tests. Change-Id: I0baa43d9a395790bbfe2ae339b1cbab5f51982d9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5534421 Commit-Queue: Matt Giuca Auto-Submit: Glen Robertson Reviewed-by: Matt Giuca Cr-Commit-Position: refs/heads/main@{#1299917} --- .../web_applications/extensions/BUILD.gn | 5 +- .../extensions/bookmark_app_util.cc | 39 -------- .../extensions/bookmark_app_util.h | 18 ---- .../extensions/bookmark_app_util_unittest.cc | 98 ------------------- 4 files changed, 1 insertion(+), 159 deletions(-) delete mode 100644 chrome/browser/web_applications/extensions/bookmark_app_util_unittest.cc diff --git a/chrome/browser/web_applications/extensions/BUILD.gn b/chrome/browser/web_applications/extensions/BUILD.gn index 9a6dfd7482d475..a6eb0e0424b6ef 100644 --- a/chrome/browser/web_applications/extensions/BUILD.gn +++ b/chrome/browser/web_applications/extensions/BUILD.gn @@ -48,10 +48,7 @@ source_set("extensions") { source_set("unit_tests") { testonly = true - sources = [ - "bookmark_app_util_unittest.cc", - "web_app_uninstall_and_replace_job_unittest.cc", - ] + sources = [ "web_app_uninstall_and_replace_job_unittest.cc" ] deps = [ ":extensions", diff --git a/chrome/browser/web_applications/extensions/bookmark_app_util.cc b/chrome/browser/web_applications/extensions/bookmark_app_util.cc index faff67c5e6e6b4..28cce5b34a334f 100644 --- a/chrome/browser/web_applications/extensions/bookmark_app_util.cc +++ b/chrome/browser/web_applications/extensions/bookmark_app_util.cc @@ -9,18 +9,11 @@ #include #include -#include "base/values.h" -#include "chrome/browser/web_applications/web_app_utils.h" -#include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h" -#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" #include "content/public/browser/browser_context.h" #include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_system.h" #include "extensions/common/extension.h" -#include "extensions/common/extension_icon_set.h" -#include "extensions/common/manifest_handlers/icons_handler.h" -#include "url/gurl.h" namespace extensions { namespace { @@ -49,36 +42,4 @@ bool BookmarkAppIsLocallyInstalled(const ExtensionPrefs* prefs, return true; } -bool IsInNavigationScopeForLaunchUrl(const GURL& launch_url, const GURL& url) { - // Drop any "suffix" components after the path (Resolve "."): - const GURL nav_scope = launch_url.GetWithoutFilename(); - - const int scope_str_length = nav_scope.spec().size(); - return std::string_view(nav_scope.spec()) == - std::string_view(url.spec()).substr(0, scope_str_length); -} - -LaunchContainerAndType GetLaunchContainerAndTypeFromDisplayMode( - web_app::DisplayMode display_mode) { - apps::LaunchContainer apps_launch_container = - web_app::ConvertDisplayModeToAppLaunchContainer(display_mode); - switch (apps_launch_container) { - case apps::LaunchContainer::kLaunchContainerNone: - return {apps::LaunchContainer::kLaunchContainerNone, - extensions::LaunchType::LAUNCH_TYPE_DEFAULT}; - case apps::LaunchContainer::kLaunchContainerPanelDeprecated: - return {apps::LaunchContainer::kLaunchContainerPanelDeprecated, - extensions::LaunchType::LAUNCH_TYPE_REGULAR}; - case apps::LaunchContainer::kLaunchContainerTab: - return {apps::LaunchContainer::kLaunchContainerTab, - extensions::LaunchType::LAUNCH_TYPE_REGULAR}; - case apps::LaunchContainer::kLaunchContainerWindow: - return {apps::LaunchContainer::kLaunchContainerTab, - display_mode == web_app::DisplayMode::kFullscreen - ? extensions::LaunchType::LAUNCH_TYPE_FULLSCREEN - : extensions::LaunchType::LAUNCH_TYPE_WINDOW}; - } - NOTREACHED(); -} - } // namespace extensions diff --git a/chrome/browser/web_applications/extensions/bookmark_app_util.h b/chrome/browser/web_applications/extensions/bookmark_app_util.h index cbb93e3d688a93..46d6aecdfe895f 100644 --- a/chrome/browser/web_applications/extensions/bookmark_app_util.h +++ b/chrome/browser/web_applications/extensions/bookmark_app_util.h @@ -5,17 +5,11 @@ #ifndef CHROME_BROWSER_WEB_APPLICATIONS_EXTENSIONS_BOOKMARK_APP_UTIL_H_ #define CHROME_BROWSER_WEB_APPLICATIONS_EXTENSIONS_BOOKMARK_APP_UTIL_H_ -#include "chrome/browser/web_applications/web_app_constants.h" -#include "chrome/browser/web_applications/web_app_install_info.h" -#include "components/services/app_service/public/cpp/app_launch_util.h" -#include "extensions/common/constants.h" namespace content { class BrowserContext; } -class GURL; - namespace extensions { class Extension; @@ -29,18 +23,6 @@ bool BookmarkAppIsLocallyInstalled(content::BrowserContext* context, bool BookmarkAppIsLocallyInstalled(const ExtensionPrefs* prefs, const Extension* extension); -// Generates a scope based on |launch_url| and checks if the |url| falls under -// it. https://www.w3.org/TR/appmanifest/#navigation-scope -bool IsInNavigationScopeForLaunchUrl(const GURL& launch_url, const GURL& url); - -struct LaunchContainerAndType { - apps::LaunchContainer launch_container; - extensions::LaunchType launch_type; -}; - -LaunchContainerAndType GetLaunchContainerAndTypeFromDisplayMode( - web_app::DisplayMode display_mode); - } // namespace extensions #endif // CHROME_BROWSER_WEB_APPLICATIONS_EXTENSIONS_BOOKMARK_APP_UTIL_H_ diff --git a/chrome/browser/web_applications/extensions/bookmark_app_util_unittest.cc b/chrome/browser/web_applications/extensions/bookmark_app_util_unittest.cc deleted file mode 100644 index 0ba0e6347a3529..00000000000000 --- a/chrome/browser/web_applications/extensions/bookmark_app_util_unittest.cc +++ /dev/null @@ -1,98 +0,0 @@ -// 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. - -#include "chrome/browser/web_applications/extensions/bookmark_app_util.h" - -#include "testing/gtest/include/gtest/gtest.h" -#include "url/gurl.h" - -namespace extensions { - -// See additional test coverage for edge cases in GURLTest.GetWithoutFilename. -TEST(BookmarkAppUtil, IsInNavigationScopeForLaunchUrl_UrlArgumentVariations) { - const GURL launch_url = GURL("https://mail.google.com/mail/u/0"); - - // Not in scope. - EXPECT_FALSE(IsInNavigationScopeForLaunchUrl( - launch_url, GURL("https://mail.google.com"))); - EXPECT_FALSE(IsInNavigationScopeForLaunchUrl( - launch_url, GURL("https://mail.google.com/mail/"))); - - // The scope itself. - EXPECT_TRUE(IsInNavigationScopeForLaunchUrl( - launch_url, GURL("https://mail.google.com/mail/u/"))); - // No match if no trailing '/' in path. - EXPECT_FALSE(IsInNavigationScopeForLaunchUrl( - launch_url, GURL("https://mail.google.com/mail/u"))); - - // Regular sub-path. - EXPECT_TRUE(IsInNavigationScopeForLaunchUrl( - launch_url, GURL("https://mail.google.com/mail/u/0/"))); - - // With a ref. - EXPECT_TRUE(IsInNavigationScopeForLaunchUrl( - launch_url, GURL("https://mail.google.com/mail/u/0/#inbox"))); - - // A launch URL with trailing '/' resolves to itself. - const GURL launch_url2 = GURL("https://example.com/path/subpath/"); - EXPECT_TRUE(IsInNavigationScopeForLaunchUrl( - launch_url2, GURL("https://example.com/path/subpath/page.html"))); - EXPECT_FALSE(IsInNavigationScopeForLaunchUrl( - launch_url2, GURL("https://example.com/path/subpath2/"))); - - // With a query. - EXPECT_TRUE(IsInNavigationScopeForLaunchUrl( - GURL("https://example.com/path/subpath"), - GURL("https://example.com/path/query?parameter"))); -} - -TEST(BookmarkAppUtil, IsInNavigationScopeForLaunchUrl_LaunchUrlVariations) { - // With a query. - EXPECT_TRUE(IsInNavigationScopeForLaunchUrl( - GURL("https://example.com/path/query?parameter"), - GURL("https://example.com/path/subpath"))); - EXPECT_FALSE(IsInNavigationScopeForLaunchUrl( - GURL("https://example.com/path/query?parameter"), - GURL("https://example.com/query"))); - - EXPECT_TRUE(IsInNavigationScopeForLaunchUrl( - GURL("https://example.com/path/query/?parameter"), - GURL("https://example.com/path/query/"))); - EXPECT_FALSE(IsInNavigationScopeForLaunchUrl( - GURL("https://example.com/path/query/?parameter"), - GURL("https://example.com/path/subpath/"))); - - // With a ref. - EXPECT_TRUE(IsInNavigationScopeForLaunchUrl( - GURL("https://example.com/path/#ref"), - GURL("https://example.com/path/subpath"))); - EXPECT_FALSE(IsInNavigationScopeForLaunchUrl( - GURL("https://example.com/path/#ref"), GURL("https://example.com/#ref"))); - - // With a ref and query. - EXPECT_TRUE(IsInNavigationScopeForLaunchUrl( - GURL("https://example.com/path/?query=param#ref"), - GURL("https://example.com/path/subpath"))); - EXPECT_FALSE(IsInNavigationScopeForLaunchUrl( - GURL("https://example.com/path/?query=param#ref"), - GURL("https://example.com/subpath"))); - - EXPECT_TRUE(IsInNavigationScopeForLaunchUrl( - GURL("https://example.com/path/#ref?query=param"), - GURL("https://example.com/path/subpath"))); - EXPECT_FALSE(IsInNavigationScopeForLaunchUrl( - GURL("https://example.com/path/#ref?query=param"), - GURL("https://example.com/subpath"))); -} - -TEST(BookmarkAppUtil, IsInNavigationScopeForLaunchUrl_Extensions) { - // The Crosh extension. - const GURL extension_launch_url = GURL( - "chrome-extension://nkoccljplnhpfnfiajclkommnmllphnl/html/crosh.html"); - EXPECT_TRUE(IsInNavigationScopeForLaunchUrl( - extension_launch_url, - GURL("chrome-extension://nkoccljplnhpfnfiajclkommnmllphnl/html/path"))); -} - -} // namespace extensions