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

Unified Diff: chrome/test/webdriver/commands/target_locator_commands.cc

Issue 6507015: Implement the target locator commands for ChromeDriver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 10 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
Index: chrome/test/webdriver/commands/target_locator_commands.cc
diff --git a/chrome/test/webdriver/commands/target_locator_commands.cc b/chrome/test/webdriver/commands/target_locator_commands.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8808ca4ca6a0c15b90a8d58e3ddb27b7df061377
--- /dev/null
+++ b/chrome/test/webdriver/commands/target_locator_commands.cc
@@ -0,0 +1,133 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/webdriver/commands/target_locator_commands.h"
+
+#include "base/string_number_conversions.h"
+#include "base/values.h"
+#include "chrome/test/webdriver/commands/response.h"
+#include "chrome/test/webdriver/error_codes.h"
+#include "chrome/test/webdriver/session.h"
+
+namespace webdriver {
+
+WindowHandleCommand::WindowHandleCommand(
+ const std::vector<std::string>& path_segments,
+ DictionaryValue* parameters)
+ : WebDriverCommand(path_segments, parameters) {}
+
+WindowHandleCommand::~WindowHandleCommand() {}
+
+bool WindowHandleCommand::DoesGet() {
+ return true;
+}
+
+void WindowHandleCommand::ExecuteGet(Response* const response) {
+ response->set_status(kSuccess);
+ response->set_value(new StringValue(
+ base::IntToString(session_->current_window_id())));
+}
+
+WindowHandlesCommand::WindowHandlesCommand(
+ const std::vector<std::string>& path_segments,
+ DictionaryValue* parameters)
+ : WebDriverCommand(path_segments, parameters) {}
+
+WindowHandlesCommand::~WindowHandlesCommand() {}
+
+bool WindowHandlesCommand::DoesGet() {
+ return true;
+}
+
+void WindowHandlesCommand::ExecuteGet(Response* const response) {
+ std::vector<int> window_ids;
+ if (!session_->GetWindowIds(&window_ids)) {
+ SET_WEBDRIVER_ERROR(
+ response, "Could not get window handles", kInternalServerError);
+ return;
+ }
+ ListValue* id_list = new ListValue();
+ for (size_t i = 0; i < window_ids.size(); ++i)
+ id_list->Append(new StringValue(base::IntToString(window_ids[i])));
+ response->set_status(kSuccess);
+ response->set_value(id_list);
+}
+
+WindowCommand::WindowCommand(
+ const std::vector<std::string>& path_segments,
+ DictionaryValue* parameters)
+ : WebDriverCommand(path_segments, parameters) {}
+
+WindowCommand::~WindowCommand() {}
+
+bool WindowCommand::DoesPost() {
+ return true;
+}
+
+bool WindowCommand::DoesDelete() {
+ return true;
+}
+
+void WindowCommand::ExecutePost(Response* const response) {
+ std::string name;
+ if (!GetStringParameter("name", &name)) {
+ SET_WEBDRIVER_ERROR(
+ response, "Missing or invalid 'name' parameter", kBadRequest);
+ return;
+ }
+
+ ErrorCode code = session_->SwitchToWindow(name);
+ if (code != kSuccess) {
+ SET_WEBDRIVER_ERROR(response, "Could not switch window", code);
+ return;
+ }
+ response->set_status(kSuccess);
+}
+
+void WindowCommand::ExecuteDelete(Response* const response) {
+ if (!session_->CloseWindow()) {
+ SET_WEBDRIVER_ERROR(
+ response, "Could not close window", kInternalServerError);
+ return;
+ }
+ response->set_status(kSuccess);
+}
+
+SwitchFrameCommand::SwitchFrameCommand(
+ const std::vector<std::string>& path_segments,
+ DictionaryValue* parameters)
+ : WebDriverCommand(path_segments, parameters) {}
+
+SwitchFrameCommand::~SwitchFrameCommand() {}
+
+bool SwitchFrameCommand::DoesPost() {
+ return true;
+}
+
+void SwitchFrameCommand::ExecutePost(Response* const response) {
+ std::string id;
+ int index = 0;
+ if (GetStringParameter("id", &id)) {
+ ErrorCode code = session_->SwitchToFrameWithNameOrId(id);
+ if (code != kSuccess) {
+ SET_WEBDRIVER_ERROR(response, "Could not switch to frame", code);
+ return;
+ }
+ } else if (GetIntegerParameter("id", &index)) {
+ ErrorCode code = session_->SwitchToFrameWithIndex(index);
+ if (code != kSuccess) {
+ SET_WEBDRIVER_ERROR(response, "Could not switch to frame", code);
+ return;
+ }
+ } else if (IsNullParameter("id")) {
+ session_->set_current_frame_xpath("");
+ } else {
+ SET_WEBDRIVER_ERROR(
+ response, "Missing or invalid 'id' parameter", kBadRequest);
+ return;
+ }
+ response->set_status(kSuccess);
+}
+
+} // namespace webdriver

Powered by Google App Engine
This is Rietveld 408576698