#include "components/favicon/content/content_favicon_driver.h"
#include <optional>
#include <set>
#include <string>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/pattern.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.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/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.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/tabs/tab_strip_model_observer.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/favicon/core/favicon_handler.h"
#include "components/favicon/core/favicon_service.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/browsing_data_remover_test_util.h"
#include "content/public/test/mock_web_contents_observer.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/url_loader_interceptor.h"
#include "net/base/load_flags.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/url_request/url_request.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/favicon/favicon_url.mojom.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "url/url_constants.h"
namespace {
ElementsAre;
std::unique_ptr<net::test_server::HttpResponse> NoContentResponseHandler(
const std::string& path,
const net::test_server::HttpRequest& request) { … }
class TestURLLoaderInterceptor { … };
class PendingTaskWaiter : public content::WebContentsObserver { … };
class PageLoadStopper : public content::WebContentsObserver { … };
}
class ContentFaviconDriverTest : public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest,
DoNotLoadFaviconsWhilePrerendering) { … }
class NoCommittedNavigationWebContentsObserver
: public content::WebContentsObserver { … };
class FaviconUpdateOnlyInitialEntryTabStripObserver
: public TabStripModelObserver { … };
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest,
FaviconUpdateOnlyInitialEntry) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, ReloadBypassingCache) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest,
ReplaceFaviconWithTouchIconViaJavascript) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, ChangeTouchIconViaJavascript) { … }
#if BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, RemoveTouchIconViaJavascript) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url = embedded_test_server()->GetURL(
"/favicon/page_change_favicon_type_to_favicon_via_js.html");
PendingTaskWaiter waiter(web_contents());
waiter.AlsoRequireTitle(u"OK");
ui_test_utils::NavigateToURLWithDisposition(
browser(), url, WindowOpenDisposition::CURRENT_TAB,
ui_test_utils::BROWSER_TEST_NO_WAIT);
waiter.Wait();
EXPECT_EQ(nullptr,
GetFaviconForPageURL(url, favicon_base::IconType::kTouchIcon)
.bitmap_data);
}
#endif
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, DoNotRemoveMappingIfStopped) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, LoadIconFromWebManifest) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest,
AssociateIconWithInitialPageDespiteMetaRefreshTag) { … }
IN_PROC_BROWSER_TEST_F(
ContentFaviconDriverTest,
AssociateIconWithInitialPageDespiteMetaRefreshTagAndLandingPageCached) { … }
IN_PROC_BROWSER_TEST_F(
ContentFaviconDriverTest,
AssociateIconWithInitialPageDespite300ResponseAndMetaRefreshTag) { … }
IN_PROC_BROWSER_TEST_F(
ContentFaviconDriverTest,
AssociateIconWithInitialPageDespite300ResponseAndMetaRefreshTagTo300) { … }
IN_PROC_BROWSER_TEST_F(
ContentFaviconDriverTest,
AssociateIconWithInitialPageDespiteLocationOverrideWithinPage) { … }
IN_PROC_BROWSER_TEST_F(
ContentFaviconDriverTest,
AssociateIconWithInitialPageDespiteLocationOverrideToOtherPage) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest,
AssociateIconWithInitialPageIconDespiteReplaceState) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest,
AssociateIconWithInitialPageIconDespitePushState) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest,
DoNotAssociateIconWithInitialPageAfterHrefAssign) { … }
#if BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest,
LoadIconFromWebManifestDespitePushState) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url =
embedded_test_server()->GetURL("/favicon/pushstate_with_manifest.html");
GURL pushstate_url = embedded_test_server()->GetURL(
"/favicon/pushstate_with_manifest.html#pushState");
PendingTaskWaiter waiter(web_contents());
waiter.AlsoRequireUrl(pushstate_url);
ui_test_utils::NavigateToURLWithDisposition(
browser(), url, WindowOpenDisposition::CURRENT_TAB,
ui_test_utils::BROWSER_TEST_NO_WAIT);
waiter.Wait();
EXPECT_NE(nullptr,
GetFaviconForPageURL(pushstate_url,
{favicon_base::IconType::kWebManifestIcon})
.bitmap_data);
}
#endif
class ContentFaviconDriverTestWithAutoupgradesDisabled
: public ContentFaviconDriverTest { … };
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTestWithAutoupgradesDisabled,
MixedContentInsecureFaviconBlocked) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTestWithAutoupgradesDisabled,
MixedContentSecureFaviconAllowed) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, SVGFavicon) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, SizesAny) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest,
FetchFaviconAfterCacheDeletion) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest,
IncognitoDownloadsCachedFavicon) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, CrossOriginCacheHTTP) { … }
IN_PROC_BROWSER_TEST_F(ContentFaviconDriverTest, CrossOriginCacheHTTPS) { … }