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

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: rebase Created 7 years, 11 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/commands.h ('k') | chrome/test/chromedriver/commands_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/commands.cc
diff --git a/chrome/test/chromedriver/commands.cc b/chrome/test/chromedriver/commands.cc
index f90388ab0648645c74f94b91098fb5b473964eda..50f26c8454a7e82ed0f9324d6e8c33849271be7d 100644
--- a/chrome/test/chromedriver/commands.cc
+++ b/chrome/test/chromedriver/commands.cc
@@ -103,5 +103,48 @@ 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 evaluate_xpath_script =
+ "function(xpath) {"
+ " return document.evaluate(xpath, document, null, "
+ " XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
+ "}";
+ std::string xpath = "(/html/body//iframe|/html/frameset/frame)";
+ std::string id_string;
+ int id_int;
+ if (id->GetAsString(&id_string)) {
+ xpath += base::StringPrintf(
+ "[@name=\"%s\" or @id=\"%s\"]", id_string.c_str(), id_string.c_str());
+ } else if (id->GetAsInteger(&id_int)) {
+ xpath += base::StringPrintf("[%d]", id_int + 1);
+ } 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(new base::StringValue(xpath));
+ std::string frame;
+ Status status = session->chrome->GetFrameByFunction(
+ session->frame, evaluate_xpath_script, args, &frame);
+ if (status.IsError())
+ return status;
+ session->frame = frame;
+ return Status(kOk);
}
« no previous file with comments | « chrome/test/chromedriver/commands.h ('k') | chrome/test/chromedriver/commands_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698