OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_TEST_WEBDRIVER_WEBDRIVER_ELEMENT_ID_H_ | |
6 #define CHROME_TEST_WEBDRIVER_WEBDRIVER_ELEMENT_ID_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "chrome/test/automation/value_conversion_traits.h" | |
11 | |
12 namespace base { | |
13 class Value; | |
14 } | |
15 | |
16 namespace webdriver { | |
17 | |
18 // This class represents a WebDriver Element ID. These IDs are mapped to | |
19 // objects in a page in JavaScript. | |
20 class ElementId { | |
21 public: | |
22 // Creates an invalid ElementId. | |
23 ElementId(); | |
24 | |
25 // Creates a valid |ElementId| using the ID of an element. An empty string | |
26 // can be used to refer to the root document of the page. | |
27 explicit ElementId(const std::string& id); | |
28 | |
29 // Creates a |ElementId| from an element dictionary returned by a WebDriver | |
30 // atom. It will be valid iff the dictionary is correctly constructed. | |
31 explicit ElementId(const base::Value* value); | |
32 | |
33 ~ElementId(); | |
34 | |
35 // Returns the appropriate |Value| type to be used to identify the element | |
36 // to a WebDriver atom. The client takes ownership. | |
37 base::Value* ToValue() const; | |
38 | |
39 // Returns whether this ID is valid. Even if the ID is valid, it may not refer | |
40 // to a valid ID on the page. | |
41 bool is_valid() const; | |
42 | |
43 private: | |
44 std::string id_; | |
45 bool is_valid_; | |
46 }; | |
47 | |
48 // WebDriver element locators. These constants are used to identify different | |
49 // ways to locate an element to WebDriver atoms. Struct is used for grouping | |
50 // purposes. | |
51 struct LocatorType { | |
52 static const char kClassName[]; | |
53 static const char kCss[]; | |
54 static const char kId[]; | |
55 static const char kLinkText[]; | |
56 static const char kName[]; | |
57 static const char kPartialLinkText[]; | |
58 static const char kTagName[]; | |
59 static const char kXpath[]; | |
60 }; | |
61 | |
62 } // namespace webdriver | |
63 | |
64 template <> | |
65 struct ValueConversionTraits<webdriver::ElementId> { | |
66 static base::Value* CreateValueFrom(const webdriver::ElementId& t); | |
67 static bool SetFromValue( | |
68 const base::Value* value, webdriver::ElementId* t); | |
69 static bool CanConvert(const base::Value* value); | |
70 }; | |
71 | |
72 #endif // CHROME_TEST_WEBDRIVER_WEBDRIVER_ELEMENT_ID_H_ | |
OLD | NEW |