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/alert_commands.h" | |
6 | |
7 #include "base/values.h" | |
8 #include "chrome/test/webdriver/commands/response.h" | |
9 #include "chrome/test/webdriver/webdriver_error.h" | |
10 #include "chrome/test/webdriver/webdriver_session.h" | |
11 | |
12 namespace webdriver { | |
13 | |
14 AlertTextCommand::AlertTextCommand( | |
15 const std::vector<std::string>& path_segments, | |
16 base::DictionaryValue* parameters) | |
17 : WebDriverCommand(path_segments, parameters) { | |
18 } | |
19 | |
20 AlertTextCommand::~AlertTextCommand() { | |
21 } | |
22 | |
23 bool AlertTextCommand::DoesGet() { | |
24 return true; | |
25 } | |
26 | |
27 bool AlertTextCommand::DoesPost() { | |
28 return true; | |
29 } | |
30 | |
31 void AlertTextCommand::ExecuteGet(Response* const response) { | |
32 std::string text; | |
33 Error* error = session_->GetAlertMessage(&text); | |
34 if (error) { | |
35 response->SetError(error); | |
36 return; | |
37 } | |
38 response->SetValue(new base::StringValue(text)); | |
39 } | |
40 | |
41 void AlertTextCommand::ExecutePost(Response* const response) { | |
42 std::string text; | |
43 if (!GetStringParameter("text", &text)) { | |
44 response->SetError(new Error( | |
45 kBadRequest, "'text' is missing or invalid")); | |
46 return; | |
47 } | |
48 Error* error = session_->SetAlertPromptText(text); | |
49 if (error) | |
50 response->SetError(error); | |
51 } | |
52 | |
53 AcceptAlertCommand::AcceptAlertCommand( | |
54 const std::vector<std::string>& path_segments, | |
55 base::DictionaryValue* parameters) | |
56 : WebDriverCommand(path_segments, parameters) { | |
57 } | |
58 | |
59 AcceptAlertCommand::~AcceptAlertCommand() { | |
60 } | |
61 | |
62 bool AcceptAlertCommand::DoesPost() { | |
63 return true; | |
64 } | |
65 | |
66 void AcceptAlertCommand::ExecutePost(Response* const response) { | |
67 Error* error = session_->AcceptOrDismissAlert(true); | |
68 if (error) | |
69 response->SetError(error); | |
70 } | |
71 | |
72 DismissAlertCommand::DismissAlertCommand( | |
73 const std::vector<std::string>& path_segments, | |
74 base::DictionaryValue* parameters) | |
75 : WebDriverCommand(path_segments, parameters) { | |
76 } | |
77 | |
78 DismissAlertCommand::~DismissAlertCommand() { | |
79 } | |
80 | |
81 bool DismissAlertCommand::DoesPost() { | |
82 return true; | |
83 } | |
84 | |
85 void DismissAlertCommand::ExecutePost(Response* const response) { | |
86 Error* error = session_->AcceptOrDismissAlert(false); | |
87 if (error) | |
88 response->SetError(error); | |
89 } | |
90 | |
91 } // namespace webdriver | |
OLD | NEW |