chromium/chrome/test/interaction/webcontents_interaction_test_util_browsertest.cc

// Copyright 2022 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/test/interaction/webcontents_interaction_test_util.h"

#include <sstream>

#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/resource_coordinator/lifecycle_unit_state.mojom-shared.h"
#include "chrome/browser/resource_coordinator/tab_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/interaction/interaction_test_util_browser.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "chrome/test/interaction/tracked_element_webcontents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_test_util.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/interaction/expect_call_in_scope.h"
#include "ui/base/interaction/interaction_sequence.h"
#include "ui/base/page_transition_types.h"
#include "ui/base/window_open_disposition.h"
#include "url/gurl.h"

namespace {

DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_CUSTOM_ELEMENT_EVENT_TYPE();
DEFINE_LOCAL_CUSTOM_ELEMENT_EVENT_TYPE();

constexpr char kEmptyDocumentURL[] =;
constexpr char kDocumentWithTitle1URL[] =;
constexpr char kDocumentWithTitle2URL[] =;
constexpr char kDocumentWithLinksURL[] =;

}  // namespace

class WebContentsInteractionTestUtilTest : public InProcessBrowserTest {};

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ElementCreatedForExistingPage) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ElementCreatedForExistingWebContentsWithoutWebView) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ElementRecreatedOnNavigate) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest, LoadPage) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest, IsPageLoaded) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ElementRecreatedWithDifferentIdOnNavigate) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ElementRecreatedWithDifferentIdOnBackForward) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ElementCreatedInFreshBrowser) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest, EvaluateInt) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest, EvaluateString) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest, EvaluatePromise) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       SendEventOnStateChangeOnCurrentCondition) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       SendEventOnStateChangeOnDelayedCondition) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       StateChangeTimeoutSendsEvent) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       StateChangeOnPromise) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       SendStateChangeEventsForDifferentDataTypes) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       SendEventOnStateChangeOnAlreadyExists) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       SendEventOnStateChangeOnExistsAfterDelay) {}

// TODO(crbug.com/40285351): Resolve flakiness on ChromeOS and re-enable the
// test.
#if BUILDFLAG(IS_CHROMEOS)
#define MAYBE_StateChangeExistsTimeoutSendsEvent
#else
#define MAYBE_StateChangeExistsTimeoutSendsEvent
#endif
IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       MAYBE_StateChangeExistsTimeoutSendsEvent) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       SendEventOnStateChangeOnAlreadyDoesNotExist) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       SendEventOnStateChangeOnDoesNotExistAfterDelay) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       StateChangeDoesNotExistTimeoutSendsEvent) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       SendEventOnStateChangeOnAlreadyExistsAndConditionTrue) {}

IN_PROC_BROWSER_TEST_F(
    WebContentsInteractionTestUtilTest,
    SendEventOnStateChangeOnExistsAndConditionTrueAfterDelay) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       StateChangeExistsAndConditionTrueTimeoutSendsEvent) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ExecuteCatchesJavascriptError) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ExecuteCanChangePageState) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ExecuteAtCanChangePageState) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       NavigatePageFromScriptCreatesNewElement) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ElementRemovedOnMoveToNewBrowser) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ElementRemovedOnPageClosed) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       OpenPageInNewTabInactive) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       OpenPageInNewTabActive) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ForNextTabInContext) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ForNextTabInBrowser) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ForNextTabInAnyBrowserFreshBrowser) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ForNextTabInAnyBrowserSameBrowser) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       MovePageToNewBrowserTriggersTabInAnyBrowser) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       MovePageToNewBrowserTriggersNextTabInBrowser) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest, ExistsInWebUIPage) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       EvaluateAtInWebUIPage) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       EvaluateAtNotExistElement) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       ExistsInStandardPage) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       EvaluateAtInStandardPage) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       SendEventOnConditionStateChangeAtInStandardPage) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       SendEventOnExistsStateChangeAtInStandardPage) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       SendEventOnExistsStateChangeContinueAcrossNavigation) {}

// This is a regression test for the case where we open a new tab in a way that
// causes it not to have a URL; previously, it would not create an element
// because navigating_away_from_ was empty.
IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       CreatesElementForPageWithBlankURL) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       PaintEventSentForExistingPage) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       PaintEventSentOnNavigate) {}

IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilTest,
                       PaintEventSentOnNavigateInBackgroundThenActivate) {}

class WebContentsInteractionTestUtilInteractiveTest
    : public InteractiveBrowserTest {};

// TODO(crbug.com/40268930): flaky on Mac - see comments below for the likely
// culprit line.
#if BUILDFLAG(IS_MAC)
#define MAYBE_TrackWebContentsAcrossReplace
#else
#define MAYBE_TrackWebContentsAcrossReplace
#endif
IN_PROC_BROWSER_TEST_F(WebContentsInteractionTestUtilInteractiveTest,
                       MAYBE_TrackWebContentsAcrossReplace) {}