| 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;
|
| +}
|
|
|