OLD | NEW |
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/browser/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 #include "content/browser/renderer_host/render_process_host.h" | 100 #include "content/browser/renderer_host/render_process_host.h" |
101 #include "content/browser/renderer_host/render_view_host.h" | 101 #include "content/browser/renderer_host/render_view_host.h" |
102 #include "content/browser/tab_contents/interstitial_page.h" | 102 #include "content/browser/tab_contents/interstitial_page.h" |
103 #include "content/common/common_param_traits.h" | 103 #include "content/common/common_param_traits.h" |
104 #include "content/common/notification_service.h" | 104 #include "content/common/notification_service.h" |
105 #include "net/base/cookie_store.h" | 105 #include "net/base/cookie_store.h" |
106 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 106 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
107 #include "ui/base/events.h" | 107 #include "ui/base/events.h" |
108 #include "ui/base/keycodes/keyboard_codes.h" | 108 #include "ui/base/keycodes/keyboard_codes.h" |
109 #include "ui/base/message_box_flags.h" | 109 #include "ui/base/message_box_flags.h" |
| 110 #include "webkit/glue/webdropdata.h" |
110 #include "webkit/plugins/npapi/plugin_list.h" | 111 #include "webkit/plugins/npapi/plugin_list.h" |
111 | 112 |
112 namespace { | 113 namespace { |
113 | 114 |
114 void SendMouseClick(int flags) { | 115 void SendMouseClick(int flags) { |
115 ui_controls::MouseButton button = ui_controls::LEFT; | 116 ui_controls::MouseButton button = ui_controls::LEFT; |
116 if ((flags & ui::EF_LEFT_BUTTON_DOWN) == | 117 if ((flags & ui::EF_LEFT_BUTTON_DOWN) == |
117 ui::EF_LEFT_BUTTON_DOWN) { | 118 ui::EF_LEFT_BUTTON_DOWN) { |
118 button = ui_controls::LEFT; | 119 button = ui_controls::LEFT; |
119 } else if ((flags & ui::EF_RIGHT_BUTTON_DOWN) == | 120 } else if ((flags & ui::EF_RIGHT_BUTTON_DOWN) == |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1065 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
1065 | 1066 |
1066 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 1067 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
1067 mouse_event.clickCount = 2; | 1068 mouse_event.clickCount = 2; |
1068 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1069 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
1069 | 1070 |
1070 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 1071 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
1071 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); | 1072 tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
1072 } | 1073 } |
1073 | 1074 |
| 1075 void TestingAutomationProvider::DragAndDropFilePaths( |
| 1076 DictionaryValue* args, IPC::Message* reply_message) { |
| 1077 TabContents* tab_contents; |
| 1078 std::string error; |
| 1079 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
| 1080 AutomationJSONReply(this, reply_message).SendError(error); |
| 1081 return; |
| 1082 } |
| 1083 |
| 1084 int x, y; |
| 1085 if (!args->GetInteger("x", &x) || !args->GetInteger("y", &y)) { |
| 1086 AutomationJSONReply(this, reply_message) |
| 1087 .SendError("(X,Y) coordinates missing or invalid"); |
| 1088 return; |
| 1089 } |
| 1090 |
| 1091 ListValue* paths = NULL; |
| 1092 if (!args->GetList("paths", &paths)) { |
| 1093 AutomationJSONReply(this, reply_message) |
| 1094 .SendError("'paths' missing or invalid"); |
| 1095 return; |
| 1096 } |
| 1097 |
| 1098 // Emulate drag and drop to set the file paths to the file upload control. |
| 1099 WebDropData drop_data; |
| 1100 for (size_t path_index = 0; path_index < paths->GetSize(); ++path_index) { |
| 1101 string16 path; |
| 1102 if (!paths->GetString(path_index, &path)) { |
| 1103 AutomationJSONReply(this, reply_message) |
| 1104 .SendError("'paths' contains a non-string type"); |
| 1105 return; |
| 1106 } |
| 1107 |
| 1108 drop_data.filenames.push_back(path); |
| 1109 } |
| 1110 |
| 1111 const gfx::Point client(x, y); |
| 1112 // We don't set any values in screen variable because DragTarget*** ignore the |
| 1113 // screen argument. |
| 1114 const gfx::Point screen; |
| 1115 |
| 1116 int operations = 0; |
| 1117 operations |= WebKit::WebDragOperationCopy; |
| 1118 operations |= WebKit::WebDragOperationLink; |
| 1119 operations |= WebKit::WebDragOperationMove; |
| 1120 |
| 1121 RenderViewHost* host = tab_contents->render_view_host(); |
| 1122 host->DragTargetDragEnter( |
| 1123 drop_data, client, screen, |
| 1124 static_cast<WebKit::WebDragOperationsMask>(operations)); |
| 1125 new DragTargetDropAckNotificationObserver(this, reply_message); |
| 1126 host->DragTargetDrop(client, screen); |
| 1127 } |
| 1128 |
1074 void TestingAutomationProvider::GetTabCount(int handle, int* tab_count) { | 1129 void TestingAutomationProvider::GetTabCount(int handle, int* tab_count) { |
1075 *tab_count = -1; // -1 is the error code | 1130 *tab_count = -1; // -1 is the error code |
1076 | 1131 |
1077 if (browser_tracker_->ContainsHandle(handle)) { | 1132 if (browser_tracker_->ContainsHandle(handle)) { |
1078 Browser* browser = browser_tracker_->GetResource(handle); | 1133 Browser* browser = browser_tracker_->GetResource(handle); |
1079 *tab_count = browser->tab_count(); | 1134 *tab_count = browser->tab_count(); |
1080 } | 1135 } |
1081 } | 1136 } |
1082 | 1137 |
1083 void TestingAutomationProvider::GetType(int handle, int* type_as_int) { | 1138 void TestingAutomationProvider::GetType(int handle, int* type_as_int) { |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 handler_map["WebkitMouseClick"] = | 2163 handler_map["WebkitMouseClick"] = |
2109 &TestingAutomationProvider::WebkitMouseClick; | 2164 &TestingAutomationProvider::WebkitMouseClick; |
2110 handler_map["WebkitMouseDrag"] = | 2165 handler_map["WebkitMouseDrag"] = |
2111 &TestingAutomationProvider::WebkitMouseDrag; | 2166 &TestingAutomationProvider::WebkitMouseDrag; |
2112 handler_map["WebkitMouseButtonUp"] = | 2167 handler_map["WebkitMouseButtonUp"] = |
2113 &TestingAutomationProvider::WebkitMouseButtonUp; | 2168 &TestingAutomationProvider::WebkitMouseButtonUp; |
2114 handler_map["WebkitMouseButtonDown"] = | 2169 handler_map["WebkitMouseButtonDown"] = |
2115 &TestingAutomationProvider::WebkitMouseButtonDown; | 2170 &TestingAutomationProvider::WebkitMouseButtonDown; |
2116 handler_map["WebkitMouseDoubleClick"] = | 2171 handler_map["WebkitMouseDoubleClick"] = |
2117 &TestingAutomationProvider::WebkitMouseDoubleClick; | 2172 &TestingAutomationProvider::WebkitMouseDoubleClick; |
| 2173 handler_map["DragAndDropFilePaths"] = |
| 2174 &TestingAutomationProvider::DragAndDropFilePaths; |
2118 handler_map["SendWebkitKeyEvent"] = | 2175 handler_map["SendWebkitKeyEvent"] = |
2119 &TestingAutomationProvider::SendWebkitKeyEvent; | 2176 &TestingAutomationProvider::SendWebkitKeyEvent; |
2120 handler_map["SendOSLevelKeyEventToTab"] = | 2177 handler_map["SendOSLevelKeyEventToTab"] = |
2121 &TestingAutomationProvider::SendOSLevelKeyEventToTab; | 2178 &TestingAutomationProvider::SendOSLevelKeyEventToTab; |
2122 handler_map["ActivateTab"] = | 2179 handler_map["ActivateTab"] = |
2123 &TestingAutomationProvider::ActivateTabJSON; | 2180 &TestingAutomationProvider::ActivateTabJSON; |
2124 handler_map["GetAppModalDialogMessage"] = | 2181 handler_map["GetAppModalDialogMessage"] = |
2125 &TestingAutomationProvider::GetAppModalDialogMessage; | 2182 &TestingAutomationProvider::GetAppModalDialogMessage; |
2126 handler_map["AcceptOrDismissAppModalDialog"] = | 2183 handler_map["AcceptOrDismissAppModalDialog"] = |
2127 &TestingAutomationProvider::AcceptOrDismissAppModalDialog; | 2184 &TestingAutomationProvider::AcceptOrDismissAppModalDialog; |
(...skipping 3768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5896 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); | 5953 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); |
5897 | 5954 |
5898 Send(reply_message_); | 5955 Send(reply_message_); |
5899 redirect_query_ = 0; | 5956 redirect_query_ = 0; |
5900 reply_message_ = NULL; | 5957 reply_message_ = NULL; |
5901 } | 5958 } |
5902 | 5959 |
5903 void TestingAutomationProvider::OnRemoveProvider() { | 5960 void TestingAutomationProvider::OnRemoveProvider() { |
5904 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5961 AutomationProviderList::GetInstance()->RemoveProvider(this); |
5905 } | 5962 } |
OLD | NEW |