chromium/chrome/test/chromedriver/window_commands.cc

// Copyright 2013 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/chromedriver/window_commands.h"

#include <stddef.h>

#include <algorithm>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include "base/containers/adapters.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversion_utils.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/test/chromedriver/basic_types.h"
#include "chrome/test/chromedriver/chrome/chrome.h"
#include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h"
#include "chrome/test/chromedriver/chrome/devtools_client.h"
#include "chrome/test/chromedriver/chrome/geoposition.h"
#include "chrome/test/chromedriver/chrome/mobile_emulation_override_manager.h"
#include "chrome/test/chromedriver/chrome/network_conditions.h"
#include "chrome/test/chromedriver/chrome/status.h"
#include "chrome/test/chromedriver/chrome/ui_events.h"
#include "chrome/test/chromedriver/chrome/web_view.h"
#include "chrome/test/chromedriver/element_commands.h"
#include "chrome/test/chromedriver/element_util.h"
#include "chrome/test/chromedriver/key_converter.h"
#include "chrome/test/chromedriver/net/command_id.h"
#include "chrome/test/chromedriver/net/timeout.h"
#include "chrome/test/chromedriver/session.h"
#include "chrome/test/chromedriver/util.h"
#include "ui/gfx/geometry/point.h"
#include "url/url_util.h"

namespace {

// The error page URL was renamed in
// https://chromium-review.googlesource.com/c/580169, but because ChromeDriver
// needs to be backward-compatible with older versions of Chrome, it is
// necessary to compare against both the old and new error URL.
static const char kUnreachableWebDataURL[] =;
const char kDeprecatedUnreachableWebDataURL[] =;

// Match to content/browser/devtools/devTools_session const of same name
const char kTargetClosedMessage[] =;

// TODO(crbug.com/chromedriver/2596): Remove when we stop supporting legacy
// protocol.
// Defaults to 20 years into the future when adding a cookie.
const double kDefaultCookieExpiryTime =;

// for pointer actions
enum class PointerActionType {};

Status GetMouseButton(const base::Value::Dict& params, MouseButton* button) {}

Status IntToStringButton(int button, std::string& out) {}

Status GetUrl(WebView* web_view, const std::string& frame, std::string* url) {}

MouseEventType StringToMouseEventType(std::string action_type) {}

MouseButton StringToMouseButton(std::string button_type) {}

TouchEventType StringToTouchEventType(std::string action_type) {}

int StringToModifierMouseButton(std::string button_type) {}

int MouseButtonToButtons(MouseButton button) {}

int KeyToKeyModifiers(std::string key) {}

PointerType StringToPointerType(std::string pointer_type) {}

struct Cookie {};

base::Value::Dict CreateDictionaryFrom(const Cookie& cookie) {}

Status GetVisibleCookies(Session* for_session,
                         WebView* web_view,
                         std::list<Cookie>* cookies) {}

Status ScrollCoordinateInToView(
    Session* session, WebView* web_view, int x, int y, int* offset_x,
    int* offset_y) {}

Status ExecuteTouchEvent(Session* session,
                         WebView* web_view,
                         TouchEventType type,
                         const base::Value::Dict& params) {}

Status WindowViewportSize(Session* session,
                          WebView* web_view,
                          int* inner_width,
                          int* inner_height) {}

Status ProcessPauseAction(const base::Value::Dict& action_item,
                          base::Value::Dict* action) {}

Status ElementInViewCenter(Session* session,
                           WebView* web_view,
                           std::string element_id,
                           int* center_x,
                           int* center_y) {}

int GetMouseClickCount(int last_click_count,
                       float x,
                       float y,
                       float last_x,
                       float last_y,
                       int button_id,
                       int last_button_id,
                       const base::TimeTicks& timestamp,
                       const base::TimeTicks& last_mouse_click_time) {}

const char kLandscape[] =;
const char kPortrait[] =;

Status ParseOrientation(const base::Value::Dict& params,
                        std::string* orientation) {}

Status ParseScale(const base::Value::Dict& params, double* scale) {}

Status ParseBoolean(const base::Value::Dict& params,
                    const std::string& name,
                    bool default_value,
                    bool* b) {}

Status GetNonNegativeDouble(const base::Value::Dict& dict,
                            const std::string& parent,
                            const std::string& child,
                            double* attribute) {}

struct Page {};

Status ParsePage(const base::Value::Dict& params, Page* page) {}

struct Margin {};

Status ParseMargin(const base::Value::Dict& params, Margin* margin) {}

Status ParsePageRanges(const base::Value::Dict& params,
                       std::string* page_ranges) {}

// Returns:
// 1. Optional with the default value, if there is no such a key in the
//    dictionary.
// 2. Empty optional, if the key is in the dictionary, but value has
//    unexpected type.
// 3. Optional with value from dictionary.
template <typename T>
std::optional<T> ParseIfInDictionary(
    const base::Value::Dict& dict,
    std::string_view key,
    T default_value,
    std::optional<T> (base::Value::*getterIfType)() const) {}

std::optional<double> ParseDoubleIfInDictionary(const base::Value::Dict& dict,
                                                std::string_view key,
                                                double default_value) {}

std::optional<int> ParseIntIfInDictionary(const base::Value::Dict& dict,
                                          std::string_view key,
                                          int default_value) {}
}  // namespace

