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

Side by Side Diff: chrome/test/webdriver/web_element_id.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: rebase 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/web_element_id.h ('k') | chrome/test/webdriver/webdriver_basic_types.h » ('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/web_element_id.h" 5 #include "chrome/test/webdriver/web_element_id.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/test/automation/javascript_message_utils.h"
9 10
10 namespace { 11 namespace {
11 12
12 // Special dictionary key to identify an element ID to WebDriver atoms and 13 // Special dictionary key to identify an element ID to WebDriver atoms and
13 // remote clients. 14 // remote clients.
14 const char kWebElementKey[] = "ELEMENT"; 15 const char kWebElementKey[] = "ELEMENT";
15 16
16 } // namespace 17 } // namespace
17 18
18 namespace webdriver { 19 namespace webdriver {
19 20
20 const char LocatorType::kClassName[] = "className"; 21 const char LocatorType::kClassName[] = "className";
21 const char LocatorType::kCss[] = "css"; 22 const char LocatorType::kCss[] = "css";
22 const char LocatorType::kId[] = "id"; 23 const char LocatorType::kId[] = "id";
23 const char LocatorType::kLinkText[] = "linkText"; 24 const char LocatorType::kLinkText[] = "linkText";
24 const char LocatorType::kName[] = "name"; 25 const char LocatorType::kName[] = "name";
25 const char LocatorType::kPartialLinkText[] = "partialLinkText"; 26 const char LocatorType::kPartialLinkText[] = "partialLinkText";
26 const char LocatorType::kTagName[] = "tagName"; 27 const char LocatorType::kTagName[] = "tagName";
27 const char LocatorType::kXpath[] = "xpath"; 28 const char LocatorType::kXpath[] = "xpath";
28 29
29 WebElementId::WebElementId() : is_valid_(false) {} 30 WebElementId::WebElementId() : is_valid_(false) {}
30 31
31 WebElementId::WebElementId(const std::string& id) : id_(id), is_valid_(true) {} 32 WebElementId::WebElementId(const std::string& id) : id_(id), is_valid_(true) {}
32 33
33 WebElementId::WebElementId(Value* value) { 34 WebElementId::WebElementId(const Value* value) {
34 is_valid_ = false; 35 is_valid_ = false;
35 if (value->IsType(Value::TYPE_DICTIONARY)) { 36 if (value->IsType(Value::TYPE_DICTIONARY)) {
36 is_valid_ = static_cast<DictionaryValue*>(value)-> 37 is_valid_ = static_cast<const DictionaryValue*>(value)->
37 GetString(kWebElementKey, &id_); 38 GetString(kWebElementKey, &id_);
38 } 39 }
39 } 40 }
40 41
41 WebElementId::~WebElementId() {} 42 WebElementId::~WebElementId() {}
42 43
43 Value* WebElementId::ToValue() const { 44 Value* WebElementId::ToValue() const {
44 CHECK(is_valid_); 45 CHECK(is_valid_);
45 if (id_.empty()) 46 if (id_.empty())
46 return Value::CreateNullValue(); 47 return Value::CreateNullValue();
47 DictionaryValue* element = new DictionaryValue(); 48 DictionaryValue* element = new DictionaryValue();
48 element->SetString(kWebElementKey, id_); 49 element->SetString(kWebElementKey, id_);
49 return element; 50 return element;
50 } 51 }
51 52
52 bool WebElementId::is_valid() const { 53 bool WebElementId::is_valid() const {
53 return is_valid_; 54 return is_valid_;
54 } 55 }
55 56
56 } // namespace webdriver 57 } // namespace webdriver
58
59 base::Value* ValueConversionTraits<webdriver::WebElementId>::CreateValueFrom(
60 const webdriver::WebElementId& t) {
61 return t.ToValue();
62 }
63
64 bool ValueConversionTraits<webdriver::WebElementId>::SetFromValue(
65 const base::Value* value, webdriver::WebElementId* t) {
66 webdriver::WebElementId id(value);
67 if (id.is_valid())
68 *t = id;
69 return id.is_valid();
70 }
71
72 bool ValueConversionTraits<webdriver::WebElementId>::CanConvert(
73 const base::Value* value) {
74 webdriver::WebElementId t;
75 return SetFromValue(value, &t);
76 }
OLDNEW
« no previous file with comments | « chrome/test/webdriver/web_element_id.h ('k') | chrome/test/webdriver/webdriver_basic_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698