1// Copyright (c) 2012 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/commands/command.h"
6
7namespace webdriver {
8
9Command::Command(const std::vector<std::string>& path_segments,
10                 const DictionaryValue* const parameters)
11    : path_segments_(path_segments),
12      parameters_(parameters) {}
13
14Command::~Command() {}
15
16bool Command::DoesDelete() {
17  return false;
18}
19
20bool Command::DoesGet() {
21  return false;
22}
23
24bool Command::DoesPost() {
25  return false;
26}
27
28bool Command::Init(Response* const response) {
29  return true;
30}
31
32void Command::Finish(Response* const response) {}
33
34std::string Command::GetPathVariable(const size_t i) const {
35  return i < path_segments_.size() ? path_segments_.at(i) : std::string();
36}
37
38bool Command::HasParameter(const std::string& key) const {
39  return parameters_.get() && parameters_->HasKey(key);
40}
41
42bool Command::IsNullParameter(const std::string& key) const {
43  const Value* value;
44  return parameters_.get() &&
45         parameters_->Get(key, &value) &&
46         value->IsType(Value::TYPE_NULL);
47}
48
49bool Command::GetStringParameter(const std::string& key,
50                                 string16* out) const {
51  return parameters_.get() != NULL && parameters_->GetString(key, out);
52}
53
54bool Command::GetStringParameter(const std::string& key,
55                                 std::string* out) const {
56  return parameters_.get() != NULL && parameters_->GetString(key, out);
57}
58
59bool Command::GetStringASCIIParameter(const std::string& key,
60                                      std::string* out) const {
61  return parameters_.get() != NULL && parameters_->GetStringASCII(key, out);
62}
63
64bool Command::GetBooleanParameter(const std::string& key,
65                                  bool* out) const {
66  return parameters_.get() != NULL && parameters_->GetBoolean(key, out);
67}
68
69bool Command::GetIntegerParameter(const std::string& key,
70                                  int* out) const {
71  return parameters_.get() != NULL && parameters_->GetInteger(key, out);
72}
73
74bool Command::GetDoubleParameter(const std::string& key, double* out) const {
75  return parameters_.get() != NULL && parameters_->GetDouble(key, out);
76}
77
78bool Command::GetDictionaryParameter(const std::string& key,
79                                     const DictionaryValue** out) const {
80  return parameters_.get() != NULL && parameters_->GetDictionary(key, out);
81}
82
83bool Command::GetListParameter(const std::string& key,
84                               const ListValue** out) const {
85  return parameters_.get() != NULL && parameters_->GetList(key, out);
86}
87
88}  // namespace webdriver
89