Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/test/webdriver/session.h

Issue 6507015: Implement the target locator commands for ChromeDriver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address Pawel's concerns Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_TEST_WEBDRIVER_SESSION_H_ 5 #ifndef CHROME_TEST_WEBDRIVER_SESSION_H_
6 #define CHROME_TEST_WEBDRIVER_SESSION_H_ 6 #define CHROME_TEST_WEBDRIVER_SESSION_H_
7 7
8 #include <map>
8 #include <string> 9 #include <string>
9 10
10 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
11 #include "base/string16.h" 12 #include "base/string16.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/test/webdriver/automation.h" 14 #include "chrome/test/webdriver/automation.h"
14 #include "chrome/test/webdriver/error_codes.h" 15 #include "chrome/test/webdriver/error_codes.h"
15 16
16 class ListValue; 17 class ListValue;
17 class Value; 18 class Value;
18 19
19 namespace base { 20 namespace base {
20 class WaitableEvent; 21 class WaitableEvent;
21 } 22 }
22 23
23 namespace webdriver { 24 namespace webdriver {
24 25
25 // Every connection made by WebDriver maps to a session object. 26 // Every connection made by WebDriver maps to a session object.
26 // This object creates the chrome instance and keeps track of the 27 // This object creates the chrome instance and keeps track of the
27 // state necessary to control the chrome browser created. 28 // state necessary to control the chrome browser created.
28 // TODO(phajdan.jr): Abstract UITestBase classes, see: 29 // TODO(phajdan.jr): Abstract UITestBase classes, see:
29 // http://code.google.com/p/chromium/issues/detail?id=56865 30 // http://code.google.com/p/chromium/issues/detail?id=56865
30 class Session { 31 class Session {
31 public: 32 public:
32 explicit Session(const std::string& id); 33 // Adds this |Session| to the |SessionManager|.
34 Session();
35 // Removes this |Session| from the |SessionManager|.
Jason Leyba 2011/02/14 21:00:23 Not a fan of these changes. I don't think it's th
33 ~Session(); 36 ~Session();
34 37
35 // Creates a browser. 38 // Starts the session thread and a new browser. Returns true on
39 // success. On failure, the session will delete itself and return false.
36 bool Init(); 40 bool Init();
37 41
38 // Terminates this session and disconnects its automation proxy. After 42 // Terminates this session and deletes itself.
39 // invoking this method, the Session can safely be deleted.
40 void Terminate(); 43 void Terminate();
41 44
42 // Executes the given |script| in the context of the frame that is currently 45 // Executes the given |script| in the context of the given window and frame.
43 // the focus of this session. The |script| should be in the form of a 46 // The |script| should be in the form of a function body
44 // function body (e.g. "return arguments[0]"), where \args| is the list of 47 // (e.g. "return arguments[0]"), where |args| is the list of arguments to
45 // arguments to pass to the function. The caller is responsible for the 48 // pass to the function. The caller is responsible for the script result
46 // script result |value|. 49 // |value|.
50 ErrorCode ExecuteScript(int window_id,
51 const std::string& frame_xpath,
52 const std::string& script,
53 const ListValue* const args,
54 Value** value);
55
56 // Same as above, but uses the currently targeted window and frame.
47 ErrorCode ExecuteScript(const std::string& script, 57 ErrorCode ExecuteScript(const std::string& script,
48 const ListValue* const args, 58 const ListValue* const args,
49 Value** value); 59 Value** value);
50 60
51 // Send the given keys to the given element dictionary. This function takes 61 // Send the given keys to the given element dictionary. This function takes
52 // ownership of |element|. 62 // ownership of |element|.
53 ErrorCode SendKeys(DictionaryValue* element, const string16& keys); 63 ErrorCode SendKeys(DictionaryValue* element, const string16& keys);
54 64
55 bool NavigateToURL(const std::string& url); 65 bool NavigateToURL(const std::string& url);
56 bool GoForward(); 66 bool GoForward();
57 bool GoBack(); 67 bool GoBack();
58 bool Reload(); 68 bool Reload();
59 bool GetURL(std::string* url); 69 bool GetURL(std::string* url);
60 bool GetTabTitle(std::string* tab_title); 70 bool GetTabTitle(std::string* tab_title);
61 71
72 // Gets all the currently existing window IDs. Returns true on success.
73 bool GetWindowIds(std::vector<int>* window_ids);
74
75 // Switches the window used by default. |name| is either an ID returned by
76 // |GetWindowIds| or the name attribute of a DOM window.
77 ErrorCode SwitchToWindow(const std::string& name);
78
79 // Switches the frame used by default. |name_or_id| is either the name or id
80 // of a frame element.
81 ErrorCode SwitchToFrameWithNameOrId(const std::string& name_or_id);
82
83 // Switches the frame used by default. |index| is the zero-based frame index.
84 ErrorCode SwitchToFrameWithIndex(int index);
85
86 // Closes the current window. If this closes the last window in the session,
87 // the session will be terminated. Returns true on success.
88 bool CloseWindow();
89
62 inline const std::string& id() const { return id_; } 90 inline const std::string& id() const { return id_; }
63 91
64 inline int implicit_wait() { return implicit_wait_; } 92 inline int implicit_wait() { return implicit_wait_; }
65 inline void set_implicit_wait(const int& timeout) { 93 inline void set_implicit_wait(const int& timeout) {
66 implicit_wait_ = timeout > 0 ? timeout : 0; 94 implicit_wait_ = timeout > 0 ? timeout : 0;
67 } 95 }
68 96
69 enum Speed { kSlow, kMedium, kFast, kUnknown }; 97 enum Speed { kSlow, kMedium, kFast, kUnknown };
70 inline Speed speed() { return speed_; } 98 inline Speed speed() { return speed_; }
71 inline void set_speed(Speed speed) { 99 inline void set_speed(Speed speed) {
72 speed_ = speed; 100 speed_ = speed;
73 } 101 }
74 102
75 inline const std::string& current_frame_xpath() const { 103 inline const std::string& current_frame_xpath() const {
76 return current_frame_xpath_; 104 return current_frame_xpath_;
77 } 105 }
78 106
79 inline void set_current_frame_xpath(const std::string& xpath) { 107 inline void set_current_frame_xpath(const std::string& xpath) {
80 current_frame_xpath_ = xpath; 108 current_frame_xpath_ = xpath;
81 } 109 }
82 110
111 inline int current_window_id() const { return current_window_id_; }
112
83 private: 113 private:
84 void RunSessionTask(Task* task); 114 void RunSessionTask(Task* task);
85 void RunSessionTaskOnSessionThread( 115 void RunSessionTaskOnSessionThread(
86 Task* task, 116 Task* task,
87 base::WaitableEvent* done_event); 117 base::WaitableEvent* done_event);
88 void InitOnSessionThread(bool* success); 118 void InitOnSessionThread(bool* success);
89 void TerminateOnSessionThread(); 119 void TerminateOnSessionThread();
90 void SendKeysOnSessionThread(const string16& keys, bool* success); 120 void SendKeysOnSessionThread(const string16& keys, bool* success);
121 ErrorCode SwitchToFrameWithJavaScriptLocatedFrame(
122 const std::string& script,
123 ListValue* args);
124
125 const std::string id_;
91 126
92 scoped_ptr<Automation> automation_; 127 scoped_ptr<Automation> automation_;
93 base::Thread thread_; 128 base::Thread thread_;
94 129
95 const std::string id_;
96
97 int window_num_;
98
99 int implicit_wait_; 130 int implicit_wait_;
100 Speed speed_; 131 Speed speed_;
101 132
102 // The XPath to the frame within this session's active tab which all 133 // The XPath to the frame within this session's active tab which all
103 // commands should be directed to. XPath strings can represent a frame deep 134 // commands should be directed to. XPath strings can represent a frame deep
104 // down the tree (across multiple frame DOMs). 135 // down the tree (across multiple frame DOMs).
105 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[1] 136 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[1]
106 // should break into 2 xpaths 137 // should break into 2 xpaths
107 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[1]. 138 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[1].
108 std::string current_frame_xpath_; 139 std::string current_frame_xpath_;
140 int current_window_id_;
109 141
110 DISALLOW_COPY_AND_ASSIGN(Session); 142 DISALLOW_COPY_AND_ASSIGN(Session);
111 }; 143 };
112 144
113 } // namespace webdriver 145 } // namespace webdriver
114 146
115 DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Session); 147 DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Session);
116 148
117 #endif // CHROME_TEST_WEBDRIVER_SESSION_H_ 149 #endif // CHROME_TEST_WEBDRIVER_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698