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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 6630001: Allow webdriver users to choose between sending the key events when... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 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/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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 2052 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 handler_map["CloseTab"] = 2063 handler_map["CloseTab"] =
2064 &TestingAutomationProvider::CloseTabJSON; 2064 &TestingAutomationProvider::CloseTabJSON;
2065 handler_map["WebkitMouseMove"] = 2065 handler_map["WebkitMouseMove"] =
2066 &TestingAutomationProvider::WebkitMouseMove; 2066 &TestingAutomationProvider::WebkitMouseMove;
2067 handler_map["WebkitMouseClick"] = 2067 handler_map["WebkitMouseClick"] =
2068 &TestingAutomationProvider::WebkitMouseClick; 2068 &TestingAutomationProvider::WebkitMouseClick;
2069 handler_map["WebkitMouseDrag"] = 2069 handler_map["WebkitMouseDrag"] =
2070 &TestingAutomationProvider::WebkitMouseDrag; 2070 &TestingAutomationProvider::WebkitMouseDrag;
2071 handler_map["SendWebkitKeyEvent"] = 2071 handler_map["SendWebkitKeyEvent"] =
2072 &TestingAutomationProvider::SendWebkitKeyEvent; 2072 &TestingAutomationProvider::SendWebkitKeyEvent;
2073 handler_map["SendOSLevelKeyEvent"] =
2074 &TestingAutomationProvider::SendOSLevelKeyEvent;
2073 handler_map["ActivateTab"] = 2075 handler_map["ActivateTab"] =
2074 &TestingAutomationProvider::ActivateTabJSON; 2076 &TestingAutomationProvider::ActivateTabJSON;
2075 #if defined(OS_CHROMEOS) 2077 #if defined(OS_CHROMEOS)
2076 handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo; 2078 handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo;
2077 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; 2079 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest;
2078 handler_map["Login"] = &TestingAutomationProvider::Login; 2080 handler_map["Login"] = &TestingAutomationProvider::Login;
2079 2081
2080 handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen; 2082 handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen;
2081 handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen; 2083 handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen;
2082 handler_map["SignoutInScreenLocker"] = 2084 handler_map["SignoutInScreenLocker"] =
(...skipping 2432 matching lines...) Expand 10 before | Expand all | Expand 10 after
4515 if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) { 4517 if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) {
4516 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( 4518 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf(
4517 "Failed to open process handle for pid %d", pid)); 4519 "Failed to open process handle for pid %d", pid));
4518 return; 4520 return;
4519 } 4521 }
4520 new RendererProcessClosedObserver(this, reply_message); 4522 new RendererProcessClosedObserver(this, reply_message);
4521 base::KillProcess(process, 0, false); 4523 base::KillProcess(process, 0, false);
4522 base::CloseProcessHandle(process); 4524 base::CloseProcessHandle(process);
4523 } 4525 }
4524 4526
4527 bool TestingAutomationProvider::BuildWebKeyEventFromArgs(
4528 DictionaryValue* args,
4529 IPC::Message* reply_message,
4530 NativeWebKeyboardEvent* event) {
4531
kkania 2011/03/24 23:20:32 remove unecessary newline
timothe 2011/03/25 11:07:59 Done.
4532 int type, modifiers;
4533 bool is_system_key;
4534 string16 unmodified_text, text;
4535 std::string key_identifier;
4536 if (!args->GetInteger("type", &type)) {
kkania 2011/03/24 23:20:32 fix indentation
timothe 2011/03/25 11:07:59 Done.
4537 AutomationJSONReply(this, reply_message)
4538 .SendError("'type' missing or invalid.");
4539 return false;
4540 }
4541 if (!args->GetBoolean("isSystemKey", &is_system_key)) {
4542 AutomationJSONReply(this, reply_message)
4543 .SendError("'isSystemKey' missing or invalid.");
4544 return false;
4545 }
4546 if (!args->GetString("unmodifiedText", &unmodified_text)) {
4547 AutomationJSONReply(this, reply_message)
4548 .SendError("'unmodifiedText' missing or invalid.");
4549 return false;
4550 }
4551 if (!args->GetString("text", &text)) {
4552 AutomationJSONReply(this, reply_message)
4553 .SendError("'text' missing or invalid.");
4554 return false;
4555 }
4556 if (!args->GetInteger("nativeKeyCode", &event->nativeKeyCode)) {
4557 AutomationJSONReply(this, reply_message)
4558 .SendError("'nativeKeyCode' missing or invalid.");
4559 return false;
4560 }
4561 if (!args->GetInteger("windowsKeyCode", &event->windowsKeyCode)) {
4562 AutomationJSONReply(this, reply_message)
4563 .SendError("'windowsKeyCode' missing or invalid.");
4564 return false;
4565 }
4566 if (!args->GetInteger("modifiers", &modifiers)) {
4567 AutomationJSONReply(this, reply_message)
4568 .SendError("'modifiers' missing or invalid.");
4569 return false;
4570 }
4571 if (args->GetString("keyIdentifier", &key_identifier)) {
4572 base::strlcpy(event->keyIdentifier,
4573 key_identifier.c_str(),
4574 WebKit::WebKeyboardEvent::keyIdentifierLengthCap);
4575 } else {
4576 event->setKeyIdentifierFromWindowsKeyCode();
4577 }
4578
4579 if (type == automation::kRawKeyDownType) {
4580 event->type = WebKit::WebInputEvent::RawKeyDown;
4581 } else if (type == automation::kKeyDownType) {
4582 event->type = WebKit::WebInputEvent::KeyDown;
4583 } else if (type == automation::kKeyUpType) {
4584 event->type = WebKit::WebInputEvent::KeyUp;
4585 } else if (type == automation::kCharType) {
4586 event->type = WebKit::WebInputEvent::Char;
4587 } else {
4588 AutomationJSONReply(this, reply_message)
4589 .SendError("'type' refers to an unrecognized keyboard event type");
4590 return false;
4591 }
4592
4593 string16 unmodified_text_truncated = unmodified_text.substr(
4594 0, WebKit::WebKeyboardEvent::textLengthCap - 1);
4595 memcpy(event->unmodifiedText,
4596 unmodified_text_truncated.c_str(),
4597 unmodified_text_truncated.length() + 1);
4598 string16 text_truncated = text.substr(
4599 0, WebKit::WebKeyboardEvent::textLengthCap - 1);
4600 memcpy(event->text, text_truncated.c_str(), text_truncated.length() + 1);
4601
4602 event->modifiers = 0;
4603 if (modifiers & automation::kShiftKeyMask)
4604 event->modifiers |= WebKit::WebInputEvent::ShiftKey;
4605 if (modifiers & automation::kControlKeyMask)
4606 event->modifiers |= WebKit::WebInputEvent::ControlKey;
4607 if (modifiers & automation::kAltKeyMask)
4608 event->modifiers |= WebKit::WebInputEvent::AltKey;
4609 if (modifiers & automation::kMetaKeyMask)
4610 event->modifiers |= WebKit::WebInputEvent::MetaKey;
4611
4612 event->isSystemKey = is_system_key;
4613 event->timeStampSeconds = base::Time::Now().ToDoubleT();
4614 event->skip_in_browser = true;
4615 return true;
4616 }
4617
4525 void TestingAutomationProvider::SendWebkitKeyEvent( 4618 void TestingAutomationProvider::SendWebkitKeyEvent(
4526 DictionaryValue* args, 4619 DictionaryValue* args,
4527 IPC::Message* reply_message) { 4620 IPC::Message* reply_message) {
4621 NativeWebKeyboardEvent event;
4622 // BuildWebKeyEventFromArgs handles telling what when wrong and sending
4623 // the reply message, if it failed we just have to stop here.
4624 if (!BuildWebKeyEventFromArgs(args, reply_message, &event))
kkania 2011/03/24 23:20:32 instead of giving reply_message, can you give it a
timothe 2011/03/25 11:07:59 Done.
4625 return;
4626
4528 TabContents* tab_contents; 4627 TabContents* tab_contents;
4529 std::string error; 4628 std::string error;
4530 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { 4629 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) {
4531 AutomationJSONReply(this, reply_message).SendError(error); 4630 AutomationJSONReply(this, reply_message).SendError(error);
4532 return; 4631 return;
4533 } 4632 }
4633 LOG(INFO) << "reply_message:" << reply_message;
Paweł Hajdan Jr. 2011/03/23 10:16:05 Please remove debugging LOG messages before checki
timothe 2011/03/23 10:54:04 Done.
4634 new InputEventAckNotificationObserver(this, reply_message, event.type);
4635 tab_contents->render_view_host()->ForwardKeyboardEvent(event);
4636 }
4534 4637
4535 int type, modifiers; 4638 void TestingAutomationProvider::SendSuccessReply(IPC::Message* reply_message) {
4536 bool is_system_key; 4639 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
4537 string16 unmodified_text, text; 4640 }
4538 std::string key_identifier; 4641
4539 NativeWebKeyboardEvent event; 4642 void TestingAutomationProvider::SendOSLevelKeyEvent(
4540 if (!args->GetInteger("type", &type)) { 4643 DictionaryValue* args,
4541 AutomationJSONReply reply(this, reply_message); 4644 IPC::Message* reply_message) {
4542 reply.SendError("'type' missing or invalid."); 4645 int modifiers, keycode;
4543 return; 4646 if (!args->GetInteger("nativeKeyCode", &keycode)) {
kkania 2011/03/24 23:20:32 ui::KeyboardCode is supposed to be a platform inde
timothe 2011/03/25 11:07:59 Done.
4544 } 4647 AutomationJSONReply(this, reply_message)
4545 if (!args->GetBoolean("isSystemKey", &is_system_key)) { 4648 .SendError("'nativeKeyCode' missing or invalid.");
4546 AutomationJSONReply reply(this, reply_message);
4547 reply.SendError("'isSystemKey' missing or invalid.");
4548 return;
4549 }
4550 if (!args->GetString("unmodifiedText", &unmodified_text)) {
4551 AutomationJSONReply reply(this, reply_message);
4552 reply.SendError("'unmodifiedText' missing or invalid.");
4553 return;
4554 }
4555 if (!args->GetString("text", &text)) {
4556 AutomationJSONReply reply(this, reply_message);
4557 reply.SendError("'text' missing or invalid.");
4558 return;
4559 }
4560 if (!args->GetInteger("nativeKeyCode", &event.nativeKeyCode)) {
4561 AutomationJSONReply reply(this, reply_message);
4562 reply.SendError("'nativeKeyCode' missing or invalid.");
4563 return;
4564 }
4565 if (!args->GetInteger("windowsKeyCode", &event.windowsKeyCode)) {
4566 AutomationJSONReply reply(this, reply_message);
4567 reply.SendError("'windowsKeyCode' missing or invalid.");
4568 return; 4649 return;
4569 } 4650 }
4570 if (!args->GetInteger("modifiers", &modifiers)) { 4651 if (!args->GetInteger("modifiers", &modifiers)) {
4571 AutomationJSONReply reply(this, reply_message); 4652 AutomationJSONReply(this, reply_message)
4572 reply.SendError("'modifiers' missing or invalid."); 4653 .SendError("'modifiers' missing or invalid.");
4573 return;
4574 }
4575 if (args->GetString("keyIdentifier", &key_identifier)) {
4576 base::strlcpy(event.keyIdentifier,
4577 key_identifier.c_str(),
4578 WebKit::WebKeyboardEvent::keyIdentifierLengthCap);
4579 } else {
4580 event.setKeyIdentifierFromWindowsKeyCode();
4581 }
4582
4583 if (type == automation::kRawKeyDownType) {
4584 event.type = WebKit::WebInputEvent::RawKeyDown;
4585 } else if (type == automation::kKeyDownType) {
4586 event.type = WebKit::WebInputEvent::KeyDown;
4587 } else if (type == automation::kKeyUpType) {
4588 event.type = WebKit::WebInputEvent::KeyUp;
4589 } else if (type == automation::kCharType) {
4590 event.type = WebKit::WebInputEvent::Char;
4591 } else {
4592 AutomationJSONReply reply(this, reply_message);
4593 reply.SendError("'type' refers to an unrecognized keyboard event type");
4594 return; 4654 return;
4595 } 4655 }
4596 4656
4597 string16 unmodified_text_truncated = unmodified_text.substr( 4657 std::string error;
4598 0, WebKit::WebKeyboardEvent::textLengthCap - 1); 4658 Browser* browser;
4599 memcpy(event.unmodifiedText, 4659 TabContents* tab_contents;
4600 unmodified_text_truncated.c_str(), 4660 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab_contents, &error)) {
4601 unmodified_text_truncated.length() + 1); 4661 AutomationJSONReply(this, reply_message).SendError(error);
4602 string16 text_truncated = text.substr( 4662 return;
4603 0, WebKit::WebKeyboardEvent::textLengthCap - 1); 4663 }
4604 memcpy(event.text, text_truncated.c_str(), text_truncated.length() + 1); 4664 // The key events will be sent ot the browser level, we need the current tab
kkania 2011/03/24 23:20:32 ot -> at
timothe 2011/03/25 11:07:59 Done.
4665 // containing the element we send the text in to be shown.
kkania 2011/03/24 23:20:32 I do not like this comment for two reasons: 1) It
timothe 2011/03/25 11:07:59 1) Done, changed to "browser window". 2) Well, Ty
kkania 2011/03/25 16:37:36 I see. I don't think we want to add SetOmniboxText
timothe 2011/03/28 18:35:48 I agree, let's not add browser centric capabilitie
4666 browser->SelectTabContentsAt(
kkania 2011/03/25 16:37:36 If you want to keep this selection here, change th
timothe 2011/03/28 18:35:48 Done. Added ToTab. On 2011/03/25 16:37:36, kkania
4667 browser->GetIndexOfController(&tab_contents->controller()), true);
4605 4668
4606 event.modifiers = 0; 4669 BrowserWindow* browser_window = browser->window();
4607 if (modifiers & automation::kShiftKeyMask) 4670 if (!browser_window) {
4608 event.modifiers |= WebKit::WebInputEvent::ShiftKey; 4671 AutomationJSONReply(this, reply_message)
4609 if (modifiers & automation::kControlKeyMask) 4672 .SendError("Could not get the browser window");
4610 event.modifiers |= WebKit::WebInputEvent::ControlKey; 4673 return;
4611 if (modifiers & automation::kAltKeyMask) 4674 }
4612 event.modifiers |= WebKit::WebInputEvent::AltKey; 4675 gfx::NativeWindow window = browser_window->GetNativeHandle();
4613 if (modifiers & automation::kMetaKeyMask) 4676 if (!window) {
4614 event.modifiers |= WebKit::WebInputEvent::MetaKey; 4677 AutomationJSONReply(this, reply_message)
4678 .SendError("Could not get the browser window handle");
4679 return;
4680 }
4615 4681
4616 event.isSystemKey = is_system_key; 4682 bool control = !!(modifiers & automation::kControlKeyMask);
4617 event.timeStampSeconds = base::Time::Now().ToDoubleT(); 4683 bool shift = !!(modifiers & automation::kShiftKeyMask);
4618 event.skip_in_browser = true; 4684 bool alt = !!(modifiers & automation::kAltKeyMask);
4619 new InputEventAckNotificationObserver(this, reply_message, event.type); 4685 bool meta = !!(modifiers & automation::kMetaKeyMask);
4620 tab_contents->render_view_host()->ForwardKeyboardEvent(event); 4686 if (!ui_controls::SendKeyPressNotifyWhenDone(
4687 window, static_cast<ui::KeyboardCode>(keycode),
4688 control, shift, alt, meta,
4689 NewRunnableMethod(this,
4690 &TestingAutomationProvider::SendSuccessReply, reply_message))) {
4691 AutomationJSONReply(this, reply_message)
4692 .SendError("Could not send the native key event");
4693 }
4621 } 4694 }
4622 4695
4623 // Sample JSON input: { "command": "GetNTPThumbnailMode" } 4696 // Sample JSON input: { "command": "GetNTPThumbnailMode" }
4624 // For output, refer to GetNTPThumbnailMode() in 4697 // For output, refer to GetNTPThumbnailMode() in
4625 // chrome/test/pyautolib/pyauto.py. 4698 // chrome/test/pyautolib/pyauto.py.
4626 void TestingAutomationProvider::GetNTPThumbnailMode( 4699 void TestingAutomationProvider::GetNTPThumbnailMode(
4627 Browser* browser, 4700 Browser* browser,
4628 DictionaryValue* args, 4701 DictionaryValue* args,
4629 IPC::Message* reply_message) { 4702 IPC::Message* reply_message) {
4630 const int shown_sections = ShownSectionsHandler::GetShownSections( 4703 const int shown_sections = ShownSectionsHandler::GetShownSections(
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
5198 // If you change this, update Observer for NotificationType::SESSION_END 5271 // If you change this, update Observer for NotificationType::SESSION_END
5199 // below. 5272 // below.
5200 MessageLoop::current()->PostTask(FROM_HERE, 5273 MessageLoop::current()->PostTask(FROM_HERE,
5201 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); 5274 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
5202 } 5275 }
5203 } 5276 }
5204 5277
5205 void TestingAutomationProvider::OnRemoveProvider() { 5278 void TestingAutomationProvider::OnRemoveProvider() {
5206 AutomationProviderList::GetInstance()->RemoveProvider(this); 5279 AutomationProviderList::GetInstance()->RemoveProvider(this);
5207 } 5280 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698