chromium/chrome/test/chromedriver/window_commands.h

// 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.

#ifndef CHROME_TEST_CHROMEDRIVER_WINDOW_COMMANDS_H_
#define CHROME_TEST_CHROMEDRIVER_WINDOW_COMMANDS_H_

#include <memory>

#include "base/functional/callback_forward.h"
#include "base/values.h"
#include "chrome/test/chromedriver/session.h"

struct Session;
class Status;
class Timeout;
class WebView;

WindowCommand;

// Execute a Window Command on the target window.
Status ExecuteWindowCommand(const WindowCommand& command,
                            Session* session,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value);

// Loads a URL.
Status ExecuteGet(Session* session,
                  WebView* web_view,
                  const base::Value::Dict& params,
                  std::unique_ptr<base::Value>* value,
                  Timeout* timeout);

// Evaluates a given synchronous script with arguments.
Status ExecuteExecuteScript(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout);

// Evaluates a given asynchronous script with arguments.
Status ExecuteExecuteAsyncScript(Session* session,
                                 WebView* web_view,
                                 const base::Value::Dict& params,
                                 std::unique_ptr<base::Value>* value,
                                 Timeout* timeout);

// Creates a new window/tab.
Status ExecuteNewWindow(Session* session,
                        WebView* web_view,
                        const base::Value::Dict& params,
                        std::unique_ptr<base::Value>* value,
                        Timeout* timeout);

// Changes the targeted frame for the given session.
Status ExecuteSwitchToFrame(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout);

// Change focus to the parent frame.
Status ExecuteSwitchToParentFrame(Session* session,
                                  WebView* web_view,
                                  const base::Value::Dict& params,
                                  std::unique_ptr<base::Value>* value,
                                  Timeout* timeout);

// Get the current page title.
Status ExecuteGetTitle(Session* session,
                       WebView* web_view,
                       const base::Value::Dict& params,
                       std::unique_ptr<base::Value>* value,
                       Timeout* timeout);

// Get the current page source.
Status ExecuteGetPageSource(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout);

// Search for an element on the page, starting from the document root.
Status ExecuteFindElement(int interval_ms,
                          Session* session,
                          WebView* web_view,
                          const base::Value::Dict& params,
                          std::unique_ptr<base::Value>* value,
                          Timeout* timeout);

// Search for multiple elements on the page, starting from the document root.
Status ExecuteFindElements(int interval_ms,
                           Session* session,
                           WebView* web_view,
                           const base::Value::Dict& params,
                           std::unique_ptr<base::Value>* value,
                           Timeout* timeout);

// Get the current page url.
Status ExecuteGetCurrentUrl(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout);

// Navigate backward in the browser history.
Status ExecuteGoBack(Session* session,
                     WebView* web_view,
                     const base::Value::Dict& params,
                     std::unique_ptr<base::Value>* value,
                     Timeout* timeout);

// Navigate forward in the browser history.
Status ExecuteGoForward(Session* session,
                        WebView* web_view,
                        const base::Value::Dict& params,
                        std::unique_ptr<base::Value>* value,
                        Timeout* timeout);

// Refresh the current page.
Status ExecuteRefresh(Session* session,
                      WebView* web_view,
                      const base::Value::Dict& params,
                      std::unique_ptr<base::Value>* value,
                      Timeout* timeout);

// Freeze the current page.
Status ExecuteFreeze(Session* session,
                     WebView* web_view,
                     const base::Value::Dict& params,
                     std::unique_ptr<base::Value>* value,
                     Timeout* timeout);

// Resume the current page.
Status ExecuteResume(Session* session,
                     WebView* web_view,
                     const base::Value::Dict& params,
                     std::unique_ptr<base::Value>* value,
                     Timeout* timeout);

// Move the mouse by an offset of the element if specified .
Status ExecuteMouseMoveTo(Session* session,
                          WebView* web_view,
                          const base::Value::Dict& params,
                          std::unique_ptr<base::Value>* value,
                          Timeout* timeout);

// Click a mouse button at the coordinates set by the last moveto.
Status ExecuteMouseClick(Session* session,
                         WebView* web_view,
                         const base::Value::Dict& params,
                         std::unique_ptr<base::Value>* value,
                         Timeout* timeout);

// Click and hold a mouse button at the coordinates set by the last moveto.
Status ExecuteMouseButtonDown(Session* session,
                              WebView* web_view,
                              const base::Value::Dict& params,
                              std::unique_ptr<base::Value>* value,
                              Timeout* timeout);

