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 2054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2065 handler_map["CloseTab"] = | 2065 handler_map["CloseTab"] = |
| 2066 &TestingAutomationProvider::CloseTabJSON; | 2066 &TestingAutomationProvider::CloseTabJSON; |
| 2067 handler_map["WebkitMouseMove"] = | 2067 handler_map["WebkitMouseMove"] = |
| 2068 &TestingAutomationProvider::WebkitMouseMove; | 2068 &TestingAutomationProvider::WebkitMouseMove; |
| 2069 handler_map["WebkitMouseClick"] = | 2069 handler_map["WebkitMouseClick"] = |
| 2070 &TestingAutomationProvider::WebkitMouseClick; | 2070 &TestingAutomationProvider::WebkitMouseClick; |
| 2071 handler_map["WebkitMouseDrag"] = | 2071 handler_map["WebkitMouseDrag"] = |
| 2072 &TestingAutomationProvider::WebkitMouseDrag; | 2072 &TestingAutomationProvider::WebkitMouseDrag; |
| 2073 handler_map["SendWebkitKeyEvent"] = | 2073 handler_map["SendWebkitKeyEvent"] = |
| 2074 &TestingAutomationProvider::SendWebkitKeyEvent; | 2074 &TestingAutomationProvider::SendWebkitKeyEvent; |
| 2075 handler_map["SendOSLevelKeyEventToTab"] = | |
| 2076 &TestingAutomationProvider::SendOSLevelKeyEventToTab; | |
| 2075 handler_map["ActivateTab"] = | 2077 handler_map["ActivateTab"] = |
| 2076 &TestingAutomationProvider::ActivateTabJSON; | 2078 &TestingAutomationProvider::ActivateTabJSON; |
| 2077 #if defined(OS_CHROMEOS) | 2079 #if defined(OS_CHROMEOS) |
| 2078 handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo; | 2080 handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo; |
| 2079 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; | 2081 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; |
| 2080 handler_map["Login"] = &TestingAutomationProvider::Login; | 2082 handler_map["Login"] = &TestingAutomationProvider::Login; |
| 2081 | 2083 |
| 2082 handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen; | 2084 handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen; |
| 2083 handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen; | 2085 handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen; |
| 2084 handler_map["SignoutInScreenLocker"] = | 2086 handler_map["SignoutInScreenLocker"] = |
| (...skipping 2432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4517 if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) { | 4519 if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) { |
| 4518 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( | 4520 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( |
| 4519 "Failed to open process handle for pid %d", pid)); | 4521 "Failed to open process handle for pid %d", pid)); |
| 4520 return; | 4522 return; |
| 4521 } | 4523 } |
| 4522 new RendererProcessClosedObserver(this, reply_message); | 4524 new RendererProcessClosedObserver(this, reply_message); |
| 4523 base::KillProcess(process, 0, false); | 4525 base::KillProcess(process, 0, false); |
| 4524 base::CloseProcessHandle(process); | 4526 base::CloseProcessHandle(process); |
| 4525 } | 4527 } |
| 4526 | 4528 |
| 4529 bool TestingAutomationProvider::BuildWebKeyEventFromArgs( | |
| 4530 DictionaryValue* args, | |
| 4531 std::string* error, | |
| 4532 NativeWebKeyboardEvent* event) { | |
| 4533 int type, modifiers; | |
| 4534 bool is_system_key; | |
| 4535 string16 unmodified_text, text; | |
| 4536 std::string key_identifier; | |
| 4537 if (!args->GetInteger("type", &type)) { | |
| 4538 *error = "'type' missing or invalid."; | |
| 4539 return false; | |
| 4540 } | |
| 4541 if (!args->GetBoolean("isSystemKey", &is_system_key)) { | |
| 4542 *error = "'isSystemKey' missing or invalid."; | |
| 4543 return false; | |
| 4544 } | |
| 4545 if (!args->GetString("unmodifiedText", &unmodified_text)) { | |
| 4546 *error = "'unmodifiedText' missing or invalid."; | |
| 4547 return false; | |
| 4548 } | |
| 4549 if (!args->GetString("text", &text)) { | |
| 4550 *error = "'text' missing or invalid."; | |
| 4551 return false; | |
| 4552 } | |
| 4553 if (!args->GetInteger("nativeKeyCode", &event->nativeKeyCode)) { | |
| 4554 *error = "'nativeKeyCode' missing or invalid."; | |
| 4555 return false; | |
| 4556 } | |
| 4557 if (!args->GetInteger("windowsKeyCode", &event->windowsKeyCode)) { | |
| 4558 *error = "'windowsKeyCode' missing or invalid."; | |
| 4559 return false; | |
| 4560 } | |
| 4561 if (!args->GetInteger("modifiers", &modifiers)) { | |
| 4562 *error = "'modifiers' missing or invalid."; | |
| 4563 return false; | |
| 4564 } | |
| 4565 if (args->GetString("keyIdentifier", &key_identifier)) { | |
| 4566 base::strlcpy(event->keyIdentifier, | |
| 4567 key_identifier.c_str(), | |
| 4568 WebKit::WebKeyboardEvent::keyIdentifierLengthCap); | |
| 4569 } else { | |
| 4570 event->setKeyIdentifierFromWindowsKeyCode(); | |
| 4571 } | |
| 4572 | |
| 4573 if (type == automation::kRawKeyDownType) { | |
| 4574 event->type = WebKit::WebInputEvent::RawKeyDown; | |
| 4575 } else if (type == automation::kKeyDownType) { | |
| 4576 event->type = WebKit::WebInputEvent::KeyDown; | |
| 4577 } else if (type == automation::kKeyUpType) { | |
| 4578 event->type = WebKit::WebInputEvent::KeyUp; | |
| 4579 } else if (type == automation::kCharType) { | |
| 4580 event->type = WebKit::WebInputEvent::Char; | |
| 4581 } else { | |
| 4582 *error = "'type' refers to an unrecognized keyboard event type"; | |
| 4583 return false; | |
| 4584 } | |
| 4585 | |
| 4586 string16 unmodified_text_truncated = unmodified_text.substr( | |
| 4587 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | |
| 4588 memcpy(event->unmodifiedText, | |
| 4589 unmodified_text_truncated.c_str(), | |
| 4590 unmodified_text_truncated.length() + 1); | |
| 4591 string16 text_truncated = text.substr( | |
| 4592 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | |
| 4593 memcpy(event->text, text_truncated.c_str(), text_truncated.length() + 1); | |
| 4594 | |
| 4595 event->modifiers = 0; | |
| 4596 if (modifiers & automation::kShiftKeyMask) | |
| 4597 event->modifiers |= WebKit::WebInputEvent::ShiftKey; | |
| 4598 if (modifiers & automation::kControlKeyMask) | |
| 4599 event->modifiers |= WebKit::WebInputEvent::ControlKey; | |
| 4600 if (modifiers & automation::kAltKeyMask) | |
| 4601 event->modifiers |= WebKit::WebInputEvent::AltKey; | |
| 4602 if (modifiers & automation::kMetaKeyMask) | |
| 4603 event->modifiers |= WebKit::WebInputEvent::MetaKey; | |
| 4604 | |
| 4605 event->isSystemKey = is_system_key; | |
| 4606 event->timeStampSeconds = base::Time::Now().ToDoubleT(); | |
| 4607 event->skip_in_browser = true; | |
| 4608 return true; | |
| 4609 } | |
| 4610 | |
| 4527 void TestingAutomationProvider::SendWebkitKeyEvent( | 4611 void TestingAutomationProvider::SendWebkitKeyEvent( |
| 4528 DictionaryValue* args, | 4612 DictionaryValue* args, |
| 4529 IPC::Message* reply_message) { | 4613 IPC::Message* reply_message) { |
| 4614 NativeWebKeyboardEvent event; | |
| 4615 // BuildWebKeyEventFromArgs handles telling what when wrong and sending | |
| 4616 // the reply message, if it failed we just have to stop here. | |
| 4617 std::string error; | |
| 4618 if (!BuildWebKeyEventFromArgs(args, &error, &event)) { | |
| 4619 AutomationJSONReply(this, reply_message).SendError(error); | |
| 4620 return; | |
| 4621 } | |
| 4622 | |
| 4530 TabContents* tab_contents; | 4623 TabContents* tab_contents; |
| 4531 std::string error; | |
| 4532 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { | 4624 if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
| 4533 AutomationJSONReply(this, reply_message).SendError(error); | 4625 AutomationJSONReply(this, reply_message).SendError(error); |
| 4534 return; | 4626 return; |
| 4535 } | 4627 } |
| 4628 new InputEventAckNotificationObserver(this, reply_message, event.type); | |
| 4629 tab_contents->render_view_host()->ForwardKeyboardEvent(event); | |
| 4630 } | |
| 4536 | 4631 |
| 4537 int type, modifiers; | 4632 void TestingAutomationProvider::SendSuccessReply(IPC::Message* reply_message) { |
|
kkania
2011/03/29 04:55:12
convention is to put funcs in .cc in the same orde
timothe
2011/03/29 14:15:37
Done.
| |
| 4538 bool is_system_key; | 4633 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 4539 string16 unmodified_text, text; | 4634 } |
| 4540 std::string key_identifier; | 4635 |
| 4541 NativeWebKeyboardEvent event; | 4636 void TestingAutomationProvider::SendOSLevelKeyEventToTab( |
| 4542 if (!args->GetInteger("type", &type)) { | 4637 DictionaryValue* args, |
| 4543 AutomationJSONReply reply(this, reply_message); | 4638 IPC::Message* reply_message) { |
| 4544 reply.SendError("'type' missing or invalid."); | 4639 int modifiers, keycode; |
| 4545 return; | 4640 if (!args->GetInteger("keyCode", &keycode)) { |
| 4546 } | 4641 AutomationJSONReply(this, reply_message) |
| 4547 if (!args->GetBoolean("isSystemKey", &is_system_key)) { | 4642 .SendError("'nativeKeyCode' missing or invalid."); |
|
kkania
2011/03/29 04:55:12
update this
timothe
2011/03/29 14:15:37
Done.
| |
| 4548 AutomationJSONReply reply(this, reply_message); | |
| 4549 reply.SendError("'isSystemKey' missing or invalid."); | |
| 4550 return; | |
| 4551 } | |
| 4552 if (!args->GetString("unmodifiedText", &unmodified_text)) { | |
| 4553 AutomationJSONReply reply(this, reply_message); | |
| 4554 reply.SendError("'unmodifiedText' missing or invalid."); | |
| 4555 return; | |
| 4556 } | |
| 4557 if (!args->GetString("text", &text)) { | |
| 4558 AutomationJSONReply reply(this, reply_message); | |
| 4559 reply.SendError("'text' missing or invalid."); | |
| 4560 return; | |
| 4561 } | |
| 4562 if (!args->GetInteger("nativeKeyCode", &event.nativeKeyCode)) { | |
| 4563 AutomationJSONReply reply(this, reply_message); | |
| 4564 reply.SendError("'nativeKeyCode' missing or invalid."); | |
| 4565 return; | |
| 4566 } | |
| 4567 if (!args->GetInteger("windowsKeyCode", &event.windowsKeyCode)) { | |
| 4568 AutomationJSONReply reply(this, reply_message); | |
| 4569 reply.SendError("'windowsKeyCode' missing or invalid."); | |
| 4570 return; | 4643 return; |
| 4571 } | 4644 } |
| 4572 if (!args->GetInteger("modifiers", &modifiers)) { | 4645 if (!args->GetInteger("modifiers", &modifiers)) { |
| 4573 AutomationJSONReply reply(this, reply_message); | 4646 AutomationJSONReply(this, reply_message) |
| 4574 reply.SendError("'modifiers' missing or invalid."); | 4647 .SendError("'modifiers' missing or invalid."); |
| 4575 return; | |
| 4576 } | |
| 4577 if (args->GetString("keyIdentifier", &key_identifier)) { | |
| 4578 base::strlcpy(event.keyIdentifier, | |
| 4579 key_identifier.c_str(), | |
| 4580 WebKit::WebKeyboardEvent::keyIdentifierLengthCap); | |
| 4581 } else { | |
| 4582 event.setKeyIdentifierFromWindowsKeyCode(); | |
| 4583 } | |
| 4584 | |
| 4585 if (type == automation::kRawKeyDownType) { | |
| 4586 event.type = WebKit::WebInputEvent::RawKeyDown; | |
| 4587 } else if (type == automation::kKeyDownType) { | |
| 4588 event.type = WebKit::WebInputEvent::KeyDown; | |
| 4589 } else if (type == automation::kKeyUpType) { | |
| 4590 event.type = WebKit::WebInputEvent::KeyUp; | |
| 4591 } else if (type == automation::kCharType) { | |
| 4592 event.type = WebKit::WebInputEvent::Char; | |
| 4593 } else { | |
| 4594 AutomationJSONReply reply(this, reply_message); | |
| 4595 reply.SendError("'type' refers to an unrecognized keyboard event type"); | |
| 4596 return; | 4648 return; |
| 4597 } | 4649 } |
| 4598 | 4650 |
| 4599 string16 unmodified_text_truncated = unmodified_text.substr( | 4651 std::string error; |
| 4600 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | 4652 Browser* browser; |
| 4601 memcpy(event.unmodifiedText, | 4653 TabContents* tab_contents; |
| 4602 unmodified_text_truncated.c_str(), | 4654 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab_contents, &error)) { |
| 4603 unmodified_text_truncated.length() + 1); | 4655 AutomationJSONReply(this, reply_message).SendError(error); |
| 4604 string16 text_truncated = text.substr( | 4656 return; |
| 4605 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | 4657 } |
| 4606 memcpy(event.text, text_truncated.c_str(), text_truncated.length() + 1); | 4658 // The key events will be sent to the browser window, we need the current tab |
| 4659 // containing the element we send the text in to be shown. | |
| 4660 browser->SelectTabContentsAt( | |
| 4661 browser->GetIndexOfController(&tab_contents->controller()), true); | |
| 4607 | 4662 |
| 4608 event.modifiers = 0; | 4663 BrowserWindow* browser_window = browser->window(); |
| 4609 if (modifiers & automation::kShiftKeyMask) | 4664 if (!browser_window) { |
| 4610 event.modifiers |= WebKit::WebInputEvent::ShiftKey; | 4665 AutomationJSONReply(this, reply_message) |
| 4611 if (modifiers & automation::kControlKeyMask) | 4666 .SendError("Could not get the browser window"); |
| 4612 event.modifiers |= WebKit::WebInputEvent::ControlKey; | 4667 return; |
| 4613 if (modifiers & automation::kAltKeyMask) | 4668 } |
| 4614 event.modifiers |= WebKit::WebInputEvent::AltKey; | 4669 gfx::NativeWindow window = browser_window->GetNativeHandle(); |
| 4615 if (modifiers & automation::kMetaKeyMask) | 4670 if (!window) { |
| 4616 event.modifiers |= WebKit::WebInputEvent::MetaKey; | 4671 AutomationJSONReply(this, reply_message) |
| 4672 .SendError("Could not get the browser window handle"); | |
| 4673 return; | |
| 4674 } | |
| 4617 | 4675 |
| 4618 event.isSystemKey = is_system_key; | 4676 bool control = !!(modifiers & automation::kControlKeyMask); |
| 4619 event.timeStampSeconds = base::Time::Now().ToDoubleT(); | 4677 bool shift = !!(modifiers & automation::kShiftKeyMask); |
| 4620 event.skip_in_browser = true; | 4678 bool alt = !!(modifiers & automation::kAltKeyMask); |
| 4621 new InputEventAckNotificationObserver(this, reply_message, event.type); | 4679 bool meta = !!(modifiers & automation::kMetaKeyMask); |
| 4622 tab_contents->render_view_host()->ForwardKeyboardEvent(event); | 4680 if (!ui_controls::SendKeyPressNotifyWhenDone( |
| 4681 window, static_cast<ui::KeyboardCode>(keycode), | |
| 4682 control, shift, alt, meta, | |
| 4683 NewRunnableMethod(this, | |
| 4684 &TestingAutomationProvider::SendSuccessReply, reply_message))) { | |
| 4685 AutomationJSONReply(this, reply_message) | |
| 4686 .SendError("Could not send the native key event"); | |
| 4687 } | |
| 4623 } | 4688 } |
| 4624 | 4689 |
| 4625 // Sample JSON input: { "command": "GetNTPThumbnailMode" } | 4690 // Sample JSON input: { "command": "GetNTPThumbnailMode" } |
| 4626 // For output, refer to GetNTPThumbnailMode() in | 4691 // For output, refer to GetNTPThumbnailMode() in |
| 4627 // chrome/test/pyautolib/pyauto.py. | 4692 // chrome/test/pyautolib/pyauto.py. |
| 4628 void TestingAutomationProvider::GetNTPThumbnailMode( | 4693 void TestingAutomationProvider::GetNTPThumbnailMode( |
| 4629 Browser* browser, | 4694 Browser* browser, |
| 4630 DictionaryValue* args, | 4695 DictionaryValue* args, |
| 4631 IPC::Message* reply_message) { | 4696 IPC::Message* reply_message) { |
| 4632 const int shown_sections = ShownSectionsHandler::GetShownSections( | 4697 const int shown_sections = ShownSectionsHandler::GetShownSections( |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5200 // If you change this, update Observer for NotificationType::SESSION_END | 5265 // If you change this, update Observer for NotificationType::SESSION_END |
| 5201 // below. | 5266 // below. |
| 5202 MessageLoop::current()->PostTask(FROM_HERE, | 5267 MessageLoop::current()->PostTask(FROM_HERE, |
| 5203 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 5268 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
| 5204 } | 5269 } |
| 5205 } | 5270 } |
| 5206 | 5271 |
| 5207 void TestingAutomationProvider::OnRemoveProvider() { | 5272 void TestingAutomationProvider::OnRemoveProvider() { |
| 5208 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5273 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 5209 } | 5274 } |
| OLD | NEW |