OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/test/webdriver/commands/target_locator_commands.h" |
| 6 |
| 7 #include "base/string_number_conversions.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/test/webdriver/commands/response.h" |
| 10 #include "chrome/test/webdriver/error_codes.h" |
| 11 #include "chrome/test/webdriver/session.h" |
| 12 |
| 13 namespace webdriver { |
| 14 |
| 15 WindowHandleCommand::WindowHandleCommand( |
| 16 const std::vector<std::string>& path_segments, |
| 17 DictionaryValue* parameters) |
| 18 : WebDriverCommand(path_segments, parameters) {} |
| 19 |
| 20 WindowHandleCommand::~WindowHandleCommand() {} |
| 21 |
| 22 bool WindowHandleCommand::DoesGet() { |
| 23 return true; |
| 24 } |
| 25 |
| 26 void WindowHandleCommand::ExecuteGet(Response* const response) { |
| 27 response->set_status(kSuccess); |
| 28 response->set_value(new StringValue( |
| 29 base::IntToString(session_->current_window_id()))); |
| 30 } |
| 31 |
| 32 WindowHandlesCommand::WindowHandlesCommand( |
| 33 const std::vector<std::string>& path_segments, |
| 34 DictionaryValue* parameters) |
| 35 : WebDriverCommand(path_segments, parameters) {} |
| 36 |
| 37 WindowHandlesCommand::~WindowHandlesCommand() {} |
| 38 |
| 39 bool WindowHandlesCommand::DoesGet() { |
| 40 return true; |
| 41 } |
| 42 |
| 43 void WindowHandlesCommand::ExecuteGet(Response* const response) { |
| 44 std::vector<int> window_ids; |
| 45 if (!session_->GetWindowIds(&window_ids)) { |
| 46 SET_WEBDRIVER_ERROR( |
| 47 response, "Could not get window handles", kInternalServerError); |
| 48 return; |
| 49 } |
| 50 ListValue* id_list = new ListValue(); |
| 51 for (size_t i = 0; i < window_ids.size(); ++i) |
| 52 id_list->Append(new StringValue(base::IntToString(window_ids[i]))); |
| 53 response->set_status(kSuccess); |
| 54 response->set_value(id_list); |
| 55 } |
| 56 |
| 57 WindowCommand::WindowCommand( |
| 58 const std::vector<std::string>& path_segments, |
| 59 DictionaryValue* parameters) |
| 60 : WebDriverCommand(path_segments, parameters) {} |
| 61 |
| 62 WindowCommand::~WindowCommand() {} |
| 63 |
| 64 bool WindowCommand::DoesPost() { |
| 65 return true; |
| 66 } |
| 67 |
| 68 bool WindowCommand::DoesDelete() { |
| 69 return true; |
| 70 } |
| 71 |
| 72 void WindowCommand::ExecutePost(Response* const response) { |
| 73 std::string name; |
| 74 if (!GetStringParameter("name", &name)) { |
| 75 SET_WEBDRIVER_ERROR( |
| 76 response, "Missing or invalid 'name' parameter", kBadRequest); |
| 77 return; |
| 78 } |
| 79 |
| 80 ErrorCode code = session_->SwitchToWindow(name); |
| 81 if (code != kSuccess) { |
| 82 SET_WEBDRIVER_ERROR(response, "Could not switch window", code); |
| 83 return; |
| 84 } |
| 85 response->set_status(kSuccess); |
| 86 } |
| 87 |
| 88 void WindowCommand::ExecuteDelete(Response* const response) { |
| 89 if (!session_->CloseWindow()) { |
| 90 SET_WEBDRIVER_ERROR( |
| 91 response, "Could not close window", kInternalServerError); |
| 92 return; |
| 93 } |
| 94 response->set_status(kSuccess); |
| 95 } |
| 96 |
| 97 SwitchFrameCommand::SwitchFrameCommand( |
| 98 const std::vector<std::string>& path_segments, |
| 99 DictionaryValue* parameters) |
| 100 : WebDriverCommand(path_segments, parameters) {} |
| 101 |
| 102 SwitchFrameCommand::~SwitchFrameCommand() {} |
| 103 |
| 104 bool SwitchFrameCommand::DoesPost() { |
| 105 return true; |
| 106 } |
| 107 |
| 108 void SwitchFrameCommand::ExecutePost(Response* const response) { |
| 109 std::string id; |
| 110 int index = 0; |
| 111 if (GetStringParameter("id", &id)) { |
| 112 ErrorCode code = session_->SwitchToFrameWithNameOrId(id); |
| 113 if (code != kSuccess) { |
| 114 SET_WEBDRIVER_ERROR(response, "Could not switch to frame", code); |
| 115 return; |
| 116 } |
| 117 } else if (GetIntegerParameter("id", &index)) { |
| 118 ErrorCode code = session_->SwitchToFrameWithIndex(index); |
| 119 if (code != kSuccess) { |
| 120 SET_WEBDRIVER_ERROR(response, "Could not switch to frame", code); |
| 121 return; |
| 122 } |
| 123 } else if (IsNullParameter("id")) { |
| 124 session_->set_current_frame_xpath(""); |
| 125 } else { |
| 126 SET_WEBDRIVER_ERROR( |
| 127 response, "Missing or invalid 'id' parameter", kBadRequest); |
| 128 return; |
| 129 } |
| 130 response->set_status(kSuccess); |
| 131 } |
| 132 |
| 133 } // namespace webdriver |
OLD | NEW |