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( |
| 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 |
| 4580 AutomationJSONReply reply(this, reply_message); | 4668 // the reply message, if it failed we just have to stop here. |
| 4581 reply.SendError("'type' missing or invalid."); | 4669 if (!BuildNativeWebKeyEventFromArgs(args, reply_message, &event)) { |
| 4582 return; | |
| 4583 } | |
| 4584 if (!args->GetBoolean("isSystemKey", &is_system_key)) { | |
| 4585 AutomationJSONReply reply(this, reply_message); | |
| 4586 reply.SendError("'isSystemKey' missing or invalid."); | |
| 4587 return; | |
| 4588 } | |
| 4589 if (!args->GetString("unmodifiedText", &unmodified_text)) { | |
| 4590 AutomationJSONReply reply(this, reply_message); | |
| 4591 reply.SendError("'unmodifiedText' missing or invalid."); | |
| 4592 return; | |
| 4593 } | |
| 4594 if (!args->GetString("text", &text)) { | |
| 4595 AutomationJSONReply reply(this, reply_message); | |
| 4596 reply.SendError("'text' missing or invalid."); | |
| 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 { | |
| 4631 AutomationJSONReply reply(this, reply_message); | |
| 4632 reply.SendError("'type' refers to an unrecognized keyboard event type"); | |
| 4633 return; | 4670 return; |
| 4634 } | 4671 } |
|
Paweł Hajdan Jr.
2011/03/08 09:25:13
nit: Remove the braces {} for a 1-line "if" statem
timothe faudot
2011/03/08 09:34:23
Done, also changed the same call on SendKeyEventTo
| |
| 4635 | 4672 |
| 4636 string16 unmodified_text_truncated = unmodified_text.substr( | 4673 new InputEventAckNotificationObserver(this, reply_message, event.type); |
| 4637 0, WebKit::WebKeyboardEvent::textLengthCap - 1); | 4674 browser->GetSelectedTabContents()->render_view_host()-> |
| 4638 memcpy(event.unmodifiedText, | 4675 ForwardKeyboardEvent(event); |
| 4639 unmodified_text_truncated.c_str(), | 4676 return; |
| 4640 unmodified_text_truncated.length() + 1); | 4677 } |
| 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 | 4678 |
| 4645 event.modifiers = 0; | 4679 void TestingAutomationProvider::SendKeyEventToActiveBrowserWindow( |
| 4646 if (modifiers & automation::kShiftKeyMask) | 4680 Browser* browser, |
| 4647 event.modifiers |= WebKit::WebInputEvent::ShiftKey; | 4681 DictionaryValue* args, |
| 4648 if (modifiers & automation::kControlKeyMask) | 4682 IPC::Message* reply_message) { |
| 4649 event.modifiers |= WebKit::WebInputEvent::ControlKey; | 4683 NativeWebKeyboardEvent event; |
| 4650 if (modifiers & automation::kAltKeyMask) | 4684 // BuildNativeWebKeyEventFromArgs handles telling what when wrong and sending |
| 4651 event.modifiers |= WebKit::WebInputEvent::AltKey; | 4685 // the reply message, if it failed we just have to stop here. |
| 4652 if (modifiers & automation::kMetaKeyMask) | 4686 if (!BuildNativeWebKeyEventFromArgs(args, reply_message, &event)) { |
| 4653 event.modifiers |= WebKit::WebInputEvent::MetaKey; | 4687 return; |
| 4688 } | |
| 4654 | 4689 |
| 4655 event.isSystemKey = is_system_key; | 4690 // The ui_controls::SendKeyPress function will generate up and down events |
| 4656 event.timeStampSeconds = base::Time::Now().ToDoubleT(); | 4691 // from one keycode for us so we only need to send one event to it. |
| 4657 event.skip_in_browser = true; | 4692 // Filtering is done via the RawKeyDown type because it is the one sent by |
| 4658 new InputEventAckNotificationObserver(this, reply_message, event.type); | 4693 // the current webdriver implementation of WebElement.SendKeys(...). |
| 4659 browser->GetSelectedTabContents()->render_view_host()-> | 4694 DictionaryValue* was_processed = new DictionaryValue(); |
|
Paweł Hajdan Jr.
2011/03/08 09:25:13
nit: |was_processed| is not a good name for the en
timothe faudot
2011/03/08 09:34:23
Done.
| |
| 4660 ForwardKeyboardEvent(event); | 4695 if (event.type != WebKit::WebInputEvent::RawKeyDown) { |
| 4696 AutomationJSONReply reply(this, reply_message); | |
| 4697 was_processed->SetBoolean("processed", false); | |
| 4698 reply.SendSuccess(was_processed); | |
| 4699 return; | |
| 4700 } | |
| 4701 BrowserWindow* browser_window = browser->window(); | |
| 4702 if (!browser_window) { | |
| 4703 AutomationJSONReply reply(this, reply_message); | |
| 4704 reply.SendError("Could not get the browser window"); | |
| 4705 return; | |
| 4706 } | |
| 4707 gfx::NativeWindow window = browser_window->GetNativeHandle(); | |
| 4708 if (!window) { | |
| 4709 AutomationJSONReply reply(this, reply_message); | |
| 4710 reply.SendError("Could not get the browser window handle"); | |
| 4711 return; | |
| 4712 } | |
| 4713 bool control = !!(event.modifiers & WebKit::WebInputEvent::ControlKey); | |
| 4714 bool shift = !!(event.modifiers & WebKit::WebInputEvent::ShiftKey); | |
| 4715 bool alt = !!(event.modifiers & WebKit::WebInputEvent::AltKey); | |
| 4716 bool meta = !!(event.modifiers & WebKit::WebInputEvent::MetaKey); | |
| 4717 if (!ui_controls::SendKeyPress( | |
| 4718 window, static_cast<ui::KeyboardCode>(event.nativeKeyCode), | |
| 4719 control, shift, alt, meta)) { | |
| 4720 AutomationJSONReply reply(this, reply_message); | |
| 4721 reply.SendError("Could not send the native key event"); | |
| 4722 return; | |
|
Paweł Hajdan Jr.
2011/03/08 09:25:13
nit: This "return" statement seems not needed now.
timothe faudot
2011/03/08 09:34:23
Done.
| |
| 4723 } else { | |
| 4724 AutomationJSONReply reply(this, reply_message); | |
| 4725 was_processed->SetBoolean("processed", true); | |
| 4726 reply.SendSuccess(was_processed); | |
| 4727 return; | |
|
Paweł Hajdan Jr.
2011/03/08 09:25:13
nit: This "return" statement seems not needed now.
timothe faudot
2011/03/08 09:34:23
Done.
| |
| 4728 } | |
| 4661 } | 4729 } |
| 4662 | 4730 |
| 4663 // Sample JSON input: { "command": "GetNTPThumbnailMode" } | 4731 // Sample JSON input: { "command": "GetNTPThumbnailMode" } |
| 4664 // For output, refer to GetNTPThumbnailMode() in | 4732 // For output, refer to GetNTPThumbnailMode() in |
| 4665 // chrome/test/pyautolib/pyauto.py. | 4733 // chrome/test/pyautolib/pyauto.py. |
| 4666 void TestingAutomationProvider::GetNTPThumbnailMode( | 4734 void TestingAutomationProvider::GetNTPThumbnailMode( |
| 4667 Browser* browser, | 4735 Browser* browser, |
| 4668 DictionaryValue* args, | 4736 DictionaryValue* args, |
| 4669 IPC::Message* reply_message) { | 4737 IPC::Message* reply_message) { |
| 4670 const int shown_sections = ShownSectionsHandler::GetShownSections( | 4738 const int shown_sections = ShownSectionsHandler::GetShownSections( |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4765 } | 4833 } |
| 4766 | 4834 |
| 4767 PrefService* prefs = browser->profile()->GetPrefs(); | 4835 PrefService* prefs = browser->profile()->GetPrefs(); |
| 4768 Section section; | 4836 Section section; |
| 4769 if (section_name.compare("apps") == 0) { | 4837 if (section_name.compare("apps") == 0) { |
| 4770 section = MENU_APPS; | 4838 section = MENU_APPS; |
| 4771 } else if (section_name.compare("most_visited") == 0) { | 4839 } else if (section_name.compare("most_visited") == 0) { |
| 4772 section = MENU_THUMB; | 4840 section = MENU_THUMB; |
| 4773 } else if (section_name.compare("recently_closed") == 0) { | 4841 } else if (section_name.compare("recently_closed") == 0) { |
| 4774 section = MENU_RECENT; | 4842 section = MENU_RECENT; |
| 4775 } | 4843 } else { |
| 4776 else { | |
| 4777 reply.SendError(StringPrintf("Unexpected section name: '%s'", | 4844 reply.SendError(StringPrintf("Unexpected section name: '%s'", |
| 4778 section_name.c_str())); | 4845 section_name.c_str())); |
| 4779 return; | 4846 return; |
| 4780 } | 4847 } |
| 4781 | 4848 |
| 4782 int shown_sections = ShownSectionsHandler::GetShownSections(prefs); | 4849 int shown_sections = ShownSectionsHandler::GetShownSections(prefs); |
| 4783 if (turn_on) { | 4850 if (turn_on) { |
| 4784 // Change the bit for the relevant section in the bitmask to 1. | 4851 // Change the bit for the relevant section in the bitmask to 1. |
| 4785 shown_sections |= section; | 4852 shown_sections |= section; |
| 4786 } else { | 4853 } 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 | 5090 // If you change this, update Observer for NotificationType::SESSION_END |
| 5024 // below. | 5091 // below. |
| 5025 MessageLoop::current()->PostTask(FROM_HERE, | 5092 MessageLoop::current()->PostTask(FROM_HERE, |
| 5026 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 5093 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
| 5027 } | 5094 } |
| 5028 } | 5095 } |
| 5029 | 5096 |
| 5030 void TestingAutomationProvider::OnRemoveProvider() { | 5097 void TestingAutomationProvider::OnRemoveProvider() { |
| 5031 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5098 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 5032 } | 5099 } |
| OLD | NEW |