Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: chrome/test/webdriver/webdriver_capabilities_parser.cc

Issue 8890026: Allow chromedriver to set local state preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/webdriver/webdriver_capabilities_parser.h" 5 #include "chrome/test/webdriver/webdriver_capabilities_parser.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 15 matching lines...) Expand all
26 return new Error(kBadRequest, base::StringPrintf( 26 return new Error(kBadRequest, base::StringPrintf(
27 "%s must be of type %s, not %s. Received: %s", 27 "%s must be of type %s, not %s. Received: %s",
28 name.c_str(), GetJsonTypeName(type), 28 name.c_str(), GetJsonTypeName(type),
29 GetJsonTypeName(option->GetType()), 29 GetJsonTypeName(option->GetType()),
30 JsonStringifyForDisplay(option).c_str())); 30 JsonStringifyForDisplay(option).c_str()));
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 Capabilities::Capabilities() 35 Capabilities::Capabilities()
36 : command(CommandLine::NO_PROGRAM), 36 : cert_revocation_checking(true),
37 command(CommandLine::NO_PROGRAM),
37 detach(false), 38 detach(false),
38 load_async(false), 39 load_async(false),
39 native_events(false), 40 native_events(false),
40 verbose(false) { } 41 verbose(false) { }
41 42
42 Capabilities::~Capabilities() { } 43 Capabilities::~Capabilities() { }
43 44
44 CapabilitiesParser::CapabilitiesParser( 45 CapabilitiesParser::CapabilitiesParser(
45 const base::DictionaryValue* capabilities_dict, 46 const base::DictionaryValue* capabilities_dict,
46 const FilePath& root_path, 47 const FilePath& root_path,
(...skipping 24 matching lines...) Expand all
71 std::map<std::string, Parser> parser_map; 72 std::map<std::string, Parser> parser_map;
72 if (legacy_options) { 73 if (legacy_options) {
73 parser_map["chrome.binary"] = &CapabilitiesParser::ParseBinary; 74 parser_map["chrome.binary"] = &CapabilitiesParser::ParseBinary;
74 parser_map["chrome.channel"] = &CapabilitiesParser::ParseChannel; 75 parser_map["chrome.channel"] = &CapabilitiesParser::ParseChannel;
75 parser_map["chrome.detach"] = &CapabilitiesParser::ParseDetach; 76 parser_map["chrome.detach"] = &CapabilitiesParser::ParseDetach;
76 parser_map["chrome.extensions"] = &CapabilitiesParser::ParseExtensions; 77 parser_map["chrome.extensions"] = &CapabilitiesParser::ParseExtensions;
77 parser_map["chrome.loadAsync"] = &CapabilitiesParser::ParseLoadAsync; 78 parser_map["chrome.loadAsync"] = &CapabilitiesParser::ParseLoadAsync;
78 parser_map["chrome.nativeEvents"] = &CapabilitiesParser::ParseNativeEvents; 79 parser_map["chrome.nativeEvents"] = &CapabilitiesParser::ParseNativeEvents;
79 parser_map["chrome.profile"] = &CapabilitiesParser::ParseProfile; 80 parser_map["chrome.profile"] = &CapabilitiesParser::ParseProfile;
80 parser_map["chrome.switches"] = &CapabilitiesParser::ParseArgs; 81 parser_map["chrome.switches"] = &CapabilitiesParser::ParseArgs;
82 parser_map["chrome.noWebsiteTestingDefaults"] =
83 &CapabilitiesParser::ParseNoWebsiteTestingDefaults;
81 parser_map["chrome.verbose"] = &CapabilitiesParser::ParseVerbose; 84 parser_map["chrome.verbose"] = &CapabilitiesParser::ParseVerbose;
82 } else { 85 } else {
83 parser_map["args"] = &CapabilitiesParser::ParseArgs; 86 parser_map["args"] = &CapabilitiesParser::ParseArgs;
84 parser_map["binary"] = &CapabilitiesParser::ParseBinary; 87 parser_map["binary"] = &CapabilitiesParser::ParseBinary;
85 parser_map["channel"] = &CapabilitiesParser::ParseChannel; 88 parser_map["channel"] = &CapabilitiesParser::ParseChannel;
86 parser_map["detach"] = &CapabilitiesParser::ParseDetach; 89 parser_map["detach"] = &CapabilitiesParser::ParseDetach;
87 parser_map["extensions"] = &CapabilitiesParser::ParseExtensions; 90 parser_map["extensions"] = &CapabilitiesParser::ParseExtensions;
88 parser_map["loadAsync"] = &CapabilitiesParser::ParseLoadAsync; 91 parser_map["loadAsync"] = &CapabilitiesParser::ParseLoadAsync;
89 parser_map["nativeEvents"] = &CapabilitiesParser::ParseNativeEvents; 92 parser_map["nativeEvents"] = &CapabilitiesParser::ParseNativeEvents;
90 parser_map["profile"] = &CapabilitiesParser::ParseProfile; 93 parser_map["profile"] = &CapabilitiesParser::ParseProfile;
94 parser_map["noWebsiteTestingDefaults"] =
95 &CapabilitiesParser::ParseNoWebsiteTestingDefaults;
91 parser_map["verbose"] = &CapabilitiesParser::ParseVerbose; 96 parser_map["verbose"] = &CapabilitiesParser::ParseVerbose;
92 } 97 }
93 98
94 base::DictionaryValue::key_iterator key_iter = options->begin_keys(); 99 base::DictionaryValue::key_iterator key_iter = options->begin_keys();
95 for (; key_iter != options->end_keys(); ++key_iter) { 100 for (; key_iter != options->end_keys(); ++key_iter) {
96 if (parser_map.find(*key_iter) == parser_map.end()) { 101 if (parser_map.find(*key_iter) == parser_map.end()) {
97 LOG(WARNING) << "Ignoring unrecognized capability: " << *key_iter; 102 LOG(WARNING) << "Ignoring unrecognized capability: " << *key_iter;
98 continue; 103 continue;
99 } 104 }
100 Value* option = NULL; 105 Value* option = NULL;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 140
136 Error* CapabilitiesParser::ParseBinary(const Value* option) { 141 Error* CapabilitiesParser::ParseBinary(const Value* option) {
137 FilePath::StringType path; 142 FilePath::StringType path;
138 if (!option->GetAsString(&path)) { 143 if (!option->GetAsString(&path)) {
139 return CreateBadInputError("binary path", Value::TYPE_STRING, option); 144 return CreateBadInputError("binary path", Value::TYPE_STRING, option);
140 } 145 }
141 caps_->command.SetProgram(FilePath(path)); 146 caps_->command.SetProgram(FilePath(path));
142 return NULL; 147 return NULL;
143 } 148 }
144 149
150 Error* CapabilitiesParser::ParseCertRevocationChecking(
Huyen 2011/12/09 23:56:55 did you forget to map this function to the parser_
kkania 2011/12/10 00:37:44 Forgot to delete this. I decided I didn't like thi
151 const base::Value* option) {
152 if (!option->GetAsBoolean(&caps_->cert_revocation_checking))
153 return CreateBadInputError("cert revocation checking",
154 Value::TYPE_BOOLEAN, option);
155 return NULL;
156 }
157
145 Error* CapabilitiesParser::ParseChannel(const Value* option) { 158 Error* CapabilitiesParser::ParseChannel(const Value* option) {
146 if (!option->GetAsString(&caps_->channel)) 159 if (!option->GetAsString(&caps_->channel))
147 return CreateBadInputError("channel", Value::TYPE_STRING, option); 160 return CreateBadInputError("channel", Value::TYPE_STRING, option);
148 return NULL; 161 return NULL;
149 } 162 }
150 163
151 Error* CapabilitiesParser::ParseDetach(const Value* option) { 164 Error* CapabilitiesParser::ParseDetach(const Value* option) {
152 if (!option->GetAsBoolean(&caps_->detach)) 165 if (!option->GetAsBoolean(&caps_->detach))
153 return CreateBadInputError("detach", Value::TYPE_BOOLEAN, option); 166 return CreateBadInputError("detach", Value::TYPE_BOOLEAN, option);
154 return NULL; 167 return NULL;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 if (!option->GetAsString(&profile_base64)) 208 if (!option->GetAsString(&profile_base64))
196 return CreateBadInputError("profile", Value::TYPE_STRING, option); 209 return CreateBadInputError("profile", Value::TYPE_STRING, option);
197 std::string error_msg; 210 std::string error_msg;
198 caps_->profile = root_.AppendASCII("profile"); 211 caps_->profile = root_.AppendASCII("profile");
199 if (!DecodeAndWriteFile(caps_->profile, profile_base64, true /* unzip */, 212 if (!DecodeAndWriteFile(caps_->profile, profile_base64, true /* unzip */,
200 &error_msg)) 213 &error_msg))
201 return new Error(kUnknownError, "unable to unpack profile: " + error_msg); 214 return new Error(kUnknownError, "unable to unpack profile: " + error_msg);
202 return NULL; 215 return NULL;
203 } 216 }
204 217
218 Error* CapabilitiesParser::ParseNoWebsiteTestingDefaults(const Value* option) {
219 if (!option->GetAsBoolean(&caps_->no_website_testing_defaults))
220 return CreateBadInputError("noWebsiteTestingDefaults",
221 Value::TYPE_BOOLEAN, option);
222 return NULL;
223 }
224
205 Error* CapabilitiesParser::ParseVerbose(const Value* option) { 225 Error* CapabilitiesParser::ParseVerbose(const Value* option) {
206 if (!option->GetAsBoolean(&caps_->verbose)) 226 if (!option->GetAsBoolean(&caps_->verbose))
207 return CreateBadInputError("verbose", Value::TYPE_BOOLEAN, option); 227 return CreateBadInputError("verbose", Value::TYPE_BOOLEAN, option);
208 return NULL; 228 return NULL;
209 } 229 }
210 230
211 bool CapabilitiesParser::DecodeAndWriteFile( 231 bool CapabilitiesParser::DecodeAndWriteFile(
212 const FilePath& path, 232 const FilePath& path,
213 const std::string& base64, 233 const std::string& base64,
214 bool unzip, 234 bool unzip,
(...skipping 16 matching lines...) Expand all
231 } else { 251 } else {
232 if (!file_util::WriteFile(path, data.c_str(), data.length())) { 252 if (!file_util::WriteFile(path, data.c_str(), data.length())) {
233 *error_msg = "Could not write file"; 253 *error_msg = "Could not write file";
234 return false; 254 return false;
235 } 255 }
236 } 256 }
237 return true; 257 return true;
238 } 258 }
239 259
240 } // namespace webdriver 260 } // namespace webdriver
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698