OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/chromedriver/commands.h" | 5 #include "chrome/test/chromedriver/commands.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const base::DictionaryValue& params, | 96 const base::DictionaryValue& params, |
97 scoped_ptr<base::Value>* value) { | 97 scoped_ptr<base::Value>* value) { |
98 std::string script; | 98 std::string script; |
99 if (!params.GetString("script", &script)) | 99 if (!params.GetString("script", &script)) |
100 return Status(kUnknownError, "'script' must be a string"); | 100 return Status(kUnknownError, "'script' must be a string"); |
101 const base::ListValue* args; | 101 const base::ListValue* args; |
102 if (!params.GetList("args", &args)) | 102 if (!params.GetList("args", &args)) |
103 return Status(kUnknownError, "'args' must be a list"); | 103 return Status(kUnknownError, "'args' must be a list"); |
104 | 104 |
105 return session->chrome->CallFunction( | 105 return session->chrome->CallFunction( |
106 "function(){" + script + "}", *args, value); | 106 session->frame, "function(){" + script + "}", *args, value); |
107 } | 107 } |
| 108 |
| 109 Status ExecuteSwitchToFrame( |
| 110 Session* session, |
| 111 const base::DictionaryValue& params, |
| 112 scoped_ptr<base::Value>* value) { |
| 113 const base::Value* id; |
| 114 if (!params.Get("id", &id)) |
| 115 return Status(kUnknownError, "missing 'id'"); |
| 116 |
| 117 if (id->IsType(base::Value::TYPE_NULL)) { |
| 118 session->frame = ""; |
| 119 return Status(kOk); |
| 120 } |
| 121 |
| 122 std::string evaluate_xpath_script = |
| 123 "function(xpath) {" |
| 124 " return document.evaluate(xpath, document, null, " |
| 125 " XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;" |
| 126 "}"; |
| 127 std::string xpath = "(/html/body//iframe|/html/frameset/frame)"; |
| 128 std::string id_string; |
| 129 int id_int; |
| 130 if (id->GetAsString(&id_string)) { |
| 131 xpath += base::StringPrintf( |
| 132 "[@name=\"%s\" or @id=\"%s\"]", id_string.c_str(), id_string.c_str()); |
| 133 } else if (id->GetAsInteger(&id_int)) { |
| 134 xpath += base::StringPrintf("[%d]", id_int + 1); |
| 135 } else if (id->IsType(base::Value::TYPE_DICTIONARY)) { |
| 136 // TODO(kkania): Implement. |
| 137 return Status(kUnknownError, "frame switching by element not implemented"); |
| 138 } else { |
| 139 return Status(kUnknownError, "invalid 'id'"); |
| 140 } |
| 141 base::ListValue args; |
| 142 args.Append(new base::StringValue(xpath)); |
| 143 std::string frame; |
| 144 Status status = session->chrome->GetFrameByFunction( |
| 145 session->frame, evaluate_xpath_script, args, &frame); |
| 146 if (status.IsError()) |
| 147 return status; |
| 148 session->frame = frame; |
| 149 return Status(kOk); |
| 150 } |
OLD | NEW |