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

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

Issue 11639019: [chromedriver] Implement SwitchToFrame command. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years 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/commands.cc
diff --git a/chrome/test/chromedriver/commands.cc b/chrome/test/chromedriver/commands.cc
index e943038159c15ffd94a28e05fed37bc483c21579..f01dd8265e8316a29181daaba8c9be4eb022241e 100644
--- a/chrome/test/chromedriver/commands.cc
+++ b/chrome/test/chromedriver/commands.cc
@@ -103,5 +103,54 @@ Status ExecuteExecuteScript(
return Status(kUnknownError, "'args' must be a list");
return session->chrome->CallFunction(
- "function(){" + script + "}", *args, value);
+ session->frame, "function(){" + script + "}", *args, value);
+}
+
+Status ExecuteSwitchToFrame(
+ Session* session,
+ const base::DictionaryValue& params,
+ scoped_ptr<base::Value>* value) {
+ const base::Value* id;
+ if (!params.Get("id", &id))
+ return Status(kUnknownError, "missing 'id'");
+
+ if (id->IsType(base::Value::TYPE_NULL)) {
+ session->frame = "";
+ return Status(kOk);
+ }
+
+ std::string script;
+ if (id->IsType(base::Value::TYPE_STRING)) {
+ script =
+ "function(arg) {"
+ " var xpath = '(/html/body//iframe|/html/frameset/frame)';"
+ " var sub = function(s) { return s.replace(/\\$/g, arg); };"
+ " xpath += sub('[@name=\"$\" or @id=\"$\"]');"
+ " return document.evaluate(xpath, document, null, "
craigdh 2012/12/20 20:03:38 Constructing these xpaths in C++ would reduce the
kkania 2013/01/08 18:30:11 I've gone and ahead and switched to C++ since it m
+ " XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
+ "}";
+ } else if (id->IsType(base::Value::TYPE_INTEGER)) {
+ script =
+ "function(index) {"
+ " var xpathIndex = '[' + (index + 1) + ']';"
+ " var xpath = '(/html/body//iframe|/html/frameset/frame)' + "
+ " xpathIndex;"
+ " return document.evaluate(xpath, document, null, "
+ " XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
+ "}";
+ } else if (id->IsType(base::Value::TYPE_DICTIONARY)) {
+ // TODO(kkania): Implement.
+ return Status(kUnknownError, "frame switching by element not implemented");
+ } else {
+ return Status(kUnknownError, "invalid 'id'");
+ }
+ base::ListValue args;
+ args.Append(id->DeepCopy());
+ std::string frame;
+ Status status = session->chrome->GetFrameByFunction(
+ session->frame, script, args, &frame);
+ if (status.IsError())
+ return status;
+ session->frame = frame;
+ return Status(kOk);
}

Powered by Google App Engine
This is Rietveld 408576698