#include "chrome/test/interaction/webcontents_interaction_test_util.h"
#include <algorithm>
#include <initializer_list>
#include <optional>
#include <set>
#include <sstream>
#include <string>
#include "base/callback_list.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_auto_reset.h"
#include "base/memory/weak_ptr.h"
#include "base/notreached.h"
#include "base/scoped_observation.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "base/values.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_observer.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/tabs/tab_strip_model_observer.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/contents_web_view.h"
#include "chrome/test/interaction/interaction_test_util_browser.h"
#include "chrome/test/interaction/tracked_element_webcontents.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/isolated_world_ids.h"
#include "content/public/test/browser_test_utils.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/interaction/framework_specific_implementation.h"
#include "ui/base/page_transition_types.h"
#include "ui/base/window_open_disposition.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/interaction/element_tracker_views.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/view_observer.h"
namespace content {
class RenderFrameHost;
}
namespace {
content::WebContents* GetWebContents(Browser* browser,
std::optional<int> tab_index) { … }
std::string GetExistsQuery(const char* on_not_found, const char* on_found) { … }
WebContentsInteractionTestUtil::StateChange ValidateAndInferStateChange(
const WebContentsInteractionTestUtil::StateChange& state_change) { … }
bool HasErrorParameter(const std::string& function) { … }
std::string GetStateChangeQuery(
const WebContentsInteractionTestUtil::StateChange& configuration) { … }
void ExecuteScript(content::RenderFrameHost* host, const std::string& script) { … }
content::EvalJsResult EvalJsLocal(
const content::ToRenderFrameHost& execution_target,
const std::string& function) { … }
void ExecuteJsLocal(const content::ToRenderFrameHost& execution_target,
const std::string& function) { … }
std::string CreateDeepQuery(
const WebContentsInteractionTestUtil::DeepQuery& where,
const std::string& function) { … }
}
WebContentsInteractionTestUtil::DeepQuery::DeepQuery() = default;
WebContentsInteractionTestUtil::DeepQuery::DeepQuery(
std::initializer_list<std::string> segments)
: … { … }
WebContentsInteractionTestUtil::DeepQuery::DeepQuery(
const WebContentsInteractionTestUtil::DeepQuery& other) = default;
WebContentsInteractionTestUtil::DeepQuery&
WebContentsInteractionTestUtil::DeepQuery::operator=(
const WebContentsInteractionTestUtil::DeepQuery& other) = default;
WebContentsInteractionTestUtil::DeepQuery&
WebContentsInteractionTestUtil::DeepQuery::operator=(
std::initializer_list<std::string> segments) { … }
WebContentsInteractionTestUtil::DeepQuery
WebContentsInteractionTestUtil::DeepQuery::operator+(
const std::string& segment) const { … }
WebContentsInteractionTestUtil::DeepQuery::~DeepQuery() = default;
WebContentsInteractionTestUtil::StateChange::StateChange() = default;
WebContentsInteractionTestUtil::StateChange::StateChange(
const WebContentsInteractionTestUtil::StateChange& other) = default;
WebContentsInteractionTestUtil::StateChange&
WebContentsInteractionTestUtil::StateChange::operator=(
const WebContentsInteractionTestUtil::StateChange& other) = default;
WebContentsInteractionTestUtil::StateChange::~StateChange() = default;
class WebContentsInteractionTestUtil::NewTabWatcher
: public TabStripModelObserver,
public BrowserListObserver { … };
class WebContentsInteractionTestUtil::Poller { … };
class WebContentsInteractionTestUtil::WebViewData : public views::ViewObserver { … };
constexpr base::TimeDelta
WebContentsInteractionTestUtil::kDefaultPollingInterval;
WebContentsInteractionTestUtil::~WebContentsInteractionTestUtil() { … }
bool WebContentsInteractionTestUtil::IsTruthy(const base::Value& value) { … }
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForExistingTabInContext(
ui::ElementContext context,
ui::ElementIdentifier page_identifier,
std::optional<int> tab_index) { … }
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForExistingTabInBrowser(
Browser* browser,
ui::ElementIdentifier page_identifier,
std::optional<int> tab_index) { … }
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForTabWebContents(
content::WebContents* web_contents,
ui::ElementIdentifier page_identifier) { … }
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForNonTabWebView(
views::WebView* web_view,
ui::ElementIdentifier page_identifier) { … }
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForNextTabInContext(
ui::ElementContext context,
ui::ElementIdentifier page_identifier) { … }
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForNextTabInBrowser(
Browser* browser,
ui::ElementIdentifier page_identifier) { … }
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForNextTabInAnyBrowser(
ui::ElementIdentifier page_identifier) { … }
bool WebContentsInteractionTestUtil::HasPageBeenPainted() const { … }
views::WebView* WebContentsInteractionTestUtil::GetWebView() { … }
void WebContentsInteractionTestUtil::LoadPage(const GURL& url) { … }
void WebContentsInteractionTestUtil::LoadPageInNewTab(const GURL& url,
bool activate_tab) { … }
base::Value WebContentsInteractionTestUtil::Evaluate(
const std::string& function,
std::string* error_message) { … }
void WebContentsInteractionTestUtil::Execute(const std::string& function) { … }
void WebContentsInteractionTestUtil::SendEventOnStateChange(
const StateChange& configuration) { … }
bool WebContentsInteractionTestUtil::Exists(const DeepQuery& query,
std::string* not_found) { … }
base::Value WebContentsInteractionTestUtil::EvaluateAt(
const DeepQuery& where,
const std::string& function,
std::string* error_message) { … }
void WebContentsInteractionTestUtil::ExecuteAt(const DeepQuery& where,
const std::string& function) { … }
bool WebContentsInteractionTestUtil::Exists(const std::string& selector) { … }
base::Value WebContentsInteractionTestUtil::EvaluateAt(
const std::string& selector,
const std::string& function) { … }
void WebContentsInteractionTestUtil::ExecuteAt(const std::string& selector,
const std::string& function) { … }
gfx::Rect WebContentsInteractionTestUtil::GetElementBoundsInScreen(
const DeepQuery& where) { … }
gfx::Rect WebContentsInteractionTestUtil::GetElementBoundsInScreen(
const std::string& where) { … }
void WebContentsInteractionTestUtil::DidStopLoading() { … }
void WebContentsInteractionTestUtil::DidFinishLoad(
content::RenderFrameHost* render_frame_host,
const GURL& validated_url) { … }
void WebContentsInteractionTestUtil::
DocumentOnLoadCompletedInPrimaryMainFrame() { … }
void WebContentsInteractionTestUtil::PrimaryPageChanged(content::Page& page) { … }
void WebContentsInteractionTestUtil::WebContentsDestroyed() { … }
void WebContentsInteractionTestUtil::DidFirstVisuallyNonEmptyPaint() { … }
void WebContentsInteractionTestUtil::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) { … }
WebContentsInteractionTestUtil::WebContentsInteractionTestUtil(
content::WebContents* web_contents,
ui::ElementIdentifier page_identifier,
std::optional<Browser*> browser,
views::WebView* web_view)
: … { … }
void WebContentsInteractionTestUtil::MaybeCreateElement() { … }
void WebContentsInteractionTestUtil::MaybeSendPaintEvent() { … }
void WebContentsInteractionTestUtil::DiscardCurrentElement() { … }
void WebContentsInteractionTestUtil::OnPollEvent(
Poller* poller,
ui::CustomElementEventType event) { … }
void WebContentsInteractionTestUtil::StartWatchingWebContents(
content::WebContents* web_contents) { … }
void PrintTo(const WebContentsInteractionTestUtil::DeepQuery& deep_query,
std::ostream* os) { … }
extern std::ostream& operator<<(
std::ostream& os,
const WebContentsInteractionTestUtil::DeepQuery& deep_query) { … }
void PrintTo(const WebContentsInteractionTestUtil::StateChange& state_change,
std::ostream* os) { … }
extern std::ostream& operator<<(
std::ostream& os,
const WebContentsInteractionTestUtil::StateChange& state_change) { … }