OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 | 8 |
9 #include "chrome/test/webdriver/commands/execute_command.h" | 9 #include "chrome/test/webdriver/commands/execute_command.h" |
10 | 10 |
11 namespace webdriver { | 11 namespace webdriver { |
12 | 12 |
13 const char kArgs[] = "args"; | 13 const char kArgs[] = "args"; |
14 const char kScript[] = "script"; | 14 const char kScript[] = "script"; |
15 | 15 |
| 16 ExecuteCommand::ExecuteCommand(const std::vector<std::string>& path_segments, |
| 17 const DictionaryValue* const parameters) |
| 18 : WebDriverCommand(path_segments, parameters) {} |
| 19 |
| 20 ExecuteCommand::~ExecuteCommand() {} |
| 21 |
| 22 |
16 bool ExecuteCommand::Init(Response* const response) { | 23 bool ExecuteCommand::Init(Response* const response) { |
17 if (!WebDriverCommand::Init(response)) { | 24 if (!WebDriverCommand::Init(response)) { |
18 SET_WEBDRIVER_ERROR(response, "Failure on Init for execute command", | 25 SET_WEBDRIVER_ERROR(response, "Failure on Init for execute command", |
19 kInternalServerError); | 26 kInternalServerError); |
20 return false; | 27 return false; |
21 } | 28 } |
22 | 29 |
23 if (!GetStringParameter(kScript, &script_)) { | 30 if (!GetStringParameter(kScript, &script_)) { |
24 SET_WEBDRIVER_ERROR(response, "No script to execute specified", | 31 SET_WEBDRIVER_ERROR(response, "No script to execute specified", |
25 kBadRequest); | 32 kBadRequest); |
26 return false; | 33 return false; |
27 } | 34 } |
28 | 35 |
29 has_args_= GetStringASCIIParameter(kArgs, &args_); | 36 has_args_= GetStringASCIIParameter(kArgs, &args_); |
30 return true; | 37 return true; |
31 } | 38 } |
32 | 39 |
| 40 bool ExecuteCommand::DoesPost() { |
| 41 return true; |
| 42 } |
| 43 |
33 void ExecuteCommand::ExecutePost(Response* const response) { | 44 void ExecuteCommand::ExecutePost(Response* const response) { |
34 int error_code = 0; | 45 int error_code = 0; |
35 std::string error_msg; | 46 std::string error_msg; |
36 Value* params = NULL; | 47 Value* params = NULL; |
37 Value* result = NULL; | 48 Value* result = NULL; |
38 | 49 |
39 if (has_args_) { | 50 if (has_args_) { |
40 params = base::JSONReader::ReadAndReturnError(args_, true, | 51 params = base::JSONReader::ReadAndReturnError(args_, true, |
41 &error_code, &error_msg); | 52 &error_code, &error_msg); |
42 if (error_code != 0) { | 53 if (error_code != 0) { |
(...skipping 23 matching lines...) Expand all Loading... |
66 if (error != kSuccess) { | 77 if (error != kSuccess) { |
67 SET_WEBDRIVER_ERROR(response, "Failed to execute script", | 78 SET_WEBDRIVER_ERROR(response, "Failed to execute script", |
68 kInternalServerError); | 79 kInternalServerError); |
69 return; | 80 return; |
70 } | 81 } |
71 | 82 |
72 response->set_value(result); | 83 response->set_value(result); |
73 response->set_status(kSuccess); | 84 response->set_status(kSuccess); |
74 } | 85 } |
75 | 86 |
| 87 bool ExecuteCommand::RequiresValidTab() { |
| 88 return true; |
| 89 } |
| 90 |
76 } // namspace webdriver | 91 } // namspace webdriver |
77 | 92 |
OLD | NEW |