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

Side by Side Diff: chrome/test/automation/automation_json_requests.cc

Issue 8806030: Add commands to Chrome WebDriver for installing and manipulating extensions. (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/automation/automation_json_requests.h" 5 #include "chrome/test/automation/automation_json_requests.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 ui::KeyboardCode key_code, 73 ui::KeyboardCode key_code,
74 const std::string& unmodified_text, 74 const std::string& unmodified_text,
75 const std::string& modified_text, 75 const std::string& modified_text,
76 int modifiers) 76 int modifiers)
77 : type(type), 77 : type(type),
78 key_code(key_code), 78 key_code(key_code),
79 unmodified_text(unmodified_text), 79 unmodified_text(unmodified_text),
80 modified_text(modified_text), 80 modified_text(modified_text),
81 modifiers(modifiers) {} 81 modifiers(modifiers) {}
82 82
83 // static
84 WebViewId WebViewId::ForView(const AutomationId& view_id) {
85 WebViewId id;
86 id.old_style_ = false;
87 id.id_ = view_id;
88 return id;
89 }
90
91 // static
92 WebViewId WebViewId::ForOldStyleTab(int tab_id) {
93 WebViewId id;
94 id.old_style_ = true;
95 id.tab_id_ = tab_id;
96 return id;
97 }
98
99 WebViewId::WebViewId() : old_style_(true) {}
100
101 void WebViewId::UpdateDictionary(DictionaryValue* dict,
102 const std::string& view_id_key) const {
103 if (old_style_) {
104 dict->SetInteger("id", tab_id_);
105 } else {
106 dict->Set(view_id_key, id_.ToValue());
107 }
108 }
109
110 bool WebViewId::IsValid() const {
111 if (old_style_)
112 return tab_id_ != 0;
113 else
114 return id_.is_valid();
115 }
116
117 AutomationId WebViewId::GetId() const {
118 if (old_style_)
119 return AutomationId(AutomationId::kTypeTab, base::IntToString(tab_id_));
120 else
121 return id_;
122 }
123
124 bool WebViewId::IsTab() const {
125 return old_style_ || id_.type() == AutomationId::kTypeTab;
126 }
127
128 int WebViewId::tab_id() const {
129 return tab_id_;
130 }
131
132 bool WebViewId::old_style() const {
133 return old_style_;
134 }
135
136 // static
137 WebViewLocator WebViewLocator::ForIndexPair(int browser_index, int tab_index) {
138 WebViewLocator locator;
139 locator.type_ = kTypeIndexPair;
140 locator.locator_.index_pair.browser_index = browser_index;
141 locator.locator_.index_pair.tab_index = tab_index;
142 return locator;
143 }
144
145 // static
146 WebViewLocator WebViewLocator::ForViewId(const AutomationId& view_id) {
147 WebViewLocator locator;
148 locator.type_ = kTypeViewId;
149 locator.locator_.view_id = view_id;
150 return locator;
151 }
152
153 WebViewLocator::WebViewLocator() {}
154
155 WebViewLocator::~WebViewLocator() {}
156
157 void WebViewLocator::UpdateDictionary(
158 DictionaryValue* dict, const std::string& view_id_key) const {
159 if (type_ == kTypeIndexPair) {
160 dict->SetInteger("windex", locator_.index_pair.browser_index);
161 dict->SetInteger("tab_index", locator_.index_pair.tab_index);
162 } else if (type_ == kTypeViewId) {
163 dict->Set(view_id_key, locator_.view_id.ToValue());
164 }
165 }
166
167 int WebViewLocator::browser_index() const {
168 return locator_.index_pair.browser_index;
169 }
170
171 int WebViewLocator::tab_index() const {
172 return locator_.index_pair.tab_index;
173 }
174
175 WebViewLocator::Locator::Locator() {}
176
177 WebViewLocator::Locator::~Locator() {}
178
179 WebViewInfo::WebViewInfo(const WebViewId& view_id,
180 const std::string& extension_id)
181 : view_id(view_id),
182 extension_id(extension_id) {}
183
184 WebViewInfo::~WebViewInfo() {}
185
83 bool SendAutomationJSONRequest(AutomationMessageSender* sender, 186 bool SendAutomationJSONRequest(AutomationMessageSender* sender,
84 const std::string& request, 187 const std::string& request,
85 int timeout_ms, 188 int timeout_ms,
86 std::string* reply, 189 std::string* reply,
87 bool* success) { 190 bool* success) {
88 return sender->Send(new AutomationMsg_SendJSONRequest( 191 return sender->Send(new AutomationMsg_SendJSONRequest(
89 -1, request, reply, success), timeout_ms); 192 -1, request, reply, success), timeout_ms);
90 } 193 }
91 194
92 bool SendAutomationJSONRequestWithDefaultTimeout( 195 bool SendAutomationJSONRequestWithDefaultTimeout(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return false; 234 return false;
132 if (!reply_dict.GetInteger("windex", browser_index)) 235 if (!reply_dict.GetInteger("windex", browser_index))
133 return false; 236 return false;
134 if (!reply_dict.GetInteger("tab_index", tab_index)) 237 if (!reply_dict.GetInteger("tab_index", tab_index))
135 return false; 238 return false;
136 return true; 239 return true;
137 } 240 }
138 241
139 bool SendNavigateToURLJSONRequest( 242 bool SendNavigateToURLJSONRequest(
140 AutomationMessageSender* sender, 243 AutomationMessageSender* sender,
141 int browser_index, 244 const WebViewLocator& locator,
142 int tab_index,
143 const std::string& url, 245 const std::string& url,
144 int navigation_count, 246 int navigation_count,
145 AutomationMsg_NavigationResponseValues* nav_response, 247 AutomationMsg_NavigationResponseValues* nav_response,
146 std::string* error_msg) { 248 std::string* error_msg) {
147 DictionaryValue dict; 249 DictionaryValue dict;
148 dict.SetString("command", "NavigateToURL"); 250 dict.SetString("command", "NavigateToURL");
149 dict.SetInteger("windex", browser_index); 251 locator.UpdateDictionary(&dict, "auto_id");
150 dict.SetInteger("tab_index", tab_index);
151 dict.SetString("url", url); 252 dict.SetString("url", url);
152 dict.SetInteger("navigation_count", navigation_count); 253 dict.SetInteger("navigation_count", navigation_count);
153 DictionaryValue reply_dict; 254 DictionaryValue reply_dict;
154 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) 255 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
155 return false; 256 return false;
156 int response = 0; 257 int response = 0;
157 if (!reply_dict.GetInteger("result", &response)) 258 if (!reply_dict.GetInteger("result", &response))
158 return false; 259 return false;
159 *nav_response = static_cast<AutomationMsg_NavigationResponseValues>(response); 260 *nav_response = static_cast<AutomationMsg_NavigationResponseValues>(response);
160 return true; 261 return true;
161 } 262 }
162 263
163 bool SendExecuteJavascriptJSONRequest( 264 bool SendExecuteJavascriptJSONRequest(
164 AutomationMessageSender* sender, 265 AutomationMessageSender* sender,
165 int browser_index, 266 const WebViewLocator& locator,
166 int tab_index,
167 const std::string& frame_xpath, 267 const std::string& frame_xpath,
168 const std::string& javascript, 268 const std::string& javascript,
169 Value** result, 269 Value** result,
170 std::string* error_msg) { 270 std::string* error_msg) {
171 DictionaryValue dict; 271 DictionaryValue dict;
172 dict.SetString("command", "ExecuteJavascript"); 272 dict.SetString("command", "ExecuteJavascript");
173 dict.SetInteger("windex", browser_index); 273 locator.UpdateDictionary(&dict, "auto_id");
174 dict.SetInteger("tab_index", tab_index);
175 dict.SetString("frame_xpath", frame_xpath); 274 dict.SetString("frame_xpath", frame_xpath);
176 dict.SetString("javascript", javascript); 275 dict.SetString("javascript", javascript);
177 DictionaryValue reply_dict; 276 DictionaryValue reply_dict;
178 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) 277 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
179 return false; 278 return false;
180 279
181 std::string json; 280 std::string json;
182 if (!reply_dict.GetString("result", &json)) { 281 if (!reply_dict.GetString("result", &json)) {
183 LOG(ERROR) << "Executed javascript but received no 'result'"; 282 LOG(ERROR) << "Executed javascript but received no 'result'";
184 return false; 283 return false;
185 } 284 }
186 // Wrap |json| in an array before deserializing because valid JSON has an 285 // Wrap |json| in an array before deserializing because valid JSON has an
187 // array or an object as the root. 286 // array or an object as the root.
188 json.insert(0, "["); 287 json.insert(0, "[");
189 json.append("]"); 288 json.append("]");
190 289
191 JSONStringValueSerializer deserializer(json); 290 JSONStringValueSerializer deserializer(json);
192 Value* value = deserializer.Deserialize(NULL, NULL); 291 Value* value = deserializer.Deserialize(NULL, NULL);
193 if (!value || !value->IsType(Value::TYPE_LIST)) { 292 if (!value || !value->IsType(Value::TYPE_LIST)) {
194 LOG(ERROR) << "Unable to deserialize returned JSON"; 293 LOG(ERROR) << "Unable to deserialize returned JSON";
195 return false; 294 return false;
196 } 295 }
197 scoped_ptr<ListValue> list(static_cast<ListValue*>(value)); 296 scoped_ptr<ListValue> list(static_cast<ListValue*>(value));
198 return list->Remove(0, result); 297 return list->Remove(0, result);
199 } 298 }
200 299
201 bool SendGoForwardJSONRequest( 300 bool SendGoForwardJSONRequest(
202 AutomationMessageSender* sender, 301 AutomationMessageSender* sender,
203 int browser_index, 302 const WebViewLocator& locator,
204 int tab_index,
205 std::string* error_msg) { 303 std::string* error_msg) {
206 DictionaryValue dict; 304 DictionaryValue dict;
207 dict.SetString("command", "GoForward"); 305 dict.SetString("command", "GoForward");
208 dict.SetInteger("windex", browser_index); 306 locator.UpdateDictionary(&dict, "auto_id");
209 dict.SetInteger("tab_index", tab_index);
210 DictionaryValue reply_dict; 307 DictionaryValue reply_dict;
211 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 308 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
212 } 309 }
213 310
214 bool SendGoBackJSONRequest( 311 bool SendGoBackJSONRequest(
215 AutomationMessageSender* sender, 312 AutomationMessageSender* sender,
216 int browser_index, 313 const WebViewLocator& locator,
217 int tab_index,
218 std::string* error_msg) { 314 std::string* error_msg) {
219 DictionaryValue dict; 315 DictionaryValue dict;
220 dict.SetString("command", "GoBack"); 316 dict.SetString("command", "GoBack");
221 dict.SetInteger("windex", browser_index); 317 locator.UpdateDictionary(&dict, "auto_id");
222 dict.SetInteger("tab_index", tab_index);
223 DictionaryValue reply_dict; 318 DictionaryValue reply_dict;
224 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 319 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
225 } 320 }
226 321
227 bool SendReloadJSONRequest( 322 bool SendReloadJSONRequest(
228 AutomationMessageSender* sender, 323 AutomationMessageSender* sender,
229 int browser_index, 324 const WebViewLocator& locator,
230 int tab_index,
231 std::string* error_msg) { 325 std::string* error_msg) {
232 DictionaryValue dict; 326 DictionaryValue dict;
233 dict.SetString("command", "Reload"); 327 dict.SetString("command", "Reload");
234 dict.SetInteger("windex", browser_index); 328 locator.UpdateDictionary(&dict, "auto_id");
235 dict.SetInteger("tab_index", tab_index);
236 DictionaryValue reply_dict; 329 DictionaryValue reply_dict;
237 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 330 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
238 } 331 }
239 332
240 bool SendCaptureEntirePageJSONRequest( 333 bool SendCaptureEntirePageJSONRequest(
241 AutomationMessageSender* sender, 334 AutomationMessageSender* sender,
242 int browser_index, 335 const WebViewLocator& locator,
243 int tab_index,
244 const FilePath& path, 336 const FilePath& path,
245 std::string* error_msg) { 337 std::string* error_msg) {
246 DictionaryValue dict; 338 DictionaryValue dict;
247 dict.SetString("command", "CaptureEntirePage"); 339 dict.SetString("command", "CaptureEntirePage");
248 dict.SetInteger("windex", browser_index); 340 locator.UpdateDictionary(&dict, "auto_id");
249 dict.SetInteger("tab_index", tab_index);
250 dict.SetString("path", path.value()); 341 dict.SetString("path", path.value());
251 DictionaryValue reply_dict; 342 DictionaryValue reply_dict;
252 343
253 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 344 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
254 } 345 }
255 346
256 bool SendGetTabURLJSONRequest(
257 AutomationMessageSender* sender,
258 int browser_index,
259 int tab_index,
260 std::string* url,
261 std::string* error_msg) {
262 DictionaryValue dict;
263 dict.SetString("command", "GetTabURL");
264 dict.SetInteger("windex", browser_index);
265 dict.SetInteger("tab_index", tab_index);
266 DictionaryValue reply_dict;
267 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
268 return false;
269 return reply_dict.GetString("url", url);
270 }
271
272 bool SendGetTabTitleJSONRequest(
273 AutomationMessageSender* sender,
274 int browser_index,
275 int tab_index,
276 std::string* tab_title,
277 std::string* error_msg) {
278 DictionaryValue dict;
279 dict.SetString("command", "GetTabTitle");
280 dict.SetInteger("windex", browser_index);
281 dict.SetInteger("tab_index", tab_index);
282 DictionaryValue reply_dict;
283 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
284 return false;
285 return reply_dict.GetString("title", tab_title);
286 }
287
288 bool SendGetCookiesJSONRequest( 347 bool SendGetCookiesJSONRequest(
289 AutomationMessageSender* sender, 348 AutomationMessageSender* sender,
290 const std::string& url, 349 const std::string& url,
291 ListValue** cookies, 350 ListValue** cookies,
292 std::string* error_msg) { 351 std::string* error_msg) {
293 DictionaryValue dict; 352 DictionaryValue dict;
294 dict.SetString("command", "GetCookies"); 353 dict.SetString("command", "GetCookies");
295 dict.SetString("url", url); 354 dict.SetString("url", url);
296 DictionaryValue reply_dict; 355 DictionaryValue reply_dict;
297 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) 356 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
(...skipping 29 matching lines...) Expand all
327 DictionaryValue dict; 386 DictionaryValue dict;
328 dict.SetString("command", "SetCookie"); 387 dict.SetString("command", "SetCookie");
329 dict.SetString("url", url); 388 dict.SetString("url", url);
330 dict.Set("cookie", cookie_dict->DeepCopy()); 389 dict.Set("cookie", cookie_dict->DeepCopy());
331 DictionaryValue reply_dict; 390 DictionaryValue reply_dict;
332 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 391 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
333 } 392 }
334 393
335 bool SendGetTabIdsJSONRequest( 394 bool SendGetTabIdsJSONRequest(
336 AutomationMessageSender* sender, 395 AutomationMessageSender* sender,
337 std::vector<int>* tab_ids, 396 std::vector<WebViewInfo>* views,
338 std::string* error_msg) { 397 std::string* error_msg) {
339 DictionaryValue dict; 398 DictionaryValue dict;
340 dict.SetString("command", "GetTabIds"); 399 dict.SetString("command", "GetTabIds");
341 DictionaryValue reply_dict; 400 DictionaryValue reply_dict;
342 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) 401 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
343 return false; 402 return false;
344 ListValue* id_list; 403 ListValue* id_list;
345 if (!reply_dict.GetList("ids", &id_list)) { 404 if (reply_dict.GetList("ids", &id_list)) {
346 LOG(ERROR) << "Returned 'ids' key is missing or invalid"; 405 for (size_t i = 0; i < id_list->GetSize(); ++i) {
406 int id;
407 if (!id_list->GetInteger(i, &id)) {
408 *error_msg = "Returned id in 'tab_ids' is not an integer";
409 return false;
410 }
411 views->push_back(WebViewInfo(
412 WebViewId::ForOldStyleTab(id), std::string()));
413 }
414 }
415 return true;
416 }
417
418 bool SendGetWebViewsJSONRequest(
419 AutomationMessageSender* sender,
420 std::vector<WebViewInfo>* views,
421 std::string* error_msg) {
422 DictionaryValue dict;
423 dict.SetString("command", "GetViews");
424 DictionaryValue reply_dict;
425 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
426 return false;
427 ListValue* views_list;
428 if (!reply_dict.GetList("views", &views_list)) {
429 *error_msg = "Returned 'views' key is missing or invalid";
347 return false; 430 return false;
348 } 431 }
349 std::vector<int> temp_ids; 432 for (size_t i = 0; i < views_list->GetSize(); ++i) {
350 for (size_t i = 0; i < id_list->GetSize(); ++i) { 433 DictionaryValue* view_dict;
351 int id; 434 if (!views_list->GetDictionary(i, &view_dict)) {
352 if (!id_list->GetInteger(i, &id)) { 435 *error_msg = "Returned 'views' key contains non-dictionary values";
353 LOG(ERROR) << "Returned 'ids' key contains non-integer values";
354 return false; 436 return false;
355 } 437 }
356 temp_ids.push_back(id); 438 AutomationId view_id;
439 if (!AutomationId::FromValueInDictionary(
440 view_dict, "auto_id", &view_id, error_msg))
441 return false;
442 std::string extension_id;
443 view_dict->GetString("extension_id", &extension_id);
444 views->push_back(WebViewInfo(
445 WebViewId::ForView(view_id), extension_id));
357 } 446 }
358 *tab_ids = temp_ids;
359 return true; 447 return true;
360 } 448 }
361 449
362 bool SendIsTabIdValidJSONRequest( 450 bool SendIsTabIdValidJSONRequest(
363 AutomationMessageSender* sender, 451 AutomationMessageSender* sender,
364 int tab_id, 452 const WebViewId& view_id,
365 bool* is_valid, 453 bool* is_valid,
366 std::string* error_msg) { 454 std::string* error_msg) {
367 DictionaryValue dict; 455 DictionaryValue dict;
368 dict.SetString("command", "IsTabIdValid"); 456 dict.SetString("command", "IsTabIdValid");
369 dict.SetInteger("id", tab_id); 457 view_id.UpdateDictionary(&dict, "tab_id");
370 DictionaryValue reply_dict; 458 DictionaryValue reply_dict;
371 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) 459 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
372 return false; 460 return false;
373 return reply_dict.GetBoolean("is_valid", is_valid); 461 return reply_dict.GetBoolean("is_valid", is_valid);
374 } 462 }
375 463
376 bool SendCloseTabJSONRequest( 464 bool SendDoesAutomationObjectExistJSONRequest(
377 AutomationMessageSender* sender, 465 AutomationMessageSender* sender,
378 int browser_index, 466 const WebViewId& view_id,
379 int tab_index, 467 bool* does_exist,
468 std::string* error_msg) {
469 DictionaryValue dict;
470 dict.SetString("command", "DoesAutomationObjectExist");
471 view_id.UpdateDictionary(&dict, "auto_id");
472 DictionaryValue reply_dict;
473 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
474 return false;
475 return reply_dict.GetBoolean("does_exist", does_exist);
476 }
477
478 bool SendCloseViewJSONRequest(
479 AutomationMessageSender* sender,
480 const WebViewLocator& locator,
380 std::string* error_msg) { 481 std::string* error_msg) {
381 DictionaryValue dict; 482 DictionaryValue dict;
382 dict.SetString("command", "CloseTab"); 483 dict.SetString("command", "CloseTab");
383 dict.SetInteger("windex", browser_index); 484 locator.UpdateDictionary(&dict, "auto_id");
384 dict.SetInteger("tab_index", tab_index);
385 DictionaryValue reply_dict; 485 DictionaryValue reply_dict;
386 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 486 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
387 } 487 }
388 488
389 bool SendMouseMoveJSONRequest( 489 bool SendMouseMoveJSONRequest(
390 AutomationMessageSender* sender, 490 AutomationMessageSender* sender,
391 int browser_index, 491 const WebViewLocator& locator,
392 int tab_index,
393 int x, 492 int x,
394 int y, 493 int y,
395 std::string* error_msg) { 494 std::string* error_msg) {
396 DictionaryValue dict; 495 DictionaryValue dict;
397 dict.SetString("command", "WebkitMouseMove"); 496 dict.SetString("command", "WebkitMouseMove");
398 dict.SetInteger("windex", browser_index); 497 locator.UpdateDictionary(&dict, "auto_id");
399 dict.SetInteger("tab_index", tab_index);
400 dict.SetInteger("x", x); 498 dict.SetInteger("x", x);
401 dict.SetInteger("y", y); 499 dict.SetInteger("y", y);
402 DictionaryValue reply_dict; 500 DictionaryValue reply_dict;
403 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 501 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
404 } 502 }
405 503
406 bool SendMouseClickJSONRequest( 504 bool SendMouseClickJSONRequest(
407 AutomationMessageSender* sender, 505 AutomationMessageSender* sender,
408 int browser_index, 506 const WebViewLocator& locator,
409 int tab_index,
410 automation::MouseButton button, 507 automation::MouseButton button,
411 int x, 508 int x,
412 int y, 509 int y,
413 std::string* error_msg) { 510 std::string* error_msg) {
414 DictionaryValue dict; 511 DictionaryValue dict;
415 dict.SetString("command", "WebkitMouseClick"); 512 dict.SetString("command", "WebkitMouseClick");
416 dict.SetInteger("windex", browser_index); 513 locator.UpdateDictionary(&dict, "auto_id");
417 dict.SetInteger("tab_index", tab_index);
418 dict.SetInteger("button", button); 514 dict.SetInteger("button", button);
419 dict.SetInteger("x", x); 515 dict.SetInteger("x", x);
420 dict.SetInteger("y", y); 516 dict.SetInteger("y", y);
421 DictionaryValue reply_dict; 517 DictionaryValue reply_dict;
422 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 518 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
423 } 519 }
424 520
425 bool SendMouseDragJSONRequest( 521 bool SendMouseDragJSONRequest(
426 AutomationMessageSender* sender, 522 AutomationMessageSender* sender,
427 int browser_index, 523 const WebViewLocator& locator,
428 int tab_index,
429 int start_x, 524 int start_x,
430 int start_y, 525 int start_y,
431 int end_x, 526 int end_x,
432 int end_y, 527 int end_y,
433 std::string* error_msg) { 528 std::string* error_msg) {
434 DictionaryValue dict; 529 DictionaryValue dict;
435 dict.SetString("command", "WebkitMouseDrag"); 530 dict.SetString("command", "WebkitMouseDrag");
436 dict.SetInteger("windex", browser_index); 531 locator.UpdateDictionary(&dict, "auto_id");
437 dict.SetInteger("tab_index", tab_index);
438 dict.SetInteger("start_x", start_x); 532 dict.SetInteger("start_x", start_x);
439 dict.SetInteger("start_y", start_y); 533 dict.SetInteger("start_y", start_y);
440 dict.SetInteger("end_x", end_x); 534 dict.SetInteger("end_x", end_x);
441 dict.SetInteger("end_y", end_y); 535 dict.SetInteger("end_y", end_y);
442 DictionaryValue reply_dict; 536 DictionaryValue reply_dict;
443 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 537 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
444 } 538 }
445 539
446 bool SendMouseButtonDownJSONRequest( 540 bool SendMouseButtonDownJSONRequest(
447 AutomationMessageSender* sender, 541 AutomationMessageSender* sender,
448 int browser_index, 542 const WebViewLocator& locator,
449 int tab_index,
450 int x, 543 int x,
451 int y, 544 int y,
452 std::string* error_msg) { 545 std::string* error_msg) {
453 DictionaryValue dict; 546 DictionaryValue dict;
454 dict.SetString("command", "WebkitMouseButtonDown"); 547 dict.SetString("command", "WebkitMouseButtonDown");
455 dict.SetInteger("windex", browser_index); 548 locator.UpdateDictionary(&dict, "auto_id");
456 dict.SetInteger("tab_index", tab_index);
457 dict.SetInteger("x", x); 549 dict.SetInteger("x", x);
458 dict.SetInteger("y", y); 550 dict.SetInteger("y", y);
459 DictionaryValue reply_dict; 551 DictionaryValue reply_dict;
460 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 552 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
461 } 553 }
462 554
463 bool SendMouseButtonUpJSONRequest( 555 bool SendMouseButtonUpJSONRequest(
464 AutomationMessageSender* sender, 556 AutomationMessageSender* sender,
465 int browser_index, 557 const WebViewLocator& locator,
466 int tab_index,
467 int x, 558 int x,
468 int y, 559 int y,
469 std::string* error_msg) { 560 std::string* error_msg) {
470 DictionaryValue dict; 561 DictionaryValue dict;
471 dict.SetString("command", "WebkitMouseButtonUp"); 562 dict.SetString("command", "WebkitMouseButtonUp");
472 dict.SetInteger("windex", browser_index); 563 locator.UpdateDictionary(&dict, "auto_id");
473 dict.SetInteger("tab_index", tab_index);
474 dict.SetInteger("x", x); 564 dict.SetInteger("x", x);
475 dict.SetInteger("y", y); 565 dict.SetInteger("y", y);
476 DictionaryValue reply_dict; 566 DictionaryValue reply_dict;
477 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 567 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
478 } 568 }
479 569
480 bool SendMouseDoubleClickJSONRequest( 570 bool SendMouseDoubleClickJSONRequest(
481 AutomationMessageSender* sender, 571 AutomationMessageSender* sender,
482 int browser_index, 572 const WebViewLocator& locator,
483 int tab_index,
484 int x, 573 int x,
485 int y, 574 int y,
486 std::string* error_msg) { 575 std::string* error_msg) {
487 DictionaryValue dict; 576 DictionaryValue dict;
488 dict.SetString("command", "WebkitMouseDoubleClick"); 577 dict.SetString("command", "WebkitMouseDoubleClick");
489 dict.SetInteger("windex", browser_index); 578 locator.UpdateDictionary(&dict, "auto_id");
490 dict.SetInteger("tab_index", tab_index);
491 dict.SetInteger("x", x); 579 dict.SetInteger("x", x);
492 dict.SetInteger("y", y); 580 dict.SetInteger("y", y);
493 DictionaryValue reply_dict; 581 DictionaryValue reply_dict;
494 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 582 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
495 } 583 }
496 584
497 bool SendWebKeyEventJSONRequest( 585 bool SendWebKeyEventJSONRequest(
498 AutomationMessageSender* sender, 586 AutomationMessageSender* sender,
499 int browser_index, 587 const WebViewLocator& locator,
500 int tab_index,
501 const WebKeyEvent& key_event, 588 const WebKeyEvent& key_event,
502 std::string* error_msg) { 589 std::string* error_msg) {
503 DictionaryValue dict; 590 DictionaryValue dict;
504 dict.SetString("command", "SendWebkitKeyEvent"); 591 dict.SetString("command", "SendWebkitKeyEvent");
505 dict.SetInteger("windex", browser_index); 592 locator.UpdateDictionary(&dict, "auto_id");
506 dict.SetInteger("tab_index", tab_index);
507 dict.SetInteger("type", key_event.type); 593 dict.SetInteger("type", key_event.type);
508 dict.SetInteger("nativeKeyCode", key_event.key_code); 594 dict.SetInteger("nativeKeyCode", key_event.key_code);
509 dict.SetInteger("windowsKeyCode", key_event.key_code); 595 dict.SetInteger("windowsKeyCode", key_event.key_code);
510 dict.SetString("unmodifiedText", key_event.unmodified_text); 596 dict.SetString("unmodifiedText", key_event.unmodified_text);
511 dict.SetString("text", key_event.modified_text); 597 dict.SetString("text", key_event.modified_text);
512 dict.SetInteger("modifiers", key_event.modifiers); 598 dict.SetInteger("modifiers", key_event.modifiers);
513 dict.SetBoolean("isSystemKey", false); 599 dict.SetBoolean("isSystemKey", false);
514 DictionaryValue reply_dict; 600 DictionaryValue reply_dict;
515 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 601 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
516 } 602 }
517 603
518 bool SendNativeKeyEventJSONRequest( 604 bool SendNativeKeyEventJSONRequest(
519 AutomationMessageSender* sender, 605 AutomationMessageSender* sender,
520 int browser_index, 606 const WebViewLocator& locator,
521 int tab_index,
522 ui::KeyboardCode key_code, 607 ui::KeyboardCode key_code,
523 int modifiers, 608 int modifiers,
524 std::string* error_msg) { 609 std::string* error_msg) {
525 DictionaryValue dict; 610 DictionaryValue dict;
526 dict.SetString("command", "SendOSLevelKeyEventToTab"); 611 dict.SetString("command", "SendOSLevelKeyEventToTab");
527 dict.SetInteger("windex", browser_index); 612 locator.UpdateDictionary(&dict, "auto_id");
528 dict.SetInteger("tab_index", tab_index);
529 dict.SetInteger("keyCode", key_code); 613 dict.SetInteger("keyCode", key_code);
530 dict.SetInteger("modifiers", modifiers); 614 dict.SetInteger("modifiers", modifiers);
531 DictionaryValue reply_dict; 615 DictionaryValue reply_dict;
532 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 616 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
533 } 617 }
534 618
535 bool SendDragAndDropFilePathsJSONRequest( 619 bool SendDragAndDropFilePathsJSONRequest(
536 AutomationMessageSender* sender, 620 AutomationMessageSender* sender,
537 int browser_index, 621 const WebViewLocator& locator,
538 int tab_index,
539 int x, 622 int x,
540 int y, 623 int y,
541 const std::vector<FilePath::StringType>& paths, 624 const std::vector<FilePath::StringType>& paths,
542 std::string* error_msg) { 625 std::string* error_msg) {
543 DictionaryValue dict; 626 DictionaryValue dict;
544 dict.SetString("command", "DragAndDropFilePaths"); 627 dict.SetString("command", "DragAndDropFilePaths");
545 dict.SetInteger("windex", browser_index); 628 locator.UpdateDictionary(&dict, "auto_id");
546 dict.SetInteger("tab_index", tab_index);
547 dict.SetInteger("x", x); 629 dict.SetInteger("x", x);
548 dict.SetInteger("y", y); 630 dict.SetInteger("y", y);
549 631
550 ListValue* list_value = new ListValue(); 632 ListValue* list_value = new ListValue();
551 for (size_t path_index = 0; path_index < paths.size(); ++path_index) { 633 for (size_t path_index = 0; path_index < paths.size(); ++path_index) {
552 list_value->Append(Value::CreateStringValue(paths[path_index])); 634 list_value->Append(Value::CreateStringValue(paths[path_index]));
553 } 635 }
554 dict.Set("paths", list_value); 636 dict.Set("paths", list_value);
555 637
556 DictionaryValue reply_dict; 638 DictionaryValue reply_dict;
(...skipping 28 matching lines...) Expand all
585 const std::string& prompt_text, 667 const std::string& prompt_text,
586 std::string* error_msg) { 668 std::string* error_msg) {
587 DictionaryValue dict; 669 DictionaryValue dict;
588 dict.SetString("command", "AcceptOrDismissAppModalDialog"); 670 dict.SetString("command", "AcceptOrDismissAppModalDialog");
589 dict.SetBoolean("accept", true); 671 dict.SetBoolean("accept", true);
590 dict.SetString("prompt_text", prompt_text); 672 dict.SetString("prompt_text", prompt_text);
591 DictionaryValue reply_dict; 673 DictionaryValue reply_dict;
592 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 674 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
593 } 675 }
594 676
595 bool SendWaitForAllTabsToStopLoadingJSONRequest( 677 bool SendWaitForAllViewsToStopLoadingJSONRequest(
596 AutomationMessageSender* sender, 678 AutomationMessageSender* sender,
597 std::string* error_msg) { 679 std::string* error_msg) {
598 DictionaryValue dict; 680 DictionaryValue dict;
599 dict.SetString("command", "WaitForAllTabsToStopLoading"); 681 dict.SetString("command", "WaitForAllTabsToStopLoading");
600 DictionaryValue reply_dict; 682 DictionaryValue reply_dict;
601 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); 683 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
602 } 684 }
603 685
604 bool SendGetChromeDriverAutomationVersion( 686 bool SendGetChromeDriverAutomationVersion(
605 AutomationMessageSender* sender, 687 AutomationMessageSender* sender,
606 int* version, 688 int* version,
607 std::string* error_msg) { 689 std::string* error_msg) {
608 DictionaryValue dict; 690 DictionaryValue dict;
609 dict.SetString("command", "GetChromeDriverAutomationVersion"); 691 dict.SetString("command", "GetChromeDriverAutomationVersion");
610 DictionaryValue reply_dict; 692 DictionaryValue reply_dict;
611 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) 693 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
612 return false; 694 return false;
613 return reply_dict.GetInteger("version", version); 695 return reply_dict.GetInteger("version", version);
614 } 696 }
615 697
698 bool SendInstallExtensionJSONRequest(
699 AutomationMessageSender* sender,
700 const FilePath& path,
701 bool with_ui,
702 std::string* extension_id,
703 std::string* error_msg) {
704 DictionaryValue dict;
705 dict.SetString("command", "InstallExtension");
706 dict.SetString("path", path.value());
707 dict.SetBoolean("with_ui", with_ui);
708 DictionaryValue reply_dict;
709 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
710 return false;
711 if (!reply_dict.GetString("id", extension_id)) {
712 *error_msg = "Missing or invalid 'id'";
713 return false;
714 }
715 return true;
716 }
717
616 bool SendGetExtensionsInfoJSONRequest( 718 bool SendGetExtensionsInfoJSONRequest(
617 AutomationMessageSender* sender, 719 AutomationMessageSender* sender,
618 ListValue* extensions_list, 720 ListValue* extensions_list,
619 std::string* error_msg) { 721 std::string* error_msg) {
620 DictionaryValue dict; 722 DictionaryValue dict;
621 dict.SetString("command", "GetExtensionsInfo"); 723 dict.SetString("command", "GetExtensionsInfo");
622 DictionaryValue reply_dict; 724 DictionaryValue reply_dict;
623 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) 725 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
624 return false; 726 return false;
625 ListValue* extensions_list_swap; 727 ListValue* extensions_list_swap;
626 if (!reply_dict.GetList("extensions", &extensions_list_swap)) { 728 if (!reply_dict.GetList("extensions", &extensions_list_swap)) {
627 *error_msg = "Missing or invalid 'extensions'"; 729 *error_msg = "Missing or invalid 'extensions'";
628 return false; 730 return false;
629 } 731 }
630 extensions_list->Swap(extensions_list_swap); 732 extensions_list->Swap(extensions_list_swap);
631 return true; 733 return true;
632 } 734 }
633 735
634 bool SendInstallExtensionJSONRequest( 736 bool SendIsPageActionVisibleJSONRequest(
635 AutomationMessageSender* sender, 737 AutomationMessageSender* sender,
636 const FilePath& path, 738 const WebViewId& tab_id,
637 bool with_ui, 739 const std::string& extension_id,
638 std::string* extension_id, 740 bool* is_visible,
639 std::string* error_msg) { 741 std::string* error_msg) {
640 DictionaryValue dict; 742 DictionaryValue dict;
641 dict.SetString("command", "InstallExtension"); 743 dict.SetString("command", "IsPageActionVisible");
642 dict.SetString("path", path.value()); 744 tab_id.UpdateDictionary(&dict, "auto_id");
643 dict.SetBoolean("with_ui", with_ui); 745 dict.SetString("extension_id", extension_id);
644 DictionaryValue reply_dict; 746 DictionaryValue reply_dict;
645 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) 747 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
646 return false; 748 return false;
647 if (!reply_dict.GetString("id", extension_id)) { 749 if (!reply_dict.GetBoolean("is_visible", is_visible)) {
648 *error_msg = "Missing or invalid 'id'"; 750 *error_msg = "Missing or invalid 'is_visible'";
649 return false; 751 return false;
650 } 752 }
651 return true; 753 return true;
754 }
755
756 bool SendSetExtensionStateJSONRequest(
757 AutomationMessageSender* sender,
758 const std::string& extension_id,
759 bool enable,
760 bool allow_in_incognito,
761 std::string* error_msg) {
762 DictionaryValue dict;
763 dict.SetString("command", "SetExtensionStateById");
764 dict.SetString("id", extension_id);
765 dict.SetBoolean("enable", enable);
766 dict.SetBoolean("allow_in_incognito", allow_in_incognito);
767 DictionaryValue reply_dict;
768 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
769 }
770
771 bool SendClickExtensionButtonJSONRequest(
772 AutomationMessageSender* sender,
773 const std::string& extension_id,
774 bool browser_action,
775 std::string* error_msg) {
776 DictionaryValue dict;
777 if (browser_action)
778 dict.SetString("command", "TriggerBrowserActionById");
779 else
780 dict.SetString("command", "TriggerPageActionById");
781 dict.SetString("id", extension_id);
782 dict.SetInteger("windex", 0);
783 dict.SetInteger("tab_index", 0);
784 DictionaryValue reply_dict;
785 return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg);
786 }
787
788 bool SendUninstallExtensionJSONRequest(
789 AutomationMessageSender* sender,
790 const std::string& extension_id,
791 std::string* error_msg) {
792 DictionaryValue dict;
793 dict.SetString("command", "UninstallExtensionById");
794 dict.SetString("id", extension_id);
795 DictionaryValue reply_dict;
796 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
797 return false;
798 bool success;
799 if (!reply_dict.GetBoolean("success", &success)) {
800 *error_msg = "Missing or invalid 'success'";
801 return false;
802 }
803 if (!success) {
804 *error_msg = "Extension uninstall not permitted";
Huyen 2011/12/08 02:10:32 is there any chance this can also mean the uninsta
kkania 2011/12/08 17:31:21 No, if you look at NOTIFICATION_EXTENSION_UNINSTAL
805 return false;
806 }
807 return true;
652 } 808 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698