1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_TEST_CHROMEDRIVER_CHROME_WEB_VIEW_H_
6 #define CHROME_TEST_CHROMEDRIVER_CHROME_WEB_VIEW_H_
12 #include "base/memory/scoped_ptr.h"
15 class DictionaryValue;
24 class JavaScriptDialogManager;
34 // Return the id for this WebView.
35 virtual std::string GetId() = 0;
37 // Return true if the web view was crashed.
38 virtual bool WasCrashed() = 0;
40 // Make DevToolsCient connect to DevTools if it is disconnected.
41 virtual Status ConnectIfNecessary() = 0;
43 // Handles events that have been received but not yet handled.
44 virtual Status HandleReceivedEvents() = 0;
46 // Load a given URL in the main frame.
47 virtual Status Load(const std::string& url) = 0;
49 // Reload the current page.
50 virtual Status Reload() = 0;
52 // Evaluates a JavaScript expression in a specified frame and returns
53 // the result. |frame| is a frame ID or an empty string for the main frame.
54 // If the expression evaluates to a element, it will be bound to a unique ID
55 // (per frame) and the ID will be returned.
56 // |result| will never be NULL on success.
57 virtual Status EvaluateScript(const std::string& frame,
58 const std::string& expression,
59 scoped_ptr<base::Value>* result) = 0;
61 // Calls a JavaScript function in a specified frame with the given args and
62 // returns the result. |frame| is a frame ID or an empty string for the main
63 // frame. |args| may contain IDs that refer to previously returned elements.
64 // These will be translated back to their referred objects before invoking the
66 // |result| will never be NULL on success.
67 virtual Status CallFunction(const std::string& frame,
68 const std::string& function,
69 const base::ListValue& args,
70 scoped_ptr<base::Value>* result) = 0;
72 // Calls a JavaScript function in a specified frame with the given args and
73 // two callbacks. The first may be invoked with a value to return to the user.
74 // The second may be used to report an error. This function waits until
75 // one of the callbacks is invoked or the timeout occurs.
76 // |result| will never be NULL on success.
77 virtual Status CallAsyncFunction(const std::string& frame,
78 const std::string& function,
79 const base::ListValue& args,
80 const base::TimeDelta& timeout,
81 scoped_ptr<base::Value>* result) = 0;
83 // Same as |CallAsyncFunction|, except no additional error callback is passed
84 // to the function. Also, |kJavaScriptError| or |kScriptTimeout| is used
85 // as the error code instead of |kUnknownError| in appropriate cases.
86 // |result| will never be NULL on success.
87 virtual Status CallUserAsyncFunction(const std::string& frame,
88 const std::string& function,
89 const base::ListValue& args,
90 const base::TimeDelta& timeout,
91 scoped_ptr<base::Value>* result) = 0;
93 // Gets the frame ID for a frame element returned by invoking the given
94 // JavaScript function. |frame| is a frame ID or an empty string for the main
96 virtual Status GetFrameByFunction(const std::string& frame,
97 const std::string& function,
98 const base::ListValue& args,
99 std::string* out_frame) = 0;
101 // Dispatch a sequence of mouse events.
102 virtual Status DispatchMouseEvents(const std::list<MouseEvent>& events,
103 const std::string& frame) = 0;
105 // Dispatch a sequence of touch events.
106 virtual Status DispatchTouchEvents(const std::list<TouchEvent>& events) = 0;
108 // Dispatch a sequence of key events.
109 virtual Status DispatchKeyEvents(const std::list<KeyEvent>& events) = 0;
111 // Return all the cookies visible to the current page.
112 virtual Status GetCookies(scoped_ptr<base::ListValue>* cookies) = 0;
114 // Delete the cookie with the given name.
115 virtual Status DeleteCookie(const std::string& name,
116 const std::string& url) = 0;
118 // Waits until all pending navigations have completed in the given frame.
119 // If |frame_id| is "", waits for navigations on the main frame.
120 // If a modal dialog appears while waiting, kUnexpectedAlertOpen will be
122 // If timeout is exceeded, will return a timeout status.
123 // If |stop_load_on_timeout| is true, will attempt to stop the page load on
124 // timeout before returning the timeout status.
125 virtual Status WaitForPendingNavigations(const std::string& frame_id,
126 const base::TimeDelta& timeout,
127 bool stop_load_on_timeout) = 0;
129 // Returns whether the frame is pending navigation.
130 virtual Status IsPendingNavigation(
131 const std::string& frame_id, bool* is_pending) = 0;
133 // Returns the JavaScriptDialogManager. Never null.
134 virtual JavaScriptDialogManager* GetJavaScriptDialogManager() = 0;
136 // Overrides normal geolocation with a given geoposition.
137 virtual Status OverrideGeolocation(const Geoposition& geoposition) = 0;
139 // Captures the visible portions of the web view as a base64-encoded PNG.
140 virtual Status CaptureScreenshot(std::string* screenshot) = 0;
142 // Set files in a file input element.
143 // |element| is the WebElement JSON Object of the input element.
144 virtual Status SetFileInputFiles(
145 const std::string& frame,
146 const base::DictionaryValue& element,
147 const std::vector<base::FilePath>& files) = 0;
149 // Take a heap snapshot which can build up a graph of Javascript objects.
150 // A raw heap snapshot is in JSON format:
151 // 1. A meta data element "snapshot" about how to parse data elements.
152 // 2. Data elements: "nodes", "edges", "strings".
153 virtual Status TakeHeapSnapshot(scoped_ptr<base::Value>* snapshot) = 0;
156 #endif // CHROME_TEST_CHROMEDRIVER_CHROME_WEB_VIEW_H_