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.
5 #include "chrome/test/webdriver/frame_path.h"
7 #include "base/string_split.h"
11 FramePath::FramePath() : path_("") {}
13 FramePath::FramePath(const FramePath
& other
) : path_(other
.path_
) {}
15 FramePath::FramePath(const std::string
& path
) : path_(path
) {}
17 FramePath::~FramePath() {}
19 FramePath
& FramePath::operator=(const FramePath
& other
) {
24 bool FramePath::operator==(const FramePath
& other
) const {
25 return path_
== other
.path_
;
28 FramePath
FramePath::Append(const FramePath
& path
) const {
29 return Append(path
.path_
);
32 FramePath
FramePath::Append(const std::string
& path
) const {
33 // An empty path refers to the root frame, so just return it.
37 // Don't append a separator if the current path is empty.
38 std::string new_path
= path_
;
41 return FramePath(new_path
+ path
);
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
));
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));
58 void FramePath::GetComponents(std::vector
<std::string
>* components
) const {
60 base::SplitString(path_
, '\n', components
);
63 bool FramePath::IsRootFrame() const {
67 bool FramePath::IsSubframe() const {
68 return path_
.length();
71 const std::string
& FramePath::value() const {
75 } // namespace webdriver