Status ExecuteWindowCommand(const WindowCommand& command,
                            Session* session,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value) {}

Status ExecuteGet(Session* session,
                  WebView* web_view,
                  const base::Value::Dict& params,
                  std::unique_ptr<base::Value>* value,
                  Timeout* timeout) {}

Status ExecuteExecuteScript(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout) {}

Status ExecuteExecuteAsyncScript(Session* session,
                                 WebView* web_view,
                                 const base::Value::Dict& params,
                                 std::unique_ptr<base::Value>* value,
                                 Timeout* timeout) {}

Status ExecuteNewWindow(Session* session,
                        WebView* web_view,
                        const base::Value::Dict& params,
                        std::unique_ptr<base::Value>* value,
                        Timeout* timeout) {}

Status ExecuteSwitchToFrame(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout) {}

Status ExecuteSwitchToParentFrame(Session* session,
                                  WebView* web_view,
                                  const base::Value::Dict& params,
                                  std::unique_ptr<base::Value>* value,
                                  Timeout* timeout) {}

Status ExecuteGetTitle(Session* session,
                       WebView* web_view,
                       const base::Value::Dict& params,
                       std::unique_ptr<base::Value>* value,
                       Timeout* timeout) {}

Status ExecuteGetPageSource(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout) {}

Status ExecuteFindElement(int interval_ms,
                          Session* session,
                          WebView* web_view,
                          const base::Value::Dict& params,
                          std::unique_ptr<base::Value>* value,
                          Timeout* timeout) {}

Status ExecuteFindElements(int interval_ms,
                           Session* session,
                           WebView* web_view,
                           const base::Value::Dict& params,
                           std::unique_ptr<base::Value>* value,
                           Timeout* timeout) {}

Status ExecuteGetCurrentUrl(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout) {}

Status ExecuteGoBack(Session* session,
                     WebView* web_view,
                     const base::Value::Dict& params,
                     std::unique_ptr<base::Value>* value,
                     Timeout* timeout) {}

Status ExecuteGoForward(Session* session,
                        WebView* web_view,
                        const base::Value::Dict& params,
                        std::unique_ptr<base::Value>* value,
                        Timeout* timeout) {}

Status ExecuteRefresh(Session* session,
                      WebView* web_view,
                      const base::Value::Dict& params,
                      std::unique_ptr<base::Value>* value,
                      Timeout* timeout) {}

Status ExecuteFreeze(Session* session,
                     WebView* web_view,
                     const base::Value::Dict& params,
                     std::unique_ptr<base::Value>* value,
                     Timeout* timeout) {}

Status ExecuteResume(Session* session,
                     WebView* web_view,
                     const base::Value::Dict& params,
                     std::unique_ptr<base::Value>* value,
                     Timeout* timeout) {}

Status ExecuteMouseMoveTo(Session* session,
                          WebView* web_view,
                          const base::Value::Dict& params,
                          std::unique_ptr<base::Value>* value,
                          Timeout* timeout) {}

Status ExecuteMouseClick(Session* session,
                         WebView* web_view,
                         const base::Value::Dict& params,
                         std::unique_ptr<base::Value>* value,
                         Timeout* timeout) {}

Status ExecuteMouseButtonDown(Session* session,
                              WebView* web_view,
                              const base::Value::Dict& params,
                              std::unique_ptr<base::Value>* value,
                              Timeout* timeout) {}

Status ExecuteMouseButtonUp(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout) {}

Status ExecuteMouseDoubleClick(Session* session,
                               WebView* web_view,
                               const base::Value::Dict& params,
                               std::unique_ptr<base::Value>* value,
                               Timeout* timeout) {}

Status ExecuteTouchDown(Session* session,
                        WebView* web_view,
                        const base::Value::Dict& params,
                        std::unique_ptr<base::Value>* value,
                        Timeout* timeout) {}

