summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 23:10:58 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-16 23:10:58 +0000
commitb56da61e79ee405291e8ea6b260f51a1541928d1 (patch)
tree21fdef964b8efa4caedea151cdd0867815de528a /chrome/browser/automation
parent938f4ea71a0e2806f4c50b4c6d59c1586f8aa399 (diff)
downloadchromium_src-b56da61e79ee405291e8ea6b260f51a1541928d1.zip
chromium_src-b56da61e79ee405291e8ea6b260f51a1541928d1.tar.gz
chromium_src-b56da61e79ee405291e8ea6b260f51a1541928d1.tar.bz2
Have ChromeDriver return the correct error code for alerts.
Also, don't throw an alert error in set selected if the selection causes an alert. BUG=94959 TEST=none Review URL: http://codereview.chromium.org/8965008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114874 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r--chrome/browser/automation/automation_provider_json.cc35
-rw-r--r--chrome/browser/automation/automation_provider_json.h7
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc3
-rw-r--r--chrome/browser/automation/automation_util.cc4
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc25
5 files changed, 40 insertions, 34 deletions
diff --git a/chrome/browser/automation/automation_provider_json.cc b/chrome/browser/automation/automation_provider_json.cc
index 27c8474a..9a5c57f 100644
--- a/chrome/browser/automation/automation_provider_json.cc
+++ b/chrome/browser/automation/automation_provider_json.cc
@@ -16,20 +16,8 @@
#include "chrome/common/automation_messages.h"
#include "content/browser/tab_contents/tab_contents.h"
-namespace {
-
-// Util for creating a JSON error return string (dict with key
-// 'error' and error string value). No need to quote input.
-std::string JSONErrorString(const std::string& err) {
- std::string prefix = "{\"error\": \"";
- std::string no_quote_err;
- std::string suffix = "\"}";
-
- base::JsonDoubleQuote(err, false, &no_quote_err);
- return prefix + no_quote_err + suffix;
-}
-
-} // namespace
+using automation::Error;
+using automation::ErrorCode;
AutomationJSONReply::AutomationJSONReply(AutomationProvider* provider,
IPC::Message* reply_message)
@@ -53,10 +41,23 @@ void AutomationJSONReply::SendSuccess(const Value* value) {
}
void AutomationJSONReply::SendError(const std::string& error_message) {
+ SendErrorInternal(Error(error_message));
+}
+
+void AutomationJSONReply::SendErrorCode(ErrorCode code) {
+ SendErrorInternal(Error(code));
+}
+
+void AutomationJSONReply::SendErrorInternal(const Error& error) {
DCHECK(message_) << "Resending reply for JSON automation request";
- std::string json_string = JSONErrorString(error_message);
- AutomationMsg_SendJSONRequest::WriteReplyParams(
- message_, json_string, false);
+
+ base::DictionaryValue dict;
+ dict.SetString("error", error.message());
+ dict.SetInteger("code", error.code());
+ std::string json;
+ base::JSONWriter::Write(&dict, false /* pretty_print */, &json);
+
+ AutomationMsg_SendJSONRequest::WriteReplyParams(message_, json, false);
provider_->Send(message_);
message_ = NULL;
}
diff --git a/chrome/browser/automation/automation_provider_json.h b/chrome/browser/automation/automation_provider_json.h
index b7a8674..7b46879 100644
--- a/chrome/browser/automation/automation_provider_json.h
+++ b/chrome/browser/automation/automation_provider_json.h
@@ -11,6 +11,7 @@
#include <string>
#include "base/compiler_specific.h"
+#include "chrome/common/automation_constants.h"
class AutomationId;
class AutomationProvider;
@@ -47,7 +48,13 @@ class AutomationJSONReply {
// Send an error reply along with error message |error_message|.
void SendError(const std::string& error_message);
+ // Send an error reply along with the specified error code and its
+ // associated error message.
+ void SendErrorCode(automation::ErrorCode code);
+
private:
+ void SendErrorInternal(const automation::Error& error);
+
AutomationProvider* provider_;
IPC::Message* message_;
};
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index c1d5be9..2435617 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -1265,8 +1265,7 @@ void DomOperationMessageSender::OnDomOperationCompleted(
void DomOperationMessageSender::OnModalDialogShown() {
if (automation_ && use_json_interface_) {
AutomationJSONReply(automation_, reply_message_.release())
- .SendError("Could not complete script execution because a modal "
- "dialog is active");
+ .SendErrorCode(automation::kBlockedByModalDialog);
delete this;
}
}
diff --git a/chrome/browser/automation/automation_util.cc b/chrome/browser/automation/automation_util.cc
index 07b6909..a092763 100644
--- a/chrome/browser/automation/automation_util.cc
+++ b/chrome/browser/automation/automation_util.cc
@@ -397,8 +397,8 @@ bool SendErrorIfModalDialogActive(AutomationProvider* provider,
IPC::Message* message) {
bool active = AppModalDialogQueue::GetInstance()->HasActiveDialog();
if (active) {
- AutomationJSONReply(provider, message).SendError(
- "Command cannot be performed because a modal dialog is active");
+ AutomationJSONReply(provider, message).SendErrorCode(
+ automation::kBlockedByModalDialog);
}
return active;
}
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index aa9591f..7068738 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -145,6 +145,8 @@
#include "chrome/browser/download/download_shelf.h"
#endif
+using automation::Error;
+using automation::ErrorCode;
using automation_util::SendErrorIfModalDialogActive;
using content::BrowserThread;
using content::ChildProcessHost;
@@ -5741,14 +5743,11 @@ namespace {
// Gets the active JavaScript modal dialog, or NULL if none.
JavaScriptAppModalDialog* GetActiveJavaScriptModalDialog(
- std::string* error_msg) {
+ ErrorCode* error_code) {
AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
- if (!dialog_queue->HasActiveDialog()) {
- *error_msg = "No modal dialog is showing";
- return NULL;
- }
- if (!dialog_queue->active_dialog()->IsJavaScriptModalDialog()) {
- *error_msg = "No JavaScript modal dialog is showing";
+ if (!dialog_queue->HasActiveDialog() ||
+ !dialog_queue->active_dialog()->IsJavaScriptModalDialog()) {
+ *error_code = automation::kNoJavaScriptModalDialogOpen;
return NULL;
}
return static_cast<JavaScriptAppModalDialog*>(dialog_queue->active_dialog());
@@ -5759,10 +5758,10 @@ JavaScriptAppModalDialog* GetActiveJavaScriptModalDialog(
void TestingAutomationProvider::GetAppModalDialogMessage(
DictionaryValue* args, IPC::Message* reply_message) {
AutomationJSONReply reply(this, reply_message);
- std::string error_msg;
- JavaScriptAppModalDialog* dialog = GetActiveJavaScriptModalDialog(&error_msg);
+ ErrorCode code;
+ JavaScriptAppModalDialog* dialog = GetActiveJavaScriptModalDialog(&code);
if (!dialog) {
- reply.SendError(error_msg);
+ reply.SendErrorCode(code);
return;
}
DictionaryValue result_dict;
@@ -5779,10 +5778,10 @@ void TestingAutomationProvider::AcceptOrDismissAppModalDialog(
return;
}
- std::string error_msg;
- JavaScriptAppModalDialog* dialog = GetActiveJavaScriptModalDialog(&error_msg);
+ ErrorCode code;
+ JavaScriptAppModalDialog* dialog = GetActiveJavaScriptModalDialog(&code);
if (!dialog) {
- reply.SendError(error_msg);
+ reply.SendErrorCode(code);
return;
}
if (accept) {