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

Unified Diff: chrome/test/chromedriver/alert_commands.cc

Issue 15393005: [chromedriver] Remove unnecessary round trips to Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 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
« no previous file with comments | « chrome/test/chromedriver/alert_commands.h ('k') | chrome/test/chromedriver/chrome/chrome.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/alert_commands.cc
diff --git a/chrome/test/chromedriver/alert_commands.cc b/chrome/test/chromedriver/alert_commands.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2ac4e4d4049c39ef144d7a94c30a627300484ec8
--- /dev/null
+++ b/chrome/test/chromedriver/alert_commands.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2013 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/chromedriver/alert_commands.h"
+
+#include "base/values.h"
+#include "chrome/test/chromedriver/chrome/chrome.h"
+#include "chrome/test/chromedriver/chrome/devtools_client.h"
+#include "chrome/test/chromedriver/chrome/javascript_dialog_manager.h"
+#include "chrome/test/chromedriver/chrome/status.h"
+#include "chrome/test/chromedriver/chrome/web_view.h"
+#include "chrome/test/chromedriver/session.h"
+
+Status ExecuteAlertCommand(
+ const AlertCommand& alert_command,
+ Session* session,
+ const base::DictionaryValue& params,
+ scoped_ptr<base::Value>* value) {
+ WebView* web_view = NULL;
+ Status status = session->GetTargetWindow(&web_view);
+ if (status.IsError())
+ return status;
+
+ status = web_view->ConnectIfNecessary();
+ if (status.IsError())
+ return status;
+
+ status = web_view->GetDevToolsClient()->HandleReceivedEvents();
+ if (status.IsError())
+ return status;
+
+ status = web_view->WaitForPendingNavigations(session->GetCurrentFrameId());
+ if (status.IsError() && status.code() != kUnexpectedAlertOpen)
+ return status;
+
+ return alert_command.Run(session, web_view, params, value);
+}
+
+Status ExecuteGetAlert(
+ Session* session,
+ WebView* web_view,
+ const base::DictionaryValue& params,
+ scoped_ptr<base::Value>* value) {
+ value->reset(base::Value::CreateBooleanValue(
+ web_view->GetJavaScriptDialogManager()->IsDialogOpen()));
+ return Status(kOk);
+}
+
+Status ExecuteGetAlertText(
+ Session* session,
+ WebView* web_view,
+ const base::DictionaryValue& params,
+ scoped_ptr<base::Value>* value) {
+ std::string message;
+ Status status =
+ web_view->GetJavaScriptDialogManager()->GetDialogMessage(&message);
+ if (status.IsError())
+ return status;
+ value->reset(base::Value::CreateStringValue(message));
+ return Status(kOk);
+}
+
+Status ExecuteSetAlertValue(
+ Session* session,
+ WebView* web_view,
+ const base::DictionaryValue& params,
+ scoped_ptr<base::Value>* value) {
+ std::string text;
+ if (!params.GetString("text", &text))
+ return Status(kUnknownError, "missing or invalid 'text'");
+
+ if (!web_view->GetJavaScriptDialogManager()->IsDialogOpen())
+ return Status(kNoAlertOpen);
+
+ session->prompt_text.reset(new std::string(text));
+ return Status(kOk);
+}
+
+Status ExecuteAcceptAlert(
+ Session* session,
+ WebView* web_view,
+ const base::DictionaryValue& params,
+ scoped_ptr<base::Value>* value) {
+ Status status = web_view->GetJavaScriptDialogManager()
+ ->HandleDialog(true, session->prompt_text.get());
+ session->prompt_text.reset();
+ return status;
+}
+
+Status ExecuteDismissAlert(
+ Session* session,
+ WebView* web_view,
+ const base::DictionaryValue& params,
+ scoped_ptr<base::Value>* value) {
+ Status status = web_view->GetJavaScriptDialogManager()
+ ->HandleDialog(false, session->prompt_text.get());
+ session->prompt_text.reset();
+ return status;
+}
« no previous file with comments | « chrome/test/chromedriver/alert_commands.h ('k') | chrome/test/chromedriver/chrome/chrome.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698