Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: chrome/test/webdriver/session.cc

Issue 7541056: Toggle a multiple select option instead of setting it as selected when (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/webdriver/session.h ('k') | chrome/test/webdriver/test/WEBDRIVER_TESTS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/webdriver/session.h" 5 #include "chrome/test/webdriver/session.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 Error* error = ExecuteScript(frame_id, script, &args, &unscoped_result); 911 Error* error = ExecuteScript(frame_id, script, &args, &unscoped_result);
912 scoped_ptr<Value> result(unscoped_result); 912 scoped_ptr<Value> result(unscoped_result);
913 if (error) 913 if (error)
914 return error; 914 return error;
915 if (!result->GetAsBoolean(is_enabled)) 915 if (!result->GetAsBoolean(is_enabled))
916 return new Error(kUnknownError, "IsEnabled atom returned non-boolean: " + 916 return new Error(kUnknownError, "IsEnabled atom returned non-boolean: " +
917 JsonStringify(result.get())); 917 JsonStringify(result.get()));
918 return NULL; 918 return NULL;
919 } 919 }
920 920
921 Error* Session::SelectOptionElement(const FrameId& frame_id, 921 Error* Session::IsOptionElementSelected(const FrameId& frame_id,
922 const WebElementId& element) { 922 const WebElementId& element,
923 bool* is_selected) {
923 ListValue args; 924 ListValue args;
924 args.Append(element.ToValue()); 925 args.Append(element.ToValue());
925 args.Append(Value::CreateBooleanValue(true)); 926
927 std::string script = base::StringPrintf(
928 "return (%s).apply(null, arguments);", atoms::IS_SELECTED);
929
930 Value* result = NULL;
931 Error* error = ExecuteScript(frame_id, script, &args, &result);
932 if (error)
933 return error;
934 scoped_ptr<Value> scoped_result(result);
935 if (!result->GetAsBoolean(is_selected)) {
936 return new Error(kUnknownError, "isSelected atom returned non-boolean: " +
937 JsonStringify(result));
938 }
939 return NULL;
940 }
941
942 Error* Session::SetOptionElementSelected(const FrameId& frame_id,
943 const WebElementId& element,
944 bool selected) {
945 ListValue args;
946 args.Append(element.ToValue());
947 args.Append(Value::CreateBooleanValue(selected));
926 948
927 std::string script = base::StringPrintf( 949 std::string script = base::StringPrintf(
928 "return (%s).apply(null, arguments);", atoms::SET_SELECTED); 950 "return (%s).apply(null, arguments);", atoms::SET_SELECTED);
929 951
930 Value* unscoped_result = NULL; 952 Value* unscoped_result = NULL;
931 Error* error = ExecuteScript(frame_id, script, &args, &unscoped_result); 953 Error* error = ExecuteScript(frame_id, script, &args, &unscoped_result);
932 scoped_ptr<Value> result(unscoped_result); 954 scoped_ptr<Value> result(unscoped_result);
933 return error; 955 return error;
934 } 956 }
935 957
958 Error* Session::ToggleOptionElement(const FrameId& frame_id,
959 const WebElementId& element) {
960 bool is_selected;
961 Error* error = IsOptionElementSelected(frame_id, element, &is_selected);
962 if (error)
963 return error;
964
965 return SetOptionElementSelected(frame_id, element, !is_selected);
966 }
967
936 Error* Session::GetElementTagName(const FrameId& frame_id, 968 Error* Session::GetElementTagName(const FrameId& frame_id,
937 const WebElementId& element, 969 const WebElementId& element,
938 std::string* tag_name) { 970 std::string* tag_name) {
939 ListValue args; 971 ListValue args;
940 args.Append(element.ToValue()); 972 args.Append(element.ToValue());
941 973
942 std::string script = "return arguments[0].tagName.toLocaleLowerCase();"; 974 std::string script = "return arguments[0].tagName.toLocaleLowerCase();";
943 975
944 Value* unscoped_result = NULL; 976 Value* unscoped_result = NULL;
945 Error* error = ExecuteScript(frame_id, script, &args, &unscoped_result); 977 Error* error = ExecuteScript(frame_id, script, &args, &unscoped_result);
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 path, 1474 path,
1443 &error)); 1475 &error));
1444 if (error) 1476 if (error)
1445 return error; 1477 return error;
1446 if (!file_util::ReadFileToString(path, png)) 1478 if (!file_util::ReadFileToString(path, png))
1447 return new Error(kUnknownError, "Could not read screenshot file"); 1479 return new Error(kUnknownError, "Could not read screenshot file");
1448 return NULL; 1480 return NULL;
1449 } 1481 }
1450 1482
1451 } // namespace webdriver 1483 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/session.h ('k') | chrome/test/webdriver/test/WEBDRIVER_TESTS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698