chromium/chrome/browser/ui/views/bookmarks/bookmark_bar_view_browsertest.cc

// Copyright 2019 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/ui/views/bookmarks/bookmark_bar_view.h"

#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/browser/preloading/chrome_preloading.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tab_ui_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view_observer.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view_test_helper.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/page_load_metrics/browser/navigation_handle_user_data.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/web_contents.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/navigation_handle_observer.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/network/public/cpp/features.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/test/test_event.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/test/button_test_api.h"

// Test suite covering the interaction between browser bookmarks and
// `Sec-Fetch-*` headers that can't be covered by Web Platform Tests (yet).
// See https://mikewest.github.io/sec-metadata/#directly-user-initiated and
// https://github.com/web-platform-tests/wpt/issues/16019.
class BookmarkBarNavigationTest : public InProcessBrowserTest,
                                  public content::WebContentsObserver {};

IN_PROC_BROWSER_TEST_F(BookmarkBarNavigationTest, SecFetchFromEmptyTab) {}

#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
//  TODO(crbug.com/40648550): Test flaky on Mac and Windows.
#define MAYBE_SecFetchSiteNoneFromNonEmptyTab
#else
#define MAYBE_SecFetchSiteNoneFromNonEmptyTab
#endif
IN_PROC_BROWSER_TEST_F(BookmarkBarNavigationTest,
                       MAYBE_SecFetchSiteNoneFromNonEmptyTab) {}

// Class intercepts invocations of external protocol handlers.
class FakeProtocolHandlerDelegate : public ExternalProtocolHandler::Delegate {};

// Checks that opening a bookmark to a URL handled by an external handler is not
// blocked by anti-flood protection. Regression test for
// https://crbug.com/1156651
IN_PROC_BROWSER_TEST_F(BookmarkBarNavigationTest, ExternalHandlerAllowed) {}

UkmEntry;
Preloading_Attempt;
Preloading_Prediction;
static const auto kMockElapsedTime =;

class PrerenderBookmarkBarNavigationTestBase
    : public BookmarkBarNavigationTest {};

// Following definitions are equal to content::PrerenderFinalStatus.
constexpr int kFinalStatusActivated =;
constexpr int kFinalStatusTriggerDestroyed =;

constexpr int kPreloadingTriggeringOutcomeSuccess =;

class PrerenderBookmarkBarOnPressedNavigationTest
    : public PrerenderBookmarkBarNavigationTestBase {};

// TODO(crbug.com/40285326): This fails with the field trial testing config.
class PrerenderBookmarkBarOnPressedNavigationTestNoTestingConfig
    : public PrerenderBookmarkBarOnPressedNavigationTest {};

IN_PROC_BROWSER_TEST_F(
    PrerenderBookmarkBarOnPressedNavigationTestNoTestingConfig,
    PrerenderActivation) {}

IN_PROC_BROWSER_TEST_F(PrerenderBookmarkBarOnPressedNavigationTest,
                       PrerenderNonHttps) {}

class PrerenderBookmarkBarOnHoverNavigationTest
    : public PrerenderBookmarkBarNavigationTestBase {};

IN_PROC_BROWSER_TEST_F(PrerenderBookmarkBarOnHoverNavigationTest,
                       PrerenderActivation) {}

// TODO(crbug.com/40285326): This fails with the field trial testing config.
class PrerenderBookmarkBarOnHoverNavigationTestNoTestingConfig
    : public PrerenderBookmarkBarOnHoverNavigationTest {};

// This test verifies prerender cancellation triggered by mouseExited, and
// another prerender can trigger normally after that.
// TODO(crbug.com/40935967): Test times out.
IN_PROC_BROWSER_TEST_F(
    PrerenderBookmarkBarOnHoverNavigationTestNoTestingConfig,
    DISABLED_PrerenderMouseExitedCancellationAndPrerenderActivation) {}

IN_PROC_BROWSER_TEST_F(PrerenderBookmarkBarOnHoverNavigationTest,
                       SetIsNavigationInDomainCallback) {}

IN_PROC_BROWSER_TEST_F(PrerenderBookmarkBarOnHoverNavigationTest,
                       PrerenderNonHttps) {}

class PrerenderBookmarkBarDisabledNavigationTest
    : public PrerenderBookmarkBarNavigationTestBase {};

IN_PROC_BROWSER_TEST_F(PrerenderBookmarkBarDisabledNavigationTest,
                       NonPrerenderingBookmarkBarNavigation) {}