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

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

Issue 7522024: Refactor chromedriver's script execution to reduce amount of custom Value parsing. (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
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_util.h" 10 #include "base/string_util.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/third_party/icu/icu_utf.h" 12 #include "base/third_party/icu/icu_utf.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/test/webdriver/commands/response.h" 14 #include "chrome/test/webdriver/commands/response.h"
15 #include "chrome/test/webdriver/session.h" 15 #include "chrome/test/webdriver/session.h"
16 #include "chrome/test/webdriver/webdriver_basic_types.h"
16 #include "chrome/test/webdriver/webdriver_error.h" 17 #include "chrome/test/webdriver/webdriver_error.h"
17 #include "third_party/webdriver/atoms.h" 18 #include "third_party/webdriver/atoms.h"
18 #include "ui/gfx/point.h"
19 #include "ui/gfx/size.h"
20 19
21 namespace webdriver { 20 namespace webdriver {
22 21
23 ///////////////////// WebElementCommand //////////////////// 22 ///////////////////// WebElementCommand ////////////////////
24 23
25 WebElementCommand::WebElementCommand( 24 WebElementCommand::WebElementCommand(
26 const std::vector<std::string>& path_segments, 25 const std::vector<std::string>& path_segments,
27 const DictionaryValue* const parameters) 26 const DictionaryValue* const parameters)
28 : WebDriverCommand(path_segments, parameters), 27 : WebDriverCommand(path_segments, parameters),
29 path_segments_(path_segments) {} 28 path_segments_(path_segments) {}
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 DictionaryValue* parameters) 272 DictionaryValue* parameters)
274 : WebElementCommand(path_segments, parameters) {} 273 : WebElementCommand(path_segments, parameters) {}
275 274
276 ElementLocationInViewCommand::~ElementLocationInViewCommand() {} 275 ElementLocationInViewCommand::~ElementLocationInViewCommand() {}
277 276
278 bool ElementLocationInViewCommand::DoesGet() { 277 bool ElementLocationInViewCommand::DoesGet() {
279 return true; 278 return true;
280 } 279 }
281 280
282 void ElementLocationInViewCommand::ExecuteGet(Response* const response) { 281 void ElementLocationInViewCommand::ExecuteGet(Response* const response) {
283 gfx::Point location; 282 Point location;
284 Error* error = session_->GetElementLocationInView(element, &location); 283 Error* error = session_->GetElementLocationInView(element, &location);
285 if (error) { 284 if (error) {
286 response->SetError(error); 285 response->SetError(error);
287 return; 286 return;
288 } 287 }
289 DictionaryValue* coord_dict = new DictionaryValue(); 288 DictionaryValue* coord_dict = new DictionaryValue();
290 coord_dict->SetInteger("x", location.x()); 289 coord_dict->SetInteger("x", location.x());
291 coord_dict->SetInteger("y", location.y()); 290 coord_dict->SetInteger("y", location.y());
292 response->SetValue(coord_dict); 291 response->SetValue(coord_dict);
293 } 292 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 DictionaryValue* parameters) 364 DictionaryValue* parameters)
366 : WebElementCommand(path_segments, parameters) {} 365 : WebElementCommand(path_segments, parameters) {}
367 366
368 ElementSizeCommand::~ElementSizeCommand() {} 367 ElementSizeCommand::~ElementSizeCommand() {}
369 368
370 bool ElementSizeCommand::DoesGet() { 369 bool ElementSizeCommand::DoesGet() {
371 return true; 370 return true;
372 } 371 }
373 372
374 void ElementSizeCommand::ExecuteGet(Response* const response) { 373 void ElementSizeCommand::ExecuteGet(Response* const response) {
375 gfx::Size size; 374 Size size;
376 Error* error = session_->GetElementSize( 375 Error* error = session_->GetElementSize(
377 session_->current_target(), element, &size); 376 session_->current_target(), element, &size);
378 if (error) { 377 if (error) {
379 response->SetError(error); 378 response->SetError(error);
380 return; 379 return;
381 } 380 }
382 DictionaryValue* dict = new DictionaryValue(); 381 DictionaryValue* dict = new DictionaryValue();
383 dict->SetInteger("width", size.width()); 382 dict->SetInteger("width", size.width());
384 dict->SetInteger("height", size.height()); 383 dict->SetInteger("height", size.height());
385 response->SetValue(dict); 384 response->SetValue(dict);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 if (!file_util::PathExists(FilePath(path))) { 562 if (!file_util::PathExists(FilePath(path))) {
564 return new Error( 563 return new Error(
565 kBadRequest, 564 kBadRequest,
566 base::StringPrintf("'%s' does not exist on the file system", 565 base::StringPrintf("'%s' does not exist on the file system",
567 path.c_str())); 566 path.c_str()));
568 } 567 }
569 568
570 paths.push_back(path); 569 paths.push_back(path);
571 } 570 }
572 571
573 gfx::Point location; 572 Point location;
574 error = session_->GetClickableLocation(element, &location); 573 error = session_->GetClickableLocation(element, &location);
575 if (error) { 574 if (error) {
576 return error; 575 return error;
577 } 576 }
578 577
579 return session_->DragAndDropFilePaths(location, paths); 578 return session_->DragAndDropFilePaths(location, paths);
580 } 579 }
581 580
582 Error* ElementValueCommand::SendKeys() const { 581 Error* ElementValueCommand::SendKeys() const {
583 ListValue* key_list; 582 ListValue* key_list;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 return; 630 return;
632 } 631 }
633 if (!result->IsType(Value::TYPE_STRING)) { 632 if (!result->IsType(Value::TYPE_STRING)) {
634 response->SetError(new Error(kUnknownError, "Result is not string type")); 633 response->SetError(new Error(kUnknownError, "Result is not string type"));
635 return; 634 return;
636 } 635 }
637 response->SetValue(result.release()); 636 response->SetValue(result.release());
638 } 637 }
639 638
640 } // namespace webdriver 639 } // namespace webdriver
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698