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

Side by Side Diff: chrome/browser/ui/views/find_bar_views_interactive_uitest.cc

Issue 2078953003: Remove find bar focus redirection on mouse events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add tap testing; make test more rigorous. Created 4 years, 6 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
« no previous file with comments | « chrome/browser/ui/views/find_bar_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/macros.h" 5 #include "base/macros.h"
6 #include "base/strings/string_util.h" 6 #include "base/strings/string_util.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
24 #include "net/test/embedded_test_server/embedded_test_server.h" 24 #include "net/test/embedded_test_server/embedded_test_server.h"
25 #include "ui/base/clipboard/clipboard.h" 25 #include "ui/base/clipboard/clipboard.h"
26 #include "ui/events/keycodes/keyboard_codes.h" 26 #include "ui/events/keycodes/keyboard_codes.h"
27 #include "ui/views/focus/focus_manager.h" 27 #include "ui/views/focus/focus_manager.h"
28 #include "ui/views/view.h" 28 #include "ui/views/view.h"
29 29
30 using base::ASCIIToUTF16; 30 using base::ASCIIToUTF16;
31 using content::WebContents; 31 using content::WebContents;
32 using ui_test_utils::IsViewFocused;
32 33
33 namespace { 34 namespace {
34
35 static const char kSimplePage[] = "/find_in_page/simple.html"; 35 static const char kSimplePage[] = "/find_in_page/simple.html";
36 } // namespace
36 37
37 class FindInPageTest : public InProcessBrowserTest { 38 class FindInPageTest : public InProcessBrowserTest {
38 public: 39 public:
39 FindInPageTest() { 40 FindInPageTest() {
40 FindBarHost::disable_animations_during_testing_ = true; 41 FindBarHost::disable_animations_during_testing_ = true;
41 } 42 }
42 43
43 base::string16 GetFindBarText() { 44 FindBarHost* GetFindBarHost() {
44 FindBar* find_bar = browser()->GetFindBarController()->find_bar(); 45 FindBar* find_bar = browser()->GetFindBarController()->find_bar();
45 return find_bar->GetFindText(); 46 return static_cast<FindBarHost*>(find_bar);
46 } 47 }
47 48
49 FindBarView* GetFindBarView() { return GetFindBarHost()->find_bar_view(); }
50
51 base::string16 GetFindBarText() { return GetFindBarHost()->GetFindText(); }
52
48 base::string16 GetFindBarSelectedText() { 53 base::string16 GetFindBarSelectedText() {
49 FindBarTesting* find_bar = 54 return GetFindBarHost()->GetFindBarTesting()->GetFindSelectedText();
50 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); 55 }
51 return find_bar->GetFindSelectedText(); 56
57 void ClickOnView(views::View* view) {
58 // EventGenerator and ui_test_utils can't target the find bar (on Windows).
59 view->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(),
60 gfx::Point(), base::TimeTicks(),
61 ui::EF_LEFT_MOUSE_BUTTON,
62 ui::EF_LEFT_MOUSE_BUTTON));
63 view->OnMouseReleased(ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(),
64 gfx::Point(), base::TimeTicks(),
65 ui::EF_LEFT_MOUSE_BUTTON,
66 ui::EF_LEFT_MOUSE_BUTTON));
67 }
68
69 void TapOnView(views::View* view) {
70 // EventGenerator and ui_test_utils can't target the find bar (on Windows).
71 ui::GestureEvent event(0, 0, 0, base::TimeTicks(),
72 ui::GestureEventDetails(ui::ET_GESTURE_TAP));
73 view->OnGestureEvent(&event);
74 }
75
76 FindNotificationDetails WaitForFindResult() {
77 content::Source<WebContents> source(
78 browser()->tab_strip_model()->GetActiveWebContents());
79 ui_test_utils::WindowedNotificationObserverWithDetails
80 <FindNotificationDetails> observer(
81 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, source);
82 observer.Wait();
83 FindNotificationDetails details;
84 EXPECT_TRUE(observer.GetDetailsFor(source.map_key(), &details));
85 return details;
52 } 86 }
53 87
54 private: 88 private:
55 DISALLOW_COPY_AND_ASSIGN(FindInPageTest); 89 DISALLOW_COPY_AND_ASSIGN(FindInPageTest);
56 }; 90 };
57 91
58 } // namespace
59
60 // Flaky because the test server fails to start? See: http://crbug.com/96594. 92 // Flaky because the test server fails to start? See: http://crbug.com/96594.
61 IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) { 93 IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) {
62 ASSERT_TRUE(embedded_test_server()->Start()); 94 ASSERT_TRUE(embedded_test_server()->Start());
63 95
64 // First we navigate to our test page (tab A). 96 // First we navigate to our test page (tab A).
65 GURL url = embedded_test_server()->GetURL(kSimplePage); 97 GURL url = embedded_test_server()->GetURL(kSimplePage);
66 ui_test_utils::NavigateToURL(browser(), url); 98 ui_test_utils::NavigateToURL(browser(), url);
67 99
68 chrome::Find(browser()); 100 chrome::Find(browser());
69 101
70 // Open another tab (tab B). 102 // Open another tab (tab B).
71 chrome::AddSelectedTabWithURL(browser(), url, ui::PAGE_TRANSITION_TYPED); 103 chrome::AddSelectedTabWithURL(browser(), url, ui::PAGE_TRANSITION_TYPED);
72 104
73 chrome::Find(browser()); 105 chrome::Find(browser());
74 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 106 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
75 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
76 107
77 // Select tab A. 108 // Select tab A.
78 browser()->tab_strip_model()->ActivateTabAt(0, true); 109 browser()->tab_strip_model()->ActivateTabAt(0, true);
79 110
80 // Close tab B. 111 // Close tab B.
81 browser()->tab_strip_model()->CloseWebContentsAt(1, 112 browser()->tab_strip_model()->CloseWebContentsAt(1,
82 TabStripModel::CLOSE_NONE); 113 TabStripModel::CLOSE_NONE);
83 114
84 // Click on the location bar so that Find box loses focus. 115 // Click on the location bar so that Find box loses focus.
85 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), 116 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(),
86 VIEW_ID_OMNIBOX)); 117 VIEW_ID_OMNIBOX));
87 // Check the location bar is focused. 118 // Check the location bar is focused.
88 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 119 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_OMNIBOX));
89 120
90 // This used to crash until bug 1303709 was fixed. 121 // This used to crash until bug 1303709 was fixed.
91 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 122 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
92 browser(), ui::VKEY_ESCAPE, false, false, false, false)); 123 browser(), ui::VKEY_ESCAPE, false, false, false, false));
93 } 124 }
94 125
95 IN_PROC_BROWSER_TEST_F(FindInPageTest, NavigationByKeyEvent) { 126 IN_PROC_BROWSER_TEST_F(FindInPageTest, NavigationByKeyEvent) {
96 ASSERT_TRUE(embedded_test_server()->Start()); 127 ASSERT_TRUE(embedded_test_server()->Start());
97 // Make sure Chrome is in the foreground, otherwise sending input 128 // Make sure Chrome is in the foreground, otherwise sending input
98 // won't do anything and the test will hang. 129 // won't do anything and the test will hang.
99 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 130 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
100 // First we navigate to any page. 131 // First we navigate to any page.
101 ui_test_utils::NavigateToURL(browser(), 132 ui_test_utils::NavigateToURL(browser(),
102 embedded_test_server()->GetURL(kSimplePage)); 133 embedded_test_server()->GetURL(kSimplePage));
103 // Show the Find bar. 134 // Show the Find bar.
104 browser()->GetFindBarController()->Show(); 135 browser()->GetFindBarController()->Show();
105 EXPECT_TRUE( 136 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
106 ui_test_utils::IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
107 ui_test_utils::FindInPage( 137 ui_test_utils::FindInPage(
108 browser()->tab_strip_model()->GetActiveWebContents(), ASCIIToUTF16("a"), 138 browser()->tab_strip_model()->GetActiveWebContents(), ASCIIToUTF16("a"),
109 true, false, NULL, NULL); 139 true, false, NULL, NULL);
110 140
111 // The previous button should still be focused after pressing [Enter] on it. 141 // The previous button should still be focused after pressing [Enter] on it.
112 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, false, 142 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, false,
113 false, false, false)); 143 false, false, false));
114 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_RETURN, false, 144 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_RETURN, false,
115 false, false, false)); 145 false, false, false));
116 EXPECT_TRUE( 146 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON));
117 ui_test_utils::IsViewFocused(browser(),
118 VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON));
119 147
120 // The next button should still be focused after pressing [Enter] on it. 148 // The next button should still be focused after pressing [Enter] on it.
121 ui_test_utils::FindInPage( 149 ui_test_utils::FindInPage(
122 browser()->tab_strip_model()->GetActiveWebContents(), ASCIIToUTF16("b"), 150 browser()->tab_strip_model()->GetActiveWebContents(), ASCIIToUTF16("b"),
123 true, false, NULL, NULL); 151 true, false, NULL, NULL);
124 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, false, 152 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, false,
125 false, false, false)); 153 false, false, false));
126 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_RETURN, false, 154 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_RETURN, false,
127 false, false, false)); 155 false, false, false));
128 EXPECT_TRUE( 156 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON));
129 ui_test_utils::IsViewFocused(browser(),
130 VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON));
131 } 157 }
132 158
133 // TODO(mpistrich): Enable again when ui_test_utils::ClickOnView works with find 159 IN_PROC_BROWSER_TEST_F(FindInPageTest, ButtonsDoNotAlterFocus) {
134 // bar view IDs.
135 // http://crbug.com/584043
136 IN_PROC_BROWSER_TEST_F(FindInPageTest, DISABLED_NavigationByMouse) {
137 ASSERT_TRUE(embedded_test_server()->Start()); 160 ASSERT_TRUE(embedded_test_server()->Start());
138 // Make sure Chrome is in the foreground, otherwise sending input 161 // Make sure Chrome is in the foreground, otherwise sending input
139 // won't do anything and the test will hang. 162 // won't do anything and the test will hang.
140 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 163 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
141 // First we navigate to any page. 164 // First we navigate to any page.
142 ui_test_utils::NavigateToURL(browser(), 165 ui_test_utils::NavigateToURL(browser(),
143 embedded_test_server()->GetURL(kSimplePage)); 166 embedded_test_server()->GetURL(kSimplePage));
144 // Show the Find bar. 167 // Show the Find bar.
145 browser()->GetFindBarController()->Show(); 168 browser()->GetFindBarController()->Show();
146 EXPECT_TRUE( 169 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
147 ui_test_utils::IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 170 const int match_count = ui_test_utils::FindInPage(
148 ui_test_utils::FindInPage( 171 browser()->tab_strip_model()->GetActiveWebContents(), ASCIIToUTF16("e"),
149 browser()->tab_strip_model()->GetActiveWebContents(), ASCIIToUTF16("a"), 172 true, false, nullptr, nullptr);
150 true, false, NULL, NULL); 173 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
151 174
152 // The textfield should be focused after clicking on any button. 175 // This test requires at least 3 possible matches.
153 ui_test_utils::ClickOnView(browser(), VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON); 176 ASSERT_GE(match_count, 3);
154 EXPECT_TRUE( 177 // Avoid GetViewByID on BrowserView; the find bar is outside its hierarchy.
155 ui_test_utils::IsViewFocused(browser(), 178 FindBarView* find_bar_view = GetFindBarView();
156 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 179 views::View* next_button =
180 find_bar_view->GetViewByID(VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON);
181 views::View* previous_button =
182 find_bar_view->GetViewByID(VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON);
157 183
158 // The textfield should be focused after clicking on any button. 184 // Clicking the next and previous buttons should not alter the focused view.
159 ui_test_utils::ClickOnView(browser(), VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON); 185 ClickOnView(next_button);
160 EXPECT_TRUE( 186 EXPECT_EQ(2, WaitForFindResult().active_match_ordinal());
161 ui_test_utils::IsViewFocused(browser(), 187 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
162 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 188 ClickOnView(previous_button);
189 EXPECT_EQ(1, WaitForFindResult().active_match_ordinal());
190 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
191
192 // Tapping the next and previous buttons should not alter the focused view.
193 TapOnView(next_button);
194 EXPECT_EQ(2, WaitForFindResult().active_match_ordinal());
195 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
196 TapOnView(previous_button);
197 EXPECT_EQ(1, WaitForFindResult().active_match_ordinal());
198 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
199
200 // The same should be true even when the previous button is focused.
201 previous_button->RequestFocus();
202 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON));
203 ClickOnView(next_button);
204 EXPECT_EQ(2, WaitForFindResult().active_match_ordinal());
205 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON));
206 TapOnView(next_button);
207 EXPECT_EQ(3, WaitForFindResult().active_match_ordinal());
208 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON));
163 } 209 }
164 210
165 IN_PROC_BROWSER_TEST_F(FindInPageTest, ButtonsDisabledWithoutText) { 211 IN_PROC_BROWSER_TEST_F(FindInPageTest, ButtonsDisabledWithoutText) {
166 ASSERT_TRUE(embedded_test_server()->Start()); 212 ASSERT_TRUE(embedded_test_server()->Start());
167 // Make sure Chrome is in the foreground, otherwise sending input 213 // Make sure Chrome is in the foreground, otherwise sending input
168 // won't do anything and the test will hang. 214 // won't do anything and the test will hang.
169 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 215 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
170 // First we navigate to any page. 216 // First we navigate to any page.
171 ui_test_utils::NavigateToURL(browser(), 217 ui_test_utils::NavigateToURL(browser(),
172 embedded_test_server()->GetURL(kSimplePage)); 218 embedded_test_server()->GetURL(kSimplePage));
173 // Show the Find bar. 219 // Show the Find bar.
174 browser()->GetFindBarController()->Show(); 220 browser()->GetFindBarController()->Show();
175 EXPECT_TRUE( 221 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
176 ui_test_utils::IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
177 222
178 // The buttons should be disabled as there is no text entered in the find bar 223 // The buttons should be disabled as there is no text entered in the find bar
179 // and no search has been issued yet. 224 // and no search has been issued yet.
180 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, false, 225 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, false,
181 false, false, false)); 226 false, false, false));
182 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 227 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON));
183 VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON));
184 } 228 }
185 229
186 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) 230 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
187 // TODO(erg): linux_aura bringup: http://crbug.com/163931 231 // TODO(erg): linux_aura bringup: http://crbug.com/163931
188 #define MAYBE_FocusRestore DISABLED_FocusRestore 232 #define MAYBE_FocusRestore DISABLED_FocusRestore
189 #else 233 #else
190 #define MAYBE_FocusRestore FocusRestore 234 #define MAYBE_FocusRestore FocusRestore
191 #endif 235 #endif
192 236
193 // Flaky because the test server fails to start? See: http://crbug.com/96594. 237 // Flaky because the test server fails to start? See: http://crbug.com/96594.
194 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestore) { 238 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestore) {
195 ASSERT_TRUE(embedded_test_server()->Start()); 239 ASSERT_TRUE(embedded_test_server()->Start());
196 240
197 GURL url = embedded_test_server()->GetURL("/title1.html"); 241 GURL url = embedded_test_server()->GetURL("/title1.html");
198 ui_test_utils::NavigateToURL(browser(), url); 242 ui_test_utils::NavigateToURL(browser(), url);
199 243
200 // Focus the location bar, open and close the find-in-page, focus should 244 // Focus the location bar, open and close the find-in-page, focus should
201 // return to the location bar. 245 // return to the location bar.
202 chrome::FocusLocationBar(browser()); 246 chrome::FocusLocationBar(browser());
203 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 247 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_OMNIBOX));
204 // Ensure the creation of the find bar controller. 248 // Ensure the creation of the find bar controller.
205 browser()->GetFindBarController()->Show(); 249 browser()->GetFindBarController()->Show();
206 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 250 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
207 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
208 browser()->GetFindBarController()->EndFindSession( 251 browser()->GetFindBarController()->EndFindSession(
209 FindBarController::kKeepSelectionOnPage, 252 FindBarController::kKeepSelectionOnPage,
210 FindBarController::kKeepResultsInFindBox); 253 FindBarController::kKeepResultsInFindBox);
211 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 254 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_OMNIBOX));
212 255
213 // Focus the location bar, find something on the page, close the find box, 256 // Focus the location bar, find something on the page, close the find box,
214 // focus should go to the page. 257 // focus should go to the page.
215 chrome::FocusLocationBar(browser()); 258 chrome::FocusLocationBar(browser());
216 chrome::Find(browser()); 259 chrome::Find(browser());
217 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 260 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
218 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
219 ui_test_utils::FindInPage( 261 ui_test_utils::FindInPage(
220 browser()->tab_strip_model()->GetActiveWebContents(), 262 browser()->tab_strip_model()->GetActiveWebContents(),
221 ASCIIToUTF16("a"), true, false, NULL, NULL); 263 ASCIIToUTF16("a"), true, false, NULL, NULL);
222 browser()->GetFindBarController()->EndFindSession( 264 browser()->GetFindBarController()->EndFindSession(
223 FindBarController::kKeepSelectionOnPage, 265 FindBarController::kKeepSelectionOnPage,
224 FindBarController::kKeepResultsInFindBox); 266 FindBarController::kKeepResultsInFindBox);
225 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 267 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
226 268
227 // Focus the location bar, open and close the find box, focus should return to 269 // Focus the location bar, open and close the find box, focus should return to
228 // the location bar (same as before, just checking that http://crbug.com/23599 270 // the location bar (same as before, just checking that http://crbug.com/23599
229 // is fixed). 271 // is fixed).
230 chrome::FocusLocationBar(browser()); 272 chrome::FocusLocationBar(browser());
231 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 273 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_OMNIBOX));
232 browser()->GetFindBarController()->Show(); 274 browser()->GetFindBarController()->Show();
233 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 275 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
234 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
235 browser()->GetFindBarController()->EndFindSession( 276 browser()->GetFindBarController()->EndFindSession(
236 FindBarController::kKeepSelectionOnPage, 277 FindBarController::kKeepSelectionOnPage,
237 FindBarController::kKeepResultsInFindBox); 278 FindBarController::kKeepResultsInFindBox);
238 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 279 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_OMNIBOX));
239 } 280 }
240 281
241
242 // TODO(phajdan.jr): Disabling due to possible timing issues on XP 282 // TODO(phajdan.jr): Disabling due to possible timing issues on XP
243 // interactive_ui_tests. 283 // interactive_ui_tests.
244 // http://crbug.com/311363 284 // http://crbug.com/311363
245 IN_PROC_BROWSER_TEST_F(FindInPageTest, DISABLED_SelectionRestoreOnTabSwitch) { 285 IN_PROC_BROWSER_TEST_F(FindInPageTest, DISABLED_SelectionRestoreOnTabSwitch) {
246 ASSERT_TRUE(embedded_test_server()->Start()); 286 ASSERT_TRUE(embedded_test_server()->Start());
247 287
248 // Make sure Chrome is in the foreground, otherwise sending input 288 // Make sure Chrome is in the foreground, otherwise sending input
249 // won't do anything and the test will hang. 289 // won't do anything and the test will hang.
250 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 290 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
251 291
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 335 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
296 browser(), ui::VKEY_HOME, false, false, false, false)); 336 browser(), ui::VKEY_HOME, false, false, false, false));
297 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 337 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
298 browser(), ui::VKEY_RIGHT, false, true, false, false)); 338 browser(), ui::VKEY_RIGHT, false, true, false, false));
299 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 339 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
300 browser(), ui::VKEY_RIGHT, false, true, false, false)); 340 browser(), ui::VKEY_RIGHT, false, true, false, false));
301 EXPECT_EQ(ASCIIToUTF16("de"), GetFindBarSelectedText()); 341 EXPECT_EQ(ASCIIToUTF16("de"), GetFindBarSelectedText());
302 342
303 // Select tab A. Find bar should select "bc". 343 // Select tab A. Find bar should select "bc".
304 browser()->tab_strip_model()->ActivateTabAt(0, true); 344 browser()->tab_strip_model()->ActivateTabAt(0, true);
305 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 345 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
306 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
307 EXPECT_EQ(ASCIIToUTF16("bc"), GetFindBarSelectedText()); 346 EXPECT_EQ(ASCIIToUTF16("bc"), GetFindBarSelectedText());
308 347
309 // Select tab B. Find bar should select "de". 348 // Select tab B. Find bar should select "de".
310 browser()->tab_strip_model()->ActivateTabAt(1, true); 349 browser()->tab_strip_model()->ActivateTabAt(1, true);
311 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 350 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
312 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
313 EXPECT_EQ(ASCIIToUTF16("de"), GetFindBarSelectedText()); 351 EXPECT_EQ(ASCIIToUTF16("de"), GetFindBarSelectedText());
314 } 352 }
315 353
316 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) 354 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
317 // TODO(erg): linux_aura bringup: http://crbug.com/163931 355 // TODO(erg): linux_aura bringup: http://crbug.com/163931
318 #define MAYBE_FocusRestoreOnTabSwitch DISABLED_FocusRestoreOnTabSwitch 356 #define MAYBE_FocusRestoreOnTabSwitch DISABLED_FocusRestoreOnTabSwitch
319 #else 357 #else
320 #define MAYBE_FocusRestoreOnTabSwitch FocusRestoreOnTabSwitch 358 #define MAYBE_FocusRestoreOnTabSwitch FocusRestoreOnTabSwitch
321 #endif 359 #endif
322 360
323 // Flaky because the test server fails to start? See: http://crbug.com/96594. 361 // Flaky because the test server fails to start? See: http://crbug.com/96594.
324 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestoreOnTabSwitch) { 362 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestoreOnTabSwitch) {
325 ASSERT_TRUE(embedded_test_server()->Start()); 363 ASSERT_TRUE(embedded_test_server()->Start());
326 364
327 // First we navigate to our test page (tab A). 365 // First we navigate to our test page (tab A).
328 GURL url = embedded_test_server()->GetURL(kSimplePage); 366 GURL url = embedded_test_server()->GetURL(kSimplePage);
329 ui_test_utils::NavigateToURL(browser(), url); 367 ui_test_utils::NavigateToURL(browser(), url);
330 368
331 chrome::Find(browser()); 369 chrome::Find(browser());
332 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 370 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
333 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
334 371
335 // Search for 'a'. 372 // Search for 'a'.
336 ui_test_utils::FindInPage( 373 ui_test_utils::FindInPage(
337 browser()->tab_strip_model()->GetActiveWebContents(), 374 browser()->tab_strip_model()->GetActiveWebContents(),
338 ASCIIToUTF16("a"), true, false, NULL, NULL); 375 ASCIIToUTF16("a"), true, false, NULL, NULL);
339 EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarSelectedText()); 376 EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarSelectedText());
340 377
341 // Open another tab (tab B). 378 // Open another tab (tab B).
342 content::WindowedNotificationObserver observer( 379 content::WindowedNotificationObserver observer(
343 content::NOTIFICATION_LOAD_STOP, 380 content::NOTIFICATION_LOAD_STOP,
344 content::NotificationService::AllSources()); 381 content::NotificationService::AllSources());
345 chrome::AddSelectedTabWithURL(browser(), url, ui::PAGE_TRANSITION_TYPED); 382 chrome::AddSelectedTabWithURL(browser(), url, ui::PAGE_TRANSITION_TYPED);
346 observer.Wait(); 383 observer.Wait();
347 384
348 // Make sure Find box is open. 385 // Make sure Find box is open.
349 chrome::Find(browser()); 386 chrome::Find(browser());
350 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 387 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
351 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
352 388
353 // Search for 'b'. 389 // Search for 'b'.
354 ui_test_utils::FindInPage( 390 ui_test_utils::FindInPage(
355 browser()->tab_strip_model()->GetActiveWebContents(), 391 browser()->tab_strip_model()->GetActiveWebContents(),
356 ASCIIToUTF16("b"), true, false, NULL, NULL); 392 ASCIIToUTF16("b"), true, false, NULL, NULL);
357 EXPECT_EQ(ASCIIToUTF16("b"), GetFindBarSelectedText()); 393 EXPECT_EQ(ASCIIToUTF16("b"), GetFindBarSelectedText());
358 394
359 // Set focus away from the Find bar (to the Location bar). 395 // Set focus away from the Find bar (to the Location bar).
360 chrome::FocusLocationBar(browser()); 396 chrome::FocusLocationBar(browser());
361 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 397 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_OMNIBOX));
362 398
363 // Select tab A. Find bar should get focus. 399 // Select tab A. Find bar should get focus.
364 browser()->tab_strip_model()->ActivateTabAt(0, true); 400 browser()->tab_strip_model()->ActivateTabAt(0, true);
365 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 401 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
366 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
367 EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarSelectedText()); 402 EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarSelectedText());
368 403
369 // Select tab B. Location bar should get focus. 404 // Select tab B. Location bar should get focus.
370 browser()->tab_strip_model()->ActivateTabAt(1, true); 405 browser()->tab_strip_model()->ActivateTabAt(1, true);
371 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 406 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_OMNIBOX));
372 } 407 }
373 408
374 // FindInPage on Mac doesn't use prepopulated values. Search there is global. 409 // FindInPage on Mac doesn't use prepopulated values. Search there is global.
375 #if !defined(OS_MACOSX) && !defined(USE_AURA) 410 #if !defined(OS_MACOSX) && !defined(USE_AURA)
376 // Flaky because the test server fails to start? See: http://crbug.com/96594. 411 // Flaky because the test server fails to start? See: http://crbug.com/96594.
377 // This tests that whenever you clear values from the Find box and close it that 412 // This tests that whenever you clear values from the Find box and close it that
378 // it respects that and doesn't show you the last search, as reported in bug: 413 // it respects that and doesn't show you the last search, as reported in bug:
379 // http://crbug.com/40121. For Aura see bug http://crbug.com/292299. 414 // http://crbug.com/40121. For Aura see bug http://crbug.com/292299.
380 IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) { 415 IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) {
381 ASSERT_TRUE(embedded_test_server()->Start()); 416 ASSERT_TRUE(embedded_test_server()->Start());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // won't do anything and the test will hang. 481 // won't do anything and the test will hang.
447 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 482 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
448 483
449 // First we navigate to any page. 484 // First we navigate to any page.
450 GURL url = embedded_test_server()->GetURL(kSimplePage); 485 GURL url = embedded_test_server()->GetURL(kSimplePage);
451 ui_test_utils::NavigateToURL(browser(), url); 486 ui_test_utils::NavigateToURL(browser(), url);
452 487
453 // Show the Find bar. 488 // Show the Find bar.
454 browser()->GetFindBarController()->Show(); 489 browser()->GetFindBarController()->Show();
455 490
456 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 491 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
457 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
458 492
459 // Search for "a". 493 // Search for "a".
460 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 494 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
461 browser(), ui::VKEY_A, false, false, false, false)); 495 browser(), ui::VKEY_A, false, false, false, false));
462 496
463 // We should find "a" here. 497 // We should find "a" here.
464 EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarText()); 498 EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarText());
465 499
466 // Reload the page to clear the matching result. 500 // Reload the page to clear the matching result.
467 chrome::Reload(browser(), CURRENT_TAB); 501 chrome::Reload(browser(), CURRENT_TAB);
468 502
469 // Focus the Find bar again to make sure the text is selected. 503 // Focus the Find bar again to make sure the text is selected.
470 browser()->GetFindBarController()->Show(); 504 browser()->GetFindBarController()->Show();
471 505
472 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 506 EXPECT_TRUE(IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
473 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
474 507
475 // "a" should be selected. 508 // "a" should be selected.
476 EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarSelectedText()); 509 EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarSelectedText());
477 510
478 // Press Ctrl-C to copy the content. 511 // Press Ctrl-C to copy the content.
479 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 512 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
480 browser(), ui::VKEY_C, true, false, false, false)); 513 browser(), ui::VKEY_C, true, false, false, false));
481 514
482 base::string16 str; 515 base::string16 str;
483 ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, 516 ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE,
484 &str); 517 &str);
485 518
486 // Make sure the text is copied successfully. 519 // Make sure the text is copied successfully.
487 EXPECT_EQ(ASCIIToUTF16("a"), str); 520 EXPECT_EQ(ASCIIToUTF16("a"), str);
488 521
489 // Press Ctrl-V to paste the content back, it should start finding even if the 522 // Press Ctrl-V to paste the content back, it should start finding even if the
490 // content is not changed. 523 // content is not changed.
491 content::Source<WebContents> notification_source(
492 browser()->tab_strip_model()->GetActiveWebContents());
493 ui_test_utils::WindowedNotificationObserverWithDetails
494 <FindNotificationDetails> observer(
495 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, notification_source);
496
497 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 524 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
498 browser(), ui::VKEY_V, true, false, false, false)); 525 browser(), ui::VKEY_V, true, false, false, false));
499 526 FindNotificationDetails details = WaitForFindResult();
500 ASSERT_NO_FATAL_FAILURE(observer.Wait());
501 FindNotificationDetails details;
502 ASSERT_TRUE(observer.GetDetailsFor(notification_source.map_key(), &details));
503 EXPECT_TRUE(details.number_of_matches() > 0); 527 EXPECT_TRUE(details.number_of_matches() > 0);
504 } 528 }
505 529
506 #if defined(OS_WIN) 530 #if defined(OS_WIN)
507 // TODO(phajdan.jr): Disabling due to possible timing issues on XP 531 // TODO(phajdan.jr): Disabling due to possible timing issues on XP
508 // interactive_ui_tests. 532 // interactive_ui_tests.
509 // http://crbug.com/311363 533 // http://crbug.com/311363
510 IN_PROC_BROWSER_TEST_F(FindInPageTest, DISABLED_CtrlEnter) { 534 IN_PROC_BROWSER_TEST_F(FindInPageTest, DISABLED_CtrlEnter) {
511 ui_test_utils::NavigateToURL(browser(), 535 ui_test_utils::NavigateToURL(browser(),
512 GURL("data:text/html,This is some text with a " 536 GURL("data:text/html,This is some text with a "
(...skipping 15 matching lines...) Expand all
528 ui_test_utils::UrlLoadObserver observer( 552 ui_test_utils::UrlLoadObserver observer(
529 GURL("about:blank"), content::NotificationService::AllSources()); 553 GURL("about:blank"), content::NotificationService::AllSources());
530 554
531 // Send Ctrl-Enter, should cause navigation to about:blank. 555 // Send Ctrl-Enter, should cause navigation to about:blank.
532 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 556 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
533 browser(), ui::VKEY_RETURN, true, false, false, false)); 557 browser(), ui::VKEY_RETURN, true, false, false, false));
534 558
535 observer.Wait(); 559 observer.Wait();
536 } 560 }
537 #endif 561 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/find_bar_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698