// Releases the mouse button previously held (where the mouse is currently at).
Status ExecuteMouseButtonUp(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout);

// Double-clicks at the current mouse coordinates (set by last moveto).
Status ExecuteMouseDoubleClick(Session* session,
                               WebView* web_view,
                               const base::Value::Dict& params,
                               std::unique_ptr<base::Value>* value,
                               Timeout* timeout);

// Touch press at a given coordinate.
Status ExecuteTouchDown(Session* session,
                        WebView* web_view,
                        const base::Value::Dict& params,
                        std::unique_ptr<base::Value>* value,
                        Timeout* timeout);

// Touch release at a given coordinate.
Status ExecuteTouchUp(Session* session,
                      WebView* web_view,
                      const base::Value::Dict& params,
                      std::unique_ptr<base::Value>* value,
                      Timeout* timeout);

// Touch move at a given coordinate.
Status ExecuteTouchMove(Session* session,
                        WebView* web_view,
                        const base::Value::Dict& params,
                        std::unique_ptr<base::Value>* value,
                        Timeout* timeout);

// Do a swipe (scroll) gesture beginning at the element.
Status ExecuteTouchScroll(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);

// Send a sequence of key strokes to the active element.
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);

// Retrieve all cookies visible to the current page.
Status ExecuteGetCookies(Session* session,
                         WebView* web_view,
                         const base::Value::Dict& params,
                         std::unique_ptr<base::Value>* value,
                         Timeout* timeout);

// Retrieve a single cookie with the requested name.
Status ExecuteGetNamedCookie(Session* session,
                             WebView* web_view,
                             const base::Value::Dict& params,
                             std::unique_ptr<base::Value>* value,
                             Timeout* timeout);

// Set a cookie. If the cookie path is not specified, it should be set to "/".
// If the domain is omitted, it should default to the current page's domain.
Status ExecuteAddCookie(Session* session,
                        WebView* web_view,
                        const base::Value::Dict& params,
                        std::unique_ptr<base::Value>* value,
                        Timeout* timeout);

// Delete the cookie with the given name if it exists in the current page.
Status ExecuteDeleteCookie(Session* session,
                           WebView* web_view,
                           const base::Value::Dict& params,
                           std::unique_ptr<base::Value>* value,
                           Timeout* timeout);

// Delete all cookies visible to the current page.
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 ExecutePerformActions(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 ExecuteReleaseActions(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 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);

// Sets the sink to be used when the web page invokes Presentation or Remote
// Playback API. Uses the "sinkName" value in |params|.
Status ExecuteSetSinkToUse(Session* session,
                           WebView* web_view,
                           const base::Value::Dict& params,
                           std::unique_ptr<base::Value>* value,
                           Timeout* timeout);

// Starts mirroring the desktop to the sink specified by the "sinkName" value in
// |params|.
Status ExecuteStartDesktopMirroring(Session* session,
                                    WebView* web_view,
                                    const base::Value::Dict& params,
                                    std::unique_ptr<base::Value>* value,
                                    Timeout* timeout);

// Starts mirroring the tab to the sink specified by the "sinkName" value in
// |params|.
Status ExecuteStartTabMirroring(Session* session,
                                WebView* web_view,
                                const base::Value::Dict& params,
                                std::unique_ptr<base::Value>* value,
                                Timeout* timeout);

// Stops casting to the sink specified by the "sinkName" value in |params|.
Status ExecuteStopCasting(Session* session,
                          WebView* web_view,
                          const base::Value::Dict& params,
                          std::unique_ptr<base::Value>* value,
                          Timeout* timeout);

// Returns a list of Cast sinks that are available.
Status ExecuteGetSinks(Session* session,
                       WebView* web_view,
                       const base::Value::Dict& params,
                       std::unique_ptr<base::Value>* value,
                       Timeout* timeout);

// Returns the outstanding issue in the Cast UI.
Status ExecuteGetIssueMessage(Session* session,
                              WebView* web_view,
                              const base::Value::Dict& params,
                              std::unique_ptr<base::Value>* value,
                              Timeout* timeout);

// Sets permissions.
Status ExecuteSetPermission(Session* session,
                            WebView* web_view,
                            const base::Value::Dict& params,
                            std::unique_ptr<base::Value>* value,
                            Timeout* timeout);

#endif  // CHROME_TEST_CHROMEDRIVER_WINDOW_COMMANDS_H_