Chromium Code Reviews| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 2122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2133 handler_map["CloseTab"] = | 2133 handler_map["CloseTab"] = |
| 2134 &TestingAutomationProvider::CloseTabJSON; | 2134 &TestingAutomationProvider::CloseTabJSON; |
| 2135 handler_map["WebkitMouseMove"] = | 2135 handler_map["WebkitMouseMove"] = |
| 2136 &TestingAutomationProvider::WebkitMouseMove; | 2136 &TestingAutomationProvider::WebkitMouseMove; |
| 2137 handler_map["WebkitMouseClick"] = | 2137 handler_map["WebkitMouseClick"] = |
| 2138 &TestingAutomationProvider::WebkitMouseClick; | 2138 &TestingAutomationProvider::WebkitMouseClick; |
| 2139 handler_map["WebkitMouseDrag"] = | 2139 handler_map["WebkitMouseDrag"] = |
| 2140 &TestingAutomationProvider::WebkitMouseDrag; | 2140 &TestingAutomationProvider::WebkitMouseDrag; |
| 2141 handler_map["SendWebkitKeyEvent"] = | 2141 handler_map["SendWebkitKeyEvent"] = |
| 2142 &TestingAutomationProvider::SendWebkitKeyEvent; | 2142 &TestingAutomationProvider::SendWebkitKeyEvent; |
| 2143 handler_map["SendOSLevelKeyEvent"] = | |
| 2144 &TestingAutomationProvider::SendOSLevelKeyEvent; | |
| 2143 handler_map["ActivateTab"] = | 2145 handler_map["ActivateTab"] = |
| 2144 &TestingAutomationProvider::ActivateTabJSON; | 2146 &TestingAutomationProvider::ActivateTabJSON; |
| 2145 #if defined(OS_CHROMEOS) | 2147 #if defined(OS_CHROMEOS) |
| 2146 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; | 2148 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; |
| 2147 handler_map["Login"] = &TestingAutomationProvider::Login; | 2149 handler_map["Login"] = &TestingAutomationProvider::Login; |
| 2148 handler_map["Logout"] = &TestingAutomationProvider::Logout; | 2150 handler_map["Logout"] = &TestingAutomationProvider::Logout; |
| 2149 handler_map["ScreenLock"] = &TestingAutomationProvider::ScreenLock; | 2151 handler_map["ScreenLock"] = &TestingAutomationProvider::ScreenLock; |
| 2150 handler_map["ScreenUnlock"] = &TestingAutomationProvider::ScreenUnlock; | 2152 handler_map["ScreenUnlock"] = &TestingAutomationProvider::ScreenUnlock; |
| 2151 | 2153 |
| 2152 handler_map["GetNetworkInfo"] = &TestingAutomationProvider::GetNetworkInfo; | 2154 handler_map["GetNetworkInfo"] = &TestingAutomationProvider::GetNetworkInfo; |
| (...skipping 2427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4580 if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) { | 4582 if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) { |
| 4581 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( | 4583 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( |
| 4582 "Failed to open process handle for pid %d", pid)); | 4584 "Failed to open process handle for pid %d", pid)); |
| 4583 return; | 4585 return; |
| 4584 } | 4586 } |
| 4585 new RendererProcessClosedObserver(this, reply_message); | 4587 new RendererProcessClosedObserver(this, reply_message); |
| 4586 base::KillProcess(process, 0, false); | 4588 base::KillProcess(process, 0, false); |
| 4587 base::CloseProcessHandle(process); | 4589 base::CloseProcessHandle(process); |
| 4588 } | 4590 } |
| 4589 | 4591 |
| 4592 bool TestingAutomationProvider::BuildWebKeyEventFromArgs( | |
| 4593 DictionaryValue* args, | |
| 4594 IPC::Message* reply_message, | |
| 4595 NativeWebKeyboardEvent* event) { | |
| 4596 | |
| 4597 int type, modifiers; | |
| 4598 bool is_system_key; | |
| 4599 string16 unmodified_text, text; | |
| 4600 std::string key_identifier; | |
| 4601 if (!args->GetInteger("type", &type)) { | |
| 4602 AutomationJSONReply(this, reply_message) | |
| 4603 .SendError("'type' missing or invalid."); | |
| 4604 return false; | |
| 4605 } | |
| 4606 if (!args->GetBoolean("isSystemKey", &is_system_key)) { | |
| 4607 AutomationJSONReply(this, reply_message) | |
| 4608 .SendError("'isSystemKey' missing or invalid."); | |
| 4609 return false; | |
| 4610 } | |
| 4611 if (!args->GetString("unmodifiedText", &unmodified_text)) { | |
| 4612 AutomationJSONReply(this, reply_message) | |
| 4613 .SendError("'unmodifiedText' missing or invalid."); | |
| 4614 return false; | |
| 4615 } | |
| 4616 if (!args->GetString("text", &text)) { | |
| 4617 AutomationJSONReply(this, reply_message) | |
| 4618 .SendError("'text' missing or invalid."); | |
| 4619 return false; | |
| 4620 } | |
| 4621 if (!args->GetInteger("nativeKeyCode", &event->nativeKeyCode)) { | |
| 4622 AutomationJSONReply(this, reply_message) | |
| 4623 .SendError("'nativeKeyCode' missing or invalid."); | |
| 4624 return false; | |
| 4625 } | |
| 4626 if (!args->GetInteger("windowsKeyCode", &event->windowsKeyCode)) { | |
| 4627 AutomationJSONReply(this, reply_message) | |
| 4628 .SendError("'windowsKeyCode' missing or invalid."); | |
| 4629 return false; | |
| 4630 } | |
| 4631 if (!args->GetInteger("modifiers", &modifiers)) { | |
| 4632 AutomationJSONReply(this, reply_message) | |
| 4633 .SendError("'modifiers' missing or invalid."); | |
| 4634 return false; | |
| 4635 } | |
| 4636 if (args->GetString("keyIdentifier", &key_identifier)) { | |
| 4637 base::strlcpy(event->keyIdentifier, | |
| 4638 key_identifier.c_str(), | |
| 4639 WebKit::WebKeyboardEvent::keyIdentifierLengthCap); | |
| 4640 } else { | |
| 4641 event->setKeyIdentifierFromWindowsKeyCode(); | |
| 4642 } | |
| 4643 | |
| 4644 if (type == automation::kRawKeyDownType) { | |
| 4645 event->type = WebKit::WebInputEvent::RawKeyDown; | |
| 4646 } else if (type == automation::kKeyDownType) { | |
| 4647 event->type = WebKit::WebInputEvent::KeyDown; | |
| 4648 } else if (type == automation::kKeyUpType) { | |
| 4649 event->type = WebKit::WebInputEvent::KeyUp; | |
| 4650 } else if (type == automation::kCharType) { | |
| 4651 event->type = WebKit::WebInputEvent::Char; | |
| 4652 } else { | |
| 4653 AutomationJSONReply(this, reply_message) | |
| 4654 .SendError("'type' refers to an unrecognized keyboard event type"); | |
| 4655 return false; | |
| 4656 } | |
| 4657 | |
| 4658 string16 unmodified_text_truncated = unmodified_text.substr( | |
| 4659 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | |
| 4660 memcpy(event->unmodifiedText, | |
| 4661 unmodified_text_truncated.c_str(), | |
| 4662 unmodified_text_truncated.length() + 1); | |
| 4663 string16 text_truncated = text.substr( | |
| 4664 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | |
| 4665 memcpy(event->text, text_truncated.c_str(), text_truncated.length() + 1); | |
| 4666 | |
| 4667 event->modifiers = 0; | |
| 4668 if (modifiers & automation::kShiftKeyMask) | |
| 4669 event->modifiers |= WebKit::WebInputEvent::ShiftKey; | |
| 4670 if (modifiers & automation::kControlKeyMask) | |
| 4671 event->modifiers |= WebKit::WebInputEvent::ControlKey; | |
| 4672 if (modifiers & automation::kAltKeyMask) | |
| 4673 event->modifiers |= WebKit::WebInputEvent::AltKey; | |
| 4674 if (modifiers & automation::kMetaKeyMask) | |
| 4675 event->modifiers |= WebKit::WebInputEvent::MetaKey; | |
| 4676 | |
| 4677 event->isSystemKey = is_system_key; | |
| 4678 event->timeStampSeconds = base::Time::Now().ToDoubleT(); | |
| 4679 event->skip_in_browser = true; | |
| 4680 return true; | |
| 4681 } | |
| 4682 | |
| 4590 void TestingAutomationProvider::SendWebkitKeyEvent( | 4683 void TestingAutomationProvider::SendWebkitKeyEvent( |
| 4591 DictionaryValue* args, | 4684 DictionaryValue* args, |
| 4592 IPC::Message* reply_message) { | 4685 IPC::Message* reply_message) { |
| 4686 NativeWebKeyboardEvent event; | |
| 4687 // BuildWebKeyEventFromArgs handles telling what when wrong and sending | |
| 4688 // the reply message, if it failed we just have to stop here. | |
| 4689 if (!BuildWebKeyEventFromArgs(args, reply_message, &event)) | |
|
kkania
2011/03/11 16:32:13
I am not sure what the benefit of having this addi
timothe
2011/03/21 18:02:05
As the fact of building a key event form the args
| |
| 4690 return; | |
| 4691 | |
| 4593 TabContents* tab_contents; | 4692 TabContents* tab_contents; |
| 4594 std::string error; | 4693 std::string error; |
| 4595 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 4694 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
| 4596 AutomationJSONReply(this, reply_message).SendError(error); | 4695 AutomationJSONReply(this, reply_message).SendError(error); |
| 4597 return; | 4696 return; |
| 4598 } | 4697 } |
| 4698 LOG(INFO) << "reply_message:" << reply_message; | |
| 4699 new InputEventAckNotificationObserver(this, reply_message, event.type); | |
| 4700 tab_contents->render_view_host()->ForwardKeyboardEvent(event); | |
| 4701 } | |
| 4599 | 4702 |
| 4600 int type, modifiers; | 4703 void TestingAutomationProvider::SendOSLevelKeyEvent( |
| 4601 bool is_system_key; | 4704 DictionaryValue* args, |
| 4602 string16 unmodified_text, text; | 4705 IPC::Message* reply_message) { |
| 4603 std::string key_identifier; | 4706 int modifiers, keycode; |
| 4604 NativeWebKeyboardEvent event; | 4707 AutomationJSONReply reply(this, reply_message); |
| 4605 if (!args->GetInteger("type", &type)) { | 4708 if (!args->GetInteger("nativeKeyCode", &keycode)) { |
|
kkania
2011/03/11 16:32:13
i think the keycode you are passing in is actually
timothe
2011/03/21 18:02:05
Yes indeed it is a ui::KeyboardCode, I don't quite
| |
| 4606 AutomationJSONReply reply(this, reply_message); | |
| 4607 reply.SendError("'type' missing or invalid."); | |
| 4608 return; | |
| 4609 } | |
| 4610 if (!args->GetBoolean("isSystemKey", &is_system_key)) { | |
| 4611 AutomationJSONReply reply(this, reply_message); | |
| 4612 reply.SendError("'isSystemKey' missing or invalid."); | |
| 4613 return; | |
| 4614 } | |
| 4615 if (!args->GetString("unmodifiedText", &unmodified_text)) { | |
| 4616 AutomationJSONReply reply(this, reply_message); | |
| 4617 reply.SendError("'unmodifiedText' missing or invalid."); | |
| 4618 return; | |
| 4619 } | |
| 4620 if (!args->GetString("text", &text)) { | |
| 4621 AutomationJSONReply reply(this, reply_message); | |
| 4622 reply.SendError("'text' missing or invalid."); | |
| 4623 return; | |
| 4624 } | |
| 4625 if (!args->GetInteger("nativeKeyCode", &event.nativeKeyCode)) { | |
| 4626 AutomationJSONReply reply(this, reply_message); | |
| 4627 reply.SendError("'nativeKeyCode' missing or invalid."); | 4709 reply.SendError("'nativeKeyCode' missing or invalid."); |
| 4628 return; | 4710 return; |
| 4629 } | 4711 } |
| 4630 if (!args->GetInteger("windowsKeyCode", &event.windowsKeyCode)) { | |
| 4631 AutomationJSONReply reply(this, reply_message); | |
| 4632 reply.SendError("'windowsKeyCode' missing or invalid."); | |
| 4633 return; | |
| 4634 } | |
| 4635 if (!args->GetInteger("modifiers", &modifiers)) { | 4712 if (!args->GetInteger("modifiers", &modifiers)) { |
| 4636 AutomationJSONReply reply(this, reply_message); | |
| 4637 reply.SendError("'modifiers' missing or invalid."); | 4713 reply.SendError("'modifiers' missing or invalid."); |
| 4638 return; | 4714 return; |
| 4639 } | 4715 } |
| 4640 if (args->GetString("keyIdentifier", &key_identifier)) { | |
| 4641 base::strlcpy(event.keyIdentifier, | |
| 4642 key_identifier.c_str(), | |
| 4643 WebKit::WebKeyboardEvent::keyIdentifierLengthCap); | |
| 4644 } else { | |
| 4645 event.setKeyIdentifierFromWindowsKeyCode(); | |
| 4646 } | |
| 4647 | 4716 |
| 4648 if (type == automation::kRawKeyDownType) { | 4717 Browser* browser; |
| 4649 event.type = WebKit::WebInputEvent::RawKeyDown; | 4718 std::string error; |
| 4650 } else if (type == automation::kKeyDownType) { | 4719 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { |
|
kkania
2011/03/11 16:32:13
I think you should also get TabContents here and t
timothe
2011/03/21 18:02:05
Done.
| |
| 4651 event.type = WebKit::WebInputEvent::KeyDown; | 4720 reply.SendError(error); |
| 4652 } else if (type == automation::kKeyUpType) { | |
| 4653 event.type = WebKit::WebInputEvent::KeyUp; | |
| 4654 } else if (type == automation::kCharType) { | |
| 4655 event.type = WebKit::WebInputEvent::Char; | |
| 4656 } else { | |
| 4657 AutomationJSONReply reply(this, reply_message); | |
| 4658 reply.SendError("'type' refers to an unrecognized keyboard event type"); | |
| 4659 return; | 4721 return; |
| 4660 } | 4722 } |
| 4661 | 4723 BrowserWindow* browser_window = browser->window(); |
| 4662 string16 unmodified_text_truncated = unmodified_text.substr( | 4724 if (!browser_window) { |
| 4663 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | 4725 reply.SendError("Could not get the browser window"); |
| 4664 memcpy(event.unmodifiedText, | 4726 return; |
| 4665 unmodified_text_truncated.c_str(), | 4727 } |
| 4666 unmodified_text_truncated.length() + 1); | 4728 gfx::NativeWindow window = browser_window->GetNativeHandle(); |
| 4667 string16 text_truncated = text.substr( | 4729 if (!window) { |
| 4668 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | 4730 reply.SendError("Could not get the browser window handle"); |
| 4669 memcpy(event.text, text_truncated.c_str(), text_truncated.length() + 1); | 4731 return; |
| 4670 | 4732 } |
| 4671 event.modifiers = 0; | 4733 bool control = !!(modifiers & automation::kControlKeyMask); |
| 4672 if (modifiers & automation::kShiftKeyMask) | 4734 bool shift = !!(modifiers & automation::kShiftKeyMask); |
| 4673 event.modifiers |= WebKit::WebInputEvent::ShiftKey; | 4735 bool alt = !!(modifiers & automation::kAltKeyMask); |
| 4674 if (modifiers & automation::kControlKeyMask) | 4736 bool meta = !!(modifiers & automation::kMetaKeyMask); |
| 4675 event.modifiers |= WebKit::WebInputEvent::ControlKey; | 4737 if (!ui_controls::SendKeyPress( |
| 4676 if (modifiers & automation::kAltKeyMask) | 4738 window, static_cast<ui::KeyboardCode>(keycode), |
| 4677 event.modifiers |= WebKit::WebInputEvent::AltKey; | 4739 control, shift, alt, meta)) { |
| 4678 if (modifiers & automation::kMetaKeyMask) | 4740 reply.SendError("Could not send the native key event"); |
| 4679 event.modifiers |= WebKit::WebInputEvent::MetaKey; | 4741 } else { |
| 4680 | 4742 reply.SendSuccess(NULL); |
| 4681 event.isSystemKey = is_system_key; | 4743 } |
| 4682 event.timeStampSeconds = base::Time::Now().ToDoubleT(); | |
| 4683 event.skip_in_browser = true; | |
| 4684 new InputEventAckNotificationObserver(this, reply_message, event.type); | |
| 4685 tab_contents->render_view_host()->ForwardKeyboardEvent(event); | |
| 4686 } | 4744 } |
| 4687 | 4745 |
| 4688 // Sample JSON input: { "command": "GetNTPThumbnailMode" } | 4746 // Sample JSON input: { "command": "GetNTPThumbnailMode" } |
| 4689 // For output, refer to GetNTPThumbnailMode() in | 4747 // For output, refer to GetNTPThumbnailMode() in |
| 4690 // chrome/test/pyautolib/pyauto.py. | 4748 // chrome/test/pyautolib/pyauto.py. |
| 4691 void TestingAutomationProvider::GetNTPThumbnailMode( | 4749 void TestingAutomationProvider::GetNTPThumbnailMode( |
| 4692 Browser* browser, | 4750 Browser* browser, |
| 4693 DictionaryValue* args, | 4751 DictionaryValue* args, |
| 4694 IPC::Message* reply_message) { | 4752 IPC::Message* reply_message) { |
| 4695 const int shown_sections = ShownSectionsHandler::GetShownSections( | 4753 const int shown_sections = ShownSectionsHandler::GetShownSections( |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5362 // If you change this, update Observer for NotificationType::SESSION_END | 5420 // If you change this, update Observer for NotificationType::SESSION_END |
| 5363 // below. | 5421 // below. |
| 5364 MessageLoop::current()->PostTask(FROM_HERE, | 5422 MessageLoop::current()->PostTask(FROM_HERE, |
| 5365 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 5423 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
| 5366 } | 5424 } |
| 5367 } | 5425 } |
| 5368 | 5426 |
| 5369 void TestingAutomationProvider::OnRemoveProvider() { | 5427 void TestingAutomationProvider::OnRemoveProvider() { |
| 5370 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5428 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 5371 } | 5429 } |
| OLD | NEW |