OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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/chromedriver/alert_commands.h" |
| 6 |
| 7 #include "base/values.h" |
| 8 #include "chrome/test/chromedriver/chrome/chrome.h" |
| 9 #include "chrome/test/chromedriver/chrome/devtools_client.h" |
| 10 #include "chrome/test/chromedriver/chrome/javascript_dialog_manager.h" |
| 11 #include "chrome/test/chromedriver/chrome/status.h" |
| 12 #include "chrome/test/chromedriver/chrome/web_view.h" |
| 13 #include "chrome/test/chromedriver/session.h" |
| 14 |
| 15 Status ExecuteAlertCommand( |
| 16 const AlertCommand& alert_command, |
| 17 Session* session, |
| 18 const base::DictionaryValue& params, |
| 19 scoped_ptr<base::Value>* value) { |
| 20 WebView* web_view = NULL; |
| 21 Status status = session->GetTargetWindow(&web_view); |
| 22 if (status.IsError()) |
| 23 return status; |
| 24 |
| 25 status = web_view->ConnectIfNecessary(); |
| 26 if (status.IsError()) |
| 27 return status; |
| 28 |
| 29 status = web_view->GetDevToolsClient()->HandleReceivedEvents(); |
| 30 if (status.IsError()) |
| 31 return status; |
| 32 |
| 33 status = web_view->WaitForPendingNavigations(session->GetCurrentFrameId()); |
| 34 if (status.IsError() && status.code() != kUnexpectedAlertOpen) |
| 35 return status; |
| 36 |
| 37 return alert_command.Run(session, web_view, params, value); |
| 38 } |
| 39 |
| 40 Status ExecuteGetAlert( |
| 41 Session* session, |
| 42 WebView* web_view, |
| 43 const base::DictionaryValue& params, |
| 44 scoped_ptr<base::Value>* value) { |
| 45 value->reset(base::Value::CreateBooleanValue( |
| 46 web_view->GetJavaScriptDialogManager()->IsDialogOpen())); |
| 47 return Status(kOk); |
| 48 } |
| 49 |
| 50 Status ExecuteGetAlertText( |
| 51 Session* session, |
| 52 WebView* web_view, |
| 53 const base::DictionaryValue& params, |
| 54 scoped_ptr<base::Value>* value) { |
| 55 std::string message; |
| 56 Status status = |
| 57 web_view->GetJavaScriptDialogManager()->GetDialogMessage(&message); |
| 58 if (status.IsError()) |
| 59 return status; |
| 60 value->reset(base::Value::CreateStringValue(message)); |
| 61 return Status(kOk); |
| 62 } |
| 63 |
| 64 Status ExecuteSetAlertValue( |
| 65 Session* session, |
| 66 WebView* web_view, |
| 67 const base::DictionaryValue& params, |
| 68 scoped_ptr<base::Value>* value) { |
| 69 std::string text; |
| 70 if (!params.GetString("text", &text)) |
| 71 return Status(kUnknownError, "missing or invalid 'text'"); |
| 72 |
| 73 if (!web_view->GetJavaScriptDialogManager()->IsDialogOpen()) |
| 74 return Status(kNoAlertOpen); |
| 75 |
| 76 session->prompt_text.reset(new std::string(text)); |
| 77 return Status(kOk); |
| 78 } |
| 79 |
| 80 Status ExecuteAcceptAlert( |
| 81 Session* session, |
| 82 WebView* web_view, |
| 83 const base::DictionaryValue& params, |
| 84 scoped_ptr<base::Value>* value) { |
| 85 Status status = web_view->GetJavaScriptDialogManager() |
| 86 ->HandleDialog(true, session->prompt_text.get()); |
| 87 session->prompt_text.reset(); |
| 88 return status; |
| 89 } |
| 90 |
| 91 Status ExecuteDismissAlert( |
| 92 Session* session, |
| 93 WebView* web_view, |
| 94 const base::DictionaryValue& params, |
| 95 scoped_ptr<base::Value>* value) { |
| 96 Status status = web_view->GetJavaScriptDialogManager() |
| 97 ->HandleDialog(false, session->prompt_text.get()); |
| 98 session->prompt_text.reset(); |
| 99 return status; |
| 100 } |
OLD | NEW |