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

Unified Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 7055004: File upload API in chromedriver (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed according to the code review Created 9 years, 7 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/browser/automation/testing_automation_provider.cc
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index f087b5f3e322625194f4219b6531a7693adcd83f..cef344f724e2e2de6dc45068e9e349769bb020c1 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -104,6 +104,7 @@
#include "ui/base/events.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/message_box_flags.h"
+#include "webkit/glue/webdropdata.h"
#include "webkit/plugins/npapi/plugin_list.h"
namespace {
@@ -1080,6 +1081,60 @@ void TestingAutomationProvider::WebkitMouseDoubleClick(
tab_contents->render_view_host()->ForwardMouseEvent(mouse_event);
}
+void TestingAutomationProvider::DragAndDropFilePaths(
+ DictionaryValue* args, IPC::Message* reply_message) {
+ TabContents* tab_contents;
+ std::string error;
+ if (!GetTabFromJSONArgs(args, &tab_contents, &error)) {
+ AutomationJSONReply(this, reply_message).SendError(error);
+ return;
+ }
+
+ int x, y;
+ if (!args->GetInteger("x", &x) || !args->GetInteger("y", &y)) {
+ AutomationJSONReply(this, reply_message)
+ .SendError("(X,Y) coordinates missing or invalid");
+ return;
+ }
+
+ ListValue* paths = NULL;
+ if (!args->GetList("paths", &paths)) {
+ AutomationJSONReply(this, reply_message)
+ .SendError("paths missing or invalid");
+ return;
+ }
+
+ // Emulate drag and drop to set the file paths to the file upload control.
+ WebDropData drop_data;
+ for (size_t path_index = 0; path_index < paths->GetSize(); ++path_index) {
+ string16 path;
+ if (!paths->GetString(path_index, &path)) {
+ AutomationJSONReply(this, reply_message)
+ .SendError("path missing or invalid");
kkania 2011/05/27 20:48:47 error is a bit off here. How about: "'paths' conta
nodchip 2011/05/30 04:51:45 Done.
+ return;
+ }
+
+ drop_data.filenames.push_back(path);
+ }
+
+ const gfx::Point client(x, y);
+ // We don't set any values in screen variable because DragTarget*** ignore the
+ // screen argument.
+ const gfx::Point screen;
+
+ int operations = 0;
+ operations |= WebKit::WebDragOperationCopy;
+ operations |= WebKit::WebDragOperationLink;
+ operations |= WebKit::WebDragOperationMove;
+
+ RenderViewHost* host = tab_contents->render_view_host();
+ host->DragTargetDragEnter(
+ drop_data, client, screen,
+ static_cast<WebKit::WebDragOperationsMask>(operations));
+ new DragTargetDropAckNotificationObserver(this, reply_message);
+ host->DragTargetDrop(client, screen);
+}
+
void TestingAutomationProvider::GetTabCount(int handle, int* tab_count) {
*tab_count = -1; // -1 is the error code
@@ -2218,6 +2273,8 @@ void TestingAutomationProvider::SendJSONRequest(int handle,
&TestingAutomationProvider::WebkitMouseButtonDown;
handler_map["WebkitMouseDoubleClick"] =
&TestingAutomationProvider::WebkitMouseDoubleClick;
+ handler_map["DragAndDropFilePaths"] =
+ &TestingAutomationProvider::DragAndDropFilePaths;
handler_map["SendWebkitKeyEvent"] =
&TestingAutomationProvider::SendWebkitKeyEvent;
handler_map["SendOSLevelKeyEventToTab"] =

Powered by Google App Engine
This is Rietveld 408576698