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 2244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2255 browser_handler_map["UnpinNTPMostVisitedThumbnail"] = | 2255 browser_handler_map["UnpinNTPMostVisitedThumbnail"] = |
| 2256 &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail; | 2256 &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail; |
| 2257 browser_handler_map["RestoreAllNTPMostVisitedThumbnails"] = | 2257 browser_handler_map["RestoreAllNTPMostVisitedThumbnails"] = |
| 2258 &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; | 2258 &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails; |
| 2259 | 2259 |
| 2260 browser_handler_map["KillRendererProcess"] = | 2260 browser_handler_map["KillRendererProcess"] = |
| 2261 &TestingAutomationProvider::KillRendererProcess; | 2261 &TestingAutomationProvider::KillRendererProcess; |
| 2262 | 2262 |
| 2263 browser_handler_map["SendKeyEventToActiveTab"] = | 2263 browser_handler_map["SendKeyEventToActiveTab"] = |
| 2264 &TestingAutomationProvider::SendKeyEventToActiveTab; | 2264 &TestingAutomationProvider::SendKeyEventToActiveTab; |
| 2265 browser_handler_map["SendKeyEventToActiveBrowserWindow"] = | |
| 2266 &TestingAutomationProvider::SendKeyEventToActiveBrowserWindow; | |
| 2265 | 2267 |
| 2266 browser_handler_map["GetNTPThumbnailMode"] = | 2268 browser_handler_map["GetNTPThumbnailMode"] = |
| 2267 &TestingAutomationProvider::GetNTPThumbnailMode; | 2269 &TestingAutomationProvider::GetNTPThumbnailMode; |
| 2268 browser_handler_map["SetNTPThumbnailMode"] = | 2270 browser_handler_map["SetNTPThumbnailMode"] = |
| 2269 &TestingAutomationProvider::SetNTPThumbnailMode; | 2271 &TestingAutomationProvider::SetNTPThumbnailMode; |
| 2270 browser_handler_map["GetNTPMenuMode"] = | 2272 browser_handler_map["GetNTPMenuMode"] = |
| 2271 &TestingAutomationProvider::GetNTPMenuMode; | 2273 &TestingAutomationProvider::GetNTPMenuMode; |
| 2272 browser_handler_map["SetNTPMenuMode"] = | 2274 browser_handler_map["SetNTPMenuMode"] = |
| 2273 &TestingAutomationProvider::SetNTPMenuMode; | 2275 &TestingAutomationProvider::SetNTPMenuMode; |
| 2274 | 2276 |
| (...skipping 2285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4560 if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) { | 4562 if (!base::OpenProcessHandle(static_cast<base::ProcessId>(pid), &process)) { |
| 4561 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( | 4563 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( |
| 4562 "Failed to open process handle for pid %d", pid)); | 4564 "Failed to open process handle for pid %d", pid)); |
| 4563 return; | 4565 return; |
| 4564 } | 4566 } |
| 4565 new RendererProcessClosedObserver(this, reply_message); | 4567 new RendererProcessClosedObserver(this, reply_message); |
| 4566 base::KillProcess(process, 0, false); | 4568 base::KillProcess(process, 0, false); |
| 4567 base::CloseProcessHandle(process); | 4569 base::CloseProcessHandle(process); |
| 4568 } | 4570 } |
| 4569 | 4571 |
| 4572 bool TestingAutomationProvider::BuildNativeWebKeyEventFromArgs( | |
| 4573 DictionaryValue* args, | |
| 4574 IPC::Message* reply_message, | |
| 4575 NativeWebKeyboardEvent* event) { | |
| 4576 int type, modifiers; | |
| 4577 bool is_system_key; | |
| 4578 string16 unmodified_text, text; | |
| 4579 std::string key_identifier; | |
| 4580 if (!args->GetInteger("type", &type)) { | |
| 4581 AutomationJSONReply reply(this, reply_message); | |
| 4582 reply.SendError("'type' missing or invalid."); | |
| 4583 return false; | |
| 4584 } | |
| 4585 if (!args->GetBoolean("isSystemKey", &is_system_key)) { | |
| 4586 AutomationJSONReply reply(this, reply_message); | |
| 4587 reply.SendError("'isSystemKey' missing or invalid."); | |
| 4588 return false; | |
| 4589 } | |
| 4590 if (!args->GetString("unmodifiedText", &unmodified_text)) { | |
| 4591 AutomationJSONReply reply(this, reply_message); | |
| 4592 reply.SendError("'unmodifiedText' missing or invalid."); | |
| 4593 return false; | |
| 4594 } | |
| 4595 if (!args->GetString("text", &text)) { | |
| 4596 AutomationJSONReply reply(this, reply_message); | |
| 4597 reply.SendError("'text' missing or invalid."); | |
| 4598 return false; | |
| 4599 } | |
| 4600 if (!args->GetInteger("nativeKeyCode", &event->nativeKeyCode)) { | |
| 4601 AutomationJSONReply reply(this, reply_message); | |
| 4602 reply.SendError("'nativeKeyCode' missing or invalid."); | |
| 4603 return false; | |
| 4604 } | |
| 4605 if (!args->GetInteger("windowsKeyCode", &event->windowsKeyCode)) { | |
| 4606 AutomationJSONReply reply(this, reply_message); | |
| 4607 reply.SendError("'windowsKeyCode' missing or invalid."); | |
| 4608 return false; | |
| 4609 } | |
| 4610 if (!args->GetInteger("modifiers", &modifiers)) { | |
| 4611 AutomationJSONReply reply(this, reply_message); | |
| 4612 reply.SendError("'modifiers' missing or invalid."); | |
| 4613 return false; | |
| 4614 } | |
| 4615 if (args->GetString("keyIdentifier", &key_identifier)) { | |
| 4616 base::strlcpy(event->keyIdentifier, | |
| 4617 key_identifier.c_str(), | |
| 4618 WebKit::WebKeyboardEvent::keyIdentifierLengthCap); | |
| 4619 } else { | |
| 4620 event->setKeyIdentifierFromWindowsKeyCode(); | |
| 4621 } | |
| 4622 | |
| 4623 if (type == automation::kRawKeyDownType) { | |
| 4624 event->type = WebKit::WebInputEvent::RawKeyDown; | |
| 4625 } else if (type == automation::kKeyDownType) { | |
| 4626 event->type = WebKit::WebInputEvent::KeyDown; | |
| 4627 } else if (type == automation::kKeyUpType) { | |
| 4628 event->type = WebKit::WebInputEvent::KeyUp; | |
| 4629 } else if (type == automation::kCharType) { | |
| 4630 event->type = WebKit::WebInputEvent::Char; | |
| 4631 } else { | |
| 4632 AutomationJSONReply reply(this, reply_message); | |
| 4633 reply.SendError("'type' refers to an unrecognized keyboard event type"); | |
| 4634 return false; | |
| 4635 } | |
| 4636 | |
| 4637 string16 unmodified_text_truncated = unmodified_text.substr( | |
| 4638 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | |
| 4639 memcpy(event->unmodifiedText, | |
| 4640 unmodified_text_truncated.c_str(), | |
| 4641 unmodified_text_truncated.length() + 1); | |
| 4642 string16 text_truncated = text.substr( | |
| 4643 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | |
| 4644 memcpy(event->text, text_truncated.c_str(), text_truncated.length() + 1); | |
| 4645 | |
| 4646 event->modifiers = 0; | |
| 4647 if (modifiers & automation::kShiftKeyMask) | |
| 4648 event->modifiers |= WebKit::WebInputEvent::ShiftKey; | |
| 4649 if (modifiers & automation::kControlKeyMask) | |
| 4650 event->modifiers |= WebKit::WebInputEvent::ControlKey; | |
| 4651 if (modifiers & automation::kAltKeyMask) | |
| 4652 event->modifiers |= WebKit::WebInputEvent::AltKey; | |
| 4653 if (modifiers & automation::kMetaKeyMask) | |
| 4654 event->modifiers |= WebKit::WebInputEvent::MetaKey; | |
| 4655 | |
| 4656 event->isSystemKey = is_system_key; | |
| 4657 event->timeStampSeconds = base::Time::Now().ToDoubleT(); | |
| 4658 event->skip_in_browser = true; | |
| 4659 return true; | |
| 4660 } | |
| 4661 | |
| 4570 void TestingAutomationProvider::SendKeyEventToActiveTab( | 4662 void TestingAutomationProvider::SendKeyEventToActiveTab( |
|
kkania
2011/03/10 00:28:58
This function has changed since a couple days ago.
timothe faudot
2011/03/10 05:34:32
Done.
| |
| 4571 Browser* browser, | 4663 Browser* browser, |
| 4572 DictionaryValue* args, | 4664 DictionaryValue* args, |
| 4573 IPC::Message* reply_message) { | 4665 IPC::Message* reply_message) { |
| 4574 int type, modifiers; | |
| 4575 bool is_system_key; | |
| 4576 string16 unmodified_text, text; | |
| 4577 std::string key_identifier; | |
| 4578 NativeWebKeyboardEvent event; | 4666 NativeWebKeyboardEvent event; |
| 4579 if (!args->GetInteger("type", &type)) { | 4667 // BuildNativeWebKeyEventFromArgs handles telling what when wrong and sending |
| 4668 // the reply message, if it failed we just have to stop here. | |
| 4669 if (!BuildNativeWebKeyEventFromArgs(args, reply_message, &event)) | |
| 4670 return; | |
| 4671 | |
| 4672 new InputEventAckNotificationObserver(this, reply_message, event.type); | |
| 4673 browser->GetSelectedTabContents()->render_view_host()-> | |
|
kkania
2011/03/10 00:28:58
4 space indentation here
timothe faudot
2011/03/10 05:34:32
Done.
| |
| 4674 ForwardKeyboardEvent(event); | |
| 4675 return; | |
|
kkania
2011/03/10 00:28:58
remove the extra return
timothe faudot
2011/03/10 05:34:32
Done.
| |
| 4676 } | |
| 4677 | |
| 4678 void TestingAutomationProvider::SendKeyEventToActiveBrowserWindow( | |
| 4679 Browser* browser, | |
| 4680 DictionaryValue* args, | |
| 4681 IPC::Message* reply_message) { | |
| 4682 NativeWebKeyboardEvent event; | |
| 4683 // BuildNativeWebKeyEventFromArgs handles telling what when wrong and sending | |
| 4684 // the reply message, if it failed we just have to stop here. | |
| 4685 if (!BuildNativeWebKeyEventFromArgs(args, reply_message, &event)) | |
| 4686 return; | |
| 4687 | |
| 4688 // The ui_controls::SendKeyPress function will generate up and down events | |
| 4689 // from one keycode for us so we only need to send one event to it. | |
| 4690 // Filtering is done via the RawKeyDown type because it is the one sent by | |
| 4691 // the current webdriver implementation of WebElement.SendKeys(...). | |
| 4692 DictionaryValue* reply_details = new DictionaryValue(); | |
| 4693 if (event.type != WebKit::WebInputEvent::RawKeyDown) { | |
| 4580 AutomationJSONReply reply(this, reply_message); | 4694 AutomationJSONReply reply(this, reply_message); |
| 4581 reply.SendError("'type' missing or invalid."); | 4695 reply_details->SetBoolean("processed", false); |
| 4696 reply.SendSuccess(reply_details); | |
| 4582 return; | 4697 return; |
| 4583 } | 4698 } |
| 4584 if (!args->GetBoolean("isSystemKey", &is_system_key)) { | 4699 BrowserWindow* browser_window = browser->window(); |
| 4700 if (!browser_window) { | |
| 4585 AutomationJSONReply reply(this, reply_message); | 4701 AutomationJSONReply reply(this, reply_message); |
| 4586 reply.SendError("'isSystemKey' missing or invalid."); | 4702 reply.SendError("Could not get the browser window"); |
| 4587 return; | 4703 return; |
| 4588 } | 4704 } |
| 4589 if (!args->GetString("unmodifiedText", &unmodified_text)) { | 4705 gfx::NativeWindow window = browser_window->GetNativeHandle(); |
| 4706 if (!window) { | |
| 4590 AutomationJSONReply reply(this, reply_message); | 4707 AutomationJSONReply reply(this, reply_message); |
| 4591 reply.SendError("'unmodifiedText' missing or invalid."); | 4708 reply.SendError("Could not get the browser window handle"); |
| 4592 return; | 4709 return; |
| 4593 } | 4710 } |
| 4594 if (!args->GetString("text", &text)) { | 4711 bool control = !!(event.modifiers & WebKit::WebInputEvent::ControlKey); |
| 4712 bool shift = !!(event.modifiers & WebKit::WebInputEvent::ShiftKey); | |
| 4713 bool alt = !!(event.modifiers & WebKit::WebInputEvent::AltKey); | |
| 4714 bool meta = !!(event.modifiers & WebKit::WebInputEvent::MetaKey); | |
| 4715 if (!ui_controls::SendKeyPress( | |
| 4716 window, static_cast<ui::KeyboardCode>(event.nativeKeyCode), | |
| 4717 control, shift, alt, meta)) { | |
| 4595 AutomationJSONReply reply(this, reply_message); | 4718 AutomationJSONReply reply(this, reply_message); |
| 4596 reply.SendError("'text' missing or invalid."); | 4719 reply.SendError("Could not send the native key event"); |
| 4597 return; | |
| 4598 } | |
| 4599 if (!args->GetInteger("nativeKeyCode", &event.nativeKeyCode)) { | |
| 4600 AutomationJSONReply reply(this, reply_message); | |
| 4601 reply.SendError("'nativeKeyCode' missing or invalid."); | |
| 4602 return; | |
| 4603 } | |
| 4604 if (!args->GetInteger("windowsKeyCode", &event.windowsKeyCode)) { | |
| 4605 AutomationJSONReply reply(this, reply_message); | |
| 4606 reply.SendError("'windowsKeyCode' missing or invalid."); | |
| 4607 return; | |
| 4608 } | |
| 4609 if (!args->GetInteger("modifiers", &modifiers)) { | |
| 4610 AutomationJSONReply reply(this, reply_message); | |
| 4611 reply.SendError("'modifiers' missing or invalid."); | |
| 4612 return; | |
| 4613 } | |
| 4614 if (args->GetString("keyIdentifier", &key_identifier)) { | |
| 4615 base::strlcpy(event.keyIdentifier, | |
| 4616 key_identifier.c_str(), | |
| 4617 WebKit::WebKeyboardEvent::keyIdentifierLengthCap); | |
| 4618 } else { | |
| 4619 event.setKeyIdentifierFromWindowsKeyCode(); | |
| 4620 } | |
| 4621 | |
| 4622 if (type == automation::kRawKeyDownType) { | |
| 4623 event.type = WebKit::WebInputEvent::RawKeyDown; | |
| 4624 } else if (type == automation::kKeyDownType) { | |
| 4625 event.type = WebKit::WebInputEvent::KeyDown; | |
| 4626 } else if (type == automation::kKeyUpType) { | |
| 4627 event.type = WebKit::WebInputEvent::KeyUp; | |
| 4628 } else if (type == automation::kCharType) { | |
| 4629 event.type = WebKit::WebInputEvent::Char; | |
| 4630 } else { | 4720 } else { |
| 4631 AutomationJSONReply reply(this, reply_message); | 4721 AutomationJSONReply reply(this, reply_message); |
| 4632 reply.SendError("'type' refers to an unrecognized keyboard event type"); | 4722 reply_details->SetBoolean("processed", true); |
| 4633 return; | 4723 reply.SendSuccess(reply_details); |
| 4634 } | 4724 } |
| 4635 | |
| 4636 string16 unmodified_text_truncated = unmodified_text.substr( | |
| 4637 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | |
| 4638 memcpy(event.unmodifiedText, | |
| 4639 unmodified_text_truncated.c_str(), | |
| 4640 unmodified_text_truncated.length() + 1); | |
| 4641 string16 text_truncated = text.substr( | |
| 4642 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | |
| 4643 memcpy(event.text, text_truncated.c_str(), text_truncated.length() + 1); | |
| 4644 | |
| 4645 event.modifiers = 0; | |
| 4646 if (modifiers & automation::kShiftKeyMask) | |
| 4647 event.modifiers |= WebKit::WebInputEvent::ShiftKey; | |
| 4648 if (modifiers & automation::kControlKeyMask) | |
| 4649 event.modifiers |= WebKit::WebInputEvent::ControlKey; | |
| 4650 if (modifiers & automation::kAltKeyMask) | |
| 4651 event.modifiers |= WebKit::WebInputEvent::AltKey; | |
| 4652 if (modifiers & automation::kMetaKeyMask) | |
| 4653 event.modifiers |= WebKit::WebInputEvent::MetaKey; | |
| 4654 | |
| 4655 event.isSystemKey = is_system_key; | |
| 4656 event.timeStampSeconds = base::Time::Now().ToDoubleT(); | |
| 4657 event.skip_in_browser = true; | |
| 4658 new InputEventAckNotificationObserver(this, reply_message, event.type); | |
| 4659 browser->GetSelectedTabContents()->render_view_host()-> | |
| 4660 ForwardKeyboardEvent(event); | |
| 4661 } | 4725 } |
| 4662 | 4726 |
| 4663 // Sample JSON input: { "command": "GetNTPThumbnailMode" } | 4727 // Sample JSON input: { "command": "GetNTPThumbnailMode" } |
| 4664 // For output, refer to GetNTPThumbnailMode() in | 4728 // For output, refer to GetNTPThumbnailMode() in |
| 4665 // chrome/test/pyautolib/pyauto.py. | 4729 // chrome/test/pyautolib/pyauto.py. |
| 4666 void TestingAutomationProvider::GetNTPThumbnailMode( | 4730 void TestingAutomationProvider::GetNTPThumbnailMode( |
| 4667 Browser* browser, | 4731 Browser* browser, |
| 4668 DictionaryValue* args, | 4732 DictionaryValue* args, |
| 4669 IPC::Message* reply_message) { | 4733 IPC::Message* reply_message) { |
| 4670 const int shown_sections = ShownSectionsHandler::GetShownSections( | 4734 const int shown_sections = ShownSectionsHandler::GetShownSections( |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4765 } | 4829 } |
| 4766 | 4830 |
| 4767 PrefService* prefs = browser->profile()->GetPrefs(); | 4831 PrefService* prefs = browser->profile()->GetPrefs(); |
| 4768 Section section; | 4832 Section section; |
| 4769 if (section_name.compare("apps") == 0) { | 4833 if (section_name.compare("apps") == 0) { |
| 4770 section = MENU_APPS; | 4834 section = MENU_APPS; |
| 4771 } else if (section_name.compare("most_visited") == 0) { | 4835 } else if (section_name.compare("most_visited") == 0) { |
| 4772 section = MENU_THUMB; | 4836 section = MENU_THUMB; |
| 4773 } else if (section_name.compare("recently_closed") == 0) { | 4837 } else if (section_name.compare("recently_closed") == 0) { |
| 4774 section = MENU_RECENT; | 4838 section = MENU_RECENT; |
| 4775 } | 4839 } else { |
| 4776 else { | |
| 4777 reply.SendError(StringPrintf("Unexpected section name: '%s'", | 4840 reply.SendError(StringPrintf("Unexpected section name: '%s'", |
| 4778 section_name.c_str())); | 4841 section_name.c_str())); |
| 4779 return; | 4842 return; |
| 4780 } | 4843 } |
| 4781 | 4844 |
| 4782 int shown_sections = ShownSectionsHandler::GetShownSections(prefs); | 4845 int shown_sections = ShownSectionsHandler::GetShownSections(prefs); |
| 4783 if (turn_on) { | 4846 if (turn_on) { |
| 4784 // Change the bit for the relevant section in the bitmask to 1. | 4847 // Change the bit for the relevant section in the bitmask to 1. |
| 4785 shown_sections |= section; | 4848 shown_sections |= section; |
| 4786 } else { | 4849 } else { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5023 // If you change this, update Observer for NotificationType::SESSION_END | 5086 // If you change this, update Observer for NotificationType::SESSION_END |
| 5024 // below. | 5087 // below. |
| 5025 MessageLoop::current()->PostTask(FROM_HERE, | 5088 MessageLoop::current()->PostTask(FROM_HERE, |
| 5026 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 5089 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
| 5027 } | 5090 } |
| 5028 } | 5091 } |
| 5029 | 5092 |
| 5030 void TestingAutomationProvider::OnRemoveProvider() { | 5093 void TestingAutomationProvider::OnRemoveProvider() { |
| 5031 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5094 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 5032 } | 5095 } |
| OLD | NEW |