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

Side by Side Diff: chrome/browser/views/find_bar_host_interactive_uitest.cc

Issue 3117030: Adds ui_test_utils::SendAndWaitForKeyPress and converts callers (where (Closed)
Patch Set: Addressed review comments Created 10 years, 4 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/keyboard_codes.h" 5 #include "base/keyboard_codes.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/automation/ui_controls.h" 9 #include "chrome/browser/automation/ui_controls.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #elif defined(OS_LINUX) 42 #elif defined(OS_LINUX)
43 gfx::NativeWindow window = browser_window->GetNativeHandle(); 43 gfx::NativeWindow window = browser_window->GetNativeHandle();
44 ASSERT_TRUE(window); 44 ASSERT_TRUE(window);
45 GtkWidget* view = ViewIDUtil::GetWidget(GTK_WIDGET(window), view_id); 45 GtkWidget* view = ViewIDUtil::GetWidget(GTK_WIDGET(window), view_id);
46 #endif 46 #endif
47 ASSERT_TRUE(view); 47 ASSERT_TRUE(view);
48 ui_controls::MoveMouseToCenterAndPress(view, 48 ui_controls::MoveMouseToCenterAndPress(view,
49 ui_controls::LEFT, 49 ui_controls::LEFT,
50 ui_controls::DOWN | ui_controls::UP, 50 ui_controls::DOWN | ui_controls::UP,
51 new MessageLoop::QuitTask()); 51 new MessageLoop::QuitTask());
52 ui_test_utils::RunMessageLoop(); 52 ASSERT_NO_FATAL_FAILURE(ui_test_utils::RunMessageLoop());
53 } 53 }
54 54
55 int GetFocusedViewID() { 55 int GetFocusedViewID() {
56 #if defined(TOOLKIT_VIEWS) 56 #if defined(TOOLKIT_VIEWS)
57 #if defined(OS_LINUX) 57 #if defined(OS_LINUX)
58 // See http://crbug.com/26873 . 58 // See http://crbug.com/26873 .
59 views::FocusManager* focus_manager = 59 views::FocusManager* focus_manager =
60 views::FocusManager::GetFocusManagerForNativeView( 60 views::FocusManager::GetFocusManagerForNativeView(
61 GTK_WIDGET(browser()->window()->GetNativeHandle())); 61 GTK_WIDGET(browser()->window()->GetNativeHandle()));
62 #else 62 #else
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 browser()->Find(); 106 browser()->Find();
107 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID()); 107 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID());
108 108
109 // Select tab A. 109 // Select tab A.
110 browser()->SelectTabContentsAt(0, true); 110 browser()->SelectTabContentsAt(0, true);
111 111
112 // Close tab B. 112 // Close tab B.
113 browser()->CloseTabContents(browser()->GetTabContentsAt(1)); 113 browser()->CloseTabContents(browser()->GetTabContentsAt(1));
114 114
115 // Click on the location bar so that Find box loses focus. 115 // Click on the location bar so that Find box loses focus.
116 ClickOnView(VIEW_ID_LOCATION_BAR); 116 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_LOCATION_BAR));
117 #if defined(TOOLKIT_VIEWS) || defined(OS_WIN) 117 #if defined(TOOLKIT_VIEWS) || defined(OS_WIN)
118 // Check the location bar is focused. 118 // Check the location bar is focused.
119 EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID()); 119 EXPECT_EQ(VIEW_ID_LOCATION_BAR, GetFocusedViewID());
120 #endif 120 #endif
121 121
122 // This used to crash until bug 1303709 was fixed. 122 // This used to crash until bug 1303709 was fixed.
123 ui_controls::SendKeyPressNotifyWhenDone( 123 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
124 browser()->window()->GetNativeHandle(), base::VKEY_ESCAPE, 124 browser()->window()->GetNativeHandle(), base::VKEY_ESCAPE,
125 false, false, false, false, new MessageLoop::QuitTask()); 125 false, false, false, false));
126 ui_test_utils::RunMessageLoop();
127 } 126 }
128 127
129 IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) { 128 IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) {
130 ASSERT_TRUE(test_server()->Start()); 129 ASSERT_TRUE(test_server()->Start());
131 130
132 GURL url = test_server()->GetURL("title1.html"); 131 GURL url = test_server()->GetURL("title1.html");
133 ui_test_utils::NavigateToURL(browser(), url); 132 ui_test_utils::NavigateToURL(browser(), url);
134 133
135 // Focus the location bar, open and close the find-in-page, focus should 134 // Focus the location bar, open and close the find-in-page, focus should
136 // return to the location bar. 135 // return to the location bar.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // First we navigate to any page. 179 // First we navigate to any page.
181 GURL url = test_server()->GetURL(kSimplePage); 180 GURL url = test_server()->GetURL(kSimplePage);
182 ui_test_utils::NavigateToURL(browser(), url); 181 ui_test_utils::NavigateToURL(browser(), url);
183 182
184 gfx::NativeWindow window = browser()->window()->GetNativeHandle(); 183 gfx::NativeWindow window = browser()->window()->GetNativeHandle();
185 184
186 // Show the Find bar. 185 // Show the Find bar.
187 browser()->GetFindBarController()->Show(); 186 browser()->GetFindBarController()->Show();
188 187
189 // Search for "a". 188 // Search for "a".
190 ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_A, 189 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
191 false, false, false, false, // No modifiers. 190 window, base::VKEY_A, false, false, false, false)); // No modifiers
192 new MessageLoop::QuitTask());
193 ui_test_utils::RunMessageLoop();
194 191
195 // We should find "a" here. 192 // We should find "a" here.
196 EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarText()); 193 EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarText());
197 194
198 // Delete "a". 195 // Delete "a".
199 ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_BACK, 196 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
200 false, false, false, false, // No modifiers. 197 window, base::VKEY_BACK, false, false, false, false)); // No modifiers.
201 new MessageLoop::QuitTask());
202 ui_test_utils::RunMessageLoop();
203 198
204 // Validate we have cleared the text. 199 // Validate we have cleared the text.
205 EXPECT_EQ(string16(), GetFindBarText()); 200 EXPECT_EQ(string16(), GetFindBarText());
206 201
207 // Close the Find box. 202 // Close the Find box.
208 ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_ESCAPE, 203 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
209 false, false, false, false, // No modifiers. 204 window, base::VKEY_ESCAPE, false, false, false, false)); // No modifiers.
210 new MessageLoop::QuitTask());
211 ui_test_utils::RunMessageLoop();
212 205
213 // Show the Find bar. 206 // Show the Find bar.
214 browser()->GetFindBarController()->Show(); 207 browser()->GetFindBarController()->Show();
215 208
216 // After the Find box has been reopened, it should not have been prepopulated 209 // After the Find box has been reopened, it should not have been prepopulated
217 // with "a" again. 210 // with "a" again.
218 EXPECT_EQ(string16(), GetFindBarText()); 211 EXPECT_EQ(string16(), GetFindBarText());
219 212
220 // Close the Find box. 213 // Close the Find box.
221 ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_ESCAPE, 214 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
222 false, false, false, false, // No modifiers. 215 window, base::VKEY_ESCAPE, false, false, false, false)); // No modifiers.
223 new MessageLoop::QuitTask());
224 ui_test_utils::RunMessageLoop();
225 216
226 // Press F3 to trigger FindNext. 217 // Press F3 to trigger FindNext.
227 ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F3, 218 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
228 false, false, false, false, // No modifiers. 219 window, base::VKEY_F3, false, false, false, false)); // No modifiers.
229 new MessageLoop::QuitTask());
230 ui_test_utils::RunMessageLoop();
231 220
232 // After the Find box has been reopened, it should still have no prepopulate 221 // After the Find box has been reopened, it should still have no prepopulate
233 // value. 222 // value.
234 EXPECT_EQ(string16(), GetFindBarText()); 223 EXPECT_EQ(string16(), GetFindBarText());
235 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698