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

Side by Side Diff: chrome/test/webdriver/commands/webelement_commands.cc

Issue 7701010: Fix file uploads in chromedriver. It should not be assumed that multiple file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 3 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 | « no previous file | chrome/test/webdriver/test/chromedriver_tests.py » ('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/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_util.h" 11 #include "base/string_util.h"
11 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
12 #include "base/third_party/icu/icu_utf.h" 13 #include "base/third_party/icu/icu_utf.h"
14 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 15 #include "base/values.h"
14 #include "chrome/test/webdriver/commands/response.h" 16 #include "chrome/test/webdriver/commands/response.h"
15 #include "chrome/test/webdriver/webdriver_basic_types.h" 17 #include "chrome/test/webdriver/webdriver_basic_types.h"
16 #include "chrome/test/webdriver/webdriver_error.h" 18 #include "chrome/test/webdriver/webdriver_error.h"
17 #include "chrome/test/webdriver/webdriver_session.h" 19 #include "chrome/test/webdriver/webdriver_session.h"
20 #include "chrome/test/webdriver/webdriver_util.h"
18 #include "third_party/webdriver/atoms.h" 21 #include "third_party/webdriver/atoms.h"
19 22
20 namespace webdriver { 23 namespace webdriver {
21 24
22 ///////////////////// WebElementCommand //////////////////// 25 ///////////////////// WebElementCommand ////////////////////
23 26
24 WebElementCommand::WebElementCommand( 27 WebElementCommand::WebElementCommand(
25 const std::vector<std::string>& path_segments, 28 const std::vector<std::string>& path_segments,
26 const DictionaryValue* const parameters) 29 const DictionaryValue* const parameters)
27 : WebDriverCommand(path_segments, parameters), 30 : WebDriverCommand(path_segments, parameters),
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 if (scoped_value->GetAsString(&actual_value)) { 525 if (scoped_value->GetAsString(&actual_value)) {
523 *result = LowerCaseEqualsASCII(actual_value, value.c_str()); 526 *result = LowerCaseEqualsASCII(actual_value, value.c_str());
524 } else { 527 } else {
525 // Note we do not handle converting a number to a string. 528 // Note we do not handle converting a number to a string.
526 *result = false; 529 *result = false;
527 } 530 }
528 return NULL; 531 return NULL;
529 } 532 }
530 533
531 Error* ElementValueCommand::DragAndDropFilePaths() const { 534 Error* ElementValueCommand::DragAndDropFilePaths() const {
535 ListValue* path_list;
536 if (!GetListParameter("value", &path_list))
537 return new Error(kBadRequest, "Missing or invalid 'value' parameter");
538
539 // Compress array into single string.
540 FilePath::StringType paths_string;
541 for (size_t i = 0; i < path_list->GetSize(); ++i) {
542 FilePath::StringType path_part;
543 if (!path_list->GetString(i, &path_part)) {
544 return new Error(
545 kBadRequest,
546 "'value' is invalid: " + JsonStringify(path_list));
547 }
548 paths_string.append(path_part);
549 }
550
551 // Separate the string into separate paths, delimited by \n.
552 std::vector<FilePath::StringType> paths;
553 base::SplitString(paths_string, '\n', &paths);
Huyen 2011/08/23 22:10:44 why not just directly go from array to vector of s
kkania 2011/08/25 20:16:58 not sure what you mean: The input is an array of
554
555 // Return an error if trying to drop multiple paths on a single file input.
532 bool multiple = false; 556 bool multiple = false;
533 Error* error = HasAttributeWithLowerCaseValueASCII("multiple", "true", 557 Error* error = HasAttributeWithLowerCaseValueASCII("multiple", "true",
534 &multiple); 558 &multiple);
559 if (error)
560 return error;
561 if (!multiple && paths.size() > 1)
562 return new Error(kBadRequest, "The element can not hold multiple files");
535 563
536 if (error) { 564 // Check the files exist.
537 return error; 565 for (size_t i = 0; i < paths.size(); ++i) {
538 } 566 if (!file_util::PathExists(FilePath(paths[i]))) {
539
540 ListValue* path_list;
541 if (!GetListParameter("value", &path_list)) {
542 return new Error(kBadRequest, "Missing or invalid 'value' parameter");
543 }
544
545 if (!multiple && path_list->GetSize() > 1) {
546 return new Error(kBadRequest, "The element can not hold multiple files");
547 }
548
549 std::vector<FilePath::StringType> paths;
550 for (size_t i = 0; i < path_list->GetSize(); ++i) {
551 FilePath::StringType path;
552 if (!path_list->GetString(i, &path)) {
553 return new Error(
554 kBadRequest,
555 base::StringPrintf("'value' list item #%" PRIuS " is not a string",
556 i + 1));
557 }
558
559 if (!file_util::PathExists(FilePath(path))) {
560 return new Error( 567 return new Error(
561 kBadRequest, 568 kBadRequest,
562 base::StringPrintf("'%s' does not exist on the file system", 569 base::StringPrintf("'%s' does not exist on the file system",
563 path.c_str())); 570 UTF16ToUTF8(FilePath(paths[i]).LossyDisplayName()).c_str()));
564 } 571 }
565
566 paths.push_back(path);
567 } 572 }
568 573
569 Point location; 574 Point location;
570 error = session_->GetClickableLocation(element, &location); 575 error = session_->GetClickableLocation(element, &location);
571 if (error) { 576 if (error)
572 return error; 577 return error;
573 }
574 578
575 return session_->DragAndDropFilePaths(location, paths); 579 return session_->DragAndDropFilePaths(location, paths);
576 } 580 }
577 581
578 Error* ElementValueCommand::SendKeys() const { 582 Error* ElementValueCommand::SendKeys() const {
579 ListValue* key_list; 583 ListValue* key_list;
580 if (!GetListParameter("value", &key_list)) { 584 if (!GetListParameter("value", &key_list)) {
581 return new Error(kBadRequest, "Missing or invalid 'value' parameter"); 585 return new Error(kBadRequest, "Missing or invalid 'value' parameter");
582 } 586 }
583 587
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 return; 632 return;
629 } 633 }
630 if (!result->IsType(Value::TYPE_STRING)) { 634 if (!result->IsType(Value::TYPE_STRING)) {
631 response->SetError(new Error(kUnknownError, "Result is not string type")); 635 response->SetError(new Error(kUnknownError, "Result is not string type"));
632 return; 636 return;
633 } 637 }
634 response->SetValue(result.release()); 638 response->SetValue(result.release());
635 } 639 }
636 640
637 } // namespace webdriver 641 } // namespace webdriver
OLDNEW
« no previous file with comments | « no previous file | chrome/test/webdriver/test/chromedriver_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698