summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-23 16:21:28 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-23 16:21:28 +0000
commit1d000681ef18ea1ebd39a19bf17a7bfccd3ed352 (patch)
treeba970b56596e6ea791b260227a8a7d73ffc696e8 /chrome/browser
parent6679aafaaa6a213759623e4a056281d209158523 (diff)
downloadchromium_src-1d000681ef18ea1ebd39a19bf17a7bfccd3ed352.zip
chromium_src-1d000681ef18ea1ebd39a19bf17a7bfccd3ed352.tar.gz
chromium_src-1d000681ef18ea1ebd39a19bf17a7bfccd3ed352.tar.bz2
Adds ui_test_utils::SendAndWaitForKeyPress and converts callers (where
appropriate) to use it. Hopefully this will help isolate why tests are failing on bot. BUG=none TEST=none; test only change. Review URL: http://codereview.chromium.org/3117030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57064 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc7
-rw-r--r--chrome/browser/automation/ui_controls.h5
-rw-r--r--chrome/browser/browser_focus_uitest.cc71
-rw-r--r--chrome/browser/browser_keyevents_browsertest.cc8
-rw-r--r--chrome/browser/views/find_bar_host_interactive_uitest.cc39
5 files changed, 56 insertions, 74 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc
index e1dc676..5b00bab 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc
@@ -125,10 +125,9 @@ class AutocompleteEditViewTest : public InProcessBrowserTest,
void SendKey(base::KeyboardCode key, bool control, bool shift, bool alt) {
gfx::NativeWindow window = NULL;
ASSERT_NO_FATAL_FAILURE(GetNativeWindow(&window));
- ui_controls::SendKeyPressNotifyWhenDone(window, key, control, shift, alt,
- false /* command */,
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ ASSERT_TRUE(
+ ui_test_utils::SendKeyPressSync(
+ window, key, control, shift, alt, false /* command */));
}
void SendKeySequence(const wchar_t* keys) {
diff --git a/chrome/browser/automation/ui_controls.h b/chrome/browser/automation/ui_controls.h
index 4d1ce79..2b26dfe 100644
--- a/chrome/browser/automation/ui_controls.h
+++ b/chrome/browser/automation/ui_controls.h
@@ -12,9 +12,9 @@
#include <wtypes.h>
#endif
+#include "base/keyboard_codes.h"
#include "gfx/native_widget_types.h"
#include "gfx/point.h"
-#include "base/keyboard_codes.h"
#if defined(TOOLKIT_VIEWS)
namespace views {
@@ -42,6 +42,9 @@ namespace ui_controls {
// these functions, so passing NULL is ok.
// Send a key press with/without modifier keys.
+//
+// If you're writing a test chances are you want the variant in ui_test_utils.
+// See it for details.
bool SendKeyPress(gfx::NativeWindow window,
base::KeyboardCode key,
bool control,
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc
index 6f2e0ad..7c28705 100644
--- a/chrome/browser/browser_focus_uitest.cc
+++ b/chrome/browser/browser_focus_uitest.cc
@@ -305,10 +305,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocus) {
VIEW_ID_LOCATION_BAR;
ASSERT_TRUE(IsViewFocused(vid));
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_TAB, true,
- false, false, false,
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_TAB, true, false, false, false));
}
// As above, but with ctrl+shift+tab.
@@ -318,10 +316,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocus) {
VIEW_ID_LOCATION_BAR;
ASSERT_TRUE(IsViewFocused(vid));
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_TAB, true,
- true, false, false,
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_TAB, true, true, false, false));
}
}
}
@@ -488,11 +484,13 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) {
false, false, false, false));
if (j < arraysize(kExpElementIDs) - 1) {
- ui_test_utils::WaitForFocusChange(browser()->GetSelectedTabContents()->
- render_view_host());
+ ASSERT_NO_FATAL_FAILURE(
+ ui_test_utils::WaitForFocusChange(
+ browser()->GetSelectedTabContents()->render_view_host()));
} else {
// On the last tab key press, the focus returns to the browser.
- ui_test_utils::WaitForFocusInBrowser(browser());
+ ASSERT_NO_FATAL_FAILURE(
+ ui_test_utils::WaitForFocusInBrowser(browser()));
}
}
@@ -515,11 +513,13 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) {
false, true, false, false));
if (j < arraysize(kExpElementIDs) - 1) {
- ui_test_utils::WaitForFocusChange(browser()->GetSelectedTabContents()->
- render_view_host());
+ ASSERT_NO_FATAL_FAILURE(
+ ui_test_utils::WaitForFocusChange(
+ browser()->GetSelectedTabContents()->render_view_host()));
} else {
// On the last tab key press, the focus returns to the browser.
- ui_test_utils::WaitForFocusInBrowser(browser());
+ ASSERT_NO_FATAL_FAILURE(
+ ui_test_utils::WaitForFocusInBrowser(browser()));
}
// Let's make sure the focus is on the expected element in the page.
@@ -588,10 +588,11 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) {
false, false, false, false));
if (j < arraysize(kExpElementIDs) - 1) {
- interstitial_page->WaitForFocusChange();
+ ASSERT_NO_FATAL_FAILURE(interstitial_page->WaitForFocusChange());
} else {
// On the last tab key press, the focus returns to the browser.
- ui_test_utils::WaitForFocusInBrowser(browser());
+ ASSERT_NO_FATAL_FAILURE(
+ ui_test_utils::WaitForFocusInBrowser(browser()));
}
}
@@ -612,10 +613,11 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) {
false, true, false, false));
if (j < arraysize(kExpElementIDs) - 1) {
- interstitial_page->WaitForFocusChange();
+ ASSERT_NO_FATAL_FAILURE(interstitial_page->WaitForFocusChange());
} else {
// On the last tab key press, the focus returns to the browser.
- ui_test_utils::WaitForFocusInBrowser(browser());
+ ASSERT_NO_FATAL_FAILURE(
+ ui_test_utils::WaitForFocusInBrowser(browser()));
}
// Let's make sure the focus is on the expected element in the page.
@@ -679,16 +681,13 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) {
#if defined(OS_MACOSX)
// Press Cmd+F, which will make the Find box open and request focus.
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F, false,
- false, false, true,
- new MessageLoop::QuitTask());
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_F, false, false, false, true));
#else
// Press Ctrl+F, which will make the Find box open and request focus.
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F, true,
- false, false, false,
- new MessageLoop::QuitTask());
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_F, true, false, false, false));
#endif
- ui_test_utils::RunMessageLoop();
// Ideally, we wouldn't sleep here and instead would intercept the
// RenderViewHostDelegate::HandleKeyboardEvent() callback. To do that, we
@@ -706,15 +705,12 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) {
// Now press Ctrl+F again and focus should move to the Find box.
#if defined(OS_MACOSX)
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F, false,
- false, false, true,
- new MessageLoop::QuitTask());
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_F, false, false, false, true));
#else
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F, true,
- false, false, false,
- new MessageLoop::QuitTask());
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_F, true, false, false, false));
#endif
- ui_test_utils::RunMessageLoop();
ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
// Set focus to the page.
@@ -723,15 +719,12 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) {
// Now press Ctrl+F again and focus should move to the Find box.
#if defined(OS_MACOSX)
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F, false,
- false, false, true,
- new MessageLoop::QuitTask());
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_F, false, false, false, true));
#else
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F, true,
- false, false, false,
- new MessageLoop::QuitTask());
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_F, true, false, false, false));
#endif
- ui_test_utils::RunMessageLoop();
// See remark above on why we wait.
MessageLoop::current()->PostDelayedTask(
diff --git a/chrome/browser/browser_keyevents_browsertest.cc b/chrome/browser/browser_keyevents_browsertest.cc
index 89f8c08..87a6bedf 100644
--- a/chrome/browser/browser_keyevents_browsertest.cc
+++ b/chrome/browser/browser_keyevents_browsertest.cc
@@ -149,10 +149,8 @@ class BrowserKeyEventsTest : public InProcessBrowserTest {
bool command) {
gfx::NativeWindow window = NULL;
ASSERT_NO_FATAL_FAILURE(GetNativeWindow(&window));
- EXPECT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
- window, key, control, shift, alt, command,
- new MessageLoop::QuitTask()));
- ui_test_utils::RunMessageLoop();
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, key, control, shift, alt, command));
}
bool IsViewFocused(ViewID vid) {
@@ -790,7 +788,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_ReservedAccelerators) {
// Ctrl+F4 to close the tab.
ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(0, true));
- ASSERT_NO_FATAL_FAILURE( SendKey(base::VKEY_F4, true, false, false, false));
+ ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_F4, true, false, false, false));
ASSERT_EQ(1, browser()->tab_count());
#endif
}
diff --git a/chrome/browser/views/find_bar_host_interactive_uitest.cc b/chrome/browser/views/find_bar_host_interactive_uitest.cc
index f866f09..69d7284 100644
--- a/chrome/browser/views/find_bar_host_interactive_uitest.cc
+++ b/chrome/browser/views/find_bar_host_interactive_uitest.cc
@@ -49,7 +49,7 @@ class FindInPageTest : public InProcessBrowserTest {
ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ ASSERT_NO_FATAL_FAILURE(ui_test_utils::RunMessageLoop());
}
int GetFocusedViewID() {
@@ -113,17 +113,16 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) {
browser()->CloseTabContents(browser()->GetTabContentsAt(1));
// Click on the location bar so that Find box loses focus.
- ClickOnView(VIEW_ID_LOCATION_BAR);
+ ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_LOCATION_BAR));
#if defined(TOOLKIT_VIEWS) || defined(OS_WIN)
// Check the location bar is focused.
EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID());
#endif
// This used to crash until bug 1303709 was fixed.
- ui_controls::SendKeyPressNotifyWhenDone(
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser()->window()->GetNativeHandle(), base::VKEY_ESCAPE,
- false, false, false, false, new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ false, false, false, false));
}
IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) {
@@ -187,28 +186,22 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) {
browser()->GetFindBarController()->Show();
// Search for "a".
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_A,
- false, false, false, false, // No modifiers.
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_A, false, false, false, false)); // No modifiers
// We should find "a" here.
EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarText());
// Delete "a".
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_BACK,
- false, false, false, false, // No modifiers.
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_BACK, false, false, false, false)); // No modifiers.
// Validate we have cleared the text.
EXPECT_EQ(string16(), GetFindBarText());
// Close the Find box.
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_ESCAPE,
- false, false, false, false, // No modifiers.
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_ESCAPE, false, false, false, false)); // No modifiers.
// Show the Find bar.
browser()->GetFindBarController()->Show();
@@ -218,16 +211,12 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) {
EXPECT_EQ(string16(), GetFindBarText());
// Close the Find box.
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_ESCAPE,
- false, false, false, false, // No modifiers.
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_ESCAPE, false, false, false, false)); // No modifiers.
// Press F3 to trigger FindNext.
- ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F3,
- false, false, false, false, // No modifiers.
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ window, base::VKEY_F3, false, false, false, false)); // No modifiers.
// After the Find box has been reopened, it should still have no prepopulate
// value.