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

Unified Diff: chrome/test/webdriver/commands/file_upload_command.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, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/webdriver/commands/file_upload_command.cc
diff --git a/chrome/test/webdriver/commands/file_upload_command.cc b/chrome/test/webdriver/commands/file_upload_command.cc
new file mode 100644
index 0000000000000000000000000000000000000000..25af36880e2af33e79281f379ddafdc2a0d3d6c6
--- /dev/null
+++ b/chrome/test/webdriver/commands/file_upload_command.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2012 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/commands/file_upload_command.h"
+
+#include "base/file_util.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
+#include "build/build_config.h"
+#include "chrome/test/webdriver/commands/response.h"
+#include "chrome/test/webdriver/webdriver_error.h"
+#include "chrome/test/webdriver/webdriver_session.h"
+#include "chrome/test/webdriver/webdriver_util.h"
+
+namespace webdriver {
+
+FileUploadCommand::FileUploadCommand(
+ const std::vector<std::string>& path_segments,
+ DictionaryValue* parameters)
+ : WebDriverCommand(path_segments, parameters) {
+}
+
+FileUploadCommand::~FileUploadCommand() {
+}
+
+bool FileUploadCommand::DoesPost() {
+ return true;
+}
+
+void FileUploadCommand::ExecutePost(Response* const response) {
+ std::string base64_zip_data;
+ if (!GetStringParameter("file", &base64_zip_data)) {
+ response->SetError(new Error(kUnknownError, "Missing or invalid 'file'"));
+ return;
+ }
+ std::string zip_data;
+ if (!Base64Decode(base64_zip_data, &zip_data)) {
+ response->SetError(new Error(kUnknownError, "Unable to decode 'file'"));
+ return;
+ }
+
+ FilePath upload_dir;
+ if (!file_util::CreateTemporaryDirInDir(
+ session_->temp_dir(), FILE_PATH_LITERAL("upload"), &upload_dir)) {
+ response->SetError(new Error(kUnknownError, "Failed to create temp dir"));
+ return;
+ }
+ std::string error_msg;
+ FilePath upload;
+ if (!UnzipSoleFile(upload_dir, zip_data, &upload, &error_msg)) {
+ response->SetError(new Error(kUnknownError, error_msg));
+ return;
+ }
+
+#if defined(OS_WIN)
+ response->SetValue(new base::StringValue(WideToUTF8(upload.value())));
+#else
+ response->SetValue(new base::StringValue(upload.value()));
+#endif
+}
+
+} // namespace webdriver
« no previous file with comments | « chrome/test/webdriver/commands/file_upload_command.h ('k') | chrome/test/webdriver/webdriver_capabilities_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698