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

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

Issue 9515005: [chromedriver] Add command for uploading a file to a remote ChromeDriver server, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 9 months 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"
8 #include "base/file_util.h" 7 #include "base/file_util.h"
9 #include "base/format_macros.h" 8 #include "base/format_macros.h"
10 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
11 #include "base/string_util.h" 10 #include "base/string_util.h"
12 #include "base/values.h" 11 #include "base/values.h"
13 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/zip.h"
15 #include "chrome/test/webdriver/webdriver_error.h" 13 #include "chrome/test/webdriver/webdriver_error.h"
16 #include "chrome/test/webdriver/webdriver_util.h" 14 #include "chrome/test/webdriver/webdriver_util.h"
17 15
18 using base::DictionaryValue; 16 using base::DictionaryValue;
19 using base::Value; 17 using base::Value;
20 18
21 namespace webdriver { 19 namespace webdriver {
22 20
23 namespace { 21 namespace {
24 22
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if (!option->GetAsList(&extensions)) 187 if (!option->GetAsList(&extensions))
190 return CreateBadInputError("extensions", Value::TYPE_LIST, option); 188 return CreateBadInputError("extensions", Value::TYPE_LIST, option);
191 for (size_t i = 0; i < extensions->GetSize(); ++i) { 189 for (size_t i = 0; i < extensions->GetSize(); ++i) {
192 std::string extension_base64; 190 std::string extension_base64;
193 if (!extensions->GetString(i, &extension_base64)) { 191 if (!extensions->GetString(i, &extension_base64)) {
194 return new Error(kBadRequest, 192 return new Error(kBadRequest,
195 "Each extension must be a base64 encoded string"); 193 "Each extension must be a base64 encoded string");
196 } 194 }
197 FilePath extension = root_.AppendASCII( 195 FilePath extension = root_.AppendASCII(
198 base::StringPrintf("extension%" PRIuS ".crx", i)); 196 base::StringPrintf("extension%" PRIuS ".crx", i));
199 std::string error_msg; 197 std::string decoded_extension;
200 if (!DecodeAndWriteFile(extension, extension_base64, false /* unzip */, 198 if (!Base64Decode(extension_base64, &decoded_extension))
201 &error_msg)) { 199 return new Error(kUnknownError, "Failed to base64 decode extension");
202 return new Error( 200 int size = static_cast<int>(decoded_extension.length());
203 kUnknownError, 201 if (file_util::WriteFile(
204 "Error occurred while parsing extension: " + error_msg); 202 extension, decoded_extension.c_str(), size) != size)
205 } 203 return new Error(kUnknownError, "Failed to write extension file");
206 caps_->extensions.push_back(extension); 204 caps_->extensions.push_back(extension);
207 } 205 }
208 return NULL; 206 return NULL;
209 } 207 }
210 208
211 Error* CapabilitiesParser::ParseLoadAsync(const Value* option) { 209 Error* CapabilitiesParser::ParseLoadAsync(const Value* option) {
212 if (!option->GetAsBoolean(&caps_->load_async)) 210 if (!option->GetAsBoolean(&caps_->load_async))
213 return CreateBadInputError("loadAsync", Value::TYPE_BOOLEAN, option); 211 return CreateBadInputError("loadAsync", Value::TYPE_BOOLEAN, option);
214 return NULL; 212 return NULL;
215 } 213 }
(...skipping 28 matching lines...) Expand all
244 return CreateBadInputError("nativeEvents", Value::TYPE_BOOLEAN, option); 242 return CreateBadInputError("nativeEvents", Value::TYPE_BOOLEAN, option);
245 return NULL; 243 return NULL;
246 } 244 }
247 245
248 Error* CapabilitiesParser::ParseProfile(const Value* option) { 246 Error* CapabilitiesParser::ParseProfile(const Value* option) {
249 std::string profile_base64; 247 std::string profile_base64;
250 if (!option->GetAsString(&profile_base64)) 248 if (!option->GetAsString(&profile_base64))
251 return CreateBadInputError("profile", Value::TYPE_STRING, option); 249 return CreateBadInputError("profile", Value::TYPE_STRING, option);
252 std::string error_msg; 250 std::string error_msg;
253 caps_->profile = root_.AppendASCII("profile"); 251 caps_->profile = root_.AppendASCII("profile");
254 if (!DecodeAndWriteFile(caps_->profile, profile_base64, true /* unzip */, 252 if (!Base64DecodeAndUnzip(caps_->profile, profile_base64, &error_msg))
255 &error_msg))
256 return new Error(kUnknownError, "unable to unpack profile: " + error_msg); 253 return new Error(kUnknownError, "unable to unpack profile: " + error_msg);
257 return NULL; 254 return NULL;
258 } 255 }
259 256
260 Error* CapabilitiesParser::ParseProxy(const base::Value* option) { 257 Error* CapabilitiesParser::ParseProxy(const base::Value* option) {
261 const DictionaryValue* options; 258 const DictionaryValue* options;
262 if (!option->GetAsDictionary(&options)) 259 if (!option->GetAsDictionary(&options))
263 return CreateBadInputError("proxy", Value::TYPE_DICTIONARY, option); 260 return CreateBadInputError("proxy", Value::TYPE_DICTIONARY, option);
264 261
265 // Quick check of proxy capabilities. 262 // Quick check of proxy capabilities.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 return NULL; 400 return NULL;
404 } 401 }
405 402
406 Error* CapabilitiesParser::ParseNoWebsiteTestingDefaults(const Value* option) { 403 Error* CapabilitiesParser::ParseNoWebsiteTestingDefaults(const Value* option) {
407 if (!option->GetAsBoolean(&caps_->no_website_testing_defaults)) 404 if (!option->GetAsBoolean(&caps_->no_website_testing_defaults))
408 return CreateBadInputError("noWebsiteTestingDefaults", 405 return CreateBadInputError("noWebsiteTestingDefaults",
409 Value::TYPE_BOOLEAN, option); 406 Value::TYPE_BOOLEAN, option);
410 return NULL; 407 return NULL;
411 } 408 }
412 409
413 bool CapabilitiesParser::DecodeAndWriteFile(
414 const FilePath& path,
415 const std::string& base64,
416 bool unzip,
417 std::string* error_msg) {
418 std::string data;
419 if (!base::Base64Decode(base64, &data)) {
420 *error_msg = "Could not decode base64 data";
421 return false;
422 }
423 if (unzip) {
424 FilePath temp_file(root_.AppendASCII(GenerateRandomID()));
425 if (!file_util::WriteFile(temp_file, data.c_str(), data.length())) {
426 *error_msg = "Could not write file";
427 return false;
428 }
429 if (!zip::Unzip(temp_file, path)) {
430 *error_msg = "Could not unzip archive";
431 return false;
432 }
433 } else {
434 if (!file_util::WriteFile(path, data.c_str(), data.length())) {
435 *error_msg = "Could not write file";
436 return false;
437 }
438 }
439 return true;
440 }
441
442 } // namespace webdriver 410 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/webdriver_capabilities_parser.h ('k') | chrome/test/webdriver/webdriver_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698