Status ExecuteTouchUp(Session* session,
                      WebView* web_view,
                      const base::Value::Dict& params,
                      std::unique_ptr<base::Value>* value,
                      Timeout* timeout) {}

Status ExecuteTouchMove(Session* session,
                        WebView* web_view,
                        const base::Value::Dict& params,
                        std::unique_ptr<base::Value>* value,
                        Timeout* timeout) {}

Status ExecuteTouchScroll(Session* session,
                          WebView* web_view,
                          const base::Value::Dict& params,
                          std::unique_ptr<base::Value>* value,
                          Timeout* timeout) {}

Status ProcessInputActionSequence(Session* session,
                                  const base::Value::Dict& action_sequence,
                                  std::vector<base::Value::Dict>* action_list) {}

Status ExecutePerformActions(Session* session,
                             WebView* web_view,
                             const base::Value::Dict& params,
                             std::unique_ptr<base::Value>* value,
                             Timeout* timeout) {}

Status ExecuteReleaseActions(Session* session,
                             WebView* web_view,
                             const base::Value::Dict& params,
                             std::unique_ptr<base::Value>* value,
                             Timeout* timeout) {}

Status ExecuteSendCommand(Session* session,
                          WebView* web_view,
                          const base::Value::Dict& params,
                          std::unique_ptr<base::Value>* value,
                          Timeout* timeout) {}

Status ExecuteSendCommandFromWebSocket(Session* session,
                                       WebView* web_view,
                                       const base::Value::Dict& params,
                                       std::unique_ptr<base::Value>* value,
                                       Timeout* timeout) {}

Status ExecuteSendCommandAndGetResult(Session* session,
                                      WebView* web_view,
                                      const base::Value::Dict& params,
                                      std::unique_ptr<base::Value>* value,
                                      Timeout* timeout) {}

Status ExecuteGetActiveElement(Session* session,
                               WebView* web_view,
                               const base::Value::Dict& params,
                               std::unique_ptr<base::Value>* value,
                               Timeout* timeout) {}

Status ExecuteSendKeysToActiveElement(Session* session,
                                      WebView* web_view,
                                      const base::Value::Dict& params,
                                      std::unique_ptr<base::Value>* value,
                                      Timeout* timeout) {}

Status ExecuteGetStorageItem(const char* storage,
                             Session* session,
                             WebView* web_view,
                             const base::Value::Dict& params,
                             std::unique_ptr<base::Value>* value,
                             Timeout* timeout) {}

Status ExecuteGetStorageKeys(const char* storage,
                             Session* session,
                             WebView* web_view,
                             const base::Value::Dict& params,
                             std::unique_ptr<base::Value>* value,
                             Timeout* timeout) {}

Status ExecuteSetStorageItem(const char* storage,
                             Session* session,
                             WebView* web_view,
                             const base::Value::Dict& params,
                             std::unique_ptr<base::Value>* value,
                             Timeout* timeout) {}

Status ExecuteRemoveStorageItem(const char* storage,
                                Session* session,
                                WebView* web_view,
                                const base::Value::Dict& params,
                                std::unique_ptr<base::Value>* value,
                                Timeout* timeout) {}

Status ExecuteClearStorage(const char* storage,
                           Session* session,
                           WebView* web_view,
                           const base::Value::Dict& params,
                           std::unique_ptr<base::Value>* value,
                           Timeout* timeout) {}

Status ExecuteGetStorageSize(const char* storage,
                             Session* session,
                             WebView* web_view,
                             const base::Value::Dict& params,
                             std::unique_ptr<base::Value>* value,
                             Timeout* timeout) {}

Status ExecuteScreenshot(Session* session,
                         WebView* web_view,
                         const base::Value::Dict& params,
                         std::unique_ptr<base::Value>* value,
                         Timeout* timeout) {}

Status ExecuteFullPageScreenshot(Session* session,
                                 WebView* web_view,
                                 const base::Value::Dict& params,
                                 std::unique_ptr<base::Value>* value,
                                 Timeout* timeout) {}

Status ExecutePrint(Session* session,
                    WebView* web_view,
                    const base::Value::Dict& params,
                    std::unique_ptr<base::Value>* value,
                    Timeout* timeout) {}

Status ExecuteGetCookies(Session* session,
                         WebView* web_view,
                         const base::Value::Dict& params,
                         std::unique_ptr<base::Value>* value,
                         Timeout* timeout) {}

