OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/commands/webelement_commands.h" | 5 #include "chrome/test/webdriver/commands/webelement_commands.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/test/webdriver/commands/response.h" | 15 #include "chrome/test/webdriver/commands/response.h" |
16 #include "chrome/test/webdriver/webdriver_basic_types.h" | 16 #include "chrome/test/webdriver/webdriver_basic_types.h" |
17 #include "chrome/test/webdriver/webdriver_error.h" | 17 #include "chrome/test/webdriver/webdriver_error.h" |
18 #include "chrome/test/webdriver/webdriver_session.h" | 18 #include "chrome/test/webdriver/webdriver_session.h" |
19 #include "chrome/test/webdriver/webdriver_util.h" | 19 #include "chrome/test/webdriver/webdriver_util.h" |
20 #include "third_party/webdriver/atoms.h" | 20 #include "third_party/webdriver/atoms.h" |
21 | 21 |
22 namespace webdriver { | 22 namespace webdriver { |
23 | 23 |
24 ///////////////////// WebElementCommand //////////////////// | 24 ///////////////////// WebElementCommand //////////////////// |
25 | 25 |
26 WebElementCommand::WebElementCommand( | 26 WebElementCommand::WebElementCommand( |
27 const std::vector<std::string>& path_segments, | 27 const std::vector<std::string>& path_segments, |
28 const DictionaryValue* const parameters) | 28 DictionaryValue* const parameters) |
29 : WebDriverCommand(path_segments, parameters), | 29 : WebDriverCommand(path_segments, parameters), |
30 path_segments_(path_segments) {} | 30 path_segments_(path_segments) {} |
31 | 31 |
32 WebElementCommand::~WebElementCommand() {} | 32 WebElementCommand::~WebElementCommand() {} |
33 | 33 |
34 bool WebElementCommand::Init(Response* const response) { | 34 bool WebElementCommand::Init(Response* const response) { |
35 if (!WebDriverCommand::Init(response)) | 35 if (!WebDriverCommand::Init(response)) |
36 return false; | 36 return false; |
37 | 37 |
38 // There should be at least 5 segments to match | 38 // There should be at least 5 segments to match |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 if (scoped_value->GetAsString(&actual_value)) { | 524 if (scoped_value->GetAsString(&actual_value)) { |
525 *result = LowerCaseEqualsASCII(actual_value, value.c_str()); | 525 *result = LowerCaseEqualsASCII(actual_value, value.c_str()); |
526 } else { | 526 } else { |
527 // Note we do not handle converting a number to a string. | 527 // Note we do not handle converting a number to a string. |
528 *result = false; | 528 *result = false; |
529 } | 529 } |
530 return NULL; | 530 return NULL; |
531 } | 531 } |
532 | 532 |
533 Error* ElementValueCommand::DragAndDropFilePaths() const { | 533 Error* ElementValueCommand::DragAndDropFilePaths() const { |
534 ListValue* path_list; | 534 const ListValue* path_list; |
535 if (!GetListParameter("value", &path_list)) | 535 if (!GetListParameter("value", &path_list)) |
536 return new Error(kBadRequest, "Missing or invalid 'value' parameter"); | 536 return new Error(kBadRequest, "Missing or invalid 'value' parameter"); |
537 | 537 |
538 // Compress array into single string. | 538 // Compress array into single string. |
539 FilePath::StringType paths_string; | 539 FilePath::StringType paths_string; |
540 for (size_t i = 0; i < path_list->GetSize(); ++i) { | 540 for (size_t i = 0; i < path_list->GetSize(); ++i) { |
541 FilePath::StringType path_part; | 541 FilePath::StringType path_part; |
542 if (!path_list->GetString(i, &path_part)) { | 542 if (!path_list->GetString(i, &path_part)) { |
543 return new Error( | 543 return new Error( |
544 kBadRequest, | 544 kBadRequest, |
(...skipping 27 matching lines...) Expand all Loading... |
572 | 572 |
573 Point location; | 573 Point location; |
574 error = session_->GetClickableLocation(element, &location); | 574 error = session_->GetClickableLocation(element, &location); |
575 if (error) | 575 if (error) |
576 return error; | 576 return error; |
577 | 577 |
578 return session_->DragAndDropFilePaths(location, paths); | 578 return session_->DragAndDropFilePaths(location, paths); |
579 } | 579 } |
580 | 580 |
581 Error* ElementValueCommand::SendKeys() const { | 581 Error* ElementValueCommand::SendKeys() const { |
582 ListValue* key_list; | 582 const ListValue* key_list; |
583 if (!GetListParameter("value", &key_list)) { | 583 if (!GetListParameter("value", &key_list)) { |
584 return new Error(kBadRequest, "Missing or invalid 'value' parameter"); | 584 return new Error(kBadRequest, "Missing or invalid 'value' parameter"); |
585 } | 585 } |
586 | 586 |
587 // Flatten the given array of strings into one. | 587 // Flatten the given array of strings into one. |
588 string16 keys; | 588 string16 keys; |
589 Error* error = FlattenStringArray(key_list, &keys); | 589 Error* error = FlattenStringArray(key_list, &keys); |
590 if (error) | 590 if (error) |
591 return error; | 591 return error; |
592 | 592 |
(...skipping 30 matching lines...) Expand all Loading... |
623 return; | 623 return; |
624 } | 624 } |
625 if (!result->IsType(Value::TYPE_STRING)) { | 625 if (!result->IsType(Value::TYPE_STRING)) { |
626 response->SetError(new Error(kUnknownError, "Result is not string type")); | 626 response->SetError(new Error(kUnknownError, "Result is not string type")); |
627 return; | 627 return; |
628 } | 628 } |
629 response->SetValue(result.release()); | 629 response->SetValue(result.release()); |
630 } | 630 } |
631 | 631 |
632 } // namespace webdriver | 632 } // namespace webdriver |
OLD | NEW |