chromium/chrome/test/interaction/webcontents_interaction_test_util.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 <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) {}

// Provides a JavaScript skeleton for "does this element exist" queries.
//
// Will evaluate and return `on_not_found` if 'err?.selector' is valid.
// Will evaluate and return `on_found` if 'el' is valid.
std::string GetExistsQuery(const char* on_not_found, const char* on_found) {}

// Does `StateChange` validation, including inferring the actual type for
// `Type::kAuto`, and returns the (potentially updated) StateChange.
WebContentsInteractionTestUtil::StateChange ValidateAndInferStateChange(
    const WebContentsInteractionTestUtil::StateChange& state_change) {}

// Detects the presence of a javascript `function` that takes (el, err) as
// parameters, for backwards-compatibility with older tests that require this.
//
// Expectation is one of:
//  ... x, y ... => ...
//  ... x, y ... { ...
//
// Functions not in this format will not be recognized as taking an error param.
bool HasErrorParameter(const std::string& function) {}

// Returns the JS query that must be sent to check a particular state change.
std::string GetStateChangeQuery(
    const WebContentsInteractionTestUtil::StateChange& configuration) {}

// Common execution code for `EvalJsLocal()` and `ExecuteJsLocal()`.
// Executes `script` on `host`.
void ExecuteScript(content::RenderFrameHost* host, const std::string& script) {}

// TODO(dfried): migrate to EvalJs, now that it supports Content Security
// Policy.
content::EvalJsResult EvalJsLocal(
    const content::ToRenderFrameHost& execution_target,
    const std::string& function) {}

// As EvalJsLocal but does not wait for a response; errors will appear in the
// test log.
void ExecuteJsLocal(const content::ToRenderFrameHost& execution_target,
                    const std::string& function) {}

std::string CreateDeepQuery(
    const WebContentsInteractionTestUtil::DeepQuery& where,
    const std::string& function) {}

}  // namespace

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 that tracks a WebView and its WebContents in a secondary UI.
class WebContentsInteractionTestUtil::WebViewData : public views::ViewObserver {};

// static
constexpr base::TimeDelta
    WebContentsInteractionTestUtil::kDefaultPollingInterval;

WebContentsInteractionTestUtil::~WebContentsInteractionTestUtil() {}

// static
bool WebContentsInteractionTestUtil::IsTruthy(const base::Value& value) {}

// static
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForExistingTabInContext(
    ui::ElementContext context,
    ui::ElementIdentifier page_identifier,
    std::optional<int> tab_index) {}

// static
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForExistingTabInBrowser(
    Browser* browser,
    ui::ElementIdentifier page_identifier,
    std::optional<int> tab_index) {}

// static
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForTabWebContents(
    content::WebContents* web_contents,
    ui::ElementIdentifier page_identifier) {}

// static
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForNonTabWebView(
    views::WebView* web_view,
    ui::ElementIdentifier page_identifier) {}

// static
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForNextTabInContext(
    ui::ElementContext context,
    ui::ElementIdentifier page_identifier) {}

// static
std::unique_ptr<WebContentsInteractionTestUtil>
WebContentsInteractionTestUtil::ForNextTabInBrowser(
    Browser* browser,
    ui::ElementIdentifier page_identifier) {}

// static
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) {}