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

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 4637 matching lines...) Expand 10 before | Expand all | Expand 10 after
4648 if (modifiers & automation::kControlKeyMask) 4648 if (modifiers & automation::kControlKeyMask)
4649 event.modifiers |= WebKit::WebInputEvent::ControlKey; 4649 event.modifiers |= WebKit::WebInputEvent::ControlKey;
4650 if (modifiers & automation::kAltKeyMask) 4650 if (modifiers & automation::kAltKeyMask)
4651 event.modifiers |= WebKit::WebInputEvent::AltKey; 4651 event.modifiers |= WebKit::WebInputEvent::AltKey;
4652 if (modifiers & automation::kMetaKeyMask) 4652 if (modifiers & automation::kMetaKeyMask)
4653 event.modifiers |= WebKit::WebInputEvent::MetaKey; 4653 event.modifiers |= WebKit::WebInputEvent::MetaKey;
4654 4654
4655 event.isSystemKey = is_system_key; 4655 event.isSystemKey = is_system_key;
4656 event.timeStampSeconds = base::Time::Now().ToDoubleT(); 4656 event.timeStampSeconds = base::Time::Now().ToDoubleT();
4657 event.skip_in_browser = true; 4657 event.skip_in_browser = true;
4658 new InputEventAckNotificationObserver(this, reply_message, event.type); 4658 bool use_native_events = false;
4659 browser->GetSelectedTabContents()->render_view_host()-> 4659 // If useNativeEvents is true, this funciton will call
Paweł Hajdan Jr. 2011/03/05 11:55:51 I'd strongly prefer to standardize on one way we i
timothe faudot 2011/03/07 02:45:26 I added some justifications in the associated bug
4660 ForwardKeyboardEvent(event); 4660 // ui_controls::endKeyPress to the native window handle of the browser,
Jason Leyba 2011/03/04 19:25:12 ui_controls::SendKeyPress
timothe faudot 2011/03/07 02:45:26 Done.
4661 // allowing events to be catched higher up; if false it will send an
4662 // event directly to webkit.
4663 if (args->GetBoolean("useNativeEvents", &use_native_events) &&
4664 use_native_events) {
4665 // The ui_controls::SendKeyPress function will generate up and down events
4666 // from one keycode for us so we only need to send one event to it.
4667 // Filtering is done via the RawKeyDown type because it is the one sent by
4668 // the current webdriver implementation of WebElement.SendKeys(...).
4669 if (event.type == WebKit::WebInputEvent::RawKeyDown) {
4670 BrowserWindow* browser_window = browser->window();
4671 if (!browser_window) {
4672 AutomationJSONReply reply(this, reply_message);
4673 reply.SendError("Could not get the browser window");
4674 return;
4675 }
4676 gfx::NativeWindow window = browser_window->GetNativeHandle();
4677 if (!window) {
4678 AutomationJSONReply reply(this, reply_message);
4679 reply.SendError("Could not get the browser window handle");
4680 return;
4681 }
4682 bool control = !!(event.modifiers & WebKit::WebInputEvent::ControlKey);
4683 bool shift = !!(event.modifiers & WebKit::WebInputEvent::ShiftKey);
4684 bool alt = !!(event.modifiers & WebKit::WebInputEvent::AltKey);
4685 bool meta = !!(event.modifiers & WebKit::WebInputEvent::MetaKey);
4686 if (!ui_controls::SendKeyPress(
4687 window, static_cast<ui::KeyboardCode>(event.nativeKeyCode),
4688 control, shift, alt, meta)) {
4689 AutomationJSONReply reply(this, reply_message);
4690 reply.SendError("Could not send the native key event");
4691 return;
4692 } else {
4693 AutomationJSONReply reply(this, reply_message);
4694 reply.SendSuccess(NULL);
4695 }
4696 } else {
4697 // Skip this event by acknowledging it without doing nothing.
4698 AutomationJSONReply reply(this, reply_message);
4699 reply.SendSuccess(NULL);
4700 return;
4701 }
4702 } else {
4703 new InputEventAckNotificationObserver(this, reply_message, event.type);
4704 browser->GetSelectedTabContents()->render_view_host()->
4705 ForwardKeyboardEvent(event);
4706 return;
4707 }
4661 } 4708 }
4662 4709
4663 // Sample JSON input: { "command": "GetNTPThumbnailMode" } 4710 // Sample JSON input: { "command": "GetNTPThumbnailMode" }
4664 // For output, refer to GetNTPThumbnailMode() in 4711 // For output, refer to GetNTPThumbnailMode() in
4665 // chrome/test/pyautolib/pyauto.py. 4712 // chrome/test/pyautolib/pyauto.py.
4666 void TestingAutomationProvider::GetNTPThumbnailMode( 4713 void TestingAutomationProvider::GetNTPThumbnailMode(
4667 Browser* browser, 4714 Browser* browser,
4668 DictionaryValue* args, 4715 DictionaryValue* args,
4669 IPC::Message* reply_message) { 4716 IPC::Message* reply_message) {
4670 const int shown_sections = ShownSectionsHandler::GetShownSections( 4717 const int shown_sections = ShownSectionsHandler::GetShownSections(
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
4765 } 4812 }
4766 4813
4767 PrefService* prefs = browser->profile()->GetPrefs(); 4814 PrefService* prefs = browser->profile()->GetPrefs();
4768 Section section; 4815 Section section;
4769 if (section_name.compare("apps") == 0) { 4816 if (section_name.compare("apps") == 0) {
4770 section = MENU_APPS; 4817 section = MENU_APPS;
4771 } else if (section_name.compare("most_visited") == 0) { 4818 } else if (section_name.compare("most_visited") == 0) {
4772 section = MENU_THUMB; 4819 section = MENU_THUMB;
4773 } else if (section_name.compare("recently_closed") == 0) { 4820 } else if (section_name.compare("recently_closed") == 0) {
4774 section = MENU_RECENT; 4821 section = MENU_RECENT;
4775 } 4822 } else {
4776 else {
4777 reply.SendError(StringPrintf("Unexpected section name: '%s'", 4823 reply.SendError(StringPrintf("Unexpected section name: '%s'",
4778 section_name.c_str())); 4824 section_name.c_str()));
4779 return; 4825 return;
4780 } 4826 }
4781 4827
4782 int shown_sections = ShownSectionsHandler::GetShownSections(prefs); 4828 int shown_sections = ShownSectionsHandler::GetShownSections(prefs);
4783 if (turn_on) { 4829 if (turn_on) {
4784 // Change the bit for the relevant section in the bitmask to 1. 4830 // Change the bit for the relevant section in the bitmask to 1.
4785 shown_sections |= section; 4831 shown_sections |= section;
4786 } else { 4832 } else {
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
5023 // If you change this, update Observer for NotificationType::SESSION_END 5069 // If you change this, update Observer for NotificationType::SESSION_END
5024 // below. 5070 // below.
5025 MessageLoop::current()->PostTask(FROM_HERE, 5071 MessageLoop::current()->PostTask(FROM_HERE,
5026 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); 5072 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
5027 } 5073 }
5028 } 5074 }
5029 5075
5030 void TestingAutomationProvider::OnRemoveProvider() { 5076 void TestingAutomationProvider::OnRemoveProvider() {
5031 AutomationProviderList::GetInstance()->RemoveProvider(this); 5077 AutomationProviderList::GetInstance()->RemoveProvider(this);
5032 } 5078 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/webdriver/automation.h » ('j') | chrome/test/webdriver/chromedriver_tests.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698