summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-04 21:11:14 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-04 21:11:14 +0000
commit2511466dd15750f2ab0e5cecc30010f0a3f7949c (patch)
tree43684f81641ff74ac452679029a18fd65cd03e79
parent9381ee13d3cb8d4531a37d4b31cbae5068bb46d5 (diff)
downloadchromium_src-2511466dd15750f2ab0e5cecc30010f0a3f7949c.zip
chromium_src-2511466dd15750f2ab0e5cecc30010f0a3f7949c.tar.gz
chromium_src-2511466dd15750f2ab0e5cecc30010f0a3f7949c.tar.bz2
Convert the autofill interactive browser test to a normal browser_test. I added testing methods to fake input events that don't depend on the OS and being at the front.
BUG=121574 Review URL: https://chromiumcodereview.appspot.com/10368010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135432 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/autofill_browsertest.cc68
-rw-r--r--chrome/browser/history/history_browsertest.cc3
-rw-r--r--chrome/browser/history/redirect_browsertest.cc2
-rw-r--r--chrome/browser/unload_browsertest.cc3
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/test/base/ui_test_utils.cc64
-rw-r--r--chrome/test/base/ui_test_utils.h13
-rw-r--r--chrome/test/data/npapi/execute_script_delete_in_mouse_up.html2
-rw-r--r--content/browser/plugin_browsertest.cc3
9 files changed, 108 insertions, 52 deletions
diff --git a/chrome/browser/autofill/autofill_browsertest.cc b/chrome/browser/autofill/autofill_browsertest.cc
index 99d6c2d..248795e 100644
--- a/chrome/browser/autofill/autofill_browsertest.cc
+++ b/chrome/browser/autofill/autofill_browsertest.cc
@@ -186,10 +186,7 @@ class AutofillTest : public InProcessBrowserTest {
void FocusFirstNameField() {
LOG(WARNING) << "Clicking on the tab.";
- ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(),
- VIEW_ID_TAB_CONTAINER));
- ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
- VIEW_ID_TAB_CONTAINER));
+ ui_test_utils::SimulateMouseClick(browser()->GetSelectedWebContents());
LOG(WARNING) << "Focusing the first name field.";
bool result = false;
@@ -215,24 +212,28 @@ class AutofillTest : public InProcessBrowserTest {
ExpectFieldValue(L"phone", "5125551234");
}
+ void SendKeyAndWait(ui::KeyboardCode key, int notification_type) {
+ ui_test_utils::WindowedNotificationObserver observer(
+ notification_type, content::Source<RenderViewHost>(render_view_host()));
+ ui_test_utils::SimulateKeyPress(
+ browser()->GetSelectedWebContents(), key, false, false, false, false);
+ observer.Wait();
+ }
+
void TryBasicFormFill() {
FocusFirstNameField();
// Start filling the first name field with "M" and wait for the popup to be
// shown.
LOG(WARNING) << "Typing 'M' to bring up the Autofill popup.";
- ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
- browser(), ui::VKEY_M, false, true, false, false,
- chrome::NOTIFICATION_AUTOFILL_DID_SHOW_SUGGESTIONS,
- content::Source<RenderViewHost>(render_view_host())));
+ SendKeyAndWait(
+ ui::VKEY_M, chrome::NOTIFICATION_AUTOFILL_DID_SHOW_SUGGESTIONS);
// Press the down arrow to select the suggestion and preview the autofilled
// form.
LOG(WARNING) << "Simulating down arrow press to initiate Autofill preview.";
- ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
- browser(), ui::VKEY_DOWN, false, false, false, false,
- chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA,
- content::Source<RenderViewHost>(render_view_host())));
+ SendKeyAndWait(
+ ui::VKEY_DOWN, chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA);
// The previewed values should not be accessible to JavaScript.
ExpectFieldValue(L"firstname", "M");
@@ -249,10 +250,8 @@ class AutofillTest : public InProcessBrowserTest {
// Press Enter to accept the autofill suggestions.
LOG(WARNING) << "Simulating Return press to fill the form.";
- ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
- browser(), ui::VKEY_RETURN, false, false, false, false,
- chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA,
- content::Source<RenderViewHost>(render_view_host())));
+ SendKeyAndWait(
+ ui::VKEY_RETURN, chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA);
// The form should be filled.
ExpectFilledTestForm();
@@ -267,7 +266,6 @@ IN_PROC_BROWSER_TEST_F(AutofillTest, BasicFormFill) {
CreateTestProfile();
// Load the test page.
- ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
GURL(std::string(kDataURIPrefix) + kTestFormString)));
@@ -289,23 +287,17 @@ IN_PROC_BROWSER_TEST_F(AutofillTest, AutofillViaDownArrow) {
// Press the down arrow to initiate Autofill and wait for the popup to be
// shown.
- ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
- browser(), ui::VKEY_DOWN, false, false, false, false,
- chrome::NOTIFICATION_AUTOFILL_DID_SHOW_SUGGESTIONS,
- content::Source<RenderViewHost>(render_view_host())));
+ SendKeyAndWait(
+ ui::VKEY_DOWN, chrome::NOTIFICATION_AUTOFILL_DID_SHOW_SUGGESTIONS);
// Press the down arrow to select the suggestion and preview the autofilled
// form.
- ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
- browser(), ui::VKEY_DOWN, false, false, false, false,
- chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA,
- content::Source<RenderViewHost>(render_view_host())));
+ SendKeyAndWait(
+ ui::VKEY_DOWN, chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA);
// Press Enter to accept the autofill suggestions.
- ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
- browser(), ui::VKEY_RETURN, false, false, false, false,
- chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA,
- content::Source<RenderViewHost>(render_view_host())));
+ SendKeyAndWait(
+ ui::VKEY_RETURN, chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA);
// The form should be filled.
ExpectFilledTestForm();
@@ -346,23 +338,17 @@ IN_PROC_BROWSER_TEST_F(AutofillTest, OnChangeAfterAutofill) {
// Start filling the first name field with "M" and wait for the popup to be
// shown.
- ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
- browser(), ui::VKEY_M, false, true, false, false,
- chrome::NOTIFICATION_AUTOFILL_DID_SHOW_SUGGESTIONS,
- content::Source<RenderViewHost>(render_view_host())));
+ SendKeyAndWait(
+ ui::VKEY_M, chrome::NOTIFICATION_AUTOFILL_DID_SHOW_SUGGESTIONS);
// Press the down arrow to select the suggestion and preview the autofilled
// form.
- ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
- browser(), ui::VKEY_DOWN, false, false, false, false,
- chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA,
- content::Source<RenderViewHost>(render_view_host())));
+ SendKeyAndWait(
+ ui::VKEY_DOWN, chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA);
// Press Enter to accept the autofill suggestions.
- ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
- browser(), ui::VKEY_RETURN, false, false, false, false,
- chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA,
- content::Source<RenderViewHost>(render_view_host())));
+ SendKeyAndWait(
+ ui::VKEY_RETURN, chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA);
// The form should be filled.
ExpectFilledTestForm();
diff --git a/chrome/browser/history/history_browsertest.cc b/chrome/browser/history/history_browsertest.cc
index 6d5ad8d..2b871bc 100644
--- a/chrome/browser/history/history_browsertest.cc
+++ b/chrome/browser/history/history_browsertest.cc
@@ -271,8 +271,7 @@ IN_PROC_BROWSER_TEST_F(HistoryBrowserTest,
// Therefore, Page 11 should be in the history in addition to Page 12.
LoadAndWaitForFile("history_length_test_page_11.html");
- ui_test_utils::SimulateMouseClick(
- browser()->GetSelectedWebContents(), 20, 20);
+ ui_test_utils::SimulateMouseClick(browser()->GetSelectedWebContents());
LoadAndWaitForFile("history_length_test_page_11.html");
}
diff --git a/chrome/browser/history/redirect_browsertest.cc b/chrome/browser/history/redirect_browsertest.cc
index a68bd30..239232f 100644
--- a/chrome/browser/history/redirect_browsertest.cc
+++ b/chrome/browser/history/redirect_browsertest.cc
@@ -161,7 +161,7 @@ IN_PROC_BROWSER_TEST_F(RedirectTest, ClientCancelled) {
// otherwise, a non user-initiated in-page location change will be treated
// as client redirect and the redirect will be recoreded, which can cause
// this test failed.
- ui_test_utils::SimulateMouseClick(web_contents, 20, 20);
+ ui_test_utils::SimulateMouseClick(web_contents);
navigation_observer.Wait();
std::vector<GURL> redirects = GetRedirects(first_url);
diff --git a/chrome/browser/unload_browsertest.cc b/chrome/browser/unload_browsertest.cc
index 0b4ab30e..a1698af 100644
--- a/chrome/browser/unload_browsertest.cc
+++ b/chrome/browser/unload_browsertest.cc
@@ -389,8 +389,7 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTabWhenOtherTabHasListener) {
ui_test_utils::WindowedNotificationObserver load_stop_observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
- ui_test_utils::SimulateMouseClick(
- browser()->GetSelectedWebContents(), 20, 20);
+ ui_test_utils::SimulateMouseClick(browser()->GetSelectedWebContents());
observer.Wait();
load_stop_observer.Wait();
CheckTitle("popup");
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index d196076..d667a07 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -491,7 +491,6 @@
],
'sources': [
'browser/accessibility/accessibility_mac_uitest.mm',
- 'browser/autofill/autofill_browsertest.cc',
'browser/browser_focus_uitest.cc',
'browser/browser_keyevents_browsertest.cc',
'browser/collected_cookies_uitest.cc',
@@ -2624,6 +2623,7 @@
'browser/accessibility/accessibility_extension_apitest.cc',
'browser/app_controller_mac_browsertest.mm',
'browser/autocomplete/autocomplete_browsertest.cc',
+ 'browser/autofill/autofill_browsertest.cc',
'browser/autofill/form_structure_browsertest.cc',
'browser/autofill/autofill_popup_view_browsertest.cc',
'browser/automation/automation_tab_helper_browsertest.cc',
diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc
index bf56033..ec38dc9 100644
--- a/chrome/test/base/ui_test_utils.cc
+++ b/chrome/test/base/ui_test_utils.cc
@@ -620,7 +620,9 @@ int FindInPage(TabContentsWrapper* tab_contents, const string16& search_string,
return observer.number_of_matches();
}
-void SimulateMouseClick(content::WebContents* tab, int x, int y) {
+void SimulateMouseClick(content::WebContents* tab) {
+ int x = tab->GetView()->GetContainerSize().width() / 2;
+ int y = tab->GetView()->GetContainerSize().height() / 2;
WebKit::WebMouseEvent mouse_event;
mouse_event.type = WebKit::WebInputEvent::MouseDown;
mouse_event.button = WebKit::WebMouseEvent::ButtonLeft;
@@ -637,6 +639,66 @@ void SimulateMouseClick(content::WebContents* tab, int x, int y) {
tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
}
+void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type,
+ ui::KeyboardCode key,
+ bool control,
+ bool shift,
+ bool alt,
+ bool command,
+ NativeWebKeyboardEvent* event) {
+ event->nativeKeyCode = 0;
+ event->windowsKeyCode = key;
+ event->setKeyIdentifierFromWindowsKeyCode();
+ event->type = type;
+ event->modifiers = 0;
+ event->isSystemKey = false;
+ event->timeStampSeconds = base::Time::Now().ToDoubleT();
+ event->skip_in_browser = true;
+
+ if (type == WebKit::WebInputEvent::Char ||
+ type == WebKit::WebInputEvent::RawKeyDown) {
+ event->text[0] = key;
+ event->unmodifiedText[0] = key;
+ }
+
+ if (control)
+ event->modifiers |= WebKit::WebInputEvent::ControlKey;
+
+ if (shift)
+ event->modifiers |= WebKit::WebInputEvent::ShiftKey;
+
+ if (alt)
+ event->modifiers |= WebKit::WebInputEvent::AltKey;
+
+ if (command)
+ event->modifiers |= WebKit::WebInputEvent::MetaKey;
+}
+
+void SimulateKeyPress(content::WebContents* tab,
+ ui::KeyboardCode key,
+ bool control,
+ bool shift,
+ bool alt,
+ bool command) {
+ NativeWebKeyboardEvent event_down;
+ BuildSimpleWebKeyEvent(
+ WebKit::WebInputEvent::RawKeyDown, key, control, shift, alt, command,
+ &event_down);
+ tab->GetRenderViewHost()->ForwardKeyboardEvent(event_down);
+
+ NativeWebKeyboardEvent char_event;
+ BuildSimpleWebKeyEvent(
+ WebKit::WebInputEvent::Char, key, control, shift, alt, command,
+ &char_event);
+ tab->GetRenderViewHost()->ForwardKeyboardEvent(char_event);
+
+ NativeWebKeyboardEvent event_up;
+ BuildSimpleWebKeyEvent(
+ WebKit::WebInputEvent::KeyUp, key, control, shift, alt, command,
+ &event_up);
+ tab->GetRenderViewHost()->ForwardKeyboardEvent(event_up);
+}
+
void RegisterAndWait(content::NotificationObserver* observer,
int type,
const content::NotificationSource& source) {
diff --git a/chrome/test/base/ui_test_utils.h b/chrome/test/base/ui_test_utils.h
index 463b2ce..9b02038 100644
--- a/chrome/test/base/ui_test_utils.h
+++ b/chrome/test/base/ui_test_utils.h
@@ -218,9 +218,18 @@ int FindInPage(TabContentsWrapper* tab,
bool case_sensitive,
int* ordinal);
-// Simulates clicking at the specified position in the given tab. Unlike
+// Simulates clicking at the center of the given tab asynchronously. Unlike
// ClickOnView, this works even if the browser isn't in the foreground.
-void SimulateMouseClick(content::WebContents* tab, int x, int y);
+void SimulateMouseClick(content::WebContents* tab);
+
+// Sends a key press asynchronously. Unlike the SendKeyPress functions, this
+// works even if the browser isn't in the foreground.
+void SimulateKeyPress(content::WebContents* tab,
+ ui::KeyboardCode key,
+ bool control,
+ bool shift,
+ bool alt,
+ bool command);
#if defined OS_MACOSX
void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds);
diff --git a/chrome/test/data/npapi/execute_script_delete_in_mouse_up.html b/chrome/test/data/npapi/execute_script_delete_in_mouse_up.html
index c4faa99..f23c088 100644
--- a/chrome/test/data/npapi/execute_script_delete_in_mouse_up.html
+++ b/chrome/test/data/npapi/execute_script_delete_in_mouse_up.html
@@ -29,6 +29,8 @@ of a synchronous mouse event.
name="execute_script_delete_in_mouse_up"
id="1"
mode="np_embed"
+ width="100%"
+ height="100%"
>
</DIV>
<script>
diff --git a/content/browser/plugin_browsertest.cc b/content/browser/plugin_browsertest.cc
index 6096e61..f35bbd4d9 100644
--- a/content/browser/plugin_browsertest.cc
+++ b/content/browser/plugin_browsertest.cc
@@ -118,8 +118,7 @@ IN_PROC_BROWSER_TEST_F(PluginTest,
ui_test_utils::TitleWatcher title_watcher(
browser()->GetSelectedWebContents(), expected_title);
title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
- ui_test_utils::SimulateMouseClick(
- browser()->GetSelectedWebContents(), 150, 250);
+ ui_test_utils::SimulateMouseClick(browser()->GetSelectedWebContents());
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
}
#endif