Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/chromedriver/capabilities.h" | 5 #include "chrome/test/chromedriver/capabilities.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/test/chromedriver/chrome/status.h" | 14 #include "chrome/test/chromedriver/chrome/status.h" |
| 15 #include "chrome/test/chromedriver/logging.h" | |
|
kkania
2013/04/18 20:27:55
you can drop this now
klm
2013/04/18 22:53:34
Done.
| |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 typedef base::Callback<Status(const base::Value&, Capabilities*)> Parser; | 19 typedef base::Callback<Status(const base::Value&, Capabilities*)> Parser; |
| 19 | 20 |
| 20 Status ParseChromeBinary( | 21 Status ParseChromeBinary( |
| 21 const base::Value& option, | 22 const base::Value& option, |
| 22 Capabilities* capabilities) { | 23 Capabilities* capabilities) { |
| 23 base::FilePath::StringType path_str; | 24 base::FilePath::StringType path_str; |
| 24 if (!option.GetAsString(&path_str)) | 25 if (!option.GetAsString(&path_str)) |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 if (!android_package_value->GetAsString(&capabilities->android_package) || | 195 if (!android_package_value->GetAsString(&capabilities->android_package) || |
| 195 capabilities->android_package.empty()) { | 196 capabilities->android_package.empty()) { |
| 196 return Status(kUnknownError, | 197 return Status(kUnknownError, |
| 197 "'androidPackage' must be a non-empty string"); | 198 "'androidPackage' must be a non-empty string"); |
| 198 } | 199 } |
| 199 } | 200 } |
| 200 } | 201 } |
| 201 return Status(kOk); | 202 return Status(kOk); |
| 202 } | 203 } |
| 203 | 204 |
| 205 Status ParseLoggingPrefs(const base::Value& option, | |
| 206 Capabilities* capabilities) { | |
| 207 const base::DictionaryValue* logging_prefs; | |
| 208 if (!option.GetAsDictionary(&logging_prefs)) | |
| 209 return Status(kUnknownError, "'loggingPrefs' must be a dictionary"); | |
| 210 // TODO(klm): verify log types. | |
| 211 // TODO(klm): verify log levels. | |
| 212 capabilities->logging_prefs.reset(logging_prefs->DeepCopy()); | |
| 213 return Status(kOk); | |
| 214 } | |
| 215 | |
| 204 } // namespace | 216 } // namespace |
| 205 | 217 |
| 206 Capabilities::Capabilities() : command(CommandLine::NO_PROGRAM) {} | 218 Capabilities::Capabilities() : command(CommandLine::NO_PROGRAM) {} |
| 207 | 219 |
| 208 Capabilities::~Capabilities() {} | 220 Capabilities::~Capabilities() {} |
| 209 | 221 |
| 210 bool Capabilities::IsAndroid() const { | 222 bool Capabilities::IsAndroid() const { |
| 211 return !android_package.empty(); | 223 return !android_package.empty(); |
| 212 } | 224 } |
| 213 | 225 |
| 214 Status Capabilities::Parse(const base::DictionaryValue& desired_caps) { | 226 Status Capabilities::Parse(const base::DictionaryValue& desired_caps) { |
| 215 Status status = ParseAndroidChromeCapabilities(desired_caps, this); | 227 Status status = ParseAndroidChromeCapabilities(desired_caps, this); |
| 216 if (status.IsError()) | 228 if (status.IsError()) |
| 217 return status; | 229 return status; |
| 218 if (IsAndroid()) | 230 if (IsAndroid()) |
| 219 return Status(kOk); | 231 return Status(kOk); |
| 220 | 232 |
| 221 std::map<std::string, Parser> parser_map; | 233 std::map<std::string, Parser> parser_map; |
| 222 parser_map["proxy"] = base::Bind(&ParseProxy); | 234 parser_map["proxy"] = base::Bind(&ParseProxy); |
| 223 parser_map["chromeOptions"] = base::Bind(&ParseDesktopChromeOption); | 235 parser_map["chromeOptions"] = base::Bind(&ParseDesktopChromeOption); |
| 236 parser_map["loggingPrefs"] = base::Bind(&ParseLoggingPrefs); | |
|
klm
2013/04/18 22:53:34
Notice how I changed the way I parse logging prefs
| |
| 224 for (std::map<std::string, Parser>::iterator it = parser_map.begin(); | 237 for (std::map<std::string, Parser>::iterator it = parser_map.begin(); |
| 225 it != parser_map.end(); ++it) { | 238 it != parser_map.end(); ++it) { |
| 226 const base::Value* capability = NULL; | 239 const base::Value* capability = NULL; |
| 227 if (desired_caps.Get(it->first, &capability)) { | 240 if (desired_caps.Get(it->first, &capability)) { |
| 228 status = it->second.Run(*capability, this); | 241 status = it->second.Run(*capability, this); |
| 229 if (status.IsError()) | 242 if (status.IsError()) |
| 230 return status; | 243 return status; |
| 231 } | 244 } |
| 232 } | 245 } |
| 233 return Status(kOk); | 246 return Status(kOk); |
| 234 } | 247 } |
| OLD | NEW |