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 #include "chrome/test/webdriver/frame_path.h" | |
6 | |
7 #include "base/strings/string_split.h" | |
8 | |
9 namespace webdriver { | |
10 | |
11 FramePath::FramePath() {} | |
12 | |
13 FramePath::FramePath(const FramePath& other) : path_(other.path_) {} | |
14 | |
15 FramePath::FramePath(const std::string& path) : path_(path) {} | |
16 | |
17 FramePath::~FramePath() {} | |
18 | |
19 FramePath& FramePath::operator=(const FramePath& other) { | |
20 path_ = other.path_; | |
21 return *this; | |
22 } | |
23 | |
24 bool FramePath::operator==(const FramePath& other) const { | |
25 return path_ == other.path_; | |
26 } | |
27 | |
28 FramePath FramePath::Append(const FramePath& path) const { | |
29 return Append(path.path_); | |
30 } | |
31 | |
32 FramePath FramePath::Append(const std::string& path) const { | |
33 // An empty path refers to the root frame, so just return it. | |
34 if (path.empty()) | |
35 return *this; | |
36 | |
37 // Don't append a separator if the current path is empty. | |
38 std::string new_path = path_; | |
39 if (path_.length()) | |
40 new_path += "\n"; | |
41 return FramePath(new_path + path); | |
42 } | |
43 | |
44 FramePath FramePath::Parent() const { | |
45 size_t i = path_.find_last_of("\n"); | |
46 if (i != std::string::npos) | |
47 return FramePath(path_.substr(0, i)); | |
48 return FramePath(); | |
49 } | |
50 | |
51 FramePath FramePath::BaseName() const { | |
52 size_t i = path_.find_last_of("\n"); | |
53 if (i != std::string::npos) | |
54 return FramePath(path_.substr(i + 1)); | |
55 return *this; | |
56 } | |
57 | |
58 void FramePath::GetComponents(std::vector<std::string>* components) const { | |
59 if (IsSubframe()) | |
60 base::SplitString(path_, '\n', components); | |
61 } | |
62 | |
63 bool FramePath::IsRootFrame() const { | |
64 return path_.empty(); | |
65 } | |
66 | |
67 bool FramePath::IsSubframe() const { | |
68 return path_.length(); | |
69 } | |
70 | |
71 const std::string& FramePath::value() const { | |
72 return path_; | |
73 } | |
74 | |
75 } // namespace webdriver | |
OLD | NEW |