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

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: Enhance py testcase for switchToWindow. 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
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..cbca531b51fea3ab2f048ba95c0d643942e9fe55 100644
--- a/chrome/test/chromedriver/session_commands.cc
+++ b/chrome/test/chromedriver/session_commands.cc
@@ -11,6 +11,7 @@
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "base/values.h"
+#include "chrome/test/chromedriver/basic_types.h"
#include "chrome/test/chromedriver/chrome.h"
#include "chrome/test/chromedriver/session.h"
#include "chrome/test/chromedriver/session_map.h"
@@ -72,6 +73,55 @@ 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;
+
+ WebView* web_view = NULL;
+ // Check if any window handle matches |name|.
+ for (std::list<WebView*>::const_iterator it = web_views.begin();
+ it != web_views.end(); ++it) {
+ if ((*it)->GetId() == name) {
+ web_view = *it;
+ break;
+ }
+ }
+ // 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) {
+ if (web_view)
+ return Status(kUnknownError, "window name or handle collision:" + name);
kkania 2013/02/12 01:33:04 i'm not sure I'd bother doing this. It's not in th
chrisgao (Use stgao instead) 2013/02/12 20:38:16 Ok. Do the same way as the old cd.
+ web_view = *it;
+ }
+ }
+
+ if (!web_view)
+ return Status(kNoSuchWindow);
+ session->window = web_view->GetId();
+ session->frame = "";
+ session->mouse_position = WebPoint(0, 0);
+ return Status(kOk);
+}
+
Status ExecuteSetTimeout(
Session* session,
const base::DictionaryValue& params,
« chrome/test/chromedriver/session_commands.h ('K') | « chrome/test/chromedriver/session_commands.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698