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

Side by Side Diff: chrome/browser/ui/search/instant_extended_browsertest.cc

Issue 13461032: Fix Windows InstantExtendedTest focus issues with OmniboxViewViews. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix another focus failure that surfaced on Mac. Created 7 years, 8 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
« no previous file with comments | « no previous file | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <sstream> 5 #include <sstream>
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 GetIntFromJS(contents, "mostVisitedItemsCount", 111 GetIntFromJS(contents, "mostVisitedItemsCount",
112 &most_visited_items_count_) && 112 &most_visited_items_count_) &&
113 GetIntFromJS(contents, "firstMostVisitedItemId", 113 GetIntFromJS(contents, "firstMostVisitedItemId",
114 &first_most_visited_item_id_) && 114 &first_most_visited_item_id_) &&
115 GetIntFromJS(contents, "onNativeSuggestionsCalls", 115 GetIntFromJS(contents, "onNativeSuggestionsCalls",
116 &on_native_suggestions_calls_) && 116 &on_native_suggestions_calls_) &&
117 GetIntFromJS(contents, "onChangeCalls", 117 GetIntFromJS(contents, "onChangeCalls",
118 &on_change_calls_); 118 &on_change_calls_);
119 } 119 }
120 120
121 // A convenience function to explicitly blur the omnibox and focus |contents|.
122 // TODO(msw|jered|sreeram): Fix test focus issues; see http://crbug.com/226189
123 void BlurOmniboxAndFocusContents(content::WebContents* contents) {
124 omnibox()->model()->OnWillKillFocus(contents->GetView()->GetNativeView());
125 omnibox()->model()->OnKillFocus();
126 contents->GetView()->Focus();
127 EXPECT_FALSE(omnibox()->model()->has_focus());
128 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
129 }
130
121 int on_most_visited_change_calls_; 131 int on_most_visited_change_calls_;
122 int most_visited_items_count_; 132 int most_visited_items_count_;
123 int first_most_visited_item_id_; 133 int first_most_visited_item_id_;
124 int on_native_suggestions_calls_; 134 int on_native_suggestions_calls_;
125 int on_change_calls_; 135 int on_change_calls_;
126 }; 136 };
127 137
128 // Test class used to verify chrome-search: scheme and access policy from the 138 // Test class used to verify chrome-search: scheme and access policy from the
129 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it 139 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it
130 // loads a theme that provides a background image. 140 // loads a theme that provides a background image.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 174
165 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { 175 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) {
166 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 176 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
167 EXPECT_TRUE(instant()->extended_enabled_); 177 EXPECT_TRUE(instant()->extended_enabled_);
168 } 178 }
169 179
170 // Test that Instant is preloaded when the omnibox is focused. 180 // Test that Instant is preloaded when the omnibox is focused.
171 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { 181 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) {
172 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 182 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
173 183
174 // Explicitly unfocus the omnibox. 184 // Blur the omnibox and focus the active web contents.
175 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 185 BlurOmniboxAndFocusContents(
Jered 2013/04/05 16:27:07 The new code does not do this. Is it unnecessary?
msw 2013/04/05 16:39:02 I suspect not if the test didn't break, but I rest
176 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 186 browser()->tab_strip_model()->GetActiveWebContents());
177
178 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
179 EXPECT_FALSE(omnibox()->model()->has_focus());
180 187
181 // Delete any existing overlay. 188 // Delete any existing overlay.
182 instant()->overlay_.reset(); 189 instant()->overlay_.reset();
183 EXPECT_FALSE(instant()->GetOverlayContents()); 190 EXPECT_FALSE(instant()->GetOverlayContents());
184 191
185 // Refocus the omnibox. The InstantController should've preloaded Instant. 192 // Refocus the omnibox. The InstantController should've preloaded Instant.
186 FocusOmniboxAndWaitForInstantExtendedSupport(); 193 FocusOmniboxAndWaitForInstantExtendedSupport();
187 194
188 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 195 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
189 EXPECT_TRUE(omnibox()->model()->has_focus()); 196 EXPECT_TRUE(omnibox()->model()->has_focus());
190 197
191 content::WebContents* overlay = instant()->GetOverlayContents(); 198 content::WebContents* overlay = instant()->GetOverlayContents();
192 EXPECT_TRUE(overlay); 199 EXPECT_TRUE(overlay);
193 200
194 // Check that the page supports Instant, but it isn't showing. 201 // Check that the page supports Instant, but it isn't showing.
195 EXPECT_TRUE(instant()->overlay_->supports_instant()); 202 EXPECT_TRUE(instant()->overlay_->supports_instant());
196 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); 203 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
197 EXPECT_TRUE(instant()->model()->mode().is_default()); 204 EXPECT_TRUE(instant()->model()->mode().is_default());
198 205
199 // Adding a new tab shouldn't delete or recreate the overlay; otherwise, 206 // Adding a new tab shouldn't delete or recreate the overlay; otherwise,
200 // what's the point of preloading? 207 // what's the point of preloading?
201 AddBlankTabAndShow(browser()); 208 AddBlankTabAndShow(browser());
202 EXPECT_EQ(overlay, instant()->GetOverlayContents()); 209 EXPECT_EQ(overlay, instant()->GetOverlayContents());
203 210
204 // Unfocusing and refocusing the omnibox should also preserve the overlay. 211 // Unfocusing and refocusing the omnibox should also preserve the overlay.
205 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 212 BlurOmniboxAndFocusContents(
206 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 213 browser()->tab_strip_model()->GetActiveWebContents());
207
208 FocusOmnibox(); 214 FocusOmnibox();
209 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 215 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
210 EXPECT_EQ(overlay, instant()->GetOverlayContents()); 216 EXPECT_EQ(overlay, instant()->GetOverlayContents());
211 } 217 }
212 218
213 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputShowsOverlay) { 219 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputShowsOverlay) {
214 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 220 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
215 221
216 // Focus omnibox and confirm overlay isn't shown. 222 // Focus omnibox and confirm overlay isn't shown.
217 FocusOmniboxAndWaitForInstantExtendedSupport(); 223 FocusOmniboxAndWaitForInstantExtendedSupport();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 content::WindowedNotificationObserver observer( 366 content::WindowedNotificationObserver observer(
361 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 367 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
362 content::NotificationService::AllSources()); 368 content::NotificationService::AllSources());
363 369
364 // Do a search and commit it. 370 // Do a search and commit it.
365 SetOmniboxTextAndWaitForOverlayToShow("hello k"); 371 SetOmniboxTextAndWaitForOverlayToShow("hello k");
366 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText()); 372 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText());
367 browser()->window()->GetLocationBar()->AcceptInput(); 373 browser()->window()->GetLocationBar()->AcceptInput();
368 observer.Wait(); 374 observer.Wait();
369 375
370 // With a committed results page, do a search by unfocusing the omnibox and 376 // With a committed results page, do a search by bluring the omnibox and
Jered 2013/04/05 16:27:07 bluring -> blurring
msw 2013/04/05 16:39:02 Done.
371 // focusing the contents. 377 // focusing the contents. Call handleOnChange before focusing the contents.
372 SetOmniboxText("hello"); 378 SetOmniboxText("hello");
373 // Calling handleOnChange manually to make sure it is called before the
374 // Focus() call below.
375 EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(), 379 EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(),
376 "suggestion = 'hello kitty';" 380 "suggestion = 'hello kitty';"
377 "handleOnChange();")); 381 "handleOnChange();"));
378 instant()->instant_tab()->contents()->GetView()->Focus(); 382 BlurOmniboxAndFocusContents(instant()->instant_tab()->contents());
379 383
380 // Search term extraction should kick in with the autocompleted text. 384 // Search term extraction should kick in with the autocompleted text.
381 EXPECT_EQ(ASCIIToUTF16("hello kitty"), omnibox()->GetText()); 385 EXPECT_EQ(ASCIIToUTF16("hello kitty"), omnibox()->GetText());
382 386
383 // Suggestion should be cleared at this point. 387 // Suggestion should be cleared at this point.
384 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText()); 388 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
385 } 389 }
386 390
387 // Checks that a previous Navigation suggestion is not re-used when a search 391 // Checks that a previous Navigation suggestion is not re-used when a search
388 // suggestion comes in. Disabled on Mac because omnibox focus loss is not 392 // suggestion comes in. Disabled on Mac because omnibox focus loss is not
(...skipping 16 matching lines...) Expand all
405 "behavior = 1;")); 409 "behavior = 1;"));
406 SetOmniboxTextAndWaitForOverlayToShow("exa"); 410 SetOmniboxTextAndWaitForOverlayToShow("exa");
407 EXPECT_EQ(ASCIIToUTF16("example.com"), omnibox()->GetText()); 411 EXPECT_EQ(ASCIIToUTF16("example.com"), omnibox()->GetText());
408 412
409 // Now send a search suggestion and see that Navigation suggestion is no 413 // Now send a search suggestion and see that Navigation suggestion is no
410 // longer kept. 414 // longer kept.
411 SetOmniboxText("exam"); 415 SetOmniboxText("exam");
412 EXPECT_TRUE(ExecuteScript("suggestion = 'exams are great';" 416 EXPECT_TRUE(ExecuteScript("suggestion = 'exams are great';"
413 "behavior = 2;" 417 "behavior = 2;"
414 "handleOnChange();")); 418 "handleOnChange();"));
415 instant()->overlay()->contents()->GetView()->Focus(); 419 BlurOmniboxAndFocusContents(instant()->overlay()->contents());
416 EXPECT_EQ(ASCIIToUTF16("exams are great"), omnibox()->GetText()); 420 EXPECT_EQ(ASCIIToUTF16("exams are great"), omnibox()->GetText());
417 421
418 // TODO(jered): Remove this after fixing OnBlur(). 422 // TODO(jered): Remove this after fixing OnBlur().
419 omnibox()->RevertAll(); 423 omnibox()->RevertAll();
420 } 424 }
421 425
422 // This test simulates a search provider using the InstantExtended API to 426 // This test simulates a search provider using the InstantExtended API to
423 // navigate through the suggested results and back to the original user query. 427 // navigate through the suggested results and back to the original user query.
424 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) { 428 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) {
425 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 429 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 content::WebContents* active_tab = 642 content::WebContents* active_tab =
639 browser()->tab_strip_model()->GetActiveWebContents(); 643 browser()->tab_strip_model()->GetActiveWebContents();
640 EXPECT_NE(ntp_url, active_tab->GetURL()); 644 EXPECT_NE(ntp_url, active_tab->GetURL());
641 } 645 }
642 646
643 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) { 647 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) {
644 // Setup Instant. 648 // Setup Instant.
645 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 649 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
646 FocusOmniboxAndWaitForInstantExtendedSupport(); 650 FocusOmniboxAndWaitForInstantExtendedSupport();
647 651
648 // Explicitly unfocus the omnibox. 652 // Explicitly blur the omnibox.
649 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 653 BlurOmniboxAndFocusContents(
Jered 2013/04/05 16:27:07 Same question here.
msw 2013/04/05 16:39:02 Done.
650 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 654 browser()->tab_strip_model()->GetActiveWebContents());
651 EXPECT_FALSE(omnibox()->model()->has_focus());
652 655
653 // Open new tab. Preloaded NTP contents should have been used. 656 // Open new tab. Preloaded NTP contents should have been used.
654 ui_test_utils::NavigateToURLWithDisposition( 657 ui_test_utils::NavigateToURLWithDisposition(
655 browser(), 658 browser(),
656 GURL(chrome::kChromeUINewTabURL), 659 GURL(chrome::kChromeUINewTabURL),
657 NEW_FOREGROUND_TAB, 660 NEW_FOREGROUND_TAB,
658 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 661 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
659 662
660 // Omnibox should have focus. 663 // Omnibox should have focus.
661 EXPECT_TRUE(omnibox()->model()->has_focus()); 664 EXPECT_TRUE(omnibox()->model()->has_focus());
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1432 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1430 1433
1431 EXPECT_EQ(instant_url(), instant()->ntp_->contents()->GetURL()); 1434 EXPECT_EQ(instant_url(), instant()->ntp_->contents()->GetURL());
1432 1435
1433 // The second argument says to use only the local overlay. 1436 // The second argument says to use only the local overlay.
1434 instant()->SetInstantEnabled(false, true); 1437 instant()->SetInstantEnabled(false, true);
1435 1438
1436 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 1439 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
1437 instant()->ntp_->contents()->GetURL()); 1440 instant()->ntp_->contents()->GetURL());
1438 } 1441 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698