Status ExecuteGetNamedCookie(Session* session,
                             WebView* web_view,
                             const base::Value::Dict& params,
                             std::unique_ptr<base::Value>* value,
                             Timeout* timeout) {}

Status ExecuteAddCookie(Session* session,
                        WebView* web_view,
                        const base::Value::Dict& params,
                        std::unique_ptr<base::Value>* value,
                        Timeout* timeout) {}

Status ExecuteDeleteCookie(Session* session,
                           WebView* web_view,
                           const base::Value::Dict& params,
                           std::unique_ptr<base::Value>* value,
                           Timeout* timeout) {}

Status ExecuteDeleteAllCookies(Session* session,
                               WebView* web_view,
                               const base::Value::Dict& params,
                               std::unique_ptr<base::Value>* value,
                               Timeout* timeout) {}

Status ExecuteRunBounceTrackingMitigations(Session* session,
                                           WebView* web_view,
                                           const base::Value::Dict& params,
                                           std::unique_ptr<base::Value>* value,
                                           Timeout* timeout) {}

Status ExecuteSetRPHRegistrationMode(Session* session,
                                     WebView* web_view,
                                     const base::Value::Dict& params,
                                     std::unique_ptr<base::Value>* value,
                                     Timeout* timeout) {}

Status ExecuteSetLocation(Session* session,
                          WebView* web_view,
                          const base::Value::Dict& params,
                          std::unique_ptr<base::Value>* value,
                          Timeout* timeout) {}

Status ExecuteSetNetworkConditions(Session* session,
                                   WebView* web_view,
                                   const base::Value::Dict& params,
                                   std::unique_ptr<base::Value>* value,
                                   Timeout* timeout) {}

Status ExecuteDeleteNetworkConditions(Session* session,
                                      WebView* web_view,
                                      const base::Value::Dict& params,
                                      std::unique_ptr<base::Value>* value,
                                      Timeout* timeout) {}

Status ExecuteTakeHeapSnapshot(Session* session,
                               WebView* web_view,
                               const base::Value::Dict& params,
                               std::unique_ptr<base::Value>* value,
                               Timeout* timeout) {}

Status ExecuteGetWindowRect(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout) {}

Status ExecuteSetWindowRect(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout) {}

Status ExecuteMaximizeWindow(Session* session,
                             WebView* web_view,
                             const base::Value::Dict& params,
                             std::unique_ptr<base::Value>* value,
                             Timeout* timeout) {}

Status ExecuteMinimizeWindow(Session* session,
                             WebView* web_view,
                             const base::Value::Dict& params,
                             std::unique_ptr<base::Value>* value,
                             Timeout* timeout) {}

Status ExecuteFullScreenWindow(Session* session,
                               WebView* web_view,
                               const base::Value::Dict& params,
                               std::unique_ptr<base::Value>* value,
                               Timeout* timeout) {}

Status ExecuteSetSinkToUse(Session* session,
                           WebView* web_view,
                           const base::Value::Dict& params,
                           std::unique_ptr<base::Value>* value,
                           Timeout* timeout) {}

Status ExecuteStartDesktopMirroring(Session* session,
                                    WebView* web_view,
                                    const base::Value::Dict& params,
                                    std::unique_ptr<base::Value>* value,
                                    Timeout* timeout) {}

Status ExecuteStartTabMirroring(Session* session,
                                WebView* web_view,
                                const base::Value::Dict& params,
                                std::unique_ptr<base::Value>* value,
                                Timeout* timeout) {}

Status ExecuteStopCasting(Session* session,
                          WebView* web_view,
                          const base::Value::Dict& params,
                          std::unique_ptr<base::Value>* value,
                          Timeout* timeout) {}

Status ExecuteGetSinks(Session* session,
                       WebView* web_view,
                       const base::Value::Dict& params,
                       std::unique_ptr<base::Value>* value,
                       Timeout* timeout) {}

Status ExecuteGetIssueMessage(Session* session,
                              WebView* web_view,
                              const base::Value::Dict& params,
                              std::unique_ptr<base::Value>* value,
                              Timeout* timeout) {}

Status ExecuteSetPermission(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout) {}

Status ExecuteSetDevicePosture(Session* session,
                               WebView* web_view,
                               const base::Value::Dict& params,
                               std::unique_ptr<base::Value>* value,
                               Timeout* timeout) {}

Status ExecuteClearDevicePosture(Session* session,
                                 WebView* web_view,
                                 const base::Value::Dict& params,
                                 std::unique_ptr<base::Value>* value,
                                 Timeout* timeout) {}