Index: chrome/test/webdriver/session.h |
diff --git a/chrome/test/webdriver/session.h b/chrome/test/webdriver/session.h |
index 8e813d4e0c6301f938ca8cbbf078042e47c61e2e..99c8f71e41ac7afceeff202b10496310eddc1b19 100644 |
--- a/chrome/test/webdriver/session.h |
+++ b/chrome/test/webdriver/session.h |
@@ -5,6 +5,7 @@ |
#ifndef CHROME_TEST_WEBDRIVER_SESSION_H_ |
#define CHROME_TEST_WEBDRIVER_SESSION_H_ |
+#include <map> |
#include <string> |
#include "base/scoped_ptr.h" |
@@ -25,25 +26,36 @@ namespace webdriver { |
// Every connection made by WebDriver maps to a session object. |
// This object creates the chrome instance and keeps track of the |
// state necessary to control the chrome browser created. |
+// A session manages its own lifetime. |
// TODO(phajdan.jr): Abstract UITestBase classes, see: |
// http://code.google.com/p/chromium/issues/detail?id=56865 |
class Session { |
public: |
- explicit Session(const std::string& id); |
+ // Adds this |Session| to the |SessionManager|. The session manages its own |
+ // lifetime. Do not call delete. |
+ Session(); |
+ // Removes this |Session| from the |SessionManager|. |
~Session(); |
- // Creates a browser. |
+ // Starts the session thread and a new browser. Returns true on |
+ // success. On failure, the session will delete itself and return false. |
bool Init(); |
- // Terminates this session and disconnects its automation proxy. After |
- // invoking this method, the Session can safely be deleted. |
+ // Terminates this session and deletes itself. |
void Terminate(); |
- // Executes the given |script| in the context of the frame that is currently |
- // the focus of this session. The |script| should be in the form of a |
- // function body (e.g. "return arguments[0]"), where |args| is the list of |
- // arguments to pass to the function. The caller is responsible for the |
- // script result |value|. |
+ // Executes the given |script| in the context of the given window and frame. |
+ // The |script| should be in the form of a function body |
+ // (e.g. "return arguments[0]"), where |args| is the list of arguments to |
+ // pass to the function. The caller is responsible for the script result |
+ // |value|. |
+ ErrorCode ExecuteScript(int window_id, |
+ const std::string& frame_xpath, |
+ const std::string& script, |
+ const ListValue* const args, |
+ Value** value); |
+ |
+ // Same as above, but uses the currently targeted window and frame. |
ErrorCode ExecuteScript(const std::string& script, |
const ListValue* const args, |
Value** value); |
@@ -65,6 +77,25 @@ class Session { |
bool DeleteCookie(const GURL& url, const std::string& cookie_name); |
bool SetCookie(const GURL& url, const std::string& cookie); |
+ // Gets all the currently existing window IDs. Returns true on success. |
+ bool GetWindowIds(std::vector<int>* window_ids); |
+ |
+ // Switches the window used by default. |name| is either an ID returned by |
+ // |GetWindowIds| or the name attribute of a DOM window. |
+ ErrorCode SwitchToWindow(const std::string& name); |
+ |
+ // Switches the frame used by default. |name_or_id| is either the name or id |
+ // of a frame element. |
+ ErrorCode SwitchToFrameWithNameOrId(const std::string& name_or_id); |
+ |
+ // Switches the frame used by default. |index| is the zero-based frame index. |
+ ErrorCode SwitchToFrameWithIndex(int index); |
+ |
+ // Closes the current window. Returns true on success. |
+ // Note: The session will be deleted if this closes the last window in the |
+ // session. |
+ bool CloseWindow(); |
+ |
inline const std::string& id() const { return id_; } |
inline int implicit_wait() { return implicit_wait_; } |
@@ -86,6 +117,8 @@ class Session { |
current_frame_xpath_ = xpath; |
} |
+ inline int current_window_id() const { return current_window_id_; } |
+ |
private: |
void RunSessionTask(Task* task); |
void RunSessionTaskOnSessionThread( |
@@ -94,13 +127,14 @@ class Session { |
void InitOnSessionThread(bool* success); |
void TerminateOnSessionThread(); |
void SendKeysOnSessionThread(const string16& keys, bool* success); |
- |
- scoped_ptr<Automation> automation_; |
- base::Thread thread_; |
+ ErrorCode SwitchToFrameWithJavaScriptLocatedFrame( |
+ const std::string& script, |
+ ListValue* args); |
const std::string id_; |
- int window_num_; |
+ scoped_ptr<Automation> automation_; |
+ base::Thread thread_; |
int implicit_wait_; |
Speed speed_; |
@@ -112,6 +146,7 @@ class Session { |
// should break into 2 xpaths |
// /html/body/table/tbody/tr/td/iframe & /frameset/frame[1]. |
std::string current_frame_xpath_; |
+ int current_window_id_; |
DISALLOW_COPY_AND_ASSIGN(Session); |
}; |