Commit 2b7461cd authored by kkania@chromium.org's avatar kkania@chromium.org

Toggle a multiple select option instead of setting it as selected when

clicking.
BUG=90994
TEST=none


Review URL: http://codereview.chromium.org/7541056

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96052 0039d316-1c4b-4281-b951-d872f2087c98
parent 2f35a315
......@@ -8,6 +8,7 @@
#include "chrome/common/automation_constants.h"
#include "chrome/test/webdriver/commands/response.h"
#include "chrome/test/webdriver/session.h"
#include "chrome/test/webdriver/utility_functions.h"
#include "chrome/test/webdriver/web_element_id.h"
#include "chrome/test/webdriver/webdriver_error.h"
#include "ui/gfx/point.h"
......@@ -44,7 +45,38 @@ void MoveAndClickCommand::ExecutePost(Response* response) {
}
if (tag_name == "option") {
error = session_->SelectOptionElement(session_->current_target(), element);
const char* kCanOptionBeToggledScript =
"return (function(option) {"
" var select = option.parentElement;"
" if (!select || select.tagName.toLowerCase() != 'select')"
" throw new Error('Option element is not in a select');"
" return select.multiple;"
"}).apply(null, arguments);";
ListValue args;
args.Append(element.ToValue());
Value* value = NULL;
error = session_->ExecuteScript(
session_->current_target(), kCanOptionBeToggledScript, &args, &value);
if (error) {
response->SetError(error);
return;
}
scoped_ptr<Value> scoped_value(value);
bool can_be_toggled;
if (!value->GetAsBoolean(&can_be_toggled)) {
response->SetError(
new Error(kUnknownError, "canOptionBeToggled returned non-boolean: " +
JsonStringify(value)));
return;
}
if (can_be_toggled) {
error = session_->ToggleOptionElement(
session_->current_target(), element);
} else {
error = session_->SetOptionElementSelected(
session_->current_target(), element, true);
}
} else {
gfx::Point location;
error = session_->GetClickableLocation(element, &location);
......
......@@ -334,24 +334,19 @@ bool ElementSelectedCommand::DoesPost() {
}
void ElementSelectedCommand::ExecuteGet(Response* const response) {
ListValue args;
args.Append(element.ToValue());
std::string script = base::StringPrintf(
"return (%s).apply(null, arguments);", atoms::IS_SELECTED);
Value* result = NULL;
Error* error = session_->ExecuteScript(script, &args, &result);
bool is_selected;
Error* error = session_->IsOptionElementSelected(
session_->current_target(), element, &is_selected);
if (error) {
response->SetError(error);
return;
}
response->SetValue(result);
response->SetValue(Value::CreateBooleanValue(is_selected));
}
void ElementSelectedCommand::ExecutePost(Response* const response) {
Error* error = session_->SelectOptionElement(
session_->current_target(), element);
Error* error = session_->SetOptionElementSelected(
session_->current_target(), element, true);
if (error) {
response->SetError(error);
return;
......
......@@ -918,11 +918,33 @@ Error* Session::IsElementEnabled(const FrameId& frame_id,
return NULL;
}
Error* Session::SelectOptionElement(const FrameId& frame_id,
const WebElementId& element) {
Error* Session::IsOptionElementSelected(const FrameId& frame_id,
const WebElementId& element,
bool* is_selected) {
ListValue args;
args.Append(element.ToValue());
std::string script = base::StringPrintf(
"return (%s).apply(null, arguments);", atoms::IS_SELECTED);
Value* result = NULL;
Error* error = ExecuteScript(frame_id, script, &args, &result);
if (error)
return error;
scoped_ptr<Value> scoped_result(result);
if (!result->GetAsBoolean(is_selected)) {
return new Error(kUnknownError, "isSelected atom returned non-boolean: " +
JsonStringify(result));
}
return NULL;
}
Error* Session::SetOptionElementSelected(const FrameId& frame_id,
const WebElementId& element,
bool selected) {
ListValue args;
args.Append(element.ToValue());
args.Append(Value::CreateBooleanValue(true));
args.Append(Value::CreateBooleanValue(selected));
std::string script = base::StringPrintf(
"return (%s).apply(null, arguments);", atoms::SET_SELECTED);
......@@ -933,6 +955,16 @@ Error* Session::SelectOptionElement(const FrameId& frame_id,
return error;
}
Error* Session::ToggleOptionElement(const FrameId& frame_id,
const WebElementId& element) {
bool is_selected;
Error* error = IsOptionElementSelected(frame_id, element, &is_selected);
if (error)
return error;
return SetOptionElementSelected(frame_id, element, !is_selected);
}
Error* Session::GetElementTagName(const FrameId& frame_id,
const WebElementId& element,
std::string* tag_name) {
......
......@@ -248,8 +248,20 @@ class Session {
const WebElementId& element,
bool* is_enabled);
// Sets the given option element as selected.
Error* SelectOptionElement(const FrameId& frame_id,
// Gets whether the option element is currently selected.
Error* IsOptionElementSelected(const FrameId& frame_id,
const WebElementId& element,
bool* is_selected);
// Set the selection state of the given option element. The option element
// must support multi selection if |selected| is false.
Error* SetOptionElementSelected(const FrameId& frame_id,
const WebElementId& element,
bool selected);
// Toggles the option element's selection state. The option element should
// support multi selection.
Error* ToggleOptionElement(const FrameId& frame_id,
const WebElementId& element);
// Gets the tag name of the given element.
......
......@@ -32,8 +32,6 @@
'executing_async_javascript_test',
'executing_javascript_test',
'form_handling_tests',
# crbug.com/90994.
'-form_handling_tests.FormHandlingTests.testTogglingAnOptionShouldToggleOptionsInAMultiSelect',
'frame_switching_tests',
# Test is asserting the wrong thing.
'-frame_switching_tests.FrameSwitchingTest.testShouldReturnFrameTitleNotWindowTitle',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment