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

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: Address comments. 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..0351a72d5f9b457408fd69d751f5b7a559dd72b0 100644
--- a/chrome/test/chromedriver/session_commands.cc
+++ b/chrome/test/chromedriver/session_commands.cc
@@ -11,12 +11,19 @@
#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"
#include "chrome/test/chromedriver/status.h"
#include "chrome/test/chromedriver/web_view.h"
+namespace {
+
+const char kWindowHandlePrefix[] = "CDwindow-";
+
+} // namespace
+
Status ExecuteSessionCommand(
SessionMap* session_map,
const SessionCommand& command,
@@ -51,7 +58,7 @@ Status ExecuteGetCurrentWindowHandle(
scoped_ptr<base::Value>* value) {
if (session->window.empty())
return Status(kNoSuchWindow);
- value->reset(new StringValue(session->window));
+ value->reset(new StringValue(kWindowHandlePrefix + session->window));
return Status(kOk);
}
@@ -66,12 +73,64 @@ Status ExecuteGetWindowHandles(
base::ListValue window_ids;
for (std::list<WebView*>::const_iterator it = web_views.begin();
it != web_views.end(); ++it) {
- window_ids.AppendString((*it)->GetId());
+ window_ids.AppendString(kWindowHandlePrefix + (*it)->GetId());
}
value->reset(window_ids.DeepCopy());
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;
+ if (name.find(kWindowHandlePrefix) == 0u) {
+ std::string handle = name.substr(std::string(kWindowHandlePrefix).length());
+ // Check if any window handle matches |handle|.
+ for (std::list<WebView*>::const_iterator it = web_views.begin();
+ it != web_views.end(); ++it) {
+ if ((*it)->GetId() == handle) {
+ web_view = *it;
+ break;
+ }
+ }
+ } else {
+ // 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) {
+ web_view = *it;
+ break;
+ }
+ }
+ }
+
+ 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,
« 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