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, |