Chromium Code Reviews| 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/chrome_impl.h" | 5 #include "chrome/test/chromedriver/chrome_impl.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 const std::string& function, | 121 const std::string& function, |
| 122 const base::ListValue& args, | 122 const base::ListValue& args, |
| 123 scoped_ptr<base::Value>* result) { | 123 scoped_ptr<base::Value>* result) { |
| 124 std::string json; | 124 std::string json; |
| 125 base::JSONWriter::Write(&args, &json); | 125 base::JSONWriter::Write(&args, &json); |
| 126 std::string expression = base::StringPrintf( | 126 std::string expression = base::StringPrintf( |
| 127 "(%s).apply(null, [%s, %s])", | 127 "(%s).apply(null, [%s, %s])", |
| 128 kCallFunctionScript, | 128 kCallFunctionScript, |
| 129 function.c_str(), | 129 function.c_str(), |
| 130 json.c_str()); | 130 json.c_str()); |
| 131 return EvaluateScript(frame, expression, result); | 131 scoped_ptr<base::Value> temp_result; |
| 132 Status status = EvaluateScript(frame, expression, &temp_result); | |
| 133 if (status.IsError()) | |
| 134 return status; | |
| 135 | |
| 136 return internal::ParseCallFunctionResult(*temp_result.get(), result); | |
|
chrisgao (Use stgao instead)
2013/01/22 19:17:31
I think "*temp_result" would also work here.
kkania
2013/02/28 21:50:17
Done.
| |
| 132 } | 137 } |
| 133 | 138 |
| 134 Status ChromeImpl::GetFrameByFunction(const std::string& frame, | 139 Status ChromeImpl::GetFrameByFunction(const std::string& frame, |
| 135 const std::string& function, | 140 const std::string& function, |
| 136 const base::ListValue& args, | 141 const base::ListValue& args, |
| 137 std::string* out_frame) { | 142 std::string* out_frame) { |
| 138 int context_id; | 143 int context_id; |
| 139 Status status = GetContextIdForFrame(dom_tracker_.get(), frame, &context_id); | 144 Status status = GetContextIdForFrame(dom_tracker_.get(), frame, &context_id); |
| 140 if (status.IsError()) | 145 if (status.IsError()) |
| 141 return status; | 146 return status; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 if (status.IsError()) | 240 if (status.IsError()) |
| 236 return status; | 241 return status; |
| 237 | 242 |
| 238 std::string type; | 243 std::string type; |
| 239 if (!temp_result->GetString("type", &type)) | 244 if (!temp_result->GetString("type", &type)) |
| 240 return Status(kUnknownError, "Runtime.evaluate missing string 'type'"); | 245 return Status(kUnknownError, "Runtime.evaluate missing string 'type'"); |
| 241 | 246 |
| 242 if (type == "undefined") { | 247 if (type == "undefined") { |
| 243 result->reset(base::Value::CreateNullValue()); | 248 result->reset(base::Value::CreateNullValue()); |
| 244 } else { | 249 } else { |
| 245 int status_code; | 250 base::Value* value; |
| 246 if (!temp_result->GetInteger("value.status", &status_code)) { | 251 if (!temp_result->Get("value", &value)) |
| 247 return Status(kUnknownError, | 252 return Status(kUnknownError, "Runtime.evaluate missing 'value'"); |
| 248 "Runtime.evaluate missing int 'value.status'"); | 253 result->reset(value->DeepCopy()); |
| 249 } | |
| 250 if (status_code != kOk) | |
| 251 return Status(static_cast<StatusCode>(status_code)); | |
| 252 base::Value* unscoped_value; | |
| 253 if (!temp_result->Get("value.value", &unscoped_value)) { | |
| 254 return Status(kUnknownError, | |
| 255 "Runtime.evaluate missing 'value.value'"); | |
| 256 } | |
| 257 result->reset(unscoped_value->DeepCopy()); | |
| 258 } | 254 } |
| 259 return Status(kOk); | 255 return Status(kOk); |
| 260 } | 256 } |
| 261 | 257 |
| 258 Status ParseCallFunctionResult(const base::Value& temp_result, | |
| 259 scoped_ptr<base::Value>* result) { | |
| 260 const base::DictionaryValue* dict; | |
| 261 if (!temp_result.GetAsDictionary(&dict)) | |
| 262 return Status(kUnknownError, "call function result must be a dictionary"); | |
| 263 int status_code; | |
| 264 if (!dict->GetInteger("status", &status_code)) { | |
| 265 return Status(kUnknownError, | |
| 266 "call function result missing int 'status'"); | |
| 267 } | |
| 268 if (status_code != kOk) | |
| 269 return Status(static_cast<StatusCode>(status_code)); | |
| 270 const base::Value* unscoped_value; | |
| 271 if (!dict->Get("value", &unscoped_value)) { | |
| 272 return Status(kUnknownError, | |
| 273 "call function result missing 'value'"); | |
| 274 } | |
| 275 result->reset(unscoped_value->DeepCopy()); | |
| 276 return Status(kOk); | |
| 277 } | |
| 278 | |
| 262 Status GetNodeIdFromFunction(DevToolsClient* client, | 279 Status GetNodeIdFromFunction(DevToolsClient* client, |
| 263 int context_id, | 280 int context_id, |
| 264 const std::string& function, | 281 const std::string& function, |
| 265 const base::ListValue& args, | 282 const base::ListValue& args, |
| 266 int* node_id) { | 283 int* node_id) { |
| 267 std::string json; | 284 std::string json; |
| 268 base::JSONWriter::Write(&args, &json); | 285 base::JSONWriter::Write(&args, &json); |
| 269 std::string expression = base::StringPrintf( | 286 std::string expression = base::StringPrintf( |
| 270 "(%s).apply(null, [%s, %s, true])", | 287 "(%s).apply(null, [%s, %s, true])", |
| 271 kCallFunctionScript, | 288 kCallFunctionScript, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 298 } | 315 } |
| 299 if (status.IsError()) | 316 if (status.IsError()) |
| 300 return status; | 317 return status; |
| 301 | 318 |
| 302 if (!cmd_result->GetInteger("nodeId", node_id)) | 319 if (!cmd_result->GetInteger("nodeId", node_id)) |
| 303 return Status(kUnknownError, "DOM.requestNode missing int 'nodeId'"); | 320 return Status(kUnknownError, "DOM.requestNode missing int 'nodeId'"); |
| 304 return Status(kOk); | 321 return Status(kOk); |
| 305 } | 322 } |
| 306 | 323 |
| 307 } // namespace internal | 324 } // namespace internal |
| OLD | NEW |