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

Unified Diff: chrome/test/chromedriver/session_commands.cc

Issue 12224106: [chromedriver] Implement command: switchToWindow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/chromedriver/session_commands.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/session_commands.cc
diff --git a/chrome/test/chromedriver/session_commands.cc b/chrome/test/chromedriver/session_commands.cc
index dfcc8a7dc2fb5c486feae398c5a985aa6edea2cd..7230dfb3d1ea2f7d42d9942335d88017eb1f6d58 100644
--- a/chrome/test/chromedriver/session_commands.cc
+++ b/chrome/test/chromedriver/session_commands.cc
@@ -72,6 +72,56 @@ Status ExecuteGetWindowHandles(
return Status(kOk);
}
+Status ExecuteSwitchToWindow(
+ Session* session,
+ const base::DictionaryValue& params,
+ scoped_ptr<base::Value>* value) {
+ std::string name;
+ if (!params.GetString("name", &name) || name.empty())
+ return Status(kUnknownError, "'name' must be a nonempty string");
+
+ std::list<WebView*> web_views;
+ Status status = session->chrome->GetWebViews(&web_views);
+ if (status.IsError())
+ return status;
+
+ // Check if any window handle matches |name|.
+ WebView* web_view = NULL;
+ for (std::list<WebView*>::const_iterator it = web_views.begin();
+ it != web_views.end(); ++it) {
+ if ((*it)->GetId() == name) {
+ web_view = *it;
+ break;
+ }
+ }
+ if (!web_view) {
+ // Check if any of the tab window names match |name|.
+ const char* kGetWindowNameScript = "function() { return window.name; }";
+ base::ListValue args;
+ for (std::list<WebView*>::const_iterator it = web_views.begin();
+ it != web_views.end(); ++it) {
+ scoped_ptr<base::Value> result;
+ status = (*it)->CallFunction("", kGetWindowNameScript, args, &result);
+ if (status.IsError())
+ return status;
+ std::string window_name;
+ if (!result->GetAsString(&window_name))
+ return Status(kUnknownError, "failed to get window name");
+ if (window_name == name) {
chrisgao (Use stgao instead) 2013/02/11 22:56:37 Should we check if two windows share the same name
craigdh 2013/02/11 23:40:12 Seems like that would be a common issue. Also what
chrisgao (Use stgao instead) 2013/02/12 01:26:02 Window handles look like: "1", "2", etc. for Linux
+ web_view = *it;
+ break;
+ }
+ }
+ }
+
+ if (!web_view)
+ return Status(kNoSuchWindow);
+ session->window = web_view->GetId();
+ session->frame = "";
+ session->mouse_position = WebPoint(0, 0);
chrisgao (Use stgao instead) 2013/02/11 22:56:37 Add chrome/test/chromedriver/basic_types.h
chrisgao (Use stgao instead) 2013/02/12 01:26:02 Done.
+ return Status(kOk);
+}
+
Status ExecuteSetTimeout(
Session* session,
const base::DictionaryValue& params,
« no previous file with comments | « chrome/test/chromedriver/session_commands.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698