summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver/frame_path.cc
blob: fd45a8d21c6415c5d443e57fa8f83336e0122ed5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/test/webdriver/frame_path.h"

#include "base/strings/string_split.h"

namespace webdriver {

FramePath::FramePath() {}

FramePath::FramePath(const FramePath& other) : path_(other.path_) {}

FramePath::FramePath(const std::string& path) : path_(path) {}

FramePath::~FramePath() {}

FramePath& FramePath::operator=(const FramePath& other) {
  path_ = other.path_;
  return *this;
}

bool FramePath::operator==(const FramePath& other) const {
  return path_ == other.path_;
}

FramePath FramePath::Append(const FramePath& path) const {
  return Append(path.path_);
}

FramePath FramePath::Append(const std::string& path) const {
  // An empty path refers to the root frame, so just return it.
  if (path.empty())
    return *this;

  // Don't append a separator if the current path is empty.
  std::string new_path = path_;
  if (path_.length())
    new_path += "\n";
  return FramePath(new_path + path);
}

FramePath FramePath::Parent() const {
  size_t i = path_.find_last_of("\n");
  if (i != std::string::npos)
    return FramePath(path_.substr(0, i));
  return FramePath();
}

FramePath FramePath::BaseName() const {
  size_t i = path_.find_last_of("\n");
  if (i != std::string::npos)
    return FramePath(path_.substr(i + 1));
  return *this;
}

void FramePath::GetComponents(std::vector<std::string>* components) const {
  if (IsSubframe())
    base::SplitString(path_, '\n', components);
}

bool FramePath::IsRootFrame() const {
  return path_.empty();
}

bool FramePath::IsSubframe() const {
  return path_.length();
}

const std::string& FramePath::value() const {
  return path_;
}

}  // namespace